forked from Third-Culture-Software/bhima
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
29 changed files
with
849 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
angular.module('bhima.components') | ||
.component('bhPermissionsTree', { | ||
bindings : { | ||
assignedUnits : '=', // array [{unit_id :1}, {unit_id : 3}, ...] | ||
}, | ||
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.$onInit = function onInit() { | ||
// bind methods | ||
ctrl.editPermissions = editPermissions; | ||
ctrl.checkboxOffset = checkboxOffset; | ||
ctrl.toggleUnitChildren = toggleUnitChildren; | ||
ctrl.toggleSuperUserPermissions = toggleSuperUserPermissions; | ||
ctrl.toggleParents = toggleParents; | ||
ctrl.loading = true; | ||
|
||
// 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; | ||
}); | ||
} | ||
// toggles all permissions to match there super user permission's setting | ||
function toggleSuperUserPermissions(bool) { | ||
ctrl.units.forEach((node) => { | ||
node.checked = bool; | ||
}); | ||
updateAssignedUnits(); | ||
} | ||
ctrl.editPermissions(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}; | ||
} |
Oops, something went wrong.