Skip to content

Commit

Permalink
Merge branch 'improve-licences-summary2' of github.com:candela97/Augm…
Browse files Browse the repository at this point in the history
…entedSteam into candela97-improve-licences-summary2
  • Loading branch information
tfedor committed Apr 10, 2024
2 parents 51ab6f3 + 5807de6 commit 7da045f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/js/Content/Features/Store/Licenses/CLicenses.js
Original file line number Diff line number Diff line change
@@ -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,
]);
}
}
117 changes: 117 additions & 0 deletions src/js/Content/Features/Store/Licenses/FLicensesSummary.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<script lang="ts" context="module">
// @ts-ignore
import self_ from "./FLicensesSummary.svelte";
import {Feature} from "../../../modulesContent";
import type {CLicenses} from "./CLicenses";
export class FLicensesSummary extends Feature<CLicenses> {
override apply(): void {
let target = document.querySelector(".youraccount_page");
if (!target) {
throw new Error("Node not found");
}
(new self_({
target,
anchor: target.firstElementChild,
}));
}
}
</script>

<script lang="js">
import {Localization} from "../../../../modulesCore";
const list = {};
const types = {};
for (const item of document.querySelectorAll(".account_table tr")) {
const dateStr = item.querySelector("td.license_date_col")?.textContent.trim();
if (!dateStr) { continue; }
const year = /\d{4}/.exec(dateStr)?.[0] ?? Localization.str.thewordunknown;
const type = item.querySelector("td.license_acquisition_col")?.textContent.trim() || Localization.str.thewordunknown;
(list[year] ??= {})[type] = (list[year][type] ?? 0) + 1;
types[type] = (types[type] ?? 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]) => `<th>${name}</th>`)
.join("");
const tableFooter = typesEntries
.map(([, value]) => `<td>${value || "0"}</td>`)
.join("");
const rows = listEntries
.map(([year, row], i) => `<tr>
<td>${year}</td>
${typesEntries
.map(([name]) => `<td>${row[name] || "0"}</td>`)
.join("")
}
<td>${totals[i] || "0"}</td>
</tr>`)
.join("");
let show = false;
</script>
<span class="h3">{Localization.str.wl.label}</span>
<button on:click={() => (show = !show)}>{show ? Localization.str.hide : Localization.str.show}</button>
{#if show}
<div class="block_content">
<table class="account_table">
<thead>
<tr>
<th>{Localization.str.year}</th>
{@html tableHeader}
<th>{Localization.str.all}</th>
</tr>
</thead>
<tbody>
{@html rows}
</tbody>
<tfoot>
<tr>
<td>{Localization.str.all}</td>
{@html tableFooter}
<td>{totalGlobal}</td>
</tr>
</tfoot>
</table>
</div>
{/if}
<style>
:global(.block) {
margin-top: 20px;
}
.h3 {
color: #ffffff;
font-size: 22px;
font-family: "Motiva Sans", Sans-serif;
font-weight: normal;
text-transform: uppercase;
}
button {
vertical-align: text-bottom;
margin-left: 5px;
cursor: pointer;
border: solid #8ecafc 1px;
padding: 0px 10px;
}
</style>
76 changes: 0 additions & 76 deletions src/js/Content/Features/Store/Licenses/FLincensesSummary.js

This file was deleted.

1 change: 1 addition & 0 deletions src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"toomanyrequests": "Too Many Requests",
"show_comments": "Show Comments",
"hide_comments": "Hide Comments",
"thewordunknown": "Unknown",
"calc_workshop_size": {
"file_size": "File size __size__",
"calc_size": "Calculate Total Size",
Expand Down

0 comments on commit 7da045f

Please sign in to comment.