Skip to content

Commit

Permalink
Merge pull request #89 from plural/search-form-formats-and-whatnot
Browse files Browse the repository at this point in the history
Add format, cardpool, snapshot and restrictions to search form.
  • Loading branch information
plural authored Oct 29, 2023
2 parents 1214fde + e94b458 commit 3c97676
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
14 changes: 13 additions & 1 deletion app/components/search/search-form.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class SearchFormComponent extends Component {
== Restrictions
[multi-select] restriction_id, b: Type: array
[multi-select] eternal_points: Type: array
has_global_penalty: Type: array
[checkbox] is_banned: Type: array
Expand Down Expand Up @@ -221,7 +222,18 @@ universal_faction_cost: Type: array
<SelectElement @emptyDefault='Any' @id='card_set' @name='Set' @options={{@cardSets}} @value={{@searchParams.card_set}} />
<DateElement @id='release_date' @name='Release Date' @value={{@searchParams.release_date}} />
</p>

<h2>Formats, Card Pools, Restrictions, & Snapshots</h2>
<p>
<SelectElement @emptyDefault='Any' @id='format' @name='Format' @options={{@formats}} @value={{@searchParams.format}} />
<SelectElement @emptyDefault='Any' @id='card_pool' @name='Card Pool' @options={{@cardPools}} @value={{@searchParams.card_pool}} />
</p>
<p>
<SelectElement @emptyDefault='Any' @id='restriction_id' @name='Restriction List' @options={{@restrictions}} @value={{@searchParams.restriction_id}} />
</p>
<p>
<SelectElement @emptyDefault='Any' @id='snapshot' @name='Snapshot (Format + Card Pool + Restriction)' @options={{@snapshots}} @value={{@searchParams.snapshot}} />
</p>
<h2>Deckbuilding Restrictions</h2>
<h2>Designers and Publishers</h2>
<p>
<SelectElement @emptyDefault='Any' @id='designed_by' @name='Designed By Org' @options={{@orgs}} @value={{@searchParams.designed_by}} />
Expand Down
57 changes: 57 additions & 0 deletions app/routes/page/advanced-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class PageAdvancedSearchRoute extends Route {
attribution: { refreshModel: true },
base_link: { refreshModel: true },
card_cycle: { refreshModel: true },
card_pool: { refreshModel: true },
card_set: { refreshModel: true },
card_subtype_id: { refreshModel: true },
card_type_id: { refreshModel: true },
Expand All @@ -22,6 +23,7 @@ export default class PageAdvancedSearchRoute extends Route {
display: { refreshModel: true },
faction_id: { refreshModel: true },
flavor: { refreshModel: true },
format: { refreshModel: true },
gains_subroutines: { refreshModel: true },
illustrator_id: { refreshModel: true },
influence_cost: { refreshModel: true },
Expand All @@ -42,8 +44,10 @@ export default class PageAdvancedSearchRoute extends Route {
recurring_credits_provided: { refreshModel: true },
release_date: { refreshModel: true },
released_by: { refreshModel: true },
restriction_id: { refreshModel: true },
rez_effect: { refreshModel: true },
side_id: { refreshModel: true },
snapshot: { refreshModel: true },
strength: { refreshmodel: true },
text: { refreshmodel: true },
title: { refreshModel: true },
Expand Down Expand Up @@ -182,6 +186,18 @@ export default class PageAdvancedSearchRoute extends Route {
if (params.release_date) {
filter.push(`release_date:${params.release_date}`);
}
if (params.card_pool) {
filter.push(`card_pool:${params.card_pool}`);
}
if (params.format) {
filter.push(`format:${params.format}`);
}
if (params.snapshot) {
filter.push(`snapshot:${params.snapshot}`);
}
if (params.restriction_id) {
filter.push(`restriction_id:${params.restriction_id}`);
}

return filter.join(' ');
}
Expand Down Expand Up @@ -219,29 +235,64 @@ export default class PageAdvancedSearchRoute extends Route {

const [
cardCycles,
cardPools,
cardSets,
cardSubtypes,
cardTypes,
factions,
formats,
illustrators,
restrictions,
sides,
snapshotsRaw,
] = await Promise.all([
this.store.query('card_cycle', { sort: '-date_release' }),
this.store.query('card_pool', { sort: 'name' }),
this.store.query('card_set', { sort: '-date_release' }),
this.store.query('card_subtype', { sort: 'name' }),
this.store.query('card_type', { sort: 'name' }),
this.store.query('faction', { sort: 'name' }),
this.store.query('format', { sort: 'name' }),
this.store.query('illustrator', { sort: 'name' }),
this.store.query('restriction', { sort: '-date_start' }),
this.store.query('side', { sort: 'name' }),
this.store.query('snapshot', { sort: 'format_id,-date_start' }),
]);

const formatMap = {};
formats.forEach((f) => {
formatMap[f.id] = f.name;
});
const cardPoolMap = {};
cardPools.forEach((p) => {
cardPoolMap[p.id] = p.name;
});
const restrictionMap = {};
restrictions.forEach((r) => {
restrictionMap[r.id] = r.name;
});

const snapshots = [];
snapshotsRaw.forEach((s) => {
let name = `${s.id}: ${formatMap[s.formatId]} / ${
cardPoolMap[s.cardPoolId]
}`;
if (s.restrictionId) {
name += ` / ${restrictionMap[s.restrictionId]}`;
}
name += s.active ? ' (active)' : '';
snapshots.push({ id: s.id, name: name });
});

if (filter) {
return RSVP.hash({
cardCycles: cardCycles,
cardPools: cardPools,
cardSets: cardSets,
cardSubtypes: cardSubtypes,
cardTypes: cardTypes,
factions: factions,
formats: formats,
illustrators: illustrators,
isUnique: isUnique,
numPrintings: numPrintings,
Expand All @@ -252,23 +303,29 @@ export default class PageAdvancedSearchRoute extends Route {
include: ['card_set', 'card_type', 'faction'],
page: { limit: params.max_records || 100 },
}),
restrictions: restrictions,
searchParams: params,
sides: sides,
snapshots: snapshots,
});
} else {
return RSVP.hash({
cardCycles: cardCycles,
cardPools: cardPools,
cardSets: cardSets,
cardSubtypes: cardSubtypes,
cardTypes: cardTypes,
factions: factions,
formats: formats,
illustrators: illustrators,
isUnique: isUnique,
numPrintings: numPrintings,
numRecords: numRecords,
orgs: orgs,
printings: [],
restrictions: restrictions,
sides: sides,
snapshots: snapshots,
});
}
}
Expand Down
7 changes: 6 additions & 1 deletion app/templates/page/advanced-search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
@isUnique={{@model.isUnique}}
@orgs={{@model.orgs}}
@cardCycles={{@model.cardCycles}}
@cardSets={{@model.cardSets}} />
@cardSets={{@model.cardSets}}
@cardPools={{@model.cardPools}}
@formats={{@model.formats}}
@restrictions={{@model.restrictions}}
@snapshots={{@model.snapshots}}
/>
</div>
</div>
</div>
Expand Down

0 comments on commit 3c97676

Please sign in to comment.