Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2607: feat(enterprise): add settings panel r=jniles a=jniles

This commit adds a new panel and CRUD interface for operation on
enterprise settings.  The settings table is linked 1-1 to the enterprise
table.  Tests have been updated accordingly.  The projects service has
also been updated to use the PrototypeApiService.

Closes Third-Culture-Software#2174.
  • Loading branch information
bors[bot] authored and jeremielodi committed Apr 2, 2018
2 parents 3d8cc58 + 69510d0 commit 6e9a508
Show file tree
Hide file tree
Showing 29 changed files with 862 additions and 710 deletions.
25 changes: 17 additions & 8 deletions client/src/i18n/en/enterprise.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{"ENTERPRISE":{"ADD_ENTERPRISE":"Add Enterprise.",
"ALL_ENTERPRISES":"All Enterprises",
"CONFIGURATION_ENTERPRISE":"Configuration Enterprise",
"DESCRIPTION_1":"Manage the application Companies from here. For now clearing the enterprise is not taken into account.",
"DESCRIPTION_2":"Edit selected Enterprise",
"DESCRIPTION_3":"Add a new enterprise.",
"EDITING_ENTERPRISE":"Editing enterprise",
"TITLE":"Enterprise Management"}}
{
"ENTERPRISE": {
"ADD_ENTERPRISE" : "Add Enterprise.",
"ALL_ENTERPRISES" : "All Enterprises",
"CONFIGURATION_ENTERPRISE" : "Configuration Enterprise",
"DESCRIPTION_1" : "Manage the application Companies from here. For now clearing the enterprise is not taken into account.",
"DESCRIPTION_2" : "Edit selected enterprise",
"DESCRIPTION_3" : "Add a new enterprise.",
"EDITING_ENTERPRISE" : "Editing enterprise",
"TITLE" : "Enterprise Management",
"SETTINGS" : {
"TITLE" : "Enterprise Settings",
"ENABLE_PRICE_LOCK_LABEL" : "Lock Price Changes for Patient Invoicing",
"ENABLE_PRICE_LOCK_HELP_TEXT" : "Enabling this feature will disallow users from modifying the prices of inventory items in the Patient Invoice module."
}
}
}
25 changes: 17 additions & 8 deletions client/src/i18n/fr/enterprise.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{"ENTERPRISE":{"ADD_ENTERPRISE":"Ajouter entreprise",
"ALL_ENTERPRISES":"Tous les entriprises",
"CONFIGURATION_ENTERPRISE":"Configuration entreprise",
"DESCRIPTION_1":"Gerer les entreprises de l'application A partir d'ici. Pour l'instant effacement de l'entrerpise n'est pas prise en compte.",
"DESCRIPTION_2":"Modifier l'enterprise sélectionner",
"DESCRIPTION_3":"Ajouter une nouvelle entreprises",
"EDITING_ENTERPRISE":"Edition entreprise",
"TITLE":"Gestion des entreprises"}}
{
"ENTERPRISE" : {
"ADD_ENTERPRISE" : "Ajouter entreprise",
"ALL_ENTERPRISES" : "Tous les entriprises",
"CONFIGURATION_ENTERPRISE" : "Configuration entreprise",
"DESCRIPTION_1" : "Gerer les entreprises de l'application A partir d'ici. Pour l'instant effacement de l'entrerpise n'est pas prise en compte.",
"DESCRIPTION_2" : "Modifier l'enterprise sélectionner",
"DESCRIPTION_3" : "Ajouter une nouvelle entreprises",
"EDITING_ENTERPRISE" : "Edition entreprise",
"TITLE" : "Gestion des entreprises",
"SETTINGS" : {
"TITLE" : "Parametres de l'Enterprise",
"ENABLE_PRICE_LOCK_LABEL" : "Verrouiller les changements de prix pour la facturation des patients",
"ENABLE_PRICE_LOCK_HELP_TEXT" : "L'activation de cette fonctionnalité empêchera les utilisateurs de modifier les prix des articles en stock dans le module Facturation de Patients."
}
}
}
142 changes: 142 additions & 0 deletions client/src/js/components/bhPermissionTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
angular.module('bhima.components')
.component('bhPermissionsTree', {
bindings: {
assignedUnits: '<?', // array [{unit_id :1}, {unit_id : 3}, ...]
onChange : '&',
},
templateUrl: 'modules/templates/bhPermissionsTree.tmpl.html',
controller: PermissionsTreeController,
});

