One example of an enum is:
RoleEnum={
None: 0,
ViewAnalytics: 1,
ManageTargets: 2,
ManageBranches: 4,
ViewActivationDetails: 8,
ManageUsers: 16,
ViewBilling: 32,
ManageQuestions: 64
};
- If the response from the database is 7, then it should return:
["None","ViewAnalytics","ManageTargets","ManageBranches"]
- If the response from the database is 3, then it should return:
["None","ViewAnalytics","ManageTargets"]
This logic applies to other cases as well.
In a .ts file, you can have:-
vm.userLevelPermission.ViewAnalytics = vm.userLevelPermission.includes('ViewAnalytics');
vm.userLevelPermission.ManageTargets = vm.userLevelPermission.includes('ManageTargets');
The permission value received from the database is added here with the logic.
<div class="panel-title"><h4 class="mts">User Level Permission Settings<button class="btn btn-primary pull-right" type="button" ng-click="vm.updateUserLevelPermission()">Save</button></h4></div>
</div>
<tr>
<td>Manage Targets</td>
<td class="text-center"><input type="checkbox" class="css-checkbox" checked="vm.userLevelPermission.ManageTargets"></td>
<td>View Analytics</td>
<td class="text-center"><input type="checkbox" class="css-checkbox" checked="vm.userLevelPermission.ViewAnalytics"></td>
</tr>
Similarly, when updating, the value should be the sum of checked boxes. If both are checked, it will return 3.