More work on home/groups and home/hosts status icons.

This commit is contained in:
Chris Houseknecht
2014-04-04 18:03:59 -04:00
parent b222fc02ee
commit 06db369757
6 changed files with 138 additions and 89 deletions

View File

@@ -122,7 +122,7 @@ Home.$inject = ['$scope', '$compile', '$routeParams', '$rootScope', '$location',
]; ];
function HomeGroups($filter, $compile, $location, $routeParams, LogViewer, HomeGroupList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, function HomeGroups($scope, $filter, $compile, $location, $routeParams, LogViewer, HomeGroupList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
GetBasePath, SearchInit, PaginateInit, FormatDate, GetHostsStatusMsg, GetSyncStatusMsg, ViewUpdateStatus, Stream, GroupsEdit, Wait, GetBasePath, SearchInit, PaginateInit, FormatDate, GetHostsStatusMsg, GetSyncStatusMsg, ViewUpdateStatus, Stream, GroupsEdit, Wait,
Alert, Rest, Empty, InventoryUpdate, Find) { Alert, Rest, Empty, InventoryUpdate, Find) {
@@ -132,9 +132,12 @@ function HomeGroups($filter, $compile, $location, $routeParams, LogViewer, HomeG
var generator = GenerateList, var generator = GenerateList,
list = HomeGroupList, list = HomeGroupList,
defaultUrl = GetBasePath('groups'), defaultUrl = GetBasePath('groups'),
scope = generator.inject(list, { mode: 'edit' }), scope = $scope,
modal_scope = $scope.$new(),
opt; opt;
generator.inject(list, { mode: 'edit', scope: scope });
function ellipsis(a) { function ellipsis(a) {
if (a.length > 20) { if (a.length > 20) {
return a.substr(0,20) + '...'; return a.substr(0,20) + '...';
@@ -285,13 +288,21 @@ function HomeGroups($filter, $compile, $location, $routeParams, LogViewer, HomeG
}); });
}; };
if (modal_scope.removeHomeGroupsRefresh) {
modal_scope.removeHomeGroupsRefresh();
}
modal_scope.removeHomeGroupsRefresh = scope.$on('HomeGroupsRefresh', function() {
scope.search(list.iterator);
});
scope.editGroup = function (group_id, inventory_id) { scope.editGroup = function (group_id, inventory_id) {
GroupsEdit({ GroupsEdit({
scope: scope, scope: modal_scope,
group_id: group_id, group_id: group_id,
inventory_id: inventory_id, inventory_id: inventory_id,
groups_reload: false, groups_reload: false,
mode: 'edit' mode: 'edit',
callback: 'HomeGroupsRefresh'
}); });
}; };
@@ -440,13 +451,21 @@ function HomeGroups($filter, $compile, $location, $routeParams, LogViewer, HomeG
Rest.get() Rest.get()
.success( function(data) { .success( function(data) {
data.results.forEach(function(host) { data.results.forEach(function(host) {
host.summary_fields.recent_jobs.every(function(job) { var found = false;
if (job.id === host.last_job) { jobs.every(function(existing_job) {
jobs.push(job); if (host.last_job === existing_job.id) {
found = true;
return false; return false;
} }
return true; return true;
}); });
if (!found) {
jobs.push({
id: host.last_job,
status: host.summary_fields.last_job.status,
name: host.summary_fields.last_job.name
});
}
}); });
scope.$emit('HostSummaryReady', event, jobs); scope.$emit('HostSummaryReady', event, jobs);
}) })
@@ -468,13 +487,13 @@ function HomeGroups($filter, $compile, $location, $routeParams, LogViewer, HomeG
} }
HomeGroups.$inject = ['$filter', '$compile', '$location', '$routeParams', 'LogViewer', 'HomeGroupList', 'GenerateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', HomeGroups.$inject = ['$scope', '$filter', '$compile', '$location', '$routeParams', 'LogViewer', 'HomeGroupList', 'GenerateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller',
'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'GetHostsStatusMsg', 'GetSyncStatusMsg', 'ViewUpdateStatus', 'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'GetHostsStatusMsg', 'GetSyncStatusMsg', 'ViewUpdateStatus',
'Stream', 'GroupsEdit', 'Wait', 'Alert', 'Rest', 'Empty', 'InventoryUpdate', 'Find' 'Stream', 'GroupsEdit', 'Wait', 'Alert', 'Rest', 'Empty', 'InventoryUpdate', 'Find'
]; ];
function HomeHosts($location, $routeParams, HomeHostList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, function HomeHosts($scope, $location, $routeParams, HomeHostList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
GetBasePath, SearchInit, PaginateInit, FormatDate, SetStatus, ToggleHostEnabled, HostsEdit, Stream, Find, ShowJobSummary) { GetBasePath, SearchInit, PaginateInit, FormatDate, SetStatus, ToggleHostEnabled, HostsEdit, Stream, Find, ShowJobSummary) {
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
@@ -482,95 +501,98 @@ function HomeHosts($location, $routeParams, HomeHostList, GenerateList, ProcessE
var generator = GenerateList, var generator = GenerateList,
list = HomeHostList, list = HomeHostList,
defaultUrl = GetBasePath('hosts'), defaultUrl = GetBasePath('hosts');
scope = generator.inject(list, { mode: 'edit' });
if (scope.removePostRefresh) { generator.inject(list, { mode: 'edit', scope: $scope });
scope.removePostRefresh();
if ($scope.removePostRefresh) {
$scope.removePostRefresh();
} }
scope.removePostRefresh = scope.$on('PostRefresh', function () { $scope.removePostRefresh = $scope.$on('PostRefresh', function () {
for (var i = 0; i < scope.hosts.length; i++) { for (var i = 0; i < $scope.hosts.length; i++) {
scope.hosts[i].inventory_name = scope.hosts[i].summary_fields.inventory.name; $scope.hosts[i].inventory_name = $scope.hosts[i].summary_fields.inventory.name;
//SetHostStatus(scope['hosts'][i]); //SetHostStatus($scope['hosts'][i]);
SetStatus({ SetStatus({
scope: scope, $scope: $scope,
host: scope.hosts[i] host: $scope.hosts[i]
}); });
} }
}); });
SearchInit({ SearchInit({
scope: scope, scope: $scope,
set: 'hosts', set: 'hosts',
list: list, list: list,
url: defaultUrl url: defaultUrl
}); });
PaginateInit({ PaginateInit({
scope: scope, scope: $scope,
list: list, list: list,
url: defaultUrl url: defaultUrl
}); });
// Process search params // Process search params
if ($routeParams.name) { if ($routeParams.name) {
scope[HomeHostList.iterator + 'InputDisable'] = false; $scope[HomeHostList.iterator + 'InputDisable'] = false;
scope[HomeHostList.iterator + 'SearchValue'] = $routeParams.name; $scope[HomeHostList.iterator + 'SearchValue'] = $routeParams.name;
scope[HomeHostList.iterator + 'SearchField'] = 'name'; $scope[HomeHostList.iterator + 'SearchField'] = 'name';
scope[HomeHostList.iterator + 'SearchFieldLabel'] = list.fields.name.label; $scope[HomeHostList.iterator + 'SearchFieldLabel'] = list.fields.name.label;
} }
if ($routeParams.id) { if ($routeParams.id) {
scope[HomeHostList.iterator + 'InputDisable'] = false; $scope[HomeHostList.iterator + 'InputDisable'] = false;
scope[HomeHostList.iterator + 'SearchValue'] = $routeParams.id; $scope[HomeHostList.iterator + 'SearchValue'] = $routeParams.id;
scope[HomeHostList.iterator + 'SearchField'] = 'id'; $scope[HomeHostList.iterator + 'SearchField'] = 'id';
scope[HomeHostList.iterator + 'SearchFieldLabel'] = list.fields.id.label; $scope[HomeHostList.iterator + 'SearchFieldLabel'] = list.fields.id.label;
scope[HomeHostList.iterator + 'SearchSelectValue'] = null; $scope[HomeHostList.iterator + 'SearchSelectValue'] = null;
} }
if ($routeParams.has_active_failures) { if ($routeParams.has_active_failures) {
scope[HomeHostList.iterator + 'InputDisable'] = true; $scope[HomeHostList.iterator + 'InputDisable'] = true;
scope[HomeHostList.iterator + 'SearchValue'] = $routeParams.has_active_failures; $scope[HomeHostList.iterator + 'SearchValue'] = $routeParams.has_active_failures;
scope[HomeHostList.iterator + 'SearchField'] = 'has_active_failures'; $scope[HomeHostList.iterator + 'SearchField'] = 'has_active_failures';
scope[HomeHostList.iterator + 'SearchFieldLabel'] = HomeHostList.fields.has_active_failures.label; $scope[HomeHostList.iterator + 'SearchFieldLabel'] = HomeHostList.fields.has_active_failures.label;
scope[HomeHostList.iterator + 'SearchSelectValue'] = ($routeParams.has_active_failures === 'true') ? { value: 1 } : { value: 0 }; $scope[HomeHostList.iterator + 'SearchSelectValue'] = ($routeParams.has_active_failures === 'true') ? { value: 1 } : { value: 0 };
} }
scope.search(list.iterator); $scope.search(list.iterator);
LoadBreadCrumbs(); LoadBreadCrumbs();
scope.showActivity = function () { $scope.showActivity = function () {
Stream({ Stream({
scope: scope scope: $scope
}); });
}; };
scope.toggle_host_enabled = function (id, sources) { $scope.toggleHostEnabled = function (id, sources) {
ToggleHostEnabled({ ToggleHostEnabled({
host_id: id, host_id: id,
external_source: sources, external_source: sources,
scope: scope scope: $scope
}); });
}; };
scope.editHost = function (host_id) { $scope.editHost = function (host_id) {
var host = Find({ var host = Find({
list: scope.hosts, list: $scope.hosts,
key: 'id', key: 'id',
val: host_id val: host_id
}); });
if (host) { if (host) {
HostsEdit({ HostsEdit({
scope: scope, scope: $scope,
host_id: host_id, host_id: host_id,
inventory_id: host.inventory, inventory_id: host.inventory,
group_id: null, group_id: null,
hostsReload: false hostsReload: false,
mode: 'edit'
}); });
} }
}; };
scope.showJobSummary = function (job_id) { $scope.showJobSummary = function (job_id) {
ShowJobSummary({ ShowJobSummary({
job_id: job_id job_id: job_id
}); });
@@ -578,7 +600,7 @@ function HomeHosts($location, $routeParams, HomeHostList, GenerateList, ProcessE
} }
HomeHosts.$inject = ['$location', '$routeParams', 'HomeHostList', 'GenerateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', HomeHosts.$inject = ['$scope', '$location', '$routeParams', 'HomeHostList', 'GenerateList', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller',
'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'SetStatus', 'ToggleHostEnabled', 'HostsEdit', 'Stream', 'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'SetStatus', 'ToggleHostEnabled', 'HostsEdit', 'Stream',
'Find', 'ShowJobSummary' 'Find', 'ShowJobSummary'
]; ];

View File

@@ -125,6 +125,7 @@ function InventoriesList($scope, $rootScope, $location, $log, $routeParams, $com
// ignore // ignore
} }
$scope.inventories.forEach(function(inventory, idx) { $scope.inventories.forEach(function(inventory, idx) {
$scope.inventories[idx].launch_class = "";
if (inventory.has_inventory_sources) { if (inventory.has_inventory_sources) {
if (inventory.inventory_sources_with_failures > 0) { if (inventory.inventory_sources_with_failures > 0) {
$scope.inventories[idx].syncStatus = 'error'; $scope.inventories[idx].syncStatus = 'error';
@@ -138,15 +139,20 @@ function InventoriesList($scope, $rootScope, $location, $log, $routeParams, $com
else { else {
$scope.inventories[idx].syncStatus = 'na'; $scope.inventories[idx].syncStatus = 'na';
$scope.inventories[idx].syncTip = 'Not configured for inventory sync.'; $scope.inventories[idx].syncTip = 'Not configured for inventory sync.';
$scope.inventories[idx].launch_class = "btn-disabled";
} }
if (inventory.has_active_failures) { if (inventory.has_active_failures) {
$scope.inventories[idx].hostsStatus = 'error'; $scope.inventories[idx].hostsStatus = 'error';
$scope.inventories[idx].hostsTip = inventory.hosts_with_active_failures + ' hosts with failures. Click for details.'; $scope.inventories[idx].hostsTip = inventory.hosts_with_active_failures + ' hosts with failures. Click for details.';
} }
else { else if (inventory.total_hosts) {
$scope.inventories[idx].hostsStatus = 'successful'; $scope.inventories[idx].hostsStatus = 'successful';
$scope.inventories[idx].hostsTip = 'No hosts with failures. Click for details.'; $scope.inventories[idx].hostsTip = 'No hosts with failures. Click for details.';
} }
else {
$scope.inventories[idx].hostsStatus = 'none';
$scope.inventories[idx].hostsTip = 'Inventory contains 0 hosts.';
}
}); });
}); });
@@ -252,20 +258,25 @@ function InventoriesList($scope, $rootScope, $location, $log, $routeParams, $com
}; };
$scope.showHostSummary = function(event, id) { $scope.showHostSummary = function(event, id) {
var url; var url, inventory;
if (!Empty(id)) { if (!Empty(id)) {
Wait('start'); inventory = Find({ list: $scope.inventories, key: 'id', val: id });
url = GetBasePath('jobs') + "?type=job&inventory=" + id + "&order_by=-finished&page_size=5"; if (inventory.total_hosts > 0) {
Rest.setUrl(url); Wait('start');
Rest.get() url = GetBasePath('jobs') + "?type=job&inventory=" + id + "&failed=";
.success( function(data) { url += (inventory.has_active_failures) ? 'true' : "false";
$scope.$emit('HostSummaryReady', event, data); url += "&order_by=-finished&page_size=5";
}) Rest.setUrl(url);
.error( function(data, status) { Rest.get()
ProcessErrors( $scope, data, status, null, { hdr: 'Error!', .success( function(data) {
msg: 'Call to ' + url + ' failed. GET returned: ' + status $scope.$emit('HostSummaryReady', event, data);
})
.error( function(data, status) {
ProcessErrors( $scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET returned: ' + status
});
}); });
}); }
} }
}; };

View File

@@ -617,6 +617,7 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, P
mode = params.mode, // 'add' or 'edit' mode = params.mode, // 'add' or 'edit'
inventory_id = params.inventory_id, inventory_id = params.inventory_id,
groups_reload = params.groups_reload, groups_reload = params.groups_reload,
callback = params.callback,
generator = GenerateForm, generator = GenerateForm,
defaultUrl, defaultUrl,
master = {}, master = {},
@@ -1044,29 +1045,26 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, P
source: (sources_scope.source && sources_scope.source.value) ? sources_scope.source.value : '' source: (sources_scope.source && sources_scope.source.value) ? sources_scope.source.value : ''
} }
}); });
} else if (parent_scope.home_groups) { } else if (callback) {
// When home.groups controller is calling, update the groups array try {
var g = Find({ $('#group-modal-dialog').dialog('close');
list: parent_scope.home_groups, }
key: 'id', catch(err) {
val: group_id //ignore
}); }
if (g) { parent_scope.$emit(callback);
g.name = properties_scope.name; } else {
g.description = properties_scope.description; if (mode === 'add') {
BuildTree({
scope: parent_scope,
inventory_id: inventory_id,
refresh: true,
new_group_id: group_id
});
}
else {
parent_scope.$emit('GroupTreeRefreshed');
} }
}
if (mode === 'add') {
BuildTree({
scope: parent_scope,
inventory_id: inventory_id,
refresh: true,
new_group_id: group_id
});
}
else {
parent_scope.$emit('GroupTreeRefreshed');
} }
} }
}); });
@@ -1142,10 +1140,15 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, P
catch(e) { catch(e) {
//ignore //ignore
} }
if (modal_scope.searchCleanup) { if (callback) {
modal_scope.searchCleanup(); parent_scope.$emit(callback);
}
else {
if (modal_scope.searchCleanup) {
modal_scope.searchCleanup();
}
WatchInventoryWindowResize();
} }
WatchInventoryWindowResize();
}; };
// Save // Save

