-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from nafoarmories/api_interactive
Api and other interactive updates
- Loading branch information
Showing
20 changed files
with
731 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -35,4 +68,4 @@ <h1 class="nafoarms-title-text">{{ site.title }}</h1> | |
</div> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.