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 IMA-WorldHealth#4146
  • Loading branch information
jniles committed Jul 22, 2020
1 parent cfb809a commit e564b86
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 148 deletions.
2 changes: 1 addition & 1 deletion client/src/i18n/fr/tree.json
Expand Up @@ -34,7 +34,7 @@
"CURRENCY":"Monnaie",
"DATA_COLLECTION": "Collecte de données",
"FORMS_MANAGEMENT": "Gestion des formulaires",
"DATA_KIT": ".Kit de collecte de données",
"DATA_KIT": "Kit de collecte de données",
"DATA_KIT_REPORT": "Rapport des collectes des données",
"DEBTOR_GROUP":"Gestion des Groupes Débiteurs",
"DEPOTS":"Dépôts",
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/components/bhNavigation.js
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
21 changes: 19 additions & 2 deletions client/src/js/services/tree.js
Expand Up @@ -30,7 +30,19 @@ function Tree($http, $translate, util, TreeClass) {
.then(data => new TreeClass(data));
}

/** recursively sort an array of BHIMA units respecting translation keys. */
// returns 1 if unit is a parent or 0 if not.
function hasChildren(unit) {
const bool = unit.children && unit.children.length > 0;
return bool ? 1 : 0;
}

/**
* @function sortByTranslationKey
*
* @description
* Recursively sort an array of BHIMA units respecting translation keys.
*
*/
function sortByTranslationKey(unitArray) {
if (angular.isUndefined(unitArray)) {
return;
Expand All @@ -39,7 +51,12 @@ function Tree($http, $translate, util, TreeClass) {
unitArray.sort((a, b) => {
const aValue = $translate.instant(a.key);
const bValue = $translate.instant(b.key);
return aValue.localeCompare(bValue);

// make sure parents sink to the bottom of the sorted list.
const parentWeight = (hasChildren(a) - hasChildren(b));

// prioritize sorting by parents, then by i18nValue
return (parentWeight || aValue.localeCompare(bValue));
});

// recursively step into each set of children
Expand Down

0 comments on commit e564b86

Please sign in to comment.