Skip to content

Commit

Permalink
feat: add linked and total entity count to Kanka Browser application …
Browse files Browse the repository at this point in the history
…for each type
  • Loading branch information
Steven Weingärtner committed Nov 12, 2023
1 parent 7680d3d commit d3d946f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Binary file modified docs/assets/browser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions src/apps/KankaBrowser/KankaBrowserApplication.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
</div>
</form>


{{#if campaign }}
<h2 class="kanka-action-row">
<span>{{campaign.name}}</span>
Expand All @@ -68,13 +67,13 @@
{{/if}}
{{#if data}}
<div class="kanka-entity-list" style="clear: both;">
{{#each (kankaGroupBy (kankaSortBy data 'type' 'name') 'type') as |entities type|}}
{{#each entities as |metaData type|}}
{{#with (lookup ../typeConfig type) as |typeConfig|}}
<details class="kanka-details" data-type="{{ type }}" {{#if typeConfig.isOpen}}open{{/if}}>
<summary class="action-row">
<i class="fas {{ typeConfig.icon }}"></i>
<div>
{{ kankaLocalize 'entityType' type }}
{{ kankaLocalize 'entityType' type }} ({{metaData.countLinked}} / {{metaData.count}})
</div>
<div class="actions">
<button type="button" data-action="open-in-kanka" data-type="{{ type }}">
Expand All @@ -92,9 +91,9 @@
</div>
</summary>
{{#if (kankaIsOneOf ../../settings.view 'grid')}}
{{>./entities/grid entities=entities}}
{{>./entities/grid entities=metaData.entities}}
{{else}}
{{>./entities/list entities=entities}}
{{>./entities/list entities=metaData.entities}}
{{/if}}
</details>
{{/with}}
Expand Down
21 changes: 21 additions & 0 deletions src/apps/KankaBrowser/KankaBrowserApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ interface TemplateData {
},
}

type TypeMetaData = {
count: number,
countLinked: number,
entities: KankaApiEntity[]
};

const entityTypes: Partial<Record<EntityType, { icon: string }>> = {
[EntityType.ability]: {
icon: 'fa-fire',
Expand Down Expand Up @@ -116,13 +122,28 @@ export default class KankaBrowserApplication extends Application {
};
});

const groupedEntities = groupBy(this.#entities ?? [], 'type');
const groupedEntitiesWithMetaData: Record<string, TypeMetaData> = {};

Array
.from(groupedEntities.entries())
.sort(([a], [b]) => a[0].localeCompare(b[0]))
.forEach(([type, entities]) => {
groupedEntitiesWithMetaData[type] = {
entities,
count: entities.length,
countLinked: entities.filter(e => !!findEntryByEntityId(e.id)).length,
};
});

return {
...super.getData(),
campaign: this.#campaign ?? { id: 0 },
// eslint-disable-next-line @typescript-eslint/naming-convention
campaigns: (this.#campaigns ?? []).reduce((choices, { id, name }) => ({ ...choices, [String(id)]: name }), { 0: '-- Please choose --' }),
currentFilter: this.#currentFilter,
typeConfig,
entities: groupedEntitiesWithMetaData,
data: this.#entities,
deletedEntries: this.deletedSnapshots,
settings: {
Expand Down

0 comments on commit d3d946f

Please sign in to comment.