Skip to content

Commit

Permalink
fix: add feature to automatically sort items
Browse files Browse the repository at this point in the history
add feature so that items gets sorted by name alphabetically
automatically.

Fix xdy#114
  • Loading branch information
jonepatr authored and xdy committed Jan 29, 2021
1 parent f4dd574 commit 9423d35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/module/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ export default function registerHandlebarsHelpers():void {
return skill!=null && !skill.flags?.twodsix?.untrainedSkill && skill.type === "skills";
});

Handlebars.registerHelper('each_sort_by_name', (array, options) => {
const sortedArray = array.slice(0).sort((a:TwodsixItem, b:TwodsixItem) => {
const aName = a.name.toLowerCase(), bName = b.name.toLowerCase();
return (aName > bName) ? 1 : ((bName > aName) ? -1 : 0);
});
return Handlebars.helpers.each(sortedArray, options);
});

// Handy for debugging
Handlebars.registerHelper('debug', function(context) {
console.log(context);
Expand Down
16 changes: 8 additions & 8 deletions static/templates/actors/parts/actor/actor-items.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class="fas fa-plus"></i></a></span>
</div>

{{#each actor.weapon as |item id|}}
{{#each_sort_by_name actor.weapon as |item id|}}
<div class="item gear">
<ol class="ol-no-indent">
<li class="item flexrow" data-item-id="{{item._id}}">
Expand Down Expand Up @@ -58,7 +58,7 @@
</li>
</ol>
</div>
{{/each}}
{{/each_sort_by_name}}
</div>

<!---- ARMOR ---->
Expand All @@ -76,7 +76,7 @@
</div>


{{#each actor.armor as |item id|}}
{{#each_sort_by_name actor.armor as |item id|}}
<div class="item gear">
<ol class="ol-no-indent">
<li class="item flexrow" data-item-id="{{item._id}}">
Expand All @@ -95,7 +95,7 @@
</li>
</ol>
</div>
{{/each}}
{{/each_sort_by_name}}
</div>

<!---- AUGMENTS ---->
Expand All @@ -112,7 +112,7 @@
class="fas fa-plus"></i></a></span>
</div>

{{#each actor.augment as |item id|}}
{{#each_sort_by_name actor.augment as |item id|}}
<div class="item gear">
<ol class="ol-no-indent">
<li class="item flexrow" data-item-id="{{item._id}}">
Expand All @@ -131,7 +131,7 @@
</li>
</ol>
</div>
{{/each}}
{{/each_sort_by_name}}
</div>

<!---- EQUIPMENT ---->
Expand All @@ -147,7 +147,7 @@
class="fas fa-plus"></i></a></span>
</div>

{{#each actor.equipment as |item id|}}
{{#each_sort_by_name actor.equipment as |item id|}}
<div class="item gear">
<ol class="ol-no-indent">
<li class="item flexrow" data-item-id="{{item._id}}">
Expand All @@ -165,6 +165,6 @@
</li>
</ol>
</div>
{{/each}}
{{/each_sort_by_name}}
</div>
</div>
4 changes: 2 additions & 2 deletions static/templates/actors/parts/actor/actor-skills.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</span>
</div>

{{#each actor.skills as |item id|}}
{{#each_sort_by_name actor.skills as |item id|}}
{{#if (twodsix_hideUntrainedSkills item.data.value)}}
<!-- Hiding {{item.name}} -->
{{else}}
Expand Down Expand Up @@ -46,7 +46,7 @@
{{/if}}
</div>
{{/if}}
{{/each}}
{{/each_sort_by_name}}
{{#if (twodsix_hideUntrainedSkills -1)}}
<div class="skill">
<span class="item skill-container">
Expand Down
4 changes: 2 additions & 2 deletions static/templates/actors/parts/ship/ship-storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>

<div class="grid-columns">
{{#each data.storage as |item id|}}
{{#each_sort_by_name data.storage as |item id|}}
<div>
<ol class="ol-no-indent">
<li class="item storage-stored" data-item-id="{{item._id}}">
Expand All @@ -39,6 +39,6 @@
</li>
</ol>
</div>
{{/each}}
{{/each_sort_by_name}}
</div>
</div>

0 comments on commit 9423d35

Please sign in to comment.