Permissions formatting, dialog queue

This commit is contained in:
Mo Bitar
2018-01-21 13:14:15 -06:00
parent 12ada8eb00
commit 614d7ba20a
4 changed files with 101 additions and 52 deletions

View File

@@ -30,46 +30,68 @@ class PermissionsModal {
controller($scope, modelManager) {
$scope.formattedPermissions = $scope.permissions.map(function(permission){
if(permission.name === "stream-items") {
var types = permission.content_types.map(function(type){
var desc = modelManager.humanReadableDisplayForContentType(type);
if(desc) {
return desc + "s";
} else {
return "items of type " + type;
}
})
var typesString = "";
var separator = ", ";
$scope.permissionsString = function() {
var finalString = "";
let permissionsCount = $scope.permissions.length;
for(var i = 0;i < types.length;i++) {
var type = types[i];
if(i == 0) {
// first element
typesString = typesString + type;
} else if(i == types.length - 1) {
// last element
if(types.length > 2) {
typesString += separator + "and " + type;
} else if(types.length == 2) {
typesString = typesString + " and " + type;
let addSeparator = (index, length) => {
if(index > 0) {
if(index == length - 1) {
if(length == 2) {
return " and ";
} else {
return ", and "
}
} else {
typesString += separator + type;
return ", ";
}
}
return typesString;
} else if(permission.name === "stream-context-item") {
var mapping = {
"editor-stack" : "working note",
"note-tags" : "working note",
"editor-editor": "working note"
}
return mapping[$scope.component.area];
return "";
}
})
$scope.permissions.forEach((permission, index) => {
if(permission.name === "stream-items") {
var types = permission.content_types.map(function(type){
var desc = modelManager.humanReadableDisplayForContentType(type);
if(desc) {
return desc + "s";
} else {
return "items of type " + type;
}
})
var typesString = "";
for(var i = 0;i < types.length;i++) {
var type = types[i];
typesString += addSeparator(i, types.length + permissionsCount - index - 1);
typesString += type;
}
finalString += addSeparator(index, permissionsCount);
finalString += typesString;
if(types.length >= 2 && index < permissionsCount - 1) {
// If you have a list of types, and still an additional root-level permission coming up, add a comma
finalString += ", ";
}
} else if(permission.name === "stream-context-item") {
var mapping = {
"editor-stack" : "working note",
"note-tags" : "working note",
"editor-editor": "working note"
}
finalString += addSeparator(index, permissionsCount, true);
finalString += mapping[$scope.component.area];
}
})
return finalString + ".";
}
}
}