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