From 1e70843886c2d3b24dda571b2f110b204b69d0d6 Mon Sep 17 00:00:00 2001 From: Minteck Date: Mon, 6 Jun 2022 18:16:25 +0200 Subject: Commit --- .DS_Store | Bin 6148 -> 6148 bytes .idea/vcs.xml | 6 ++ assets/logo-alt.svg | 29 ++++++++ assets/logo.icns | Bin 0 -> 402662 bytes assets/logo.ico | Bin 0 -> 139062 bytes assets/logo.png | Bin 0 -> 4968 bytes build.sh | 4 + index.html | 210 ++++++++++++++++++++++++++++++++-------------------- 8 files changed, 168 insertions(+), 81 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 assets/logo-alt.svg create mode 100644 assets/logo.icns create mode 100644 assets/logo.ico create mode 100644 assets/logo.png create mode 100755 build.sh diff --git a/.DS_Store b/.DS_Store index a33b7f3..3ed63fb 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/assets/logo-alt.svg b/assets/logo-alt.svg new file mode 100644 index 0000000..3526ee2 --- /dev/null +++ b/assets/logo-alt.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/logo.icns b/assets/logo.icns new file mode 100644 index 0000000..1738301 Binary files /dev/null and b/assets/logo.icns differ diff --git a/assets/logo.ico b/assets/logo.ico new file mode 100644 index 0000000..189621b Binary files /dev/null and b/assets/logo.ico differ diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000..d39dcd7 Binary files /dev/null and b/assets/logo.png differ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..cd8dfd8 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +npx electron-packager . Bits --overwrite --out build --arch arm64 --platform darwin --icon assets/logo.icns +npx electron-packager . Bits --overwrite --out build --arch x64 --platform darwin --icon assets/logo.icns +npx electron-packager . Bits --overwrite --out build --arch x64 --platform win32 --icon assets/logo.ico +npx electron-packager . Bits --overwrite --out build --arch x64 --platform linux --icon assets/logo.png \ No newline at end of file diff --git a/index.html b/index.html index 6dfdd74..ab93a30 100644 --- a/index.html +++ b/index.html @@ -45,88 +45,134 @@ } else { console.info("Authenticated successfully"); - document.getElementById("username").innerText = JSON.parse(await (await window.fetch("https://money.equestria.dev/Authentication/Username")).text()).name; - - window.transactions = JSON.parse(await (await window.fetch("https://money.equestria.dev/Application/TransactionsList")).text()); - - for (let transaction of transactions) { - demo = document.getElementById("demo-transaction"); - demo.id = ""; - - if (transaction.type === "pay") { - word = "used"; - color = "#b31500"; - } else { - word = "added"; - color = "#0065b3"; - } - - if (transaction.amount['original'] === "eur") { - baseCurrency = transaction.amount['eur'].toFixed(2) + "€"; - convertedCurrency = "£" + transaction.amount['gbp'].toFixed(2); - } else { - baseCurrency = "£" + transaction.amount['gbp'].toFixed(2); - convertedCurrency = transaction.amount['eur'].toFixed(2) + "€"; - } - - document.getElementById("transactions").innerHTML += demo.outerHTML - .replace("%user%", transaction.author.name) - .replace("%picture%", "\" src=\"" + transaction.author.avatar + "\"") - .replace("%time%", transaction.date.relative) - .replace("%description%", transaction.description.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")) - .replace("%type%", word) - .replace("%amount_bc%", baseCurrency) - .replace("%amount_cc%", convertedCurrency) - .replace("%type%", word) - .replace("var(--perc-color)", color) - - demo.id = "demo-transaction"; - } - - try { - totalPaidEUR = transactions.filter(i => i.type === "pay").map(i => { return i.amount['eur']; }).reduce((a, b) => { return a+b; }); - } catch (e) { - totalPaidEUR = 0; - } - - try { - totalPaidGBP = transactions.filter(i => i.type === "pay").map(i => { return i.amount['gbp']; }).reduce((a, b) => { return a+b; }); - } catch (e) { - totalPaidGBP = 0; - } - - - try { - totalGainedEUR = transactions.filter(i => i.type !== "pay").map(i => { return i.amount['eur']; }).reduce((a, b) => { return a+b; }); - } catch (e) { - totalGainedEUR = 0; - } - - try { - totalGainedGBP = transactions.filter(i => i.type !== "pay").map(i => { return i.amount['gbp']; }).reduce((a, b) => { return a+b; }); - } catch (e) { - totalGainedGBP = 0; - } - - totalEUR = totalGainedEUR - totalPaidEUR; - totalGBP = totalGainedGBP - totalPaidGBP; - - document.getElementById("balance-eur").innerText = totalEUR.toFixed(2); - document.getElementById("balance-gbp").innerText = totalGBP.toFixed(2); - - document.getElementById("app").style.display = ""; - document.getElementById("loader").style.opacity = "0"; - document.getElementById("loader").style.pointerEvents = "none"; + await refresh(); } }, 1000) } + + async function refresh() { + document.getElementById("transactions").innerHTML = ""; + document.getElementById("username").innerText = JSON.parse(await (await window.fetch("https://money.equestria.dev/Authentication/Username")).text()).name; + + window.transactions = JSON.parse(await (await window.fetch("https://money.equestria.dev/Application/TransactionsList")).text()); + + for (let transaction of transactions) { + demo = document.getElementById("demo-transaction"); + demo.id = ""; + + if (transaction.type === "pay") { + word = "used"; + color = "#b31500"; + } else { + word = "added"; + color = "#0065b3"; + } + + if (transaction.amount['original'] === "eur") { + baseCurrency = transaction.amount['eur'].toFixed(2) + "€"; + convertedCurrency = "£" + transaction.amount['gbp'].toFixed(2); + } else { + baseCurrency = "£" + transaction.amount['gbp'].toFixed(2); + convertedCurrency = transaction.amount['eur'].toFixed(2) + "€"; + } + + document.getElementById("transactions").innerHTML += demo.outerHTML + .replace("%user%", transaction.author.name) + .replace("%picture%", "\" src=\"" + transaction.author.avatar + "\"") + .replace("%time%", transaction.date.relative) + .replace("%transactionId%", transaction.date.absolute) + .replace("%description%", transaction.description.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")) + .replace("%type%", word) + .replace("%amount_bc%", baseCurrency) + .replace("%amount_cc%", convertedCurrency) + .replace("%type%", word) + .replace("var(--perc-color)", color) + + demo.id = "demo-transaction"; + } + + try { + totalPaidEUR = transactions.filter(i => i.type === "pay").map(i => { return i.amount['eur']; }).reduce((a, b) => { return a+b; }); + } catch (e) { + totalPaidEUR = 0; + } + + try { + totalPaidGBP = transactions.filter(i => i.type === "pay").map(i => { return i.amount['gbp']; }).reduce((a, b) => { return a+b; }); + } catch (e) { + totalPaidGBP = 0; + } + + + try { + totalGainedEUR = transactions.filter(i => i.type !== "pay").map(i => { return i.amount['eur']; }).reduce((a, b) => { return a+b; }); + } catch (e) { + totalGainedEUR = 0; + } + + try { + totalGainedGBP = transactions.filter(i => i.type !== "pay").map(i => { return i.amount['gbp']; }).reduce((a, b) => { return a+b; }); + } catch (e) { + totalGainedGBP = 0; + } + + totalEUR = totalGainedEUR - totalPaidEUR; + totalGBP = totalGainedGBP - totalPaidGBP; + + document.getElementById("balance-eur").innerText = totalEUR.toFixed(2); + document.getElementById("balance-gbp").innerText = totalGBP.toFixed(2); + + document.getElementById("app").style.display = ""; + document.getElementById("loader").style.opacity = "0"; + document.getElementById("loader").style.pointerEvents = "none"; + + for (let item of Array.from(document.getElementsByClassName("transaction"))) { + item.onclick = () => { + deleteTransaction(item.getAttribute("data-transaction-id")); + } + } + } + + async function createTransaction() { + document.getElementById('create-action').disabled = true; + document.getElementById('create-currency').disabled = true; + document.getElementById('create-description').disabled = true; + document.getElementById('create-amount').disabled = true; + document.getElementById('create-button-create').disabled = true; + document.getElementById('create-button-cancel').disabled = true; + + await (await window.fetch("https://money.equestria.dev/Application/AddTransaction/?Currency=" + document.getElementById('create-currency').value + "&Amount=" + document.getElementById('create-amount').value + "&Operation=" + document.getElementById('create-action').value + "&Description=" + Buffer.from(document.getElementById('create-description').value).toString("base64url"))).text(); + + await refresh(); + + document.getElementById('create-action').disabled = false; + document.getElementById('create-currency').disabled = false; + document.getElementById('create-description').disabled = false; + document.getElementById('create-amount').disabled = false; + document.getElementById('create-button-create').disabled = false; + document.getElementById('create-button-cancel').disabled = false; + document.getElementById('create-modal').style.display = 'none'; + document.getElementById('create-action').value = '+'; + document.getElementById('create-currency').value = '£'; + document.getElementById('create-description').value = ''; + document.getElementById('create-amount').value = ''; + } + + async function deleteTransaction(id) { + let transaction = transactions.filter(i => i.date.absolute === id)[0]; + console.log(transaction); + if (confirm("This will remove the transaction made by " + transaction.author.name + " " + transaction.date.relative + ".\nIt will be removed from the list and the global balance will be recalculated without this transaction.")) { + await (await window.fetch("https://money.equestria.dev/Application/RemoveTransaction/?Transaction=" + Buffer.from(id).toString("base64url"))).text(); + await refresh(); + } + } -- cgit