Skip to content

Commit

Permalink
chore: add subfolders for reports
Browse files Browse the repository at this point in the history
Adds subfolders for reports to each top-level module.

Closes Third-Culture-Software#4146
  • Loading branch information
jniles committed Jul 17, 2020
1 parent d8fd687 commit 97203c6
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 146 deletions.
2 changes: 1 addition & 1 deletion client/src/js/components/bhNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function NavigationController($location, $rootScope, Tree, AppCache, Notify, $tr
function loadTreeUnits() {
Tree.units()
.then(units => {

Tree.sortByTranslationKey(units);

$ctrl.units = units;

calculateUnitIndex($ctrl.units);
Expand Down
16 changes: 15 additions & 1 deletion client/src/js/services/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,27 @@ function Tree($http, $translate, util, TreeClass) {
.then(data => new TreeClass(data));
}

/** recursively sort an array of BHIMA units respecting translation keys. */
function hasChildren(unit) {
return unit.children && unit.children.length > 0;
}

/**
* @function sortByTranslationKey
*
* @description
* Recursively sort an array of BHIMA units respecting translation keys.
*
*/
function sortByTranslationKey(unitArray) {
if (angular.isUndefined(unitArray)) {
return;
}

unitArray.sort((a, b) => {
// push parents to the bottom of the list
if (hasChildren(a)) { return 1; }
if (hasChildren(b)) { return -1; }

const aValue = $translate.instant(a.key);
const bValue = $translate.instant(b.key);
return aValue.localeCompare(bValue);
Expand Down
Loading

0 comments on commit 97203c6

Please sign in to comment.