From f5c487aab8b9379c4029ba8aa106e3843ad14629 Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Tue, 21 May 2013 11:27:59 -0400 Subject: [PATCH] Inventory hosts now appear in All Hosts folder. User not allowed to add hosts outside of a group (i.e. cannot add to All Hosts group). Fixed job template so that a credential can be removed. --- lib/ui/static/js/controllers/Inventories.js | 17 +++++--- lib/ui/static/js/controllers/JobTemplates.js | 2 +- lib/ui/static/js/helpers/Lookup.js | 2 +- lib/ui/static/js/helpers/inventory.js | 21 +++++++-- lib/ui/static/js/lists/Jobs.js | 8 ++-- lib/ui/static/lib/ansible/directives.js | 45 +++++++++++--------- 6 files changed, 61 insertions(+), 34 deletions(-) diff --git a/lib/ui/static/js/controllers/Inventories.js b/lib/ui/static/js/controllers/Inventories.js index 09f084f097..20004f133c 100644 --- a/lib/ui/static/js/controllers/Inventories.js +++ b/lib/ui/static/js/controllers/Inventories.js @@ -343,7 +343,8 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP }; scope.treeController = function($node) { - if ($($node).attr('type') == 'host') { + var nodeType = $($node).attr('type'); + if (nodeType == 'host') { return { edit: { label: 'Edit Host', @@ -386,7 +387,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP } } } - else if ($($node).attr('type') == 'inventory') { + else if (nodeType == 'inventory') { return { addGroup: { label: 'Add Group', @@ -411,19 +412,22 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP action: function(obj) { LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('id'), title: $(obj).attr('name') }); changePath($location.path() + '/groups/' + $(obj).attr('id') + '/children'); - } + }, + "_disabled": (nodeType == 'all-hosts-group') ? true : false }, addHost: { label: 'Add Host', action: function(obj) { LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('id'), title: $(obj).attr('name') }); changePath($location.path() + '/groups/' + $(obj).attr('id') + '/hosts'); - } + }, + "_disabled": (nodeType == 'all-hosts-group') ? true : false }, edit: { label: 'Edit Group', action: function(obj) { changePath($location.path() + '/groups/' + $(obj).attr('id')); }, - separator_before: true + separator_before: true, + "_disabled": (nodeType == 'all-hosts-group') ? true : false }, delete: { label: 'Delete Group', @@ -454,7 +458,8 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP keyboard: true, show: true }); - } + }, + "_disabled": (nodeType == 'all-hosts-group') ? true : false }, variables: { label: 'Group variables', diff --git a/lib/ui/static/js/controllers/JobTemplates.js b/lib/ui/static/js/controllers/JobTemplates.js index 345dd149d7..717fa47862 100644 --- a/lib/ui/static/js/controllers/JobTemplates.js +++ b/lib/ui/static/js/controllers/JobTemplates.js @@ -475,7 +475,7 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route // Save changes to the parent scope.formSave = function() { - Rest.setUrl(defaultUrl + $routeParams.id); + Rest.setUrl(defaultUrl + $routeParams.id + '/'); var data = {} for (var fld in form.fields) { if (form.fields[fld].type == 'select' && fld != 'playbook') { diff --git a/lib/ui/static/js/helpers/Lookup.js b/lib/ui/static/js/helpers/Lookup.js index 4ab1600b5e..82de899e98 100644 --- a/lib/ui/static/js/helpers/Lookup.js +++ b/lib/ui/static/js/helpers/Lookup.js @@ -28,7 +28,7 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P var postAction = params.postAction //action to perform post user selection - // Show pop-up to select user + // Show pop-up var name = list.iterator.charAt(0).toUpperCase() + list.iterator.substring(1); var defaultUrl = (list.name == 'inventories') ? GetBasePath('inventory') : GetBasePath(list.name); var hdr = (params.hdr) ? params.hdr : 'Select ' + name; diff --git a/lib/ui/static/js/helpers/inventory.js b/lib/ui/static/js/helpers/inventory.js index 2547792de6..53acd0fa02 100644 --- a/lib/ui/static/js/helpers/inventory.js +++ b/lib/ui/static/js/helpers/inventory.js @@ -149,14 +149,14 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi }); }); - // Load inventory top-level hosts + // Load inventory all hosts Rest.setUrl(hosts + '?order_by=name'); Rest.get() .success ( function(data, status, headers, config) { treeData = []; treeData.push({ data: { - title: inventory_name, + title: inventory_name }, attr: { type: 'inventory', @@ -168,8 +168,22 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi state: 'open', children:[] }); + //treeData[0].children.push({ + var all_hosts_node = { + data: { + title: 'All Hosts' + }, + attr: { + type: 'all-hosts-group', + id: 'all-hosts-group', + url: hosts + '?order_by=name', + name: 'All Hosts' + }, + state: 'closed', + children: [] + }; for (var i=0; i < data.results.length; i++ ) { - treeData[0].children.push({ + all_hosts_node.children.push({ data: { title: data.results[i].name, icon: '/' @@ -186,6 +200,7 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi }, }); } + treeData[0].children.push(all_hosts_node); scope.$emit('hostsLoaded'); }) .error ( function(data, status, headers, config) { diff --git a/lib/ui/static/js/lists/Jobs.js b/lib/ui/static/js/lists/Jobs.js index 917a3a100e..bc435a8a5e 100644 --- a/lib/ui/static/js/lists/Jobs.js +++ b/lib/ui/static/js/lists/Jobs.js @@ -24,14 +24,14 @@ angular.module('JobsListDefinition', []) desc: true, searchType: 'int' }, - created: { - label: 'Creation Date', - link: true - }, name: { label: 'Name', link: true, }, + created: { + label: 'Creation Date', + link: true + }, status: { label: 'Status', icon: 'icon-circle', diff --git a/lib/ui/static/lib/ansible/directives.js b/lib/ui/static/lib/ansible/directives.js index df7a1937e6..da22518830 100644 --- a/lib/ui/static/lib/ansible/directives.js +++ b/lib/ui/static/lib/ansible/directives.js @@ -101,25 +101,32 @@ angular.module('AWDirectives', ['RestServices']) require: 'ngModel', link: function(scope, elm, attrs, ctrl) { ctrl.$parsers.unshift( function(viewValue) { - url = elm.attr('data-url'); - url = url.replace(/\:value/,escape(viewValue)); - scope[elm.attr('data-source')] = null; - Rest.setUrl(url); - Rest.get().then( function(data) { - var results = data.data.results; - if (results.length > 0) { - scope[elm.attr('data-source')] = results[0].id; - scope[elm.attr('name')] = results[0].name; - ctrl.$setValidity('required', true); - ctrl.$setValidity('awlookup', true); - return viewValue; - } - else { - ctrl.$setValidity('required', true); - ctrl.$setValidity('awlookup', false); - return undefined; - } - }); + if (viewValue !== '') { + url = elm.attr('data-url'); + url = url.replace(/\:value/,escape(viewValue)); + scope[elm.attr('data-source')] = null; + Rest.setUrl(url); + Rest.get().then( function(data) { + var results = data.data.results; + if (results.length > 0) { + scope[elm.attr('data-source')] = results[0].id; + scope[elm.attr('name')] = results[0].name; + ctrl.$setValidity('required', true); + ctrl.$setValidity('awlookup', true); + return viewValue; + } + else { + ctrl.$setValidity('required', true); + ctrl.$setValidity('awlookup', false); + return undefined; + } + }); + + } + else { + ctrl.$setValidity('awlookup', true); + scope[elm.attr('data-source')] = null; + } }) } }