Skip to content

Commit

Permalink
Merge pull request #33895 from dimagi/es/sort-options
Browse files Browse the repository at this point in the history
Show case tile sort options in configured order, not header order
  • Loading branch information
esoergel committed Dec 19, 2023
2 parents df41a25 + 80d1c97 commit e35bc99
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,6 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
templateContext: function () {
const paginateItems = formplayerUtils.paginateOptions(this.options.currentPage, this.options.pageCount);
const casesPerPage = parseInt($.cookie("cases-per-page-limit")) || (this.smallScreenEnabled ? 5 : 10);
const boldSortedCharIcon = (header) => {
const headerWords = header.trim().split(' ');
const lastChar = headerWords.pop();

return lastChar === "Λ" || lastChar === "V"
? `${headerWords.join(' ')} <b>${lastChar}</b>`
: header;
};
let description = this.options.description;
let title = this.options.title;
if (this.options.sidebarEnabled && this.options.collection.queryResponse) {
Expand All @@ -955,7 +947,7 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
startPage: paginateItems.startPage,
title: title.trim(),
description: description === undefined ? "" : DOMPurify.sanitize(markdown.render(description.trim())),
headers: this.headers.map(boldSortedCharIcon),
headers: this.headers,
widthHints: this.options.widthHints,
actions: this.options.actions,
currentPage: this.options.currentPage,
Expand Down Expand Up @@ -1108,6 +1100,21 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
const dict = CaseTileListView.__super__.templateContext.apply(this, arguments);
dict.useTiles = true;
dict.isMultiSelect = this.options.isMultiSelect;
dict.sortOptions = _.map(dict.sortIndices, function (sortIndex) {
let header = dict.headers[sortIndex],
sortOrder = null,
headerWords = header.trim().split(' '),
lastChar = headerWords.pop();
if (lastChar === "Λ" || lastChar === "V") {
header = headerWords.join(' ');
sortOrder = lastChar;
}
return {
index: sortIndex,
header: header,
sortOrder: sortOrder,
};
});
return dict;
},

Expand Down
13 changes: 9 additions & 4 deletions corehq/apps/cloudcare/templates/formplayer/case_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ <h1 aria-label="<%- title %>" tabindex="0" class="page-title"><%- title %></h1>
<span> {% trans "Sort By" %} </span><i class="fa fa-sort" aria-hidden="true"></i>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="case-list-sort-by">
<% _.each(headers, function(header, index) { %>
<% if (columnSortable(index)) { %>
<li tabindex="0" class="header-clickable formplayer-request" data-id="<%- index %>" role="menuitem"><a><%= header %></a></li>
<% } %>
<% _.each(sortOptions, function(sortOption) { %>
<li tabindex="0" class="header-clickable formplayer-request" data-id="<%- sortOption.index %>" role="menuitem">
<a>
<%= sortOption.header %>
<% if (sortOption.sortOrder) { %>
<i class="fa fa-arrow-<%= sortOption.sortOrder === 'V' ? 'down' : 'up' %> pull-right"></i>
<% } %>
</a>
</li>
<% }); %>
</ul>
</div>
Expand Down

0 comments on commit e35bc99

Please sign in to comment.