Skip to content

Commit

Permalink
SELV3-792: adjust the naming of the rights when a role is of the repo…
Browse files Browse the repository at this point in the history
…rts type
  • Loading branch information
olewandowski1 committed Jan 9, 2025
1 parent 54d8990 commit c5a8d79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/admin-role-form/right.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,38 @@
.module('admin-role-form')
.filter('right', roleRightFilter);

roleRightFilter.$inject = ['messageService', '$filter'];
roleRightFilter.$inject = ['messageService', '$filter', 'ROLE_TYPES'];

function roleRightFilter(messageService, $filter) {
return function(rightName) {
function roleRightFilter(messageService, $filter, ROLE_TYPES) {
return function(rightName, roleType) {
if (!rightName) {
return undefined;
}

if (roleType === ROLE_TYPES.REPORTS) {
return createReportRightName(rightName);
}

return messageService.get('adminRoleForm.' + $filter('camelCase')(rightName));
};
}

/**
* @ngdoc method
* @methodOf admin-role-form.filter:right
* @name createReportRightName
*
* @description
* Formats the given right name into more user-friendly string. First, it replaces all underscores. Then, it
* lowercases the string, splits it by spaces, capitalizes the first letter of each word, and joins them back.
*/
function createReportRightName(rightName) {
return rightName
.replace(/_/g, ' ')
.toLowerCase()
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
}

})();
2 changes: 1 addition & 1 deletion src/admin-role-form/role-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>{{(vm.role.id ? 'adminRoleForm.updateRole' : 'adminRoleForm.createRole') | m
<legend>Rights</legend>
<label ng-repeat="right in vm.rights" class="checkbox">
<input type="checkbox" ng-model="right.checked" ng-required="vm.isNoneSelected()"/>
{{right.name | right}}
{{right.name | right:vm.type}}
</label>
</fieldset>
</form>
Expand Down

0 comments on commit c5a8d79

Please sign in to comment.