1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 18:21:12 +03:00

fixed related lists for users and teams edit

This commit is contained in:
John Mitchell 2016-04-27 11:27:45 -04:00
parent ce14c0daff
commit e3d0309089
7 changed files with 154 additions and 230 deletions

View File

@ -199,7 +199,8 @@ export function TeamsEdit($scope, $rootScope, $location,
generator = GenerateForm,
form = TeamForm,
id = $stateParams.team_id,
relatedSets = {};
relatedSets = {},
set;
$scope.team_id = id;
@ -263,6 +264,12 @@ export function TeamsEdit($scope, $rootScope, $location,
relatedSets: relatedSets
});
for (set in relatedSets) {
$scope.search(relatedSets[set].iterator);
}
$scope.team_obj = data;
LookUpInit({
url: GetBasePath('organizations'),
scope: $scope,
@ -298,6 +305,14 @@ export function TeamsEdit($scope, $rootScope, $location,
init();
$scope.convertApiUrl = function(str) {
if (str) {
return str.replace("api/v1", "#");
} else {
return null;
}
};
/* Related Set implementation TDB */
}

View File

@ -231,7 +231,8 @@ export function UsersEdit($scope, $rootScope, $location,
form = UserForm,
master = {},
id = $stateParams.user_id,
relatedSets = {};
relatedSets = {},
set;
generator.inject(form, { mode: 'edit', related: true, scope: $scope });
generator.reset();
@ -248,17 +249,25 @@ export function UsersEdit($scope, $rootScope, $location,
return;
};
$scope.convertApiUrl = function(str) {
if (str) {
return str.replace("api/v1", "#");
} else {
return null;
}
};
var setScopeRelated = function(data, related){
_(related)
.pick(function(value, key){
return data.related.hasOwnProperty(key) === true;
})
.forEach(function(value, key){
relatedSets[key] = {
url: data.related[key],
iterator: value.iterator
};
})
.pick(function(value, key){
return data.related.hasOwnProperty(key) === true;
})
.forEach(function(value, key){
relatedSets[key] = {
url: data.related[key],
iterator: value.iterator
};
})
.value();
};
// prepares a data payload for a PUT request to the API
@ -295,6 +304,11 @@ export function UsersEdit($scope, $rootScope, $location,
scope: $scope,
relatedSets: relatedSets
});
for (set in relatedSets) {
$scope.search(relatedSets[set].iterator);
}
Wait('stop');
})
.error(function (data, status) {

View File

@ -59,11 +59,10 @@ export default
},
related: {
/*
permissions: {
access_list: {
basePath: 'teams/:id/access_list/',
type: 'collection',
title: 'Permissions',
title: 'Users',
iterator: 'permission',
index: false,
open: false,
@ -76,148 +75,50 @@ export default
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD'
}
}
},
*/
credentials: {
type: 'collection',
title: 'Credentials',
iterator: 'credential',
open: false,
index: false,
actions: {
add: {
ngClick: "add('credentials')",
label: 'Add',
add: 'Add a new credential',
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD'
}
},
fields: {
name: {
key: true,
label: 'Name'
},
description: {
label: 'Description'
}
},
fieldActions: {
edit: {
label: 'Edit',
ngClick: "edit('credentials', credential.id, credential.name)",
icon: 'icon-edit',
awToolTip: 'Modify the credential',
'class': 'btn btn-default'
},
"delete": {
label: 'Delete',
ngClick: "delete('credentials', credential.id, credential.name, 'credential')",
icon: 'icon-trash',
"class": 'btn-danger',
awToolTip: 'Remove the credential'
}
}
},
projects: {
type: 'collection',
title: 'Projects',
iterator: 'project',
open: false,
index: false,
actions: {
add: {
ngClick: "add('projects')",
label: 'Add',
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD'
}
},
fields: {
name: {
key: true,
label: 'Name'
},
description: {
label: 'Description'
}
},
fieldActions: {
edit: {
label: 'Edit',
ngClick: "edit('projects', project.id, project.name)",
icon: 'icon-edit',
awToolTip: 'Modify the project',
'class': 'btn btn-default'
},
"delete": {
label: 'Delete',
ngClick: "delete('projects', project.id, project.name, 'project')",
icon: 'icon-trash',
"class": 'btn-danger',
awToolTip: 'Remove the project'
}
}
},
users: {
type: 'collection',
title: 'Users',
iterator: 'user',
open: false,
index: false,
actions: {
add: {
ngClick: "add('users')",
label: 'Add',
awToolTip: 'Add a user',
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD'
}
},
fields: {
username: {
key: true,
label: 'Username'
label: 'User',
linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
},
first_name: {
label: 'First Name'
},
last_name: {
label: 'Last Name'
}
},
fieldActions: {
edit: {
label: 'Edit',
ngClick: "edit('users', user.id, user.username)",
icon: 'icon-edit',
awToolTip: 'Edit user',
'class': 'btn btn-default'
},
"delete": {
label: 'Delete',
ngClick: "delete('users', user.id, user.username, 'user')",
icon: 'icon-terash',
"class": 'btn-danger',
awToolTip: 'Remove user'
role: {
label: 'Role',
type: 'role',
noSort: true,
class: 'col-lg-9 col-md-9 col-sm-9 col-xs-8'
}
}
},
roles: {
type: 'collection',
title: 'Permissions',
iterator: 'role',
open: false,
index: false,
actions: {},
fields: {
name: {
label: 'Name',
ngBind: 'role.summary_fields.resource_name',
linkTo: '{{convertApiUrl(role.related[role.summary_fields.resource_type])}}',
noSort: true
},
type: {
label: 'Type',
ngBind: 'role.summary_fields.resource_type_display_name',
noSort: true
},
role: {
label: 'Role',
ngBind: 'role.name',
noSort: true
}
},
hideOnSuperuser: true
}
}
}); //InventoryForm

