Skip to content

Commit

Permalink
Merge pull request #38 from nafoarmories/api_interactive
Browse files Browse the repository at this point in the history
Api and other interactive updates
  • Loading branch information
okawo80085 authored Oct 10, 2024
2 parents 46d010d + 215c098 commit 4e96b05
Show file tree
Hide file tree
Showing 20 changed files with 731 additions and 98 deletions.
21 changes: 12 additions & 9 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
base64 (0.2.0)
bigdecimal (3.1.6)
coffee-script (2.4.1)
Expand All @@ -21,7 +21,7 @@ GEM
coffee-script-source (1.12.2)
colorator (1.1.0)
commonmarker (0.23.10)
concurrent-ruby (1.2.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
dnsruby (1.70.0)
simpleidn (~> 0.2.1)
Expand All @@ -38,7 +38,10 @@ GEM
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
net-http
ffi (1.16.3)
ffi (1.17.0)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
forwardable-extended (2.6.0)
gemoji (4.1.0)
github-pages (230)
Expand Down Expand Up @@ -96,7 +99,7 @@ GEM
activesupport (>= 2)
nokogiri (>= 1.4)
http_parser.rb (0.8.0)
i18n (1.14.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
jekyll (3.9.5)
addressable (~> 2.4)
Expand Down Expand Up @@ -211,7 +214,7 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.4)
listen (3.8.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
Expand All @@ -238,12 +241,12 @@ GEM
sawyer (~> 0.9)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (5.0.4)
public_suffix (5.1.1)
racc (1.7.3)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
rb-inotify (0.11.1)
ffi (~> 1.0)
rexml (3.2.6)
rexml (3.3.8)
rouge (3.30.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand Down
5 changes: 1 addition & 4 deletions docs/_data/links.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
donation:
- name: [email protected] - currently unavailable
img: assets/images/paypal-logo-small.png
text: true
- name: NAFO Armories Monobank Jar
- name: Our Monobank Jar
img: assets/images/monobank-logo-small.png
link: https://send.monobank.ua/jar/41VstyWxB9

Expand Down
9 changes: 6 additions & 3 deletions docs/_data/stats.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
current_fundraiser:
- title: 🎯Goal
count: 10237$/14000$
tag: goal
count: 14000$

# calculated as total of the sum of all previous fundraisers (95126$)
# plus the current fundraiser total
# TODO: remove this cuz its old and not used anymore
define: &total_raised 105,363$

overall_stats:
- title: Total Money Raised
tag: total
count: *total_raised
- title: Drop Rig Systems
count: 800
- title: Leyleys
Expand All @@ -19,5 +24,3 @@ overall_stats:
count: 1
- title: Laptops
count: 1
- title: Total Money Raised
count: *total_raised
31 changes: 16 additions & 15 deletions docs/_includes/donate_section.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@
</script>

<div class="dono-elements">
{% if include.title %}
<h2>{{ include.title }}</h2>
{% endif %}
{% for item in include.links %}
{% if item.text == true %}
<div class="link" onClick="copyToClipboard('{{ item.name }}')">
{% else %}
<div class="link">
{% endif %}
{% if item.img %}
<img src="{{ item.img | relative_url }}">
{% endif %}
{% if item.text == true %}
<div class="tooltip">
<p class="tooltiptext">Copy to Clipboard</p>
<p>{{ item.name }}</p>
</div>
{% endif %}
{% if item.link %}
<a href="{{ item.link | relative_url }}">{{ item.name }}</a>
<div class="link-pre">
<a href="{{ item.link }}">
<div class="link-inner">
{% endif %}
{% if item.img %}
<img src="{{ item.img | relative_url }}">
{% endif %}
<p>{{ item.name }}</p>
{% if item.link %}
</div>
</a>
</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>
140 changes: 140 additions & 0 deletions docs/_includes/half_circle_chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<div class="nafoarms-dono-chart">
<canvas id="myChart" style="border-radius: 25px;">Loading...</canvas>
</div>

<script>
console.log(`GET: {{ include.data.api }}`);
const resp = fetch('https://api.nafoarmories.org/{{ include.data.api }}');
resp.then((res) => {
if (!res.ok) {
return "ERROR";
}
return res.json();
}).then((promise_data) => {
let ctx = document.getElementById('myChart');

const chartMin = {{ include.data.min }};
const chartValue = promise_data.total.replace("$", "");
const chartMax = {{ include.data.max }};


const data = [chartValue, chartMax-chartValue];
const labels = ["Total Donations", "Left to Go"];
const chartColors = [
"#22ffc7",
"white"
];

const offBySize = (x, y, size, yOff=0) => {
return {
x: (x),
y: (y + (size.actualBoundingBoxAscent + size.actualBoundingBoxDescent) /2 +
yOff)
};
};

const plugin = {
id: 'showMinMax',
defaults: {
min: "0",
current: "50",
max: "100",
font: "Arial"
},
beforeDraw: (chart, args, options) => {
const {ctx} = chart;
let data = chart._metasets[0].data[0];
let radius = data.innerRadius + (data.outerRadius - data.innerRadius) / 2;
let centerX = data.x;
let centerY = data.y;

let left = centerX - radius;
let right = centerX + radius;

ctx.save();

ctx.beginPath();
const min_pos = offBySize(
left,
centerY,
ctx.measureText(chart.options.plugins.showMinMax.min),
20);
ctx.font = `20px ${chart.options.plugins.showMinMax.font}`;
ctx.textAlign = "center";
ctx.fillText(
chart.options.plugins.showMinMax.min,
min_pos.x,
min_pos.y);
ctx.stroke();

ctx.beginPath();
const curr_pos = offBySize(
centerX,
centerY,
ctx.measureText(chart.options.plugins.showMinMax.current),
-radius/3);
ctx.font = `18px ${chart.options.plugins.showMinMax.font}`;
ctx.textAlign = "center";
ctx.fillText(
chart.options.plugins.showMinMax.current,
curr_pos.x,
curr_pos.y);
ctx.stroke();

ctx.beginPath();
const max_pos = offBySize(
right,
centerY,
ctx.measureText(chart.options.plugins.showMinMax.max),
10);
ctx.font = `20px ${chart.options.plugins.showMinMax.font}`;
ctx.textAlign = "center";
ctx.fillText(
chart.options.plugins.showMinMax.max,
max_pos.x,
max_pos.y);
ctx.stroke();

ctx.restore();
}
};

Chart.register(plugin);

new Chart(ctx, {
type: "doughnut",
data: {
labels: labels,
datasets: [{
backgroundColor: chartColors,
data: data
}]
},

options: {
maintainAspectRatio: false,
radius: '80%',
rotation: -90,
circumference: 180,
scale: {
ticks: {min:0, max:14000}
},
plugins: {
title: {
display: true,
color: "black",
font: {
size: 30
},
text: "Total raised"
},
showMinMax: {
min: `${chartMin}$`,
max: `${chartMax}$`,
current: `${chartValue}$`
}
}
}
});
});
</script>
35 changes: 34 additions & 1 deletion docs/_includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@
<link rel="stylesheet" href="{{ '/assets/css/nafoarms.css' | relative_url }}">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<!-- <script src="https://unpkg.com/[email protected]" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script> -->

<script
src="https://cdn.jsdelivr.net/npm/chart.js">
</script>

<script>
function toggleLang() {
const ua = document.querySelectorAll("div.lang-ua");
const eng = document.querySelectorAll("div.lang-eng");

if (eng[0].getAttribute('about') === "") {
for (let i=0; i<ua.length;i++) {
ua[i].setAttribute('style', "display: none; visibility: hidden;");
ua[i].setAttribute('about', "");
}
for (let i=0; i<eng.length;i++) {
eng[i].setAttribute('style', "display: block; visibility: visible;");
eng[i].setAttribute('about', "shown");
}
} else {
for (let i=0; i<ua.length;i++) {
ua[i].setAttribute('style', "display: block; visibility: visible;");
ua[i].setAttribute('about', "shown");
}
for (let i=0; i<eng.length;i++) {
eng[i].setAttribute('style', "display: none; visibility: hidden;");
eng[i].setAttribute('about', "");
}
}
}
</script>

{% include head-custom.html %}
</head>
<body>
Expand All @@ -35,4 +68,4 @@ <h1 class="nafoarms-title-text">{{ site.title }}</h1>
</div>
{% endfor %}
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions docs/_includes/lang-toggle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


<div class="lang-button">
<input
onclick="toggleLang()"
id="lang-button"
type="checkbox"
class="lang-toggle lang-button-check"/>
<label for="lang-button"></label>
<span class="on">EN</span>
<span class="off">UA</span>
</div>

39 changes: 39 additions & 0 deletions docs/_includes/recent_donations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

<div class="nafoarms-recent-dono-outter">
<h2>Recent donations</h2>
<div class="nafoarms-recent-donations nafoarms-recent-donations-rounded">
<table>
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Name</th>
</tr>
</thead>
<tbody id="recent-dono">
</tbody>
</table>
</div>
</div>

<script>
(async () => {
try {
const resp = await fetch('https://api.nafoarmories.org/donations/get/recent');
console.log(`GET: donations/get/recent`);

if (resp.ok) {
const data = await resp.json();
console.log(data);
for (const itm in data) {
console.log(data[itm]);
document.getElementById("recent-dono").innerHTML +=
`<tr><td>${data[itm].time}</td><td>${data[itm].amount}</td><td>${data[itm].name}</td></tr>`;
}
}
} catch (err) {
console.log(err);
// document.getElementById("{{ include.api_id }}").innerHTML = "ERROR";
}
})();
</script>
Loading

0 comments on commit 4e96b05

Please sign in to comment.