mirror of
https://github.com/ansible/awx.git
synced 2026-05-24 00:57:48 -02:30
AC-502 Finally figured out how to fix the awToolTip directive so that it watches a variable for tool tip text changes and updates the tool tip text. Pass in the variable name using badgeTipWatch. Used on home/hosts page and inventory/N/hosts page when toggling the enabled flag.
This commit is contained in:
@@ -116,7 +116,7 @@ HomeGroups.$inject = [ '$location', '$routeParams', 'HomeGroupList', 'GenerateLi
|
|||||||
|
|
||||||
|
|
||||||
function HomeHosts ($location, $routeParams, HomeHostList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
function HomeHosts ($location, $routeParams, HomeHostList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
||||||
GetBasePath, SearchInit, PaginateInit, FormatDate, SetHostStatus) {
|
GetBasePath, SearchInit, PaginateInit, FormatDate, SetHostStatus, 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.
|
||||||
@@ -153,12 +153,12 @@ function HomeHosts ($location, $routeParams, HomeHostList, GenerateList, Process
|
|||||||
|
|
||||||
LoadBreadCrumbs();
|
LoadBreadCrumbs();
|
||||||
|
|
||||||
scope.viewUpdateStatus = function(id) { ViewUpdateStatus({ scope: scope, group_id: id }) };
|
scope.toggle_host_enabled = function(id, sources) { ToggleHostEnabled(id, sources, scope); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HomeGroups.$inject = [ '$location', '$routeParams', 'HomeGroupList', 'GenerateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller',
|
HomeGroups.$inject = [ '$location', '$routeParams', 'HomeGroupList', 'GenerateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller',
|
||||||
'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'HostsStatusMsg', 'UpdateStatusMsg', 'ViewUpdateStatus',
|
'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'HostsStatusMsg', 'UpdateStatusMsg', 'ViewUpdateStatus',
|
||||||
'SetHostStatus'
|
'SetHostStatus', 'ToggleHostEnabled'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -13,7 +13,8 @@ function InventoryHosts ($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
||||||
GetBasePath, HostsList, HostsAdd, HostsEdit, HostsDelete,
|
GetBasePath, HostsList, HostsAdd, HostsEdit, HostsDelete,
|
||||||
HostsReload, BuildTree, EditHostGroups, InventoryHostsHelp, HelpDialog, Wait)
|
HostsReload, BuildTree, EditHostGroups, InventoryHostsHelp, HelpDialog, Wait,
|
||||||
|
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.
|
||||||
@@ -76,38 +77,7 @@ function InventoryHosts ($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
$location.url('/jobs/?job_host_summaries__host=' + id);
|
$location.url('/jobs/?job_host_summaries__host=' + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.toggle_host_enabled = function(id, sources) {
|
scope.toggle_host_enabled = function(id, sources) { ToggleHostEnabled(id, sources, scope); }
|
||||||
var host;
|
|
||||||
var i;
|
|
||||||
if (!sources) {
|
|
||||||
// Host is not managed by an external source
|
|
||||||
Wait('start');
|
|
||||||
for (i=0; i < scope.hosts.length; i++) {
|
|
||||||
if (scope.hosts[i].id == id) {
|
|
||||||
scope.hosts[i].enabled = (scope.hosts[i].enabled) ? false : true;
|
|
||||||
scope.hosts[i].enabled_flag = scope.hosts[i].enabled;
|
|
||||||
host = scope.hosts[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rest.setUrl(GetBasePath('hosts') + id + '/');
|
|
||||||
Rest.put(host)
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
Wait('stop');
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
scope.hosts[i].enabled = (scope.hosts[i].enabled) ? false : true;
|
|
||||||
scope.hosts[i].enabled_flag = scope.hosts[i].enabled;
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.allHostSummaries = function(id, name, inventory_id) {
|
scope.allHostSummaries = function(id, name, inventory_id) {
|
||||||
LoadBreadCrumbs({ path: '/hosts/' + id, title: name, altPath: '/inventories/' + inventory_id + '/hosts',
|
LoadBreadCrumbs({ path: '/hosts/' + id, title: name, altPath: '/inventories/' + inventory_id + '/hosts',
|
||||||
@@ -180,6 +150,7 @@ InventoryHosts.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$lo
|
|||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
|
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
|
||||||
'GetBasePath', 'HostsList', 'HostsAdd', 'HostsEdit', 'HostsDelete',
|
'GetBasePath', 'HostsList', 'HostsAdd', 'HostsEdit', 'HostsDelete',
|
||||||
'HostsReload', 'BuildTree', 'EditHostGroups', 'InventoryHostsHelp', 'HelpDialog', 'Wait'
|
'HostsReload', 'BuildTree', 'EditHostGroups', 'InventoryHostsHelp', 'HelpDialog', 'Wait',
|
||||||
|
'ToggleHostEnabled'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res
|
|||||||
SearchInit({ scope: scope, set: 'inventories', list: list, url: defaultUrl });
|
SearchInit({ scope: scope, set: 'inventories', list: list, url: defaultUrl });
|
||||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||||
|
|
||||||
|
if ($routeParams['name']) {
|
||||||
|
scope[InventoryList.iterator + 'InputDisable'] = false;
|
||||||
|
scope[InventoryList.iterator + 'SearchValue'] = $routeParams['name'];
|
||||||
|
scope[InventoryList.iterator + 'SearchField'] = 'name';
|
||||||
|
scope[InventoryList.iterator + 'SearchFieldLabel'] = InventoryList.fields['name'].label;
|
||||||
|
scope[InventoryList.iterator + 'SearchSelectValue'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
if ($routeParams['has_active_failures']) {
|
if ($routeParams['has_active_failures']) {
|
||||||
//scope.resetSearch(InventoryHostsForm.iterator);
|
//scope.resetSearch(InventoryHostsForm.iterator);
|
||||||
scope[InventoryList.iterator + 'InputDisable'] = true;
|
scope[InventoryList.iterator + 'InputDisable'] = true;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ angular.module('InventoryHostsFormDefinition', [])
|
|||||||
badgePlacement: 'left',
|
badgePlacement: 'left',
|
||||||
badgeToolTip: "\{\{ host.enabledToolTip \}\}",
|
badgeToolTip: "\{\{ host.enabledToolTip \}\}",
|
||||||
badgeTipPlacement: "top",
|
badgeTipPlacement: "top",
|
||||||
|
badgeTipWatch: "host.enabledToolTip",
|
||||||
ngClick: "toggle_host_enabled(\{\{ host.id \}\}, \{\{ host.has_inventory_sources \}\})",
|
ngClick: "toggle_host_enabled(\{\{ host.id \}\}, \{\{ host.has_inventory_sources \}\})",
|
||||||
searchable: false,
|
searchable: false,
|
||||||
showValue: false
|
showValue: false
|
||||||
|
|||||||
@@ -49,6 +49,55 @@ 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;
|
||||||
|
|
||||||
|
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.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sources) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rest.setUrl(GetBasePath('hosts') + id + '/');
|
||||||
|
Rest.put(scope['hosts'][i])
|
||||||
|
.success( function(data, status, headers, config) {
|
||||||
|
Wait('stop');
|
||||||
|
})
|
||||||
|
.error( function(data, status, headers, config) {
|
||||||
|
// Flip the enabled flag back
|
||||||
|
setMsg();
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}])
|
||||||
|
|
||||||
.factory('HostsList', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
|
.factory('HostsList', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
|
||||||
'Prompt', 'SearchInit', 'PaginateInit', 'ProcessErrors', 'GetBasePath', 'HostsAdd', 'HostsReload',
|
'Prompt', 'SearchInit', 'PaginateInit', 'ProcessErrors', 'GetBasePath', 'HostsAdd', 'HostsReload',
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ angular.module('HomeHostListDefinition', [])
|
|||||||
selectTitle: 'Add Existing Hosts',
|
selectTitle: 'Add Existing Hosts',
|
||||||
editTitle: 'Hosts',
|
editTitle: 'Hosts',
|
||||||
index: true,
|
index: true,
|
||||||
|
hover: true,
|
||||||
well: true,
|
well: true,
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
@@ -30,7 +31,7 @@ angular.module('HomeHostListDefinition', [])
|
|||||||
sourceModel: 'inventory',
|
sourceModel: 'inventory',
|
||||||
sourceField: 'name',
|
sourceField: 'name',
|
||||||
columnClass: 'col-lg-3 col-md3 col-sm-2',
|
columnClass: 'col-lg-3 col-md3 col-sm-2',
|
||||||
linkTo: "\{\{ '/#/inventories/' + group.inventory \}\}"
|
linkTo: "\{\{ '/#/inventories/?name=' + host.summary_fields.inventory.name \}\}"
|
||||||
},
|
},
|
||||||
active_failures: {
|
active_failures: {
|
||||||
label: 'Job Status',
|
label: 'Job Status',
|
||||||
@@ -51,17 +52,11 @@ angular.module('HomeHostListDefinition', [])
|
|||||||
badgePlacement: 'left',
|
badgePlacement: 'left',
|
||||||
badgeToolTip: "\{\{ host.enabledToolTip \}\}",
|
badgeToolTip: "\{\{ host.enabledToolTip \}\}",
|
||||||
badgeTipPlacement: "top",
|
badgeTipPlacement: "top",
|
||||||
|
badgeTipWatch: "host.enabledToolTip",
|
||||||
ngClick: "toggle_host_enabled(\{\{ host.id \}\}, \{\{ host.has_inventory_sources \}\})",
|
ngClick: "toggle_host_enabled(\{\{ host.id \}\}, \{\{ host.has_inventory_sources \}\})",
|
||||||
searchable: false,
|
searchable: false,
|
||||||
showValue: false
|
showValue: false
|
||||||
},
|
},
|
||||||
groups: {
|
|
||||||
label: 'Groups',
|
|
||||||
searchable: true,
|
|
||||||
sourceModel: 'groups',
|
|
||||||
sourceField: 'name',
|
|
||||||
nosort: true
|
|
||||||
},
|
|
||||||
enabled: {
|
enabled: {
|
||||||
label: 'Disabled?',
|
label: 'Disabled?',
|
||||||
searchSingleValue: true,
|
searchSingleValue: true,
|
||||||
|
|||||||
@@ -234,6 +234,17 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Hos
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
$(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) {
|
||||||
|
// Add 'data-tip-watch=<variable to watch>' and we'll watch for changes
|
||||||
|
scope.$watch(attrs.tipWatch, function(newVal, oldVal) {
|
||||||
|
if (newVal !== oldVal) {
|
||||||
|
// Where did fixTitle come frome?:
|
||||||
|
// http://stackoverflow.com/questions/9501921/change-twitter-bootstrap-tooltip-content-on-click
|
||||||
|
$(element).tooltip('hide').attr('data-original-title', newVal).tooltip('fixTitle')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ angular.module('GeneratorHelpers', ['GeneratorHelpers'])
|
|||||||
html += (field.ngClick) ? "ng-click=\"" + field.ngClick + "\" " : "";
|
html += (field.ngClick) ? "ng-click=\"" + field.ngClick + "\" " : "";
|
||||||
html += " aw-tool-tip=\"" + field.badgeToolTip + "\"";
|
html += " aw-tool-tip=\"" + field.badgeToolTip + "\"";
|
||||||
html += (field.badgeTipPlacement) ? " data-placement=\"" + field.badgeTipPlacement + "\"" : "";
|
html += (field.badgeTipPlacement) ? " data-placement=\"" + field.badgeTipPlacement + "\"" : "";
|
||||||
|
html += (field.badgeTipWatch) ? " data-tip-watch=\"" + field.badgeTipWatch + "\"" : "";
|
||||||
html += (field.badgeShow) ? " ng-show=\"" + field.badgeShow + "\"" : "";
|
html += (field.badgeShow) ? " ng-show=\"" + field.badgeShow + "\"" : "";
|
||||||
html += ">";
|
html += ">";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user