diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index c635386b66..ee212514f7 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -319,7 +319,7 @@ InventoriesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$lo function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateList, ClearScope, InventoryGroups, InventoryHosts, BuildTree, Wait, GetSyncStatusMsg, InjectHosts, HostsReload, GroupsAdd, GroupsEdit, GroupsDelete, Breadcrumbs, LoadBreadCrumbs, Empty, Rest, ProcessErrors, InventoryUpdate, Alert, ToggleChildren, ViewUpdateStatus, GroupsCancelUpdate, Find, - HostsCreate, EditInventoryProperties, HostsEdit, HostsDelete) + HostsCreate, EditInventoryProperties, HostsEdit, HostsDelete, ToggleHostEnabled) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -499,6 +499,10 @@ function InventoriesEdit ($scope, $location, $routeParams, $compile, GenerateLis HostsDelete({ scope: $scope, host_id: host_id, host_name: host_name }); } + $scope.toggleHostEnabled = function(host_id, external_source) { + ToggleHostEnabled({ scope: $scope, host_id: host_id, external_source: external_source }); + } + //Load tree data for the first time BuildTree({ scope: $scope, inventory_id: $scope.inventory_id, refresh: false }); @@ -508,6 +512,6 @@ InventoriesEdit.$inject = [ '$scope', '$location', '$routeParams', '$compile', ' 'BuildTree', 'Wait', 'GetSyncStatusMsg', 'InjectHosts', 'HostsReload', 'GroupsAdd', 'GroupsEdit', 'GroupsDelete', 'Breadcrumbs', 'LoadBreadCrumbs', 'Empty', 'Rest', 'ProcessErrors', 'InventoryUpdate', 'Alert', 'ToggleChildren', 'ViewUpdateStatus', 'GroupsCancelUpdate', 'Find', 'HostsCreate', 'EditInventoryProperties', 'HostsEdit', - 'HostsDelete' + 'HostsDelete', 'ToggleHostEnabled' ]; diff --git a/awx/ui/static/js/helpers/Hosts.js b/awx/ui/static/js/helpers/Hosts.js index 1094c73935..921257b4ba 100644 --- a/awx/ui/static/js/helpers/Hosts.js +++ b/awx/ui/static/js/helpers/Hosts.js @@ -14,8 +14,21 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H ]) - .factory('HostsReload', [ 'Empty', 'InventoryHosts', 'GetBasePath', 'SearchInit', 'PaginateInit', 'Wait', - function(Empty, InventoryHosts, GetBasePath, SearchInit, PaginateInit, Wait) { + .factory('SetEnabledMsg', [ function() { + return function(host) { + if (host.has_inventory_sources) { + // Inventory sync managed, so not clickable + host.enabledToolTip = (host.enabled) ? 'Host is available' : 'Host is not available'; + } + else { + // Clickable + host.enabledToolTip = (host.enabled) ? 'Host is available. Click to toggle.' : 'Host is not available. Click to toggle.'; + } + } + }]) + + .factory('HostsReload', [ 'Empty', 'InventoryHosts', 'GetBasePath', 'SearchInit', 'PaginateInit', 'Wait', 'SetEnabledMsg', + function(Empty, InventoryHosts, GetBasePath, SearchInit, PaginateInit, Wait, SetEnabledMsg) { return function(params) { var scope = params.scope; @@ -32,6 +45,10 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H scope.removePostRefresh(); } scope.removePostRefresh = scope.$on('PostRefresh', function(e) { + for (var i=0; i < scope.hosts.length; i++) { + //Set tooltip for host enabled flag + SetEnabledMsg(scope.hosts[i]); + } Wait('stop'); scope.$emit('HostReloadComplete'); }); @@ -94,53 +111,46 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H } }]) - - .factory('ToggleHostEnabled', [ 'GetBasePath', 'Rest', 'Wait', 'ProcessErrors', 'Alert', - function(GetBasePath, Rest, Wait, ProcessErrors, Alert) { - return function(id, sources, scope) { - var i; + + .factory('ToggleHostEnabled', [ 'GetBasePath', 'Rest', 'Wait', 'ProcessErrors', 'Alert', 'Find', 'SetEnabledMsg', + function(GetBasePath, Rest, Wait, ProcessErrors, Alert, Find, SetEnabledMsg) { + return function(params) { - function setMsg() { - scope['hosts'][i].enabled = (scope['hosts'][i].enabled) ? false : true; - scope['hosts'][i].enabled_flag = scope['hosts'][i].enabled; - if (scope['hosts'][i].has_inventory_sources) { - // Inventory sync managed, so not clickable - scope['hosts'][i].enabledToolTip = (scope['hosts'][i].enabled) ? 'Ready! Availabe to running jobs.' : - 'Out to lunch! This host is not available to running jobs.'; - } - else { - // Clickable - scope['hosts'][i].enabledToolTip = (scope['hosts'][i].enabled) ? 'Ready! Available to running jobs. Click to toggle.' : - 'Out to lunch! Host not available to running jobs. Click to toggle.'; - } + var id = params.host_id; + var external_source = params.external_source; + var scope = params.scope + + var host; + + function setMsg(host) { + host.enabled = (host.enabled) ? false : true; + host.enabled_flag = host.enabled; + SetEnabledMsg(host); } - if (!sources) { + if (!external_source) { // Host is not managed by an external source Wait('start'); - for (i=0; i < scope.hosts.length; i++) { - if (scope.hosts[i].id == id) { - //host = scope.hosts[i]; - setMsg(); - break; - } - } + host = Find({ list: scope.hosts, key: 'id', val: id }); + setMsg(host); + Rest.setUrl(GetBasePath('hosts') + id + '/'); - Rest.put(scope['hosts'][i]) + Rest.put(host) .success( function(data, status, headers, config) { Wait('stop'); }) .error( function(data, status, headers, config) { // Flip the enabled flag back - setMsg(); + setMsg(host); Wait('stop'); ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to update host. PUT returned status: ' + status }); }); } else { - Alert('External Host', 'This host is part of an external inventory. It can only be enabled or disabled by the ' + - 'inventory sync process.', 'alert-info'); + Alert('Action Not Allowed', 'This host is part of a cloud inventory. It can only be disabled in the cloud.' + + ' After disabling it, run an inventory sync to see the new status reflected here.', + 'alert-info'); } } }]) diff --git a/awx/ui/static/js/lists/InventoryHosts.js b/awx/ui/static/js/lists/InventoryHosts.js index 225b0ea799..0809886692 100644 --- a/awx/ui/static/js/lists/InventoryHosts.js +++ b/awx/ui/static/js/lists/InventoryHosts.js @@ -66,6 +66,7 @@ angular.module('InventoryHostsDefinition', []) iconClass: "\{\{ 'fa icon-enabled-' + host.enabled \}\}", dataPlacement: 'top', awToolTip: "\{\{ host.enabledToolTip \}\}", + dataTipWatch: "host.enabledToolTip", ngClick: "toggleHostEnabled(\{\{ host.id \}\}, \{\{ host.has_inventory_sources \}\})" }, active_failures: { diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index c99676f731..370461f299 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -256,7 +256,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService']) $(element).tooltip({ placement: placement, delay: delay, html: true, title: attrs.awToolTip, container: 'body' }); if (attrs.tipWatch) { - // Add 'data-tip-watch=' and we'll watch for changes + // Add dataTipWatch: 'variable_name' scope.$watch(attrs.tipWatch, function(newVal, oldVal) { if (newVal !== oldVal) { // Where did fixTitle come frome?: diff --git a/awx/ui/static/lib/ansible/generator-helpers.js b/awx/ui/static/lib/ansible/generator-helpers.js index 085976f177..2a8caf82b0 100644 --- a/awx/ui/static/lib/ansible/generator-helpers.js +++ b/awx/ui/static/lib/ansible/generator-helpers.js @@ -62,6 +62,9 @@ angular.module('GeneratorHelpers', ['GeneratorHelpers']) case 'awTipPlacement': result = "aw-tip-placement=\"" + value + "\" "; break; + case 'dataTipWatch': + result = "data-tip-watch=\"" + value + "\" "; + break; case 'columnShow': result = "ng-show=\"" + value + "\" "; break; @@ -534,6 +537,9 @@ angular.module('GeneratorHelpers', ['GeneratorHelpers']) if (field.dataPlacement) { html += Attr(field,'dataPlacement'); } + if (field.dataTipWatch) { + html += Attr(field,'dataTipWatch'); + } } html += (cap) ? ">" : ""; }