View File

@ -115,71 +115,6 @@ export default
},
related: {
/*
permissions: {
basePath: 'teams/:id/access_list/',
type: 'collection',
title: 'Permissions',
iterator: 'permission',
index: false,
open: false,
searchType: 'select',
actions: {
add: {
ngClick: "addPermission",
label: 'Add',
awToolTip: 'Add a permission',
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD'
}
}
},
*/
credentials: {
type: 'collection',
title: 'Credentials',
iterator: 'credential',
open: false,
index: false,
actions: {
add: {
ngClick: "add('credentials')",
label: 'Add',
awToolTip: 'Add a credential for this user',
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD'
}
},
fields: {
name: {
key: true,
label: 'Name'
},
description: {
label: 'Description'
}
},
fieldActions: {
edit: {
label: 'Edit',
ngClick: "edit('credentials', credential.id, credential.name)",
icon: 'icon-edit',
awToolTip: 'Edit the credential',
'class': 'btn btn-default'
},
"delete": {
label: 'Delete',
ngClick: "delete('credentials', credential.id, credential.name, 'credential')",
icon: 'icon-trash',
"class": 'btn-danger',
awToolTip: 'Delete the credential'
}
}
},
organizations: {
type: 'collection',
title: 'Organizations',
@ -197,9 +132,9 @@ export default
description: {
label: 'Description'
}
}
},
hideOnSuperuser: true
},
teams: {
type: 'collection',
title: 'Teams',
@ -217,8 +152,38 @@ export default
description: {
label: 'Description'
}
}
},
hideOnSuperuser: true
},
roles: {
hideSearchAndActions: true,
type: 'collection',
title: 'Permissions',
iterator: 'permission',
open: false,
index: false,
actions: {},
fields: {
name: {
label: 'Name',
ngBind: 'permission.summary_fields.resource_name',
linkTo: '{{convertApiUrl(permission.related[permission.summary_fields.resource_type])}}',
noSort: true
},
type: {
label: 'Type',
ngBind: 'permission.summary_fields.resource_type_display_name',
noSort: true
},
role: {
label: 'Role',
ngBind: 'permission.name',
noSort: true
}
},
hideOnSuperuser: true
}
}
}); //UserForm
});

View File

