From 7434bb8a9ed94131fcb67472ecd9254aba7dfd4c Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Tue, 28 Jan 2014 15:57:00 -0500 Subject: [PATCH] AC-985 edit now edit's inventory properties via dialog- using the same edit code already written for the wrench button on inventory->groups/hosts page. --- awx/ui/static/js/controllers/Inventories.js | 16 ++++++- awx/ui/static/js/helpers/Groups.js | 1 - awx/ui/static/js/helpers/inventory.js | 48 +++++++++++++++++---- awx/ui/static/js/helpers/search.js | 32 ++++++++++---- awx/ui/static/js/lists/Inventories.js | 2 +- awx/ui/static/js/widgets/Stream.js | 3 +- 6 files changed, 80 insertions(+), 22 deletions(-) diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index 6547d9565c..773f340263 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -12,7 +12,7 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, InventoryList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, - ClearScope, ProcessErrors, GetBasePath, Wait, Stream) + ClearScope, ProcessErrors, GetBasePath, Wait, Stream, EditInventoryProperties) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -128,9 +128,21 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res } }); + + if (scope.removeRefreshInventories) { + scope.removeRefreshInventories(); + } + scope.removeRefreshInventories = scope.$on('RefreshInventories', function() { + // Reflect changes after inventory properties edit completes + scope.search(list.iterator); + }); scope.showActivity = function() { Stream({ scope: scope }); } + scope.editInventoryProperties = function(inventory_id) { + EditInventoryProperties({ scope: scope, inventory_id: inventory_id }); + } + scope.addInventory = function() { $location.path($location.path() + '/add'); } @@ -186,7 +198,7 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res InventoriesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'InventoryList', 'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors', - 'GetBasePath', 'Wait', 'Stream' ]; + 'GetBasePath', 'Wait', 'Stream', 'EditInventoryProperties']; function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm, diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index 4624e1eb89..bc43f150ce 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -27,7 +27,6 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' Rest.options() .success( function(data, status, headers, config) { var choices = data.actions.GET.source.choices - console.log(choices); for (var i=0; i < choices.length; i++) { if (choices[i][0] !== 'file') { scope[variable].push({ diff --git a/awx/ui/static/js/helpers/inventory.js b/awx/ui/static/js/helpers/inventory.js index 30258b9c05..ce5be78385 100644 --- a/awx/ui/static/js/helpers/inventory.js +++ b/awx/ui/static/js/helpers/inventory.js @@ -9,7 +9,7 @@ */ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition', 'ListGenerator', 'AuthService', - 'InventoryHelper', 'InventoryFormDefinition', 'ParseHelper' + 'InventoryHelper', 'InventoryFormDefinition', 'ParseHelper', 'SearchHelper' ]) .factory('SaveInventory', ['InventoryForm', 'Rest', 'Alert', 'ProcessErrors', 'LookUpInit', 'OrganizationList', @@ -20,6 +20,7 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi // Save inventory property modifications var scope = params.scope; + var form = InventoryForm; var defaultUrl=GetBasePath('inventory'); @@ -71,7 +72,6 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi } }) .error( function(data, status, headers, config) { - Wait('stop'); ProcessErrors(scope, data, status, form, { hdr: 'Error!', msg: 'Failed to update inventory. POST returned status: ' + status }); }); @@ -85,9 +85,9 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi .factory('EditInventoryProperties', ['InventoryForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LookUpInit', 'OrganizationList', - 'GetBasePath', 'ParseTypeChange', 'SaveInventory', 'Wait', + 'GetBasePath', 'ParseTypeChange', 'SaveInventory', 'Wait', 'Store', 'SearchInit', function(InventoryForm, GenerateForm, Rest, Alert, ProcessErrors, LookUpInit, OrganizationList, GetBasePath, ParseTypeChange, SaveInventory, - Wait) { + Wait, Store, SearchInit) { return function(params) { var parent_scope = params.scope @@ -98,6 +98,9 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi var defaultUrl=GetBasePath('inventory'); var master = {}; + // Hang onto current search params + var PreviousSearchParams = Store('CurrentSearchParams'); + form.well = false; //form.formLabelSize = 'col-lg-3'; //form.formFieldSize = 'col-lg-9'; @@ -116,8 +119,6 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi scope.formModalInfo = false; scope.formModalHeader = 'Inventory Properties'; - $('#form-modal .btn-success').removeClass('btn-none').addClass('btn-success'); - Wait('start'); Rest.setUrl(GetBasePath('inventory') + inventory_id + '/'); Rest.get() @@ -170,7 +171,6 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi }) .error( function(data, status, headers, config) { - Wait('stop'); ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get inventory: ' + inventory_id + '. GET returned: ' + status }); }); @@ -179,11 +179,41 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi scope.removeInventorySaved(); } scope.removeInventorySaved = scope.$on('InventorySaved', function() { - $('#form-modal').modal('hide'); + $('#form-modal').modal('hide'); + // Restore prior search state + if (scope.searchCleanp) { + scope.searchCleanup(); + } + SearchInit({ + scope: parent_scope, + set: PreviousSearchParams.set, + list: PreviousSearchParams.list, + url: PreviousSearchParams.defaultUrl, + iterator: PreviousSearchParams.iterator, + sort_order: PreviousSearchParams.sort_order, + setWidgets: false + }); + parent_scope.$emit('RefreshInventories'); }); + scope.cancelModal = function() { + // Restore prior search state + if (scope.searchCleanp) { + scope.searchCleanup(); + } + SearchInit({ + scope: parent_scope, + set: PreviousSearchParams.set, + list: PreviousSearchParams.list, + url: PreviousSearchParams.defaultUrl, + iterator: PreviousSearchParams.iterator, + sort_order: PreviousSearchParams.sort_order, + setWidgets: false + }); + } + scope.formModalAction = function() { - scope.inventory_id = inventory_id; + parent_scope.inventory_id = inventory_id; parent_scope.inventory_name = scope.inventory_name; SaveInventory({ scope: scope }); } diff --git a/awx/ui/static/js/helpers/search.js b/awx/ui/static/js/helpers/search.js index 422636cf2f..3d4116781d 100644 --- a/awx/ui/static/js/helpers/search.js +++ b/awx/ui/static/js/helpers/search.js @@ -27,14 +27,15 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) var list = params.list; var iterator = (params.iterator) ? params.iterator : list.iterator; var setWidgets = (params.setWidgets == false) ? false : true; - - var sort_order, expected_objects=0, found_objects=0; + var sort_order = params.sort_order || ''; + var expected_objects=0, found_objects=0; var params = { set: set, defaultUrl: defaultUrl, list: list, - iterator: iterator + iterator: iterator, + sort_order: sort_order }; Store('CurrentSearchParams', params); // Save in case Activity Stream widget needs to restore @@ -136,6 +137,17 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) } } + var params = { + set: set, + defaultUrl: defaultUrl, + list: list, + iterator: iterator, + sort_order: sort_order + }; + + Store('CurrentSearchParams', params); // Save in case Activity Stream widget needs to restore + + // Functions to handle search widget changes scope.setSearchField = function(iterator, fld, label, widget) { @@ -237,7 +249,8 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) // scope[iterator + 'Loading'] = (load == undefined || load == true) ? true : false; var url = defaultUrl; - + var connect; + //finalize and execute the query scope[iterator + 'Page'] = (page) ? parseInt(page) - 1 : 0; if (scope[iterator + 'SearchParams']) { @@ -248,14 +261,17 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) url += '&' + scope[iterator + 'SearchParams']; } } - url = url.replace(/\&\&/,'&'); - url += (scope[iterator + '_page_size']) ? '&page_size=' + scope[iterator + '_page_size'] : ""; + connect = (/\/$/.test(url)) ? '?' : '&'; + url += (scope[iterator + '_page_size']) ? connect + 'page_size=' + scope[iterator + '_page_size'] : ""; if (page) { - url += '&page=' + page; + connect = (/\/$/.test(url)) ? '?' : '&'; + url += connect + 'page=' + page; } if (scope[iterator + 'ExtraParms']) { - url += scope[iterator + 'ExtraParms']; + connect = (/\/$/.test(url)) ? '?' : '&'; + url += connect + scope[iterator + 'ExtraParms']; } + url = url.replace(/\&\&/,'&'); Refresh({ scope: scope, set: set, iterator: iterator, url: url }); }); diff --git a/awx/ui/static/js/lists/Inventories.js b/awx/ui/static/js/lists/Inventories.js index d33a32ccf5..d089c7194e 100644 --- a/awx/ui/static/js/lists/Inventories.js +++ b/awx/ui/static/js/lists/Inventories.js @@ -84,7 +84,7 @@ angular.module('InventoriesListDefinition', []) }, edit: { label: 'Edit', - ngClick: "editInventory(\{\{ inventory.id \}\})", + ngClick: 'editInventoryProperties(inventory.id)', awToolTip: 'Edit inventory', dataPlacement: 'top' }, diff --git a/awx/ui/static/js/widgets/Stream.js b/awx/ui/static/js/widgets/Stream.js index 5fa61f73f2..d13d76a525 100644 --- a/awx/ui/static/js/widgets/Stream.js +++ b/awx/ui/static/js/widgets/Stream.js @@ -267,7 +267,7 @@ angular.module('StreamWidget', ['RestServices', 'Utilities', 'StreamListDefiniti var parent_scope = params.scope; // Hang onto current search params - var PreviousSearchParams = Store('SearchInitParams'); + var PreviousSearchParams = Store('CurrentSearchParams'); // pass in an inventory name to fix breadcrumb display var inventory_name = (params) ? params.inventory_name : null; @@ -340,6 +340,7 @@ angular.module('StreamWidget', ['RestServices', 'Utilities', 'StreamListDefiniti list: PreviousSearchParams.list, url: PreviousSearchParams.defaultUrl, iterator: PreviousSearchParams.iterator, + sort_order: PreviousSearchParams.sort_order, setWidgets: false }); } if (inUrl) {