From f8aae3e7f48f4fa812c07b3ba01d1ae2c104b6a2 Mon Sep 17 00:00:00 2001 From: candela97 <54083835+candela97@users.noreply.github.com> Date: Sun, 31 Mar 2024 04:57:23 +0800 Subject: [PATCH] Refactor licenses page summary --- .../Features/Store/Licenses/CLicenses.js | 4 +- .../Store/Licenses/FLicensesSummary.svelte | 121 ++++++++++++++++++ .../Store/Licenses/FLincensesSummary.js | 76 ----------- 3 files changed, 123 insertions(+), 78 deletions(-) create mode 100644 src/js/Content/Features/Store/Licenses/FLicensesSummary.svelte delete mode 100644 src/js/Content/Features/Store/Licenses/FLincensesSummary.js diff --git a/src/js/Content/Features/Store/Licenses/CLicenses.js b/src/js/Content/Features/Store/Licenses/CLicenses.js index 8d350ff7d..e37e89737 100644 --- a/src/js/Content/Features/Store/Licenses/CLicenses.js +++ b/src/js/Content/Features/Store/Licenses/CLicenses.js @@ -1,12 +1,12 @@ import {Context, ContextType} from "../../../modulesContent"; -import FLincensesSummary from "./FLincensesSummary"; +import {FLicensesSummary} from "./FLicensesSummary.svelte"; export class CLicenses extends Context { constructor() { super(ContextType.LICENSES, [ - FLincensesSummary, + FLicensesSummary, ]); } } diff --git a/src/js/Content/Features/Store/Licenses/FLicensesSummary.svelte b/src/js/Content/Features/Store/Licenses/FLicensesSummary.svelte new file mode 100644 index 000000000..f58b943b2 --- /dev/null +++ b/src/js/Content/Features/Store/Licenses/FLicensesSummary.svelte @@ -0,0 +1,121 @@ + + + + +{Localization.str.wl.label} + +{#if show} +
+ + + + + {@html tableHeader} + + + + + {@html rows} + + + + + {@html tableFooter} + + + +
{Localization.str.year}{Localization.str.all}
{Localization.str.all}{totalGlobal}
+
+{/if} + + + diff --git a/src/js/Content/Features/Store/Licenses/FLincensesSummary.js b/src/js/Content/Features/Store/Licenses/FLincensesSummary.js deleted file mode 100644 index 89d951820..000000000 --- a/src/js/Content/Features/Store/Licenses/FLincensesSummary.js +++ /dev/null @@ -1,76 +0,0 @@ -import {HTML, Localization} from "../../../../modulesCore"; -import {Feature} from "../../../modulesContent"; - -export default class FLincensesSummary extends Feature { - - apply() { - const all = document.querySelectorAll(".account_table tr[data-panel]"); - const list = {}; - const types = {}; - - for (const item of all) { - const dateStr = item.querySelector(".license_date_col").textContent.trim(); - const year = /\d{4}/.exec(dateStr)?.[0] ?? ""; - const typ = item.querySelector(".license_acquisition_col").textContent.trim(); - - (list[year] ??= {})[typ] = (list[year][typ] ?? 0) + 1; - types[typ] = (types[typ] ?? 0) + 1; - } - - const listEntries = Object.entries(list).reverse(); - const totals = listEntries.map( - ([, row]) => Object.entries(row) - .map(([, count]) => count) - .reduce((a, b) => a + b, 0) - ); - - const totalGlobal = totals.reduce((a, b) => a + b, 0); - const typesEntries = Object.entries(types); - - const tableHeader = typesEntries - .map(([name]) => `${name}`) - .join(""); - - const tableFooter = typesEntries - .map(([, value]) => `${value || "0"}`) - .join(""); - - const rows = listEntries - .map(([year, row], i) => ` - ${year} - ${typesEntries - .map(([name]) => `${row[name] || "0"}`) - .join("") - } - ${totals[i] || "0"} - `) - .join(""); - - HTML.beforeBegin( - document.querySelector(".youraccount_page > .block"), - `
-
- - - - - ${tableHeader} - - - - - ${rows} - - - - - ${tableFooter} - - - - -
-
` - ); - } -}