Skip to content

Commit f8c0657

Browse files
committed
Add some comments and tidy up a bit.
1 parent 186faa7 commit f8c0657

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

app/Resources/views/Formats/formats.html.twig

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
</div>
2323
</div>
2424
<script>
25-
2625
function makeIdMap(json) {
2726
const out = new Map();
2827
json.data.forEach(d => {
@@ -34,7 +33,6 @@ function makeIdMap(json) {
3433
async function buildFormatsView() {
3534
const desiredFormats = new Set(['eternal', 'standard', 'startup']);
3635
37-
//const [snapshotsResponse, restrictionsResponse] = await Promise.all(
3836
const [r1, r2, r3, r4, r5] = await Promise.all(
3937
[
4038
fetch('{{ v3_api_url }}/api/v3/public/snapshots?filter[active]=true').then(data => data.json()),
@@ -46,14 +44,22 @@ async function buildFormatsView() {
4644
);
4745
4846
const restrictions = makeIdMap(r2);
49-
const cycles = r3.data;
5047
const cyclesById = makeIdMap(r3);
5148
const sets = r4.data;
5249
const setsById = makeIdMap(r4);
5350
const formatsById = makeIdMap(r5);
5451
55-
const formats = r1.data.filter(snapshot => desiredFormats.has(snapshot.attributes.format_id)).sort((a, b) => (a.attributes.format_id < b.attributes.format_id) ? 1 : -1);
56-
52+
// Support our supported formats in descending order by name.
53+
const formats = r1.data
54+
.filter(snapshot => desiredFormats.has(snapshot.attributes.format_id))
55+
.sort((a, b) => (a.attributes.format_id < b.attributes.format_id) ? 1 : -1);
56+
57+
// Each Format is a column, with the following struction:
58+
// - Name
59+
// - Banlist (if any)
60+
// - Corp & Runner Decklist Search Links
61+
// - Legal Card Count
62+
// - Legal Cycles and Sets (if a cycle is incomplete)
5763
formats.forEach(format => {
5864
const legalCycleIds = new Set(format.attributes.card_cycle_ids);
5965
const incompleteCycleIds = new Set();
@@ -102,7 +108,7 @@ async function buildFormatsView() {
102108
$(`#${format.id}`).append(`<h4>Legal Card Cycles - <a href="${Routing.generate('cards_find', {q: 'e:' + packs.join('|') } )}">${format.attributes.num_cards} Unique Cards</a></h4>`);
103109
104110
$(`#${format.id}`).append(`<ul id="${format.id}_cycles"></ul>`);
105-
cycles.forEach(cycle => {
111+
cyclesById.forEach((cycle, cycle_id) => {
106112
if (legalCycleIds.has(cycle.id)) {
107113
$(`#${format.id}_cycles`).append(`<li><a href="${Routing.generate('cards_cycle', {cycle_code: cycle.attributes.legacy_code})}">${cycle.attributes.name}</a></li>`);
108114
} else if (incompleteCycleIds.has(cycle.id)) {

0 commit comments

Comments
 (0)