PermissionsTreeController.$inject = [
'$translate', '$http', 'util', 'NodeTreeService', 'NotifyService',
];

function PermissionsTreeController($translate, $http, util, NT, Notify) {
const ctrl = this;
ctrl.editPermissions = editPermissions;
ctrl.checkboxOffset = checkboxOffset;
ctrl.toggleUnitChildren = toggleUnitChildren;
ctrl.toggleSuperUserPermissions = toggleSuperUserPermissions;
ctrl.toggleParents = toggleParents;

ctrl.$onInit = function onInit() {
// bind methods
ctrl.onChange = ctrl.onChange || angular.noop;
ctrl.loading = true;
ctrl.editPermissions();
};

// loads the permissions tree
function editPermissions() {
let units;

// load the tree units
loadUnits()
.then((data) => {

// unit value comparison function
function cmp(nodeA, nodeB) {
const a = $translate.instant(nodeA.key);
const b = $translate.instant(nodeB.key);
return a > b ? 1 : -1;
}

// build tree before flattening
const tree = NT.buildNodeTree(data);
units = NT.flattenInPlace(tree, cmp);

// make sure that we have the proper permissions selected
return ctrl.assignedUnits;
})
.then((permissions) => {
// loop through units, giving permissions in line with those in the
// database
permissions.forEach((object) => {
units.forEach((unit) => {
if (unit.id === object.unit_id) {
unit.checked = true;
}
});
});

ctrl.units = units;
})
.catch(Notify.handleError)
.finally(() => {
ctrl.loading = false;
});
}


// used in the view to set permission's tree padding based on depth
function checkboxOffset(depth) {
return {
'padding-left': ''.concat(30 * depth, 'px'),
};
}

// loads tree units on demand Used for assigning user's permissions
function loadUnits() {
return $http.get('/units')
.then(util.unwrapHttpResponse);
}

// traverse upwards, toggling parents
function toggleParents(unit) {
if (unit.parent !== 0 && unit.checked) {
const parent = ctrl.units.filter((item) => {
return item.id === unit.parent;
});
parent[0].checked = unit.checked;

if (parent[0].parent) {
ctrl.toggleParents(parent);
}
}
updateAssignedUnits();
}

// toggle the selection all child nodes
function toggleUnitChildren(unit, children) {
if (!unit.checked) {
ctrl.super = false;
}

if (unit.parent !== 0) {
ctrl.toggleParents(unit); // traverse upwards, toggling parents
}

children.forEach((node) => {
node.checked = unit.checked;
if (node.children) {
toggleUnitChildren(node, node.children);
}
});
updateAssignedUnits();
}


function updateAssignedUnits() {

ctrl.assignedUnits = ctrl.units.filter((u) => {
return u.checked;
})
.map((unit) => {
const u = {
unit_id: unit.id
};
return u;
});

ctrl.onChange()(ctrl.assignedUnits);
}
// toggles all permissions to match there super user permission's setting
function toggleSuperUserPermissions(bool) {
ctrl.units.forEach((node) => {
node.checked = bool;
});
updateAssignedUnits();
}

}
28 changes: 17 additions & 11 deletions client/src/js/components/bhYesNoRadios.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
angular.module('bhima.components')
.component('bhYesNoRadios', {
bindings : {
defaultValue : '@?',
value : '=',
label : '@?',
value : '<',
label : '@',
name : '@',
helpText : '@?',
onChangeCallback : '&',
},
templateUrl : 'modules/templates/bhYesNoRadios.tmpl.html',
controller : YesNoRadio,
controller : YesNoRadioController,
});

function YesNoRadio() {
/**
* @function YesNoRadioController
*
* @description
* This component makes yes/no options a bit easier to navigate.
*/
function YesNoRadioController() {
const $ctrl = this;
$ctrl.$onInit = function onInit() {
$ctrl.onChangeCallback = $ctrl.onChangeCallback;
$ctrl.defaultValue = $ctrl.defaultValue;
$ctrl.value = ($ctrl.defaultValue) ? 1 : 0;
$ctrl.label = $ctrl.label;
$ctrl.helpText = $ctrl.helpText;

$ctrl.$onInit = () => {
$ctrl.value = Number.parseInt($ctrl.value, 10);
};

$ctrl.onChange = (value) => {
$ctrl.onChangeCallback({ value });
};
}
Loading

0 comments on commit 6e9a508

Please sign in to comment.