View File

@@ -141,7 +141,7 @@ angular.module('HomeGroupListDefinition', [])
edit: { edit: {
label: 'Edit', label: 'Edit',
mode: 'all', mode: 'all',
ngClick: "editGroup(group.id)", ngClick: "editGroup(group.id, group.inventory)",
awToolTip: 'Edit group', awToolTip: 'Edit group',
dataPlacement: "top" dataPlacement: "top"
} }

View File

@@ -22,6 +22,17 @@ angular.module('HomeHostListDefinition', [])
well: true, well: true,
fields: { fields: {
status: {
label: "Status",
iconOnly: true,
icon: "{{ 'icon-job-' + host.active_failures }}",
awToolTip: "{{ host.badgeToolTip }}",
awTipPlacement: "top",
ngClick:"bob",
columnClass: "col-md-1 col-sm-2 col-xs-3",
searchable: false,
nosort: true
},
name: { name: {
key: true, key: true,
label: 'Name', label: 'Name',
@@ -71,7 +82,7 @@ angular.module('HomeHostListDefinition', [])
dataTipWatch: "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: {
//label: 'Job Status', //label: 'Job Status',
//ngHref: "\{\{'/#/hosts/' + host.id + '/job_host_summaries/?inventory=' + inventory_id \}\}", //ngHref: "\{\{'/#/hosts/' + host.id + '/job_host_summaries/?inventory=' + inventory_id \}\}",
awPopOver: "{{ host.job_status_html }}", awPopOver: "{{ host.job_status_html }}",
@@ -80,7 +91,7 @@ angular.module('HomeHostListDefinition', [])
awTipPlacement: 'top', awTipPlacement: 'top',
dataPlacement: 'left', dataPlacement: 'left',
iconClass: "{{ 'fa icon-failures-' + host.has_active_failures }}" iconClass: "{{ 'fa icon-failures-' + host.has_active_failures }}"
}, }*/
edit: { edit: {
label: 'Edit', label: 'Edit',
ngClick: "editHost(host.id)", ngClick: "editHost(host.id)",

View File

@@ -32,12 +32,14 @@ angular.module('InventoriesListDefinition', [])
icon: "{{ 'icon-cloud-' + inventory.syncStatus }}", icon: "{{ 'icon-cloud-' + inventory.syncStatus }}",
awToolTip: "{{ inventory.syncTip }}", awToolTip: "{{ inventory.syncTip }}",
awTipPlacement: "top", awTipPlacement: "top",
ngClick: "showGroupSummary($event, inventory.id)" ngClick: "showGroupSummary($event, inventory.id)",
ngClass: "inventory.launch_class"
},{ },{
icon: "{{ 'icon-job-' + inventory.hostsStatus }}", icon: "{{ 'icon-job-' + inventory.hostsStatus }}",
awToolTip: "{{ inventory.hostsTip }}", awToolTip: "{{ inventory.hostsTip }}",
awTipPlacement: "top", awTipPlacement: "top",
ngClick: "showHostSummary($event, inventory.id)" ngClick: "showHostSummary($event, inventory.id)",
ngClass: ""
}] }]
}, },
name: { name: {