mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 12:41:19 -03:30
AC-689 no longer storing selected array in scope object. SelectionInit should be called before Search in controllers- Users had it in the wrong order. Added ability to override internal selected array in SelectionInit with reference to external array to support the groups page. Fixed cosmetic/styling differences between hosts and groups inventory pages.
This commit is contained in:
parent
fae51d12f0
commit
54ec61f2b7
@ -25,6 +25,10 @@ function UsersList ($scope, $rootScope, $location, $log, $routeParams, Rest, Ale
|
||||
var scope = view.inject(UserList, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
var url = (base == 'organizations') ? GetBasePath('organizations') + $routeParams.organization_id + '/users/' :
|
||||
GetBasePath('teams') + $routeParams.team_id + '/users/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
if (scope.removePostRefresh) {
|
||||
scope.removePostRefresh();
|
||||
}
|
||||
@ -41,10 +45,6 @@ function UsersList ($scope, $rootScope, $location, $log, $routeParams, Rest, Ale
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
var url = (base == 'organizations') ? GetBasePath('organizations') + $routeParams.organization_id + '/users/' :
|
||||
GetBasePath('teams') + $routeParams.team_id + '/users/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
scope.showActivity = function() { Stream(); }
|
||||
|
||||
scope.addUser = function() {
|
||||
|
||||
@ -81,7 +81,7 @@ angular.module('InventoryHostsFormDefinition', [])
|
||||
ngClick: "addHost()",
|
||||
ngHide: "hostAddHide",
|
||||
awToolTip: "Copy an existing host to the selected group",
|
||||
dataPlacement: 'bottom',
|
||||
dataPlacement: 'top',
|
||||
'class': 'btn-xs btn-success',
|
||||
icon: 'icon-check'
|
||||
},
|
||||
@ -90,7 +90,7 @@ angular.module('InventoryHostsFormDefinition', [])
|
||||
ngClick: 'createHost()',
|
||||
ngHide: 'hostCreateHide',
|
||||
awToolTip: 'Create a new host and add it to the selected group',
|
||||
dataPlacement: 'bottom',
|
||||
dataPlacement: 'top',
|
||||
'class': 'btn-xs btn-success',
|
||||
icon: 'icon-plus'
|
||||
},
|
||||
|
||||
@ -239,18 +239,17 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
|
||||
$('#form-modal').modal({ backdrop: 'static', keyboard: false });
|
||||
|
||||
// Initialize the selection list
|
||||
var url = (group_id) ? GetBasePath('groups') + group_id + '/children/' :
|
||||
GetBasePath('inventory') + inventory_id + '/groups/';
|
||||
var selected = [];
|
||||
SelectionInit({ scope: scope, list: list, url: url, selected: selected });
|
||||
|
||||
SelectionInit({ scope: scope, list: list, url: url });
|
||||
|
||||
//var finish = scope.finishSelection;
|
||||
|
||||
scope.formModalAction = function() {
|
||||
var groups = [];
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
if (scope.inventoryRootGroups.indexOf(scope.selected[j].id) > -1) {
|
||||
groups.push(scope.selected[j].name);
|
||||
for (var j=0; j < selected.length; j++) {
|
||||
if (scope.inventoryRootGroups.indexOf(selected[j].id) > -1) {
|
||||
groups.push(selected[j].name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,19 +285,6 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
}
|
||||
}
|
||||
|
||||
/* Now using /potential_children resource, so should not need to do this any longer.
|
||||
if (scope.PostRefreshRemove) {
|
||||
scope.PostRefreshRemove();
|
||||
}
|
||||
scope.PostRefreshRemove = scope.$on('PostRefresh', function() {
|
||||
for (var i=0; i < scope.groups.length; i++) {
|
||||
if (scope.groups[i].id == group_id) {
|
||||
scope.groups.splice(i,1);
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
var searchUrl = (group_id) ? GetBasePath('groups') + group_id + '/potential_children/' :
|
||||
GetBasePath('inventory') + inventory_id + '/groups/';
|
||||
|
||||
|
||||
@ -20,9 +20,16 @@ angular.module('SelectionHelper', ['Utilities', 'RestServices'])
|
||||
var list = params.list; // list object
|
||||
var target_url = params.url; // URL to POST selected objects
|
||||
var returnToCaller = params.returnToCaller;
|
||||
|
||||
scope.selected = []; //array of selected row IDs
|
||||
|
||||
if (params.selected !== undefined) {
|
||||
var selected = params.selected;
|
||||
}
|
||||
else {
|
||||
var selected = []; //array of selected row IDs
|
||||
}
|
||||
|
||||
scope.formModalActionDisabled = true;
|
||||
scope.disableSelectBtn = true;
|
||||
|
||||
// toggle row selection
|
||||
scope['toggle_' + list.iterator] = function(id, ischeckbox) {
|
||||
@ -35,14 +42,14 @@ angular.module('SelectionHelper', ['Utilities', 'RestServices'])
|
||||
|
||||
// add selected object to the array
|
||||
var found = false;
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
if (scope.selected[j].id == id) {
|
||||
for (var j=0; j < selected.length; j++) {
|
||||
if (selected[j].id == id) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
scope.selected.push(scope[list.name][i]);
|
||||
selected.push(scope[list.name][i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -51,87 +58,89 @@ angular.module('SelectionHelper', ['Utilities', 'RestServices'])
|
||||
scope[list.name][i]['success_class'] = '';
|
||||
|
||||
// remove selected object from the array
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
if (scope.selected[j].id == id) {
|
||||
scope.selected.splice(j,1);
|
||||
for (var j=0; j < selected.length; j++) {
|
||||
if (selected[j].id == id) {
|
||||
selected.splice(j,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scope.selected.length > 0) {
|
||||
scope.formModalActionDisabled = false;
|
||||
if (selected.length > 0) {
|
||||
scope.formModalActionDisabled = false;
|
||||
scope.disableSelectBtn = false;
|
||||
}
|
||||
else {
|
||||
scope.formModalActionDisabled = true;
|
||||
scope.disableSelectBtn = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the selections
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl(target_url);
|
||||
var queue = [];
|
||||
scope.formModalActionDisabled = true;
|
||||
scope.disableSelectBtn = true;
|
||||
|
||||
Wait('start');
|
||||
|
||||
if (target_url) {
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl(target_url);
|
||||
scope.queue = [];
|
||||
scope.formModalActionDisabled = true;
|
||||
|
||||
Wait('start');
|
||||
function finished() {
|
||||
selected = [];
|
||||
if (returnToCaller !== undefined) {
|
||||
ReturnToCaller(returnToCaller);
|
||||
}
|
||||
else {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('modalClosed');
|
||||
}
|
||||
}
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemove = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected item. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (queue.length == selected.length) {
|
||||
Wait('stop');
|
||||
var errors = 0;
|
||||
for (var i=0; i < queue.length; i++) {
|
||||
if (queue[i].result == 'error') {
|
||||
ProcessErrors(scope, queue[i].data, queue[i].status, null,
|
||||
{ hdr: 'POST Failure', msg: 'Failed to add ' + list.iterator +
|
||||
'. POST returned status: ' + queue[i].status });
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors == 0) {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function finished() {
|
||||
scope.selected = [];
|
||||
if (returnToCaller !== undefined) {
|
||||
ReturnToCaller(returnToCaller);
|
||||
}
|
||||
else {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('modalClosed');
|
||||
}
|
||||
}
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
if (selected.length > 0 ) {
|
||||
for (var j=0; j < selected.length; j++) {
|
||||
Rest.post(selected[j])
|
||||
.success( function(data, status, headers, config) {
|
||||
queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
scope.callFinishedRemove = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected item. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
Wait('stop');
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
ProcessErrors(scope, scope.queue[i].data, scope.queue[i].status, null,
|
||||
{ hdr: 'POST Failure', msg: 'Failed to add ' + list.iterator +
|
||||
'. POST returned status: ' + scope.queue[i].status });
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors == 0) {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
Rest.post(scope.selected[j])
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
scope.formModalAction = scope.finishSelection;
|
||||
|
||||
// Initialize our data set after a refresh
|
||||
// Initialize our data set after a refresh (page change or search)
|
||||
if (scope.SelectPostRefreshRemove) {
|
||||
scope.SelectPostRefreshRemove();
|
||||
}
|
||||
@ -139,8 +148,8 @@ angular.module('SelectionHelper', ['Utilities', 'RestServices'])
|
||||
if (scope[list.name]) {
|
||||
for (var i=0; i < scope[list.name].length; i++) {
|
||||
var found = false;
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
if (scope.selected[j].id == scope[list.name][i].id) {
|
||||
for (var j=0; j < selected.length; j++) {
|
||||
if (selected[j].id == scope[list.name][i].id) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ angular.module('GroupListDefinition', [])
|
||||
help: {
|
||||
awPopOver: "Choose groups by clicking on each group you wish to add. Click the <em>Select</em> button to add the groups to " +
|
||||
"the selected inventory group.",
|
||||
dataPlacement: 'top',
|
||||
dataPlacement: 'left',
|
||||
dataContainer: '#form-modal .modal-content',
|
||||
icon: "icon-question-sign",
|
||||
mode: 'all',
|
||||
|
||||
@ -15,7 +15,7 @@ angular.module('HostListDefinition', [])
|
||||
selectTitle: 'Add Existing Hosts',
|
||||
editTitle: 'Hosts',
|
||||
index: true,
|
||||
well: true,
|
||||
well: false,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
@ -31,7 +31,7 @@ angular.module('HostListDefinition', [])
|
||||
actions: {
|
||||
help: {
|
||||
awPopOver: "Select hosts by clicking on each host you wish to add. Add the selected hosts to the group by clicking the <em>Select</em> button.",
|
||||
dataPlacement: 'top',
|
||||
dataPlacement: 'left',
|
||||
dataContainer: '#form-modal .modal-content',
|
||||
icon: "icon-question-sign",
|
||||
mode: 'all',
|
||||
|
||||
@ -1345,7 +1345,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += "<div class=\"col-lg-8\">\n";
|
||||
html += "<div class=\"hosts-well well\">\n";
|
||||
html += SearchWidget({ iterator: form.iterator, template: form, mini: true, size: 'col-md-5 col-lg-5'});
|
||||
html += "<div class=\"col-md-6 col-lg-6\">\n"
|
||||
html += "<div class=\"col-md-7 col-lg-7\">\n"
|
||||
html += "<div class=\"list-actions\">\n";
|
||||
|
||||
// Add actions(s)
|
||||
|
||||
@ -402,7 +402,7 @@ angular.module('ListGenerator', ['GeneratorHelpers'])
|
||||
if (options.mode == 'select' && (options.selectButton == undefined || options.selectButton == true)) {
|
||||
html += "<div class=\"navigation-buttons\">\n";
|
||||
html += " <button class=\"btn btn-sm btn-primary pull-right\" aw-tool-tip=\"Complete your selection\" " +
|
||||
"ng-click=\"finishSelection()\" ng-disabled=\"selected.length == 0\"><i class=\"icon-check\"></i> Select</button>\n";
|
||||
"ng-click=\"finishSelection()\" ng-disabled=\"disableSelectBtn\"><i class=\"icon-check\"></i> Select</button>\n";
|
||||
html += "</div>\n";
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user