@ -16,6 +16,7 @@ export default ['GetBasePath', function(GetBasePath) {
delete f[i].ngClass;
delete f[i].ngClick;
delete f[i].icon;
delete f[i].linkTo;
return {[i]: f[i]};
}).reduce(function (acc, i) {
var key = Object.keys(i);

View File

@ -1462,7 +1462,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += (options.mode === 'edit') ? this.form.editTitle : this.form.addTitle;
if(this.form.name === "user"){
html+= "<span class=\"Form-title--is_superuser\" "+
"ng-if=is_superuser>Admin</span>";
"ng-if=is_superuser>System Administrator</span>";
}
html += "</div>\n";
html += "<div class=\"Form-header--fields\">";
@ -1781,14 +1781,16 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
});
html += `
<div class=\"row\">
<div class=\"row\"
ng-show=\"${collection.hideSearchAndActions ? true : false}\">
<div class=\"col-lg-8\"
ng-show=\"${collection.iterator}Loading == true ||
${collection.iterator}_active_search == true || (
${collection.iterator}Loading == false &&
${collection.iterator}_active_search == false &&
${collection.iterator}_total_rows > 0
)\">
${collection.iterator}_total_rows > 0)\"
ng-hide=\"is_superuser && ${collection.hideOnSuperuser}\"
>
${tagSearch}
</div>
<div class=\"col-lg-4\">
@ -1800,18 +1802,39 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
`;
// Message for when a search returns no results. This should only get shown after a search is executed with no results.
html += "<div class=\"row\" ng-show=\"" + collection.iterator + "Loading == false && " + collection.iterator + "_active_search == true && " + itm + ".length == 0\">\n";
html += "<div class=\"col-lg-12 List-searchNoResults\">No records matched your search.</div>\n";
html += "</div>\n";
var hideOnSuperuser = (hideOnSuperuser === true) ? true : false;
html += `
<div
class=\"row\"
ng-show=\" ${collection.iterator}Loading == false &&
${collection.iterator}_active_search == true &&
${itm}.length == 0 &&
!(is_superuser && ${collection.hideOnSuperuser})\">
<div class=\"col-lg-12 List-searchNoResults\">
No records matched your search.
</div>
</div>
`;
// Show the "no items" box when loading is done and the user isn't actively searching and there are no results
html += "<div class=\"List-noItems\" ng-show=\"" + collection.iterator + "Loading == false && " + collection.iterator + "_active_search == false && " + collection.iterator + "_total_rows < 1\">PLEASE ADD ITEMS TO THIS LIST</div>";
html += `
<div class=\"List-noItems\" ng-show=\"is_superuser\">
System Administrators have access to all ${collection.iterator}s
</div>
`;
// Start the list
html += "<div class=\"list-wrapper\" ng-show=\"" + collection.iterator + "Loading == true || (" + collection.iterator + "Loading == false && " + itm + ".length > 0)\">\n";
html += "<table id=\"" + itm + "_table" + "\" class=\"" + collection.iterator + " List-table\">\n";
html += "<thead>\n";
html += "<tr class=\"List-tableHeaderRow\">\n";
html += `
<div class=\"list-wrapper\"
ng-show=\"(${collection.iterator}Loading == true ||
(${collection.iterator}Loading == false && ${itm}.length > 0)) &&
!(is_superuser && ${collection.hideOnSuperuser})\">
<table id=\"${itm}_table\" class=\"${collection.iterator} List-table\">
<thead>
<tr class=\"List-tableHeaderRow\">
`;
html += (collection.index === undefined || collection.index !== false) ? "<th class=\"col-xs-1\">#</th>\n" : "";
for (fld in collection.fields) {
html += "<th class=\"List-tableHeader list-header ";
@ -1918,7 +1941,8 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += PaginateWidget({
set: itm,
iterator: collection.iterator,
mini: true
mini: true,
hideOnSuperuser: collection.hideOnSuperuser
});
return html;
}

View File

@ -772,9 +772,13 @@ angular.module('GeneratorHelpers', [systemStatus.name])
return function (params) {
var iterator = params.iterator,
set = params.set,
hideOnSuperuser = (params.hideOnSuperuser) ? true : false,
html = '';
html += "<!-- Paginate Widget -->\n";
html += "<div id=\"" + iterator + "-pagination\" class=\"List-pagination page-row\">\n";
html += `
<div id=\"${iterator}-pagination\" class=\"List-pagination page-row\"
ng-hide=\"is_superuser && ${hideOnSuperuser}\">
`;
html += "<div class=\"List-paginationPagerHolder\">";
html += "<div class=\"List-paginationPager\" ng-hide=\"" + iterator + "HidePaginator || " + iterator + "_num_pages <= 1\">";
html += "<ul id=\"pagination-links\" class=\"pagination\">\n";