elements
- $(this).remove();
- });
- // $("#configure-jobs").show();
- // $("#configure-schedules-form-container").hide();
- // $('#configure-schedules-list').empty();
- // $('#configure-schedules-form').empty();
- // $('#configure-schedules-detail').empty();
- // $('#configure-tower-dialog').hide();
- $(this).dialog('destroy');
- scope.cancelConfigure();
- },
- });
-
-
-
- // Cancel
- scope.cancelConfigure = function () {
- try {
- $('#custom-script-dialog').dialog('close');
- }
- catch(e) {
- //ignore
- }
- if (scope.searchCleanup) {
- scope.searchCleanup();
- }
- // if (!Empty(parent_scope) && parent_scope.restoreSearch) {
- // parent_scope.restoreSearch();
- // }
- else {
- Wait('stop');
- }
- };
-
- scope.editCustomInv = function(id){
- CustomInventoryEdit({
- scope: scope,
- id: id
});
- };
- scope.deleteCustomInv = function(id, name){
- var action = function () {
- $('#prompt-modal').modal('hide');
- Wait('start');
- var url = defaultUrl + id + '/';
- Rest.setUrl(url);
- Rest.destroy()
- .success(function () {
- scope.search(list.iterator);
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
- });
+
+
+ // Cancel
+ scope.cancelConfigure = function () {
+ try {
+ $('#custom-script-dialog').dialog('close');
+ }
+ catch(e) {
+ //ignore
+ }
+ if (scope.searchCleanup) {
+ scope.searchCleanup();
+ }
+ // if (!Empty(parent_scope) && parent_scope.restoreSearch) {
+ // parent_scope.restoreSearch();
+ // }
+ else {
+ Wait('stop');
+ }
};
- Prompt({
- hdr: 'Delete',
- body: "
",
- action: action
+ scope.editCustomInv = function(id){
+ CustomInventoryEdit({
+ scope: scope,
+ id: id
+ });
+ };
+ scope.deleteCustomInv = function(id, name){
+
+ var action = function () {
+ $('#prompt-modal').modal('hide');
+ Wait('start');
+ var url = defaultUrl + id + '/';
+ Rest.setUrl(url);
+ Rest.destroy()
+ .success(function () {
+ scope.search(list.iterator);
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
+ });
+ };
+
+ Prompt({
+ hdr: 'Delete',
+ body: "
",
+ action: action
+ });
+ };
+
+ scope.addCustomInv = function(){
+ CustomInventoryAdd({
+ scope: scope
+ });
+ };
+
+
+
+ };
+ }])
+
+
+ .factory('CustomInventoryAdd', ['$compile','SchedulerInit', 'Rest', 'Wait', 'CustomInventoryList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm',
+ 'SearchInit' , 'PaginateInit', 'GenerateList', 'LookUpInit', 'OrganizationList',
+ function($compile, SchedulerInit, Rest, Wait, CustomInventoryList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm,
+ SearchInit, PaginateInit, GenerateList, LookUpInit, OrganizationList) {
+ return function(params) {
+ var scope = params.scope,
+ generator = GenerateForm,
+ form = CustomInventoryForm,
+ view = GenerateList,
+ list = CustomInventoryList,
+ url = GetBasePath('inventory_scripts');
+
+ generator.inject(form, { id:'custom-script-dialog', mode: 'add' , scope:scope, related: false, breadCrumbs: false});
+ generator.reset();
+
+ LookUpInit({
+ url: GetBasePath('organization'),
+ scope: scope,
+ form: form,
+ // hdr: "Select Custom Inventory",
+ list: OrganizationList,
+ field: 'organization',
+ input_type: 'radio'
});
+
+ // Save
+ scope.formSave = function () {
+ generator.clearApiErrors();
+ Wait('start');
+ Rest.setUrl(url);
+ Rest.post({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script })
+ .success(function () {
+ view.inject( list, {
+ id : 'custom-script-dialog',
+ mode: 'edit',
+ scope: scope,
+ breadCrumbs: false,
+ activityStream: false,
+ showSearch: true
+ });
+
+ SearchInit({
+ scope: scope,
+ set: 'source_scripts', //'custom_inventories',
+ list: list,
+ url: url
+ });
+ PaginateInit({
+ scope: scope,
+ list: list,
+ url: url
+ });
+
+ scope.search(list.iterator);
+ Wait('stop');
+ Wait('stop');
+
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, form, { hdr: 'Error!',
+ msg: 'Failed to add new inventory script. POST returned status: ' + status });
+ });
};
- scope.addCustomInv = function(){
- CustomInventoryAdd({
- scope: scope
- });
+ // Cancel
+ scope.formReset = function () {
+ generator.reset();
};
-
-
-
};
}])
+ .factory('CustomInventoryEdit', ['$compile','CustomInventoryList', 'Rest', 'Wait', 'GenerateList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm',
+ 'SearchInit', 'PaginateInit', '$routeParams', 'OrganizationList', 'LookUpInit',
+ function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm,
+ SearchInit, PaginateInit, $routeParams, OrganizationList, LookUpInit) {
+ return function(params) {
+ var scope = params.scope,
+ id = params.id,
+ generator = GenerateForm,
+ form = CustomInventoryForm,
+ view = GenerateList,
+ list = CustomInventoryList,
+ master = {},
+ url = GetBasePath('inventory_scripts');
-.factory('CustomInventoryAdd', ['$compile','SchedulerInit', 'Rest', 'Wait', 'CustomInventoryList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm',
- 'SearchInit' , 'PaginateInit', 'GenerateList', 'LookUpInit', 'OrganizationList',
-function($compile, SchedulerInit, Rest, Wait, CustomInventoryList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm,
- SearchInit, PaginateInit, GenerateList, LookUpInit, OrganizationList) {
- return function(params) {
- var scope = params.scope,
- generator = GenerateForm,
- form = CustomInventoryForm,
- view = GenerateList,
- list = CustomInventoryList,
- url = GetBasePath('inventory_scripts');
+ generator.inject(form, {
+ id:'custom-script-dialog',
+ mode: 'edit' ,
+ scope:scope,
+ related: false,
+ breadCrumbs: false,
+ activityStream: false
+ });
+ generator.reset();
+ LookUpInit({
+ url: GetBasePath('organization'),
+ scope: scope,
+ form: form,
+ // hdr: "Select Custom Inventory",
+ list: OrganizationList,
+ field: 'organization',
+ input_type: 'radio'
+ });
- generator.inject(form, { id:'custom-script-dialog', mode: 'add' , scope:scope, related: false, breadCrumbs: false});
- generator.reset();
-
- LookUpInit({
- url: GetBasePath('organization'),
- scope: scope,
- form: form,
- // hdr: "Select Custom Inventory",
- list: OrganizationList,
- field: 'organization',
- input_type: 'radio'
- });
-
- // Save
- scope.formSave = function () {
- generator.clearApiErrors();
+ // Retrieve detail record and prepopulate the form
Wait('start');
- Rest.setUrl(url);
- Rest.post({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script })
- .success(function () {
- view.inject( list, {
- id : 'custom-script-dialog',
- mode: 'edit',
- scope: scope,
- breadCrumbs: false,
- activityStream: false,
- showSearch: true
- });
+ Rest.setUrl(url + id+'/');
+ Rest.get()
+ .success(function (data) {
+ var fld;
+ for (fld in form.fields) {
+ if (data[fld]) {
+ scope[fld] = data[fld];
+ master[fld] = data[fld];
+ }
- SearchInit({
- scope: scope,
- set: 'source_scripts', //'custom_inventories',
- list: list,
- url: url
- });
- PaginateInit({
- scope: scope,
- list: list,
- url: url
- });
-
- scope.search(list.iterator);
+ if (form.fields[fld].sourceModel && data.summary_fields &&
+ data.summary_fields[form.fields[fld].sourceModel]) {
+ scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
+ data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
+ master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
+ data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
+ }
+ }
Wait('stop');
- Wait('stop');
-
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
- msg: 'Failed to add new inventory script. POST returned status: ' + status });
+ msg: 'Failed to retrieve inventory script: ' + $routeParams.id + '. GET status: ' + status });
});
- };
- // Cancel
- scope.formReset = function () {
- generator.reset();
- };
- };
-}])
+ scope.formSave = function () {
+ generator.clearApiErrors();
+ Wait('start');
+ Rest.setUrl(url+ id+'/');
+ Rest.put({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script })
+ .success(function () {
+ view.inject( list, {
+ id : 'custom-script-dialog',
+ mode: 'edit',
+ scope: scope,
+ breadCrumbs: false,
+ activityStream: false,
+ showSearch: true
+ });
-.factory('CustomInventoryEdit', ['$compile','CustomInventoryList', 'Rest', 'Wait', 'GenerateList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm',
- 'SearchInit', 'PaginateInit', '$routeParams', 'OrganizationList', 'LookUpInit',
-function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm,
- SearchInit, PaginateInit, $routeParams, OrganizationList, LookUpInit) {
- return function(params) {
- var scope = params.scope,
- id = params.id,
- generator = GenerateForm,
- form = CustomInventoryForm,
- view = GenerateList,
- list = CustomInventoryList,
- master = {},
- url = GetBasePath('inventory_scripts');
+ SearchInit({
+ scope: scope,
+ set: 'source_scripts', //'custom_inventories',
+ list: list,
+ url: url
+ });
+ PaginateInit({
+ scope: scope,
+ list: list,
+ url: url
+ });
- generator.inject(form, {
- id:'custom-script-dialog',
- mode: 'edit' ,
- scope:scope,
- related: false,
- breadCrumbs: false,
- activityStream: false
- });
- generator.reset();
- LookUpInit({
- url: GetBasePath('organization'),
- scope: scope,
- form: form,
- // hdr: "Select Custom Inventory",
- list: OrganizationList,
- field: 'organization',
- input_type: 'radio'
- });
+ scope.search(list.iterator);
- // Retrieve detail record and prepopulate the form
- Wait('start');
- Rest.setUrl(url + id+'/');
- Rest.get()
- .success(function (data) {
- var fld;
- for (fld in form.fields) {
- if (data[fld]) {
- scope[fld] = data[fld];
- master[fld] = data[fld];
- }
+ Wait('stop');
- if (form.fields[fld].sourceModel && data.summary_fields &&
- data.summary_fields[form.fields[fld].sourceModel]) {
- scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
- data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
- master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
- data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
- }
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, form, { hdr: 'Error!',
+ msg: 'Failed to add new inventory script. PUT returned status: ' + status });
+ });
+ };
+
+ scope.formReset = function () {
+ generator.reset();
+ for (var fld in master) {
+ scope[fld] = master[fld];
}
- Wait('stop');
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, form, { hdr: 'Error!',
- msg: 'Failed to retrieve inventory script: ' + $routeParams.id + '. GET status: ' + status });
- });
+ scope.organization_name = master.organization_name;
- scope.formSave = function () {
- generator.clearApiErrors();
- Wait('start');
- Rest.setUrl(url+ id+'/');
- Rest.put({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script })
- .success(function () {
- view.inject( list, {
- id : 'custom-script-dialog',
- mode: 'edit',
- scope: scope,
- breadCrumbs: false,
- activityStream: false,
- showSearch: true
- });
-
- SearchInit({
- scope: scope,
- set: 'source_scripts', //'custom_inventories',
- list: list,
- url: url
- });
- PaginateInit({
- scope: scope,
- list: list,
- url: url
- });
-
- scope.search(list.iterator);
-
- Wait('stop');
-
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, form, { hdr: 'Error!',
- msg: 'Failed to add new inventory script. PUT returned status: ' + status });
- });
+ };
};
-
- scope.formReset = function () {
- generator.reset();
- for (var fld in master) {
- scope[fld] = master[fld];
- }
- scope.organization_name = master.organization_name;
-
- };
- };
-}]);
+ }]);
diff --git a/awx/ui/static/js/helpers/EventViewer.js b/awx/ui/static/js/helpers/EventViewer.js
index 240d990737..945275ea1c 100644
--- a/awx/ui/static/js/helpers/EventViewer.js
+++ b/awx/ui/static/js/helpers/EventViewer.js
@@ -10,555 +10,555 @@
* @description eventviewerhelper
*/
+export default
+ angular.module('EventViewerHelper', ['ModalDialog', 'Utilities', 'EventsViewerFormDefinition', 'HostsHelper'])
-angular.module('EventViewerHelper', ['ModalDialog', 'Utilities', 'EventsViewerFormDefinition', 'HostsHelper'])
+ .factory('EventViewer', ['$compile', 'CreateDialog', 'GetEvent', 'Wait', 'EventAddTable', 'GetBasePath', 'LookUpName', 'Empty', 'EventAddPreFormattedText',
+ function($compile, CreateDialog, GetEvent, Wait, EventAddTable, GetBasePath, LookUpName, Empty, EventAddPreFormattedText) {
+ return function(params) {
+ var parent_scope = params.scope,
+ url = params.url,
+ event_id = params.event_id,
+ parent_id = params.parent_id,
+ title = params.title, //optional
+ scope = parent_scope.$new(true),
+ index = params.index,
+ page,
+ current_event;
- .factory('EventViewer', ['$compile', 'CreateDialog', 'GetEvent', 'Wait', 'EventAddTable', 'GetBasePath', 'LookUpName', 'Empty', 'EventAddPreFormattedText',
- function($compile, CreateDialog, GetEvent, Wait, EventAddTable, GetBasePath, LookUpName, Empty, EventAddPreFormattedText) {
- return function(params) {
- var parent_scope = params.scope,
- url = params.url,
- event_id = params.event_id,
- parent_id = params.parent_id,
- title = params.title, //optional
- scope = parent_scope.$new(true),
- index = params.index,
- page,
- current_event;
-
- if (scope.removeShowNextEvent) {
- scope.removeShowNextEvent();
- }
- scope.removeShowNextEvent = scope.$on('ShowNextEvent', function(e, data, show_event) {
- scope.events = data;
- $('#event-next-spinner').hide(400);
- if (show_event === 'prev') {
- showEvent(scope.events.length - 1);
+ if (scope.removeShowNextEvent) {
+ scope.removeShowNextEvent();
}
- else if (show_event === 'next') {
- showEvent(0);
- }
- });
-
- // show scope.events[idx]
- function showEvent(idx) {
- var show_tabs = false, elem, data;
-
- if (idx > scope.events.length - 1) {
- GetEvent({
- scope: scope,
- url: scope.next_event_set,
- show_event: 'next'
- });
- return;
- }
-
- if (idx < 0) {
- GetEvent({
- scope: scope,
- url: scope.prev_event_set,
- show_event: 'prev'
- });
- return;
- }
-
- data = scope.events[idx];
- current_event = idx;
-
- $('#status-form-container').empty();
- $('#results-form-container').empty();
- $('#timing-form-container').empty();
- $('#stdout-form-container').empty();
- $('#stderr-form-container').empty();
- $('#traceback-form-container').empty();
- $('#json-form-container').empty();
- $('#eventview-tabs li:eq(1)').hide();
- $('#eventview-tabs li:eq(2)').hide();
- $('#eventview-tabs li:eq(3)').hide();
- $('#eventview-tabs li:eq(4)').hide();
- $('#eventview-tabs li:eq(5)').hide();
- $('#eventview-tabs li:eq(6)').hide();
-
- EventAddTable({ scope: scope, id: 'status-form-container', event: data, section: 'Event' });
-
- if (EventAddTable({ scope: scope, id: 'results-form-container', event: data, section: 'Results'})) {
- show_tabs = true;
- $('#eventview-tabs li:eq(1)').show();
- }
-
- if (EventAddTable({ scope: scope, id: 'timing-form-container', event: data, section: 'Timing' })) {
- show_tabs = true;
- $('#eventview-tabs li:eq(2)').show();
- }
-
- if (data.stdout) {
- show_tabs = true;
- $('#eventview-tabs li:eq(3)').show();
- EventAddPreFormattedText({
- id: 'stdout-form-container',
- val: data.stdout
- });
- }
-
- if (data.stderr) {
- show_tabs = true;
- $('#eventview-tabs li:eq(4)').show();
- EventAddPreFormattedText({
- id: 'stderr-form-container',
- val: data.stderr
- });
- }
-
- if (data.traceback) {
- show_tabs = true;
- $('#eventview-tabs li:eq(5)').show();
- EventAddPreFormattedText({
- id: 'traceback-form-container',
- val: data.traceback
- });
- }
-
- show_tabs = true;
- $('#eventview-tabs li:eq(6)').show();
- EventAddPreFormattedText({
- id: 'json-form-container',
- val: JSON.stringify(data, null, 2)
- });
-
- if (!show_tabs) {
- $('#eventview-tabs').hide();
- }
-
- elem = angular.element(document.getElementById('eventviewer-modal-dialog'));
- $compile(elem)(scope);
- }
-
- function setButtonMargin() {
- var width = ($('.ui-dialog[aria-describedby="eventviewer-modal-dialog"] .ui-dialog-buttonpane').innerWidth() / 2) - $('#events-next-button').outerWidth() - 73;
- $('#events-next-button').css({'margin-right': width + 'px'});
- }
-
- function addSpinner() {
- var position;
- if ($('#event-next-spinner').length > 0) {
- $('#event-next-spinner').remove();
- }
- position = $('#events-next-button').position();
- $('#events-next-button').after('
');
- }
-
- if (scope.removeModalReady) {
- scope.removeModalReady();
- }
- scope.removeModalReady = scope.$on('ModalReady', function() {
- Wait('stop');
- $('#eventviewer-modal-dialog').dialog('open');
- });
-
- if (scope.removeJobReady) {
- scope.removeJobReady();
- }
- scope.removeEventReady = scope.$on('EventReady', function(e, data) {
- var btns;
- scope.events = data;
- if (event_id) {
- // find and show the selected event
- data.every(function(row, idx) {
- if (parseInt(row.id,10) === parseInt(event_id,10)) {
- current_event = idx;
- return false;
- }
- return true;
- });
- }
- else {
- current_event = 0;
- }
- showEvent(current_event);
-
- btns = [];
- if (scope.events.length > 1) {
- btns.push({
- label: "Prev",
- onClick: function () {
- if (current_event - 1 === 0 && !scope.prev_event_set) {
- $('#events-prev-button').prop('disabled', true);
- }
- if (current_event - 1 < scope.events.length - 1) {
- $('#events-next-button').prop('disabled', false);
- }
- showEvent(current_event - 1);
- },
- icon: "fa-chevron-left",
- "class": "btn btn-primary",
- id: "events-prev-button"
- });
- btns.push({
- label: "Next",
- onClick: function() {
- if (current_event + 1 > 0) {
- $('#events-prev-button').prop('disabled', false);
- }
- if (current_event + 1 >= scope.events.length - 1 && !scope.next_event_set) {
- $('#events-next-button').prop('disabled', true);
- }
- showEvent(current_event + 1);
- },
- icon: "fa-chevron-right",
- "class": "btn btn-primary",
- id: "events-next-button"
- });
- }
- btns.push({
- label: "OK",
- onClick: function() {
- scope.modalOK();
- },
- icon: "",
- "class": "btn btn-primary",
- id: "dialog-ok-button"
- });
-
- CreateDialog({
- scope: scope,
- width: 675,
- height: 600,
- minWidth: 450,
- callback: 'ModalReady',
- id: 'eventviewer-modal-dialog',
- // onResizeStop: resizeText,
- title: ( (title) ? title : 'Host Event' ),
- buttons: btns,
- closeOnEscape: true,
- onResizeStop: function() {
- setButtonMargin();
- addSpinner();
- },
- onClose: function() {
- try {
- scope.$destroy();
- }
- catch(e) {
- //ignore
- }
- },
- onOpen: function() {
- $('#eventview-tabs a:first').tab('show');
- $('#dialog-ok-button').focus();
- if (scope.events.length > 1 && current_event === 0 && !scope.prev_event_set) {
- $('#events-prev-button').prop('disabled', true);
- }
- if ((current_event === scope.events.length - 1) && !scope.next_event_set) {
- $('#events-next-button').prop('disabled', true);
- }
- if (scope.events.length > 1) {
- setButtonMargin();
- addSpinner();
- }
+ scope.removeShowNextEvent = scope.$on('ShowNextEvent', function(e, data, show_event) {
+ scope.events = data;
+ $('#event-next-spinner').hide(400);
+ if (show_event === 'prev') {
+ showEvent(scope.events.length - 1);
+ }
+ else if (show_event === 'next') {
+ showEvent(0);
}
});
- });
- page = (index) ? Math.ceil((index+1)/50) : 1;
- url += (/\/$/.test(url)) ? '?' : '&';
- url += (parent_id) ? 'page='+page +'&parent=' + parent_id + '&page_size=50&order=host_name,counter' : 'page_size=50&order=host_name,counter';
+ // show scope.events[idx]
+ function showEvent(idx) {
+ var show_tabs = false, elem, data;
- GetEvent({
- url: url,
- scope: scope
- });
+ if (idx > scope.events.length - 1) {
+ GetEvent({
+ scope: scope,
+ url: scope.next_event_set,
+ show_event: 'next'
+ });
+ return;
+ }
- scope.modalOK = function() {
- $('#eventviewer-modal-dialog').dialog('close');
- scope.$destroy();
- };
+ if (idx < 0) {
+ GetEvent({
+ scope: scope,
+ url: scope.prev_event_set,
+ show_event: 'prev'
+ });
+ return;
+ }
- };
- }])
+ data = scope.events[idx];
+ current_event = idx;
- .factory('GetEvent', ['Wait', 'Rest', 'ProcessErrors',
- function(Wait, Rest, ProcessErrors) {
- return function(params) {
- var url = params.url,
- scope = params.scope,
- show_event = params.show_event,
- results= [];
+ $('#status-form-container').empty();
+ $('#results-form-container').empty();
+ $('#timing-form-container').empty();
+ $('#stdout-form-container').empty();
+ $('#stderr-form-container').empty();
+ $('#traceback-form-container').empty();
+ $('#json-form-container').empty();
+ $('#eventview-tabs li:eq(1)').hide();
+ $('#eventview-tabs li:eq(2)').hide();
+ $('#eventview-tabs li:eq(3)').hide();
+ $('#eventview-tabs li:eq(4)').hide();
+ $('#eventview-tabs li:eq(5)').hide();
+ $('#eventview-tabs li:eq(6)').hide();
- if (show_event) {
- $('#event-next-spinner').show();
- }
- else {
- Wait('start');
- }
+ EventAddTable({ scope: scope, id: 'status-form-container', event: data, section: 'Event' });
- function getStatus(e) {
- return (e.event === "runner_on_unreachable") ? "unreachable" : (e.event === "runner_on_skipped") ? 'skipped' : (e.failed) ? 'failed' :
- (e.changed) ? 'changed' : 'ok';
- }
+ if (EventAddTable({ scope: scope, id: 'results-form-container', event: data, section: 'Results'})) {
+ show_tabs = true;
+ $('#eventview-tabs li:eq(1)').show();
+ }
- Rest.setUrl(url);
- Rest.get()
- .success( function(data) {
+ if (EventAddTable({ scope: scope, id: 'timing-form-container', event: data, section: 'Timing' })) {
+ show_tabs = true;
+ $('#eventview-tabs li:eq(2)').show();
+ }
- if(jQuery.isEmptyObject(data)) {
- Wait('stop');
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to get event ' + url + '. ' });
+ if (data.stdout) {
+ show_tabs = true;
+ $('#eventview-tabs li:eq(3)').show();
+ EventAddPreFormattedText({
+ id: 'stdout-form-container',
+ val: data.stdout
+ });
+ }
+ if (data.stderr) {
+ show_tabs = true;
+ $('#eventview-tabs li:eq(4)').show();
+ EventAddPreFormattedText({
+ id: 'stderr-form-container',
+ val: data.stderr
+ });
+ }
+
+ if (data.traceback) {
+ show_tabs = true;
+ $('#eventview-tabs li:eq(5)').show();
+ EventAddPreFormattedText({
+ id: 'traceback-form-container',
+ val: data.traceback
+ });
+ }
+
+ show_tabs = true;
+ $('#eventview-tabs li:eq(6)').show();
+ EventAddPreFormattedText({
+ id: 'json-form-container',
+ val: JSON.stringify(data, null, 2)
+ });
+
+ if (!show_tabs) {
+ $('#eventview-tabs').hide();
+ }
+
+ elem = angular.element(document.getElementById('eventviewer-modal-dialog'));
+ $compile(elem)(scope);
+ }
+
+ function setButtonMargin() {
+ var width = ($('.ui-dialog[aria-describedby="eventviewer-modal-dialog"] .ui-dialog-buttonpane').innerWidth() / 2) - $('#events-next-button').outerWidth() - 73;
+ $('#events-next-button').css({'margin-right': width + 'px'});
+ }
+
+ function addSpinner() {
+ var position;
+ if ($('#event-next-spinner').length > 0) {
+ $('#event-next-spinner').remove();
+ }
+ position = $('#events-next-button').position();
+ $('#events-next-button').after('
');
+ }
+
+ if (scope.removeModalReady) {
+ scope.removeModalReady();
+ }
+ scope.removeModalReady = scope.$on('ModalReady', function() {
+ Wait('stop');
+ $('#eventviewer-modal-dialog').dialog('open');
+ });
+
+ if (scope.removeJobReady) {
+ scope.removeJobReady();
+ }
+ scope.removeEventReady = scope.$on('EventReady', function(e, data) {
+ var btns;
+ scope.events = data;
+ if (event_id) {
+ // find and show the selected event
+ data.every(function(row, idx) {
+ if (parseInt(row.id,10) === parseInt(event_id,10)) {
+ current_event = idx;
+ return false;
+ }
+ return true;
+ });
}
else {
- scope.next_event_set = data.next;
- scope.prev_event_set = data.previous;
- data.results.forEach(function(event) {
- var msg, key, event_data = {};
- if (event.event_data.res) {
- if (typeof event.event_data.res !== 'object') {
- // turn event_data.res into an object
- msg = event.event_data.res;
- event.event_data.res = {};
- event.event_data.res.msg = msg;
+ current_event = 0;
+ }
+ showEvent(current_event);
+
+ btns = [];
+ if (scope.events.length > 1) {
+ btns.push({
+ label: "Prev",
+ onClick: function () {
+ if (current_event - 1 === 0 && !scope.prev_event_set) {
+ $('#events-prev-button').prop('disabled', true);
}
- for (key in event.event_data) {
- if (key !== "res") {
- event.event_data.res[key] = event.event_data[key];
- }
+ if (current_event - 1 < scope.events.length - 1) {
+ $('#events-next-button').prop('disabled', false);
}
- if (event.event_data.res.ansible_facts) {
- // don't show fact gathering results
- event.event_data.res.task = "Gathering Facts";
- delete event.event_data.res.ansible_facts;
- }
- event.event_data.res.status = getStatus(event);
- event_data = event.event_data.res;
- }
- else {
- event.event_data.status = getStatus(event);
- event_data = event.event_data;
- }
- // convert results to stdout
- if (event_data.results && typeof event_data.results === "object" && Array.isArray(event_data.results)) {
- event_data.stdout = "";
- event_data.results.forEach(function(row) {
- event_data.stdout += row + "\n";
- });
- delete event_data.results;
- }
- if (event_data.invocation) {
- for (key in event_data.invocation) {
- event_data[key] = event_data.invocation[key];
- }
- delete event_data.invocation;
- }
- event_data.play = event.play;
- if (event.task) {
- event_data.task = event.task;
- }
- event_data.created = event.created;
- event_data.role = event.role;
- event_data.host_id = event.host;
- event_data.host_name = event.host_name;
- if (event_data.host) {
- delete event_data.host;
- }
- event_data.id = event.id;
- event_data.parent = event.parent;
- event_data.event = (event.event_display) ? event.event_display : event.event;
- results.push(event_data);
+ showEvent(current_event - 1);
+ },
+ icon: "fa-chevron-left",
+ "class": "btn btn-primary",
+ id: "events-prev-button"
});
- if (show_event) {
- scope.$emit('ShowNextEvent', results, show_event);
+ btns.push({
+ label: "Next",
+ onClick: function() {
+ if (current_event + 1 > 0) {
+ $('#events-prev-button').prop('disabled', false);
+ }
+ if (current_event + 1 >= scope.events.length - 1 && !scope.next_event_set) {
+ $('#events-next-button').prop('disabled', true);
+ }
+ showEvent(current_event + 1);
+ },
+ icon: "fa-chevron-right",
+ "class": "btn btn-primary",
+ id: "events-next-button"
+ });
+ }
+ btns.push({
+ label: "OK",
+ onClick: function() {
+ scope.modalOK();
+ },
+ icon: "",
+ "class": "btn btn-primary",
+ id: "dialog-ok-button"
+ });
+
+ CreateDialog({
+ scope: scope,
+ width: 675,
+ height: 600,
+ minWidth: 450,
+ callback: 'ModalReady',
+ id: 'eventviewer-modal-dialog',
+ // onResizeStop: resizeText,
+ title: ( (title) ? title : 'Host Event' ),
+ buttons: btns,
+ closeOnEscape: true,
+ onResizeStop: function() {
+ setButtonMargin();
+ addSpinner();
+ },
+ onClose: function() {
+ try {
+ scope.$destroy();
+ }
+ catch(e) {
+ //ignore
+ }
+ },
+ onOpen: function() {
+ $('#eventview-tabs a:first').tab('show');
+ $('#dialog-ok-button').focus();
+ if (scope.events.length > 1 && current_event === 0 && !scope.prev_event_set) {
+ $('#events-prev-button').prop('disabled', true);
+ }
+ if ((current_event === scope.events.length - 1) && !scope.next_event_set) {
+ $('#events-next-button').prop('disabled', true);
+ }
+ if (scope.events.length > 1) {
+ setButtonMargin();
+ addSpinner();
+ }
+ }
+ });
+ });
+
+ page = (index) ? Math.ceil((index+1)/50) : 1;
+ url += (/\/$/.test(url)) ? '?' : '&';
+ url += (parent_id) ? 'page='+page +'&parent=' + parent_id + '&page_size=50&order=host_name,counter' : 'page_size=50&order=host_name,counter';
+
+ GetEvent({
+ url: url,
+ scope: scope
+ });
+
+ scope.modalOK = function() {
+ $('#eventviewer-modal-dialog').dialog('close');
+ scope.$destroy();
+ };
+
+ };
+ }])
+
+ .factory('GetEvent', ['Wait', 'Rest', 'ProcessErrors',
+ function(Wait, Rest, ProcessErrors) {
+ return function(params) {
+ var url = params.url,
+ scope = params.scope,
+ show_event = params.show_event,
+ results= [];
+
+ if (show_event) {
+ $('#event-next-spinner').show();
+ }
+ else {
+ Wait('start');
+ }
+
+ function getStatus(e) {
+ return (e.event === "runner_on_unreachable") ? "unreachable" : (e.event === "runner_on_skipped") ? 'skipped' : (e.failed) ? 'failed' :
+ (e.changed) ? 'changed' : 'ok';
+ }
+
+ Rest.setUrl(url);
+ Rest.get()
+ .success( function(data) {
+
+ if(jQuery.isEmptyObject(data)) {
+ Wait('stop');
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to get event ' + url + '. ' });
+
}
else {
- scope.$emit('EventReady', results);
+ scope.next_event_set = data.next;
+ scope.prev_event_set = data.previous;
+ data.results.forEach(function(event) {
+ var msg, key, event_data = {};
+ if (event.event_data.res) {
+ if (typeof event.event_data.res !== 'object') {
+ // turn event_data.res into an object
+ msg = event.event_data.res;
+ event.event_data.res = {};
+ event.event_data.res.msg = msg;
+ }
+ for (key in event.event_data) {
+ if (key !== "res") {
+ event.event_data.res[key] = event.event_data[key];
+ }
+ }
+ if (event.event_data.res.ansible_facts) {
+ // don't show fact gathering results
+ event.event_data.res.task = "Gathering Facts";
+ delete event.event_data.res.ansible_facts;
+ }
+ event.event_data.res.status = getStatus(event);
+ event_data = event.event_data.res;
+ }
+ else {
+ event.event_data.status = getStatus(event);
+ event_data = event.event_data;
+ }
+ // convert results to stdout
+ if (event_data.results && typeof event_data.results === "object" && Array.isArray(event_data.results)) {
+ event_data.stdout = "";
+ event_data.results.forEach(function(row) {
+ event_data.stdout += row + "\n";
+ });
+ delete event_data.results;
+ }
+ if (event_data.invocation) {
+ for (key in event_data.invocation) {
+ event_data[key] = event_data.invocation[key];
+ }
+ delete event_data.invocation;
+ }
+ event_data.play = event.play;
+ if (event.task) {
+ event_data.task = event.task;
+ }
+ event_data.created = event.created;
+ event_data.role = event.role;
+ event_data.host_id = event.host;
+ event_data.host_name = event.host_name;
+ if (event_data.host) {
+ delete event_data.host;
+ }
+ event_data.id = event.id;
+ event_data.parent = event.parent;
+ event_data.event = (event.event_display) ? event.event_display : event.event;
+ results.push(event_data);
+ });
+ if (show_event) {
+ scope.$emit('ShowNextEvent', results, show_event);
+ }
+ else {
+ scope.$emit('EventReady', results);
+ }
+ } //else statement
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to get event ' + url + '. GET returned: ' + status });
+ });
+ };
+ }])
+
+ .factory('EventAddTable', ['$compile', '$filter', 'Empty', 'EventsViewerForm', function($compile, $filter, Empty, EventsViewerForm) {
+ return function(params) {
+ var scope = params.scope,
+ id = params.id,
+ event = params.event,
+ section = params.section,
+ html = '', e;
+
+ function parseObject(obj) {
+ // parse nested JSON objects. a mini version of parseJSON without references to the event form object.
+ var i, key, html = '';
+ for (key in obj) {
+ if (typeof obj[key] === "boolean" || typeof obj[key] === "number" || typeof obj[key] === "string") {
+ html += "
";
+ }
+ else if (typeof obj[key] === "object" && Array.isArray(obj[key])) {
+ html += "
\n";
+ }
+ else if (typeof obj[key] === "object") {
+ html += "
\n";
}
- } //else statement
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to get event ' + url + '. GET returned: ' + status });
- });
- };
- }])
-
- .factory('EventAddTable', ['$compile', '$filter', 'Empty', 'EventsViewerForm', function($compile, $filter, Empty, EventsViewerForm) {
- return function(params) {
- var scope = params.scope,
- id = params.id,
- event = params.event,
- section = params.section,
- html = '', e;
-
- function parseObject(obj) {
- // parse nested JSON objects. a mini version of parseJSON without references to the event form object.
- var i, key, html = '';
- for (key in obj) {
- if (typeof obj[key] === "boolean" || typeof obj[key] === "number" || typeof obj[key] === "string") {
- html += "
";
}
- else if (typeof obj[key] === "object" && Array.isArray(obj[key])) {
- html += "
\n";
+ }
+ else if (typeof itm === "object" && Array.isArray(itm)) {
+ html += "
\n";
}
- else if (typeof obj[key] === "object") {
- html += "
\n";
+ else if (typeof itm === "object") {
+ html += "
\n";
}
+ return html;
}
- return html;
- }
- function parseItem(itm, key, label) {
- var i, html = '';
- if (Empty(itm)) {
- // exclude empty items
- }
- else if (typeof itm === "boolean" || typeof itm === "number" || typeof itm === "string") {
- html += "
" + label + ": ";
- if (key === "status") {
- html += " " + itm;
- }
- else if (key === "start" || key === "end" || key === "created") {
- if (!/Z$/.test(itm)) {
- itm = itm.replace(/\ /,'T') + 'Z';
- html += $filter('date')(itm, 'MM/dd/yy HH:mm:ss.sss');
- }
- else {
- html += $filter('date')(itm, 'MM/dd/yy HH:mm:ss');
- }
- }
- else if (key === "host_name" && event.host_id) {
- html += "" + itm + " ";
- }
- else {
- if( typeof itm === "string"){
- if(itm.indexOf('<') > -1 || itm.indexOf('>') > -1){
- itm = itm.replace(//g, ">");
+ function parseJSON(obj) {
+ var h, html = '', key, keys, found = false, string_warnings = "", string_cmd = "";
+ if (typeof obj === "object") {
+ html += "\n";
+ html += "\n";
+ keys = [];
+ for (key in EventsViewerForm.fields) {
+ if (EventsViewerForm.fields[key].section === section) {
+ keys.push(key);
}
}
- html += "" + itm + " ";
- }
-
- html += "\n";
- }
- else if (typeof itm === "object" && Array.isArray(itm)) {
- html += "" + label + ": [";
- for (i = 0; i < itm.length; i++) {
- html += itm[i] + ",";
- }
- html = html.replace(/,$/,'');
- html += "] \n";
- }
- else if (typeof itm === "object") {
- html += "" + label + ": \n\n" + parseObject(itm) + " \n
\n \n";
- }
- return html;
- }
-
- function parseJSON(obj) {
- var h, html = '', key, keys, found = false, string_warnings = "", string_cmd = "";
- if (typeof obj === "object") {
- html += "\n";
- html += "\n";
- keys = [];
- for (key in EventsViewerForm.fields) {
- if (EventsViewerForm.fields[key].section === section) {
- keys.push(key);
- }
- }
- keys.forEach(function(key) {
- var h, label;
- label = EventsViewerForm.fields[key].label;
- h = parseItem(obj[key], key, label);
- if (h) {
- html += h;
- found = true;
- }
- });
- if (section === 'Results') {
- // Add to result fields that might not be found in the form object.
- for (key in obj) {
- h = '';
- if (key !== 'host_id' && key !== 'parent' && key !== 'event' && key !== 'src' && key !== 'md5sum' &&
- key !== 'stdout' && key !== 'traceback' && key !== 'stderr' && key !== 'cmd' && key !=='changed' && key !== "verbose_override" &&
- key !== 'feature_result' && key !== 'warnings') {
- if (!EventsViewerForm.fields[key]) {
- h = parseItem(obj[key], key, key);
- if (h) {
- html += h;
- found = true;
+ keys.forEach(function(key) {
+ var h, label;
+ label = EventsViewerForm.fields[key].label;
+ h = parseItem(obj[key], key, label);
+ if (h) {
+ html += h;
+ found = true;
+ }
+ });
+ if (section === 'Results') {
+ // Add to result fields that might not be found in the form object.
+ for (key in obj) {
+ h = '';
+ if (key !== 'host_id' && key !== 'parent' && key !== 'event' && key !== 'src' && key !== 'md5sum' &&
+ key !== 'stdout' && key !== 'traceback' && key !== 'stderr' && key !== 'cmd' && key !=='changed' && key !== "verbose_override" &&
+ key !== 'feature_result' && key !== 'warnings') {
+ if (!EventsViewerForm.fields[key]) {
+ h = parseItem(obj[key], key, key);
+ if (h) {
+ html += h;
+ found = true;
+ }
}
- }
- } else if (key === 'cmd') {
- // only show cmd if it's a cmd that was run
- if (!EventsViewerForm.fields[key] && obj[key].length > 0) {
- // include the label head Shell Command instead of CMD in the modal
- string_cmd += obj[key].join(" ");
- h = parseItem(string_cmd, key, "Shell Command");
- if (h) {
- html += h;
- found = true;
+ } else if (key === 'cmd') {
+ // only show cmd if it's a cmd that was run
+ if (!EventsViewerForm.fields[key] && obj[key].length > 0) {
+ // include the label head Shell Command instead of CMD in the modal
+ string_cmd += obj[key].join(" ");
+ h = parseItem(string_cmd, key, "Shell Command");
+ if (h) {
+ html += h;
+ found = true;
+ }
}
- }
- } else if (key === 'warnings') {
- if (!EventsViewerForm.fields[key] && obj[key].length > 0) {
- string_warnings += obj[key].join(" ");
- h = parseItem(string_warnings, key, "Warnings");
- if (h) {
- html += h;
- found = true;
+ } else if (key === 'warnings') {
+ if (!EventsViewerForm.fields[key] && obj[key].length > 0) {
+ string_warnings += obj[key].join(" ");
+ h = parseItem(string_warnings, key, "Warnings");
+ if (h) {
+ html += h;
+ found = true;
+ }
}
}
}
}
+ html += " \n";
+ html += "
\n";
}
- html += " \n";
- html += "
\n";
+ return (found) ? html : '';
}
- return (found) ? html : '';
- }
- html = parseJSON(event);
+ html = parseJSON(event);
- e = angular.element(document.getElementById(id));
- e.empty();
- if (html) {
- e.html(html);
- $compile(e)(scope);
- }
- return (html) ? true : false;
- };
- }])
-
- .factory('EventAddTextarea', [ function() {
- return function(params) {
- var container_id = params.container_id,
- val = params.val,
- fld_id = params.fld_id,
- html;
- html = "\n" +
- "" +
- "
\n";
- $('#' + container_id).empty().html(html);
- };
- }])
-
- .factory('EventAddPreFormattedText', [function() {
- return function(params) {
- var id = params.id,
- val = params.val,
- html;
- if( typeof val === "string"){
- if(val.indexOf('<') > -1 || val.indexOf('>') > -1){
- val = val.replace(//g, ">");
+ e = angular.element(document.getElementById(id));
+ e.empty();
+ if (html) {
+ e.html(html);
+ $compile(e)(scope);
}
- }
- html = "" + val + " \n";
- $('#' + id).empty().html(html);
- };
- }]);
+ return (html) ? true : false;
+ };
+ }])
+
+ .factory('EventAddTextarea', [ function() {
+ return function(params) {
+ var container_id = params.container_id,
+ val = params.val,
+ fld_id = params.fld_id,
+ html;
+ html = "\n" +
+ "" +
+ "
\n";
+ $('#' + container_id).empty().html(html);
+ };
+ }])
+
+ .factory('EventAddPreFormattedText', [function() {
+ return function(params) {
+ var id = params.id,
+ val = params.val,
+ html;
+ if( typeof val === "string"){
+ if(val.indexOf('<') > -1 || val.indexOf('>') > -1){
+ val = val.replace(//g, ">");
+ }
+ }
+ html = "" + val + " \n";
+ $('#' + id).empty().html(html);
+ };
+ }]);
diff --git a/awx/ui/static/js/helpers/Events.js b/awx/ui/static/js/helpers/Events.js
index 8532f3c5a9..3b9909f7f0 100644
--- a/awx/ui/static/js/helpers/Events.js
+++ b/awx/ui/static/js/helpers/Events.js
@@ -12,29 +12,53 @@
* @description EventView - show the job_events form in a modal dialog
*/
+export default
+ angular.module('EventsHelper', ['RestServices', 'Utilities', 'JobEventDataDefinition', 'JobEventsFormDefinition'])
-angular.module('EventsHelper', ['RestServices', 'Utilities', 'JobEventDataDefinition', 'JobEventsFormDefinition'])
+ .factory('EventView', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm',
+ 'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'JobEventDataForm', 'Empty', 'JobEventsForm',
+ function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath,
+ FormatDate, JobEventDataForm, Empty, JobEventsForm) {
+ return function (params) {
- .factory('EventView', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm',
- 'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'JobEventDataForm', 'Empty', 'JobEventsForm',
- function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath,
- FormatDate, JobEventDataForm, Empty, JobEventsForm) {
- return function (params) {
+ var event_id = params.event_id,
+ generator = GenerateForm,
+ form = angular.copy(JobEventsForm),
+ scope,
+ defaultUrl = GetBasePath('base') + 'job_events/' + event_id + '/';
- var event_id = params.event_id,
- generator = GenerateForm,
- form = angular.copy(JobEventsForm),
- scope,
- defaultUrl = GetBasePath('base') + 'job_events/' + event_id + '/';
+ // Retrieve detail record and prepopulate the form
+ Rest.setUrl(defaultUrl);
+ Rest.get()
+ .success(function (data) {
+ var i, n, fld, rows, txt, cDate;
- // Retrieve detail record and prepopulate the form
- Rest.setUrl(defaultUrl);
- Rest.get()
- .success(function (data) {
- var i, n, fld, rows, txt, cDate;
+ // If event_data is not available, remove fields that depend on it
+ if ($.isEmptyObject(data.event_data) || !data.event_data.res || typeof data.event_data.res === 'string') {
+ for (fld in form.fields) {
+ switch (fld) {
+ case 'start':
+ case 'end':
+ case 'delta':
+ case 'msg':
+ case 'stdout':
+ case 'stderr':
+ case 'msg':
+ case 'results':
+ case 'module_name':
+ case 'module_args':
+ case 'rc':
+ delete form.fields[fld];
+ break;
+ }
+ }
+ }
- // If event_data is not available, remove fields that depend on it
- if ($.isEmptyObject(data.event_data) || !data.event_data.res || typeof data.event_data.res === 'string') {
+ if ($.isEmptyObject(data.event_data) || !data.event_data.res || typeof data.event_data.res !== 'string') {
+ delete form.fields.traceback;
+ }
+
+ // Remove remaining form fields that do not have a corresponding data value
for (fld in form.fields) {
switch (fld) {
case 'start':
@@ -44,196 +68,172 @@ angular.module('EventsHelper', ['RestServices', 'Utilities', 'JobEventDataDefini
case 'stdout':
case 'stderr':
case 'msg':
+ case 'rc':
+ if (data.event_data && data.event_data.res && Empty(data.event_data.res[fld])) {
+ delete form.fields[fld];
+ } else {
+ if (form.fields[fld].type === 'textarea') {
+ n = data.event_data.res[fld].match(/\n/g);
+ rows = (n) ? n.length : 1;
+ rows = (rows > 10) ? 10 : rows;
+ rows = (rows < 3) ? 3 : rows;
+ form.fields[fld].rows = rows;
+ }
+ }
+ break;
case 'results':
+ if (data.event_data && data.event_data.res && data.event_data.res[fld] === undefined) {
+ // not defined
+ delete form.fields[fld];
+ } else if (!Array.isArray(data.event_data.res[fld]) || data.event_data.res[fld].length === 0) {
+ // defined, but empty
+ delete form.fields[fld];
+ } else {
+ // defined and not empty, so attempt to size the textarea field
+ txt = '';
+ for (i = 0; i < data.event_data.res[fld].length; i++) {
+ txt += data.event_data.res[fld][i];
+ }
+ if (txt === '') {
+ // there's an array, but the actual text is empty
+ delete form.fields[fld];
+ } else {
+ n = txt.match(/\n/g);
+ rows = (n) ? n.length : 1;
+ rows = (rows > 10) ? 10 : rows;
+ rows = (rows < 3) ? 3 : rows;
+ form.fields[fld].rows = rows;
+ }
+ }
+ break;
case 'module_name':
case 'module_args':
- case 'rc':
- delete form.fields[fld];
+ if (data.event_data && data.event_data.res) {
+ if (data.event_data.res.invocation === undefined ||
+ data.event_data.res.invocation[fld] === undefined) {
+ delete form.fields[fld];
+ }
+ }
break;
}
}
- }
- if ($.isEmptyObject(data.event_data) || !data.event_data.res || typeof data.event_data.res !== 'string') {
- delete form.fields.traceback;
- }
-
- // Remove remaining form fields that do not have a corresponding data value
- for (fld in form.fields) {
- switch (fld) {
- case 'start':
- case 'end':
- case 'delta':
- case 'msg':
- case 'stdout':
- case 'stderr':
- case 'msg':
- case 'rc':
- if (data.event_data && data.event_data.res && Empty(data.event_data.res[fld])) {
- delete form.fields[fld];
- } else {
- if (form.fields[fld].type === 'textarea') {
- n = data.event_data.res[fld].match(/\n/g);
- rows = (n) ? n.length : 1;
- rows = (rows > 10) ? 10 : rows;
- rows = (rows < 3) ? 3 : rows;
- form.fields[fld].rows = rows;
- }
- }
- break;
- case 'results':
- if (data.event_data && data.event_data.res && data.event_data.res[fld] === undefined) {
- // not defined
- delete form.fields[fld];
- } else if (!Array.isArray(data.event_data.res[fld]) || data.event_data.res[fld].length === 0) {
- // defined, but empty
- delete form.fields[fld];
- } else {
- // defined and not empty, so attempt to size the textarea field
- txt = '';
- for (i = 0; i < data.event_data.res[fld].length; i++) {
- txt += data.event_data.res[fld][i];
- }
- if (txt === '') {
- // there's an array, but the actual text is empty
- delete form.fields[fld];
- } else {
- n = txt.match(/\n/g);
- rows = (n) ? n.length : 1;
- rows = (rows > 10) ? 10 : rows;
- rows = (rows < 3) ? 3 : rows;
- form.fields[fld].rows = rows;
- }
- }
- break;
- case 'module_name':
- case 'module_args':
- if (data.event_data && data.event_data.res) {
- if (data.event_data.res.invocation === undefined ||
- data.event_data.res.invocation[fld] === undefined) {
- delete form.fields[fld];
- }
- }
- break;
- }
- }
-
- // load the form
- scope = generator.inject(form, {
- mode: 'edit',
- modal: true,
- related: false
- });
- generator.reset();
- scope.formModalAction = function () {
- $('#form-modal').modal("hide");
- };
- scope.formModalActionLabel = 'OK';
- scope.formModalCancelShow = false;
- scope.formModalInfo = 'View JSON';
- $('#form-modal .btn-success').removeClass('btn-success').addClass('btn-none');
- $('#form-modal').addClass('skinny-modal');
- scope.formModalHeader = data.event_display.replace(/^\u00a0*/g, '');
-
- // Respond to View JSON button
- scope.formModalInfoAction = function () {
- var generator = GenerateForm,
- scope = generator.inject(JobEventDataForm, {
+ // load the form
+ scope = generator.inject(form, {
mode: 'edit',
modal: true,
- related: false,
- modal_selector: '#form-modal2',
- modal_body_id: 'form-modal2-body',
- modal_title_id: 'formModal2Header'
+ related: false
});
generator.reset();
- scope.formModal2Header = data.event_display.replace(/^\u00a0*/g, '');
- scope.event_data = JSON.stringify(data.event_data, null, '\t');
- scope.formModal2ActionLabel = 'OK';
- scope.formModal2CancelShow = false;
- scope.formModal2Info = false;
- scope.formModalInfo = 'View JSON';
- scope.formModal2Action = function () {
- $('#form-modal2').modal("hide");
+ scope.formModalAction = function () {
+ $('#form-modal').modal("hide");
};
- $('#form-modal2 .btn-success').removeClass('btn-success').addClass('btn-none');
- };
+ scope.formModalActionLabel = 'OK';
+ scope.formModalCancelShow = false;
+ scope.formModalInfo = 'View JSON';
+ $('#form-modal .btn-success').removeClass('btn-success').addClass('btn-none');
+ $('#form-modal').addClass('skinny-modal');
+ scope.formModalHeader = data.event_display.replace(/^\u00a0*/g, '');
- if (typeof data.event_data.res === 'string') {
- scope.traceback = data.event_data.res;
- }
+ // Respond to View JSON button
+ scope.formModalInfoAction = function () {
+ var generator = GenerateForm,
+ scope = generator.inject(JobEventDataForm, {
+ mode: 'edit',
+ modal: true,
+ related: false,
+ modal_selector: '#form-modal2',
+ modal_body_id: 'form-modal2-body',
+ modal_title_id: 'formModal2Header'
+ });
+ generator.reset();
+ scope.formModal2Header = data.event_display.replace(/^\u00a0*/g, '');
+ scope.event_data = JSON.stringify(data.event_data, null, '\t');
+ scope.formModal2ActionLabel = 'OK';
+ scope.formModal2CancelShow = false;
+ scope.formModal2Info = false;
+ scope.formModalInfo = 'View JSON';
+ scope.formModal2Action = function () {
+ $('#form-modal2').modal("hide");
+ };
+ $('#form-modal2 .btn-success').removeClass('btn-success').addClass('btn-none');
+ };
- for (fld in form.fields) {
- switch (fld) {
- case 'status':
- if (data.failed) {
- scope.status = 'error';
- } else if (data.changed) {
- scope.status = 'changed';
- } else {
- scope.status = 'success';
- }
- break;
- case 'created':
- cDate = new Date(data.created);
- scope.created = FormatDate(cDate);
- break;
- case 'host':
- if (data.summary_fields && data.summary_fields.host) {
- scope.host = data.summary_fields.host.name;
- }
- break;
- case 'id':
- case 'task':
- case 'play':
- scope[fld] = data[fld];
- break;
- case 'start':
- case 'end':
- if (data.event_data && data.event_data.res && !Empty(data.event_data.res[fld])) {
- scope[fld] = data.event_data.res[fld];
- }
-
- break;
- case 'results':
- if (Array.isArray(data.event_data.res[fld]) && data.event_data.res[fld].length > 0) {
- txt = '';
- for (i = 0; i < data.event_data.res[fld].length; i++) {
- txt += data.event_data.res[fld][i];
- }
- if (txt !== '') {
- scope[fld] = txt;
- }
- }
- break;
- case 'msg':
- case 'stdout':
- case 'stderr':
- case 'delta':
- case 'rc':
- if (data.event_data && data.event_data.res && data.event_data.res[fld] !== undefined) {
- scope[fld] = data.event_data.res[fld];
- }
- break;
- case 'module_name':
- case 'module_args':
- if (data.event_data.res && data.event_data.res.invocation) {
- scope[fld] = data.event_data.res.invocation[fld];
- }
- break;
+ if (typeof data.event_data.res === 'string') {
+ scope.traceback = data.event_data.res;
}
- }
- if (!scope.$$phase) {
- scope.$digest();
- }
+ for (fld in form.fields) {
+ switch (fld) {
+ case 'status':
+ if (data.failed) {
+ scope.status = 'error';
+ } else if (data.changed) {
+ scope.status = 'changed';
+ } else {
+ scope.status = 'success';
+ }
+ break;
+ case 'created':
+ cDate = new Date(data.created);
+ scope.created = FormatDate(cDate);
+ break;
+ case 'host':
+ if (data.summary_fields && data.summary_fields.host) {
+ scope.host = data.summary_fields.host.name;
+ }
+ break;
+ case 'id':
+ case 'task':
+ case 'play':
+ scope[fld] = data[fld];
+ break;
+ case 'start':
+ case 'end':
+ if (data.event_data && data.event_data.res && !Empty(data.event_data.res[fld])) {
+ scope[fld] = data.event_data.res[fld];
+ }
- })
- .error(function (data, status) {
- $('#form-modal').modal("hide");
- ProcessErrors(scope, data, status, form, { hdr: 'Error!',
- msg: 'Failed to retrieve event: ' + event_id + '. GET status: ' + status });
- });
- };
- }
- ]);
\ No newline at end of file
+ break;
+ case 'results':
+ if (Array.isArray(data.event_data.res[fld]) && data.event_data.res[fld].length > 0) {
+ txt = '';
+ for (i = 0; i < data.event_data.res[fld].length; i++) {
+ txt += data.event_data.res[fld][i];
+ }
+ if (txt !== '') {
+ scope[fld] = txt;
+ }
+ }
+ break;
+ case 'msg':
+ case 'stdout':
+ case 'stderr':
+ case 'delta':
+ case 'rc':
+ if (data.event_data && data.event_data.res && data.event_data.res[fld] !== undefined) {
+ scope[fld] = data.event_data.res[fld];
+ }
+ break;
+ case 'module_name':
+ case 'module_args':
+ if (data.event_data.res && data.event_data.res.invocation) {
+ scope[fld] = data.event_data.res.invocation[fld];
+ }
+ break;
+ }
+ }
+
+ if (!scope.$$phase) {
+ scope.$digest();
+ }
+
+ })
+ .error(function (data, status) {
+ $('#form-modal').modal("hide");
+ ProcessErrors(scope, data, status, form, { hdr: 'Error!',
+ msg: 'Failed to retrieve event: ' + event_id + '. GET status: ' + status });
+ });
+ };
+ }
+ ]);
diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js
index 5abc73cb20..1f68ff75ae 100644
--- a/awx/ui/static/js/helpers/Groups.js
+++ b/awx/ui/static/js/helpers/Groups.js
@@ -6,18 +6,20 @@
* Routines that handle group add/edit/delete on the Inventory tree widget.
*
*/
-
+'use strict';
/**
* @ngdoc function
* @name helpers.function:Groups
* @description inventory tree widget add/edit/delete
*/
+
+export default
angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'GroupListDefinition', 'SearchHelper',
-'PaginationHelpers', 'ListGenerator', 'AuthService', 'GroupsHelper', 'InventoryHelper', 'SelectionHelper',
-'JobSubmissionHelper', 'RefreshHelper', 'PromptDialog', 'CredentialsListDefinition', 'InventoryTree',
-'InventoryStatusDefinition', 'VariablesHelper', 'SchedulesListDefinition', 'SourceFormDefinition', 'LogViewerHelper',
-'SchedulesHelper'
+ 'PaginationHelpers', 'ListGenerator', 'AuthService', 'GroupsHelper', 'InventoryHelper', 'SelectionHelper',
+ 'JobSubmissionHelper', 'RefreshHelper', 'PromptDialog', 'CredentialsListDefinition', 'InventoryTree',
+ 'InventoryStatusDefinition', 'VariablesHelper', 'SchedulesListDefinition', 'SourceFormDefinition', 'LogViewerHelper',
+ 'SchedulesHelper'
])
/**
@@ -26,35 +28,35 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GetSourceTypeOptions', ['Rest', 'ProcessErrors', 'GetBasePath',
- function (Rest, ProcessErrors, GetBasePath) {
- return function (params) {
- var scope = params.scope,
- variable = params.variable;
+ function (Rest, ProcessErrors, GetBasePath) {
+ return function (params) {
+ var scope = params.scope,
+ variable = params.variable;
- if (scope[variable] === undefined) {
- scope[variable] = [];
- Rest.setUrl(GetBasePath('inventory_sources'));
- Rest.options()
- .success(function (data) {
- var i, choices = data.actions.GET.source.choices;
- for (i = 0; i < choices.length; i++) {
- if (choices[i][0] !== 'file') {
- scope[variable].push({
- label: ((choices[i][0] === '') ? 'Manual' : choices[i][1]),
- value: (choices[i][0] === '') ? 'manual' : choices[i][0]
- });
- }
- }
- scope.$emit('sourceTypeOptionsReady');
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve options for inventory_sources.source. OPTIONS status: ' + status
- });
- });
- }
- };
- }
+ if (scope[variable] === undefined) {
+ scope[variable] = [];
+ Rest.setUrl(GetBasePath('inventory_sources'));
+ Rest.options()
+ .success(function (data) {
+ var i, choices = data.actions.GET.source.choices;
+ for (i = 0; i < choices.length; i++) {
+ if (choices[i][0] !== 'file') {
+ scope[variable].push({
+ label: ((choices[i][0] === '') ? 'Manual' : choices[i][1]),
+ value: (choices[i][0] === '') ? 'manual' : choices[i][0]
+ });
+ }
+ }
+ scope.$emit('sourceTypeOptionsReady');
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve options for inventory_sources.source. OPTIONS status: ' + status
+ });
+ });
+ }
+ };
+ }
])
/**
@@ -63,47 +65,47 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('ViewUpdateStatus', ['Rest', 'ProcessErrors', 'GetBasePath', 'Alert', 'Wait', 'Empty', 'Find', 'LogViewer',
- function (Rest, ProcessErrors, GetBasePath, Alert, Wait, Empty, Find, LogViewer) {
- return function (params) {
+ function (Rest, ProcessErrors, GetBasePath, Alert, Wait, Empty, Find, LogViewer) {
+ return function (params) {
- var scope = params.scope,
- group_id = params.group_id,
- group = Find({ list: scope.groups, key: 'id', val: group_id });
+ var scope = params.scope,
+ group_id = params.group_id,
+ group = Find({ list: scope.groups, key: 'id', val: group_id });
- if (scope.removeSourceReady) {
- scope.removeSourceReady();
- }
- scope.removeSourceReady = scope.$on('SourceReady', function(e, url) {
- LogViewer({
- scope: scope,
- url: url
- });
- });
+ if (scope.removeSourceReady) {
+ scope.removeSourceReady();
+ }
+ scope.removeSourceReady = scope.$on('SourceReady', function(e, url) {
+ LogViewer({
+ scope: scope,
+ url: url
+ });
+ });
- if (group) {
- if (Empty(group.source)) {
- // do nothing
- } else if (Empty(group.status) || group.status === "never updated") {
- Alert('No Status Available', 'An inventory sync has not been performed for the selected group. Start the process by ' +
- 'clicking the button.', 'alert-info');
- } else {
- Wait('start');
- Rest.setUrl(group.related.inventory_source);
- Rest.get()
- .success(function (data) {
- var url = (data.related.current_update) ? data.related.current_update : data.related.last_update;
- scope.$emit('SourceReady', url);
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve inventory source: ' + group.related.inventory_source +
- ' GET returned status: ' + status });
- });
- }
- }
+ if (group) {
+ if (Empty(group.source)) {
+ // do nothing
+ } else if (Empty(group.status) || group.status === "never updated") {
+ Alert('No Status Available', 'An inventory sync has not been performed for the selected group. Start the process by ' +
+ 'clicking the button.', 'alert-info');
+ } else {
+ Wait('start');
+ Rest.setUrl(group.related.inventory_source);
+ Rest.get()
+ .success(function (data) {
+ var url = (data.related.current_update) ? data.related.current_update : data.related.last_update;
+ scope.$emit('SourceReady', url);
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve inventory source: ' + group.related.inventory_source +
+ ' GET returned status: ' + status });
+ });
+ }
+ }
- };
- }
+ };
+ }
])
/**
@@ -113,38 +115,38 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*/
.factory('GetHostsStatusMsg', [
function () {
- return function (params) {
+ return function (params) {
- var active_failures = params.active_failures,
- total_hosts = params.total_hosts,
- tip, failures, html_class;
+ var active_failures = params.active_failures,
+ total_hosts = params.total_hosts,
+ tip, failures, html_class;
- // Return values for use on host status indicator
+ // Return values for use on host status indicator
- if (active_failures > 0) {
- tip = total_hosts + ((total_hosts === 1) ? ' host' : ' hosts') + '. ' + active_failures + ' with failed jobs.';
- html_class = 'error';
- failures = true;
+ if (active_failures > 0) {
+ tip = total_hosts + ((total_hosts === 1) ? ' host' : ' hosts') + '. ' + active_failures + ' with failed jobs.';
+ html_class = 'error';
+ failures = true;
+ } else {
+ failures = false;
+ if (total_hosts === 0) {
+ // no hosts
+ tip = "Contains 0 hosts.";
+ html_class = 'none';
} else {
- failures = false;
- if (total_hosts === 0) {
- // no hosts
- tip = "Contains 0 hosts.";
- html_class = 'none';
- } else {
- // many hosts with 0 failures
- tip = total_hosts + ((total_hosts === 1) ? ' host' : ' hosts') + '. No job failures';
- html_class = 'success';
- }
+ // many hosts with 0 failures
+ tip = total_hosts + ((total_hosts === 1) ? ' host' : ' hosts') + '. No job failures';
+ html_class = 'success';
}
+ }
- return {
- tooltip: tip,
- failures: failures,
- 'class': html_class
- };
+ return {
+ tooltip: tip,
+ failures: failures,
+ 'class': html_class
};
- }
+ };
+}
])
/**
@@ -153,78 +155,78 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GetSyncStatusMsg', [ 'Empty',
- function (Empty) {
- return function (params) {
+ function (Empty) {
+ return function (params) {
- var status = params.status,
- source = params.source,
- has_inventory_sources = params.has_inventory_sources,
- launch_class = '',
- launch_tip = 'Start sync process',
- stat, stat_class, status_tip;
+ var status = params.status,
+ source = params.source,
+ has_inventory_sources = params.has_inventory_sources,
+ launch_class = '',
+ launch_tip = 'Start sync process',
+ stat, stat_class, status_tip;
- stat = status;
- stat_class = stat;
+ stat = status;
+ stat_class = stat;
- switch (status) {
- case 'never updated':
- stat = 'never';
- stat_class = 'na';
- status_tip = 'Sync not performed. Click to start it now.';
- break;
- case 'none':
- case 'ok':
- case '':
- launch_class = 'btn-disabled';
- stat = 'n/a';
- stat_class = 'na';
- status_tip = 'Cloud source not configured. Click to update.';
- launch_tip = 'Cloud source not configured.';
- break;
- case 'canceled':
- status_tip = 'Sync canceled. Click to view log.';
- break;
- case 'failed':
- status_tip = 'Sync failed. Click to view log.';
- break;
- case 'successful':
- status_tip = 'Sync completed. Click to view log.';
- break;
- case 'pending':
- status_tip = 'Sync pending.';
- launch_class = "btn-disabled";
- launch_tip = "Sync pending";
- break;
- case 'updating':
- case 'running':
- launch_class = "btn-disabled";
- launch_tip = "Sync running";
- status_tip = "Sync running. Click to view log.";
- break;
- }
+ switch (status) {
+ case 'never updated':
+ stat = 'never';
+ stat_class = 'na';
+ status_tip = 'Sync not performed. Click to start it now.';
+ break;
+ case 'none':
+ case 'ok':
+ case '':
+ launch_class = 'btn-disabled';
+ stat = 'n/a';
+ stat_class = 'na';
+ status_tip = 'Cloud source not configured. Click to update.';
+ launch_tip = 'Cloud source not configured.';
+ break;
+ case 'canceled':
+ status_tip = 'Sync canceled. Click to view log.';
+ break;
+ case 'failed':
+ status_tip = 'Sync failed. Click to view log.';
+ break;
+ case 'successful':
+ status_tip = 'Sync completed. Click to view log.';
+ break;
+ case 'pending':
+ status_tip = 'Sync pending.';
+ launch_class = "btn-disabled";
+ launch_tip = "Sync pending";
+ break;
+ case 'updating':
+ case 'running':
+ launch_class = "btn-disabled";
+ launch_tip = "Sync running";
+ status_tip = "Sync running. Click to view log.";
+ break;
+ }
- if (has_inventory_sources && Empty(source)) {
- // parent has a source, therefore this group should not have a source
- launch_class = "btn-disabled";
- status_tip = 'Managed by an external cloud source.';
- launch_tip = 'Can only be updated by running a sync on the parent group.';
- }
+ if (has_inventory_sources && Empty(source)) {
+ // parent has a source, therefore this group should not have a source
+ launch_class = "btn-disabled";
+ status_tip = 'Managed by an external cloud source.';
+ launch_tip = 'Can only be updated by running a sync on the parent group.';
+ }
- if (has_inventory_sources === false && Empty(source)) {
- launch_class = 'btn-disabled';
- status_tip = 'Cloud source not configured. Click to update.';
- launch_tip = 'Cloud source not configured.';
- }
+ if (has_inventory_sources === false && Empty(source)) {
+ launch_class = 'btn-disabled';
+ status_tip = 'Cloud source not configured. Click to update.';
+ launch_tip = 'Cloud source not configured.';
+ }
- return {
- "class": stat_class,
- "tooltip": status_tip,
- "status": stat,
- "launch_class": launch_class,
- "launch_tip": launch_tip
- };
- };
- }
+ return {
+ "class": stat_class,
+ "tooltip": status_tip,
+ "status": stat,
+ "launch_class": launch_class,
+ "launch_tip": launch_tip
+ };
+ };
+ }
])
/**
@@ -233,99 +235,99 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('SourceChange', ['GetBasePath', 'CredentialList', 'LookUpInit', 'Empty', 'Wait', 'ParseTypeChange', 'CustomInventoryList' ,
- function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, CustomInventoryList) {
- return function (params) {
+ function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, CustomInventoryList) {
+ return function (params) {
- var scope = params.scope,
- form = params.form,
- kind, url, callback, invUrl;
+ var scope = params.scope,
+ form = params.form,
+ kind, url, callback, invUrl;
- if (!Empty(scope.source)) {
- if (scope.source.value === 'file') {
- scope.sourcePathRequired = true;
- } else {
- scope.sourcePathRequired = false;
- // reset fields
- scope.source_path = '';
- scope[form.name + '_form'].source_path.$setValidity('required', true);
- }
- if (scope.source.value === 'rax') {
- scope.source_region_choices = scope.rax_regions;
- //$('#s2id_group_source_regions').select2('data', []);
- $('#s2id_source_source_regions').select2('data', [{
- id: 'all',
- text: 'All'
- }]);
- $('#source_form').addClass('squeeze');
- } else if (scope.source.value === 'ec2') {
- scope.source_region_choices = scope.ec2_regions;
- $('#s2id_source_source_regions').select2('data', [{
- id: 'all',
- text: 'All'
- }]);
- scope.group_by_choices = scope.ec2_group_by;
- $('#s2id_group_by').select2('data', []);
- $('#source_form').addClass('squeeze');
- } else if (scope.source.value === 'gce') {
- scope.source_region_choices = scope.gce_regions;
- //$('#s2id_group_source_regions').select2('data', []);
- $('#s2id_source_source_regions').select2('data', [{
- id: 'all',
- text: 'All'
- }]);
- $('#source_form').addClass('squeeze');
- } else if (scope.source.value === 'azure') {
- scope.source_region_choices = scope.azure_regions;
- //$('#s2id_group_source_regions').select2('data', []);
- $('#s2id_source_source_regions').select2('data', [{
- id: 'all',
- text: 'All'
- }]);
- $('#source_form').addClass('squeeze');
- }
- if(scope.source.value==="custom"){
- // need to filter the possible custom scripts by the organization defined for the current inventory
- invUrl = GetBasePath('inventory_scripts') + '?organization='+scope.$parent.inventory.organization;
- LookUpInit({
- url: invUrl,
- scope: scope,
- form: form,
- hdr: "Select Custom Inventory",
- list: CustomInventoryList,
- field: 'source_script',
- input_type: 'radio'
- });
- scope.extra_vars = (Empty(scope.source_vars)) ? "---" : scope.source_vars;
- ParseTypeChange({ scope: scope, variable: 'extra_vars', parse_variable: form.fields.extra_vars.parseTypeName,
- field_id: 'source_extra_vars', onReady: callback });
- }
- if(scope.source.value==="vmware"){
- scope.inventory_variables = (Empty(scope.source_vars)) ? "---" : scope.source_vars;
- ParseTypeChange({ scope: scope, variable: 'inventory_variables', parse_variable: form.fields.inventory_variables.parseTypeName,
- field_id: 'source_inventory_variables', onReady: callback });
- }
- if (scope.source.value === 'rax' || scope.source.value === 'ec2'|| scope.source.value==='gce' || scope.source.value === 'azure' || scope.source.value === 'vmware') {
- kind = (scope.source.value === 'rax') ? 'rax' : (scope.source.value==='gce') ? 'gce' : (scope.source.value==='azure') ? 'azure' : (scope.source.value === 'vmware') ? 'vmware' : 'aws' ;
- url = GetBasePath('credentials') + '?cloud=true&kind=' + kind;
- LookUpInit({
- url: url,
- scope: scope,
- form: form,
- list: CredentialList,
- field: 'credential',
- input_type: "radio"
- });
- if ($('#group_tabs .active a').text() === 'Source' && (scope.source.value === 'ec2' )) {
- callback = function(){ Wait('stop'); };
- Wait('start');
- scope.source_vars = (Empty(scope.source_vars)) ? "---" : scope.source_vars;
- ParseTypeChange({ scope: scope, variable: 'source_vars', parse_variable: form.fields.source_vars.parseTypeName,
- field_id: 'source_source_vars', onReady: callback });
- }
- }
- }
- };
- }
+ if (!Empty(scope.source)) {
+ if (scope.source.value === 'file') {
+ scope.sourcePathRequired = true;
+ } else {
+ scope.sourcePathRequired = false;
+ // reset fields
+ scope.source_path = '';
+ scope[form.name + '_form'].source_path.$setValidity('required', true);
+ }
+ if (scope.source.value === 'rax') {
+ scope.source_region_choices = scope.rax_regions;
+ //$('#s2id_group_source_regions').select2('data', []);
+ $('#s2id_source_source_regions').select2('data', [{
+ id: 'all',
+ text: 'All'
+ }]);
+ $('#source_form').addClass('squeeze');
+ } else if (scope.source.value === 'ec2') {
+ scope.source_region_choices = scope.ec2_regions;
+ $('#s2id_source_source_regions').select2('data', [{
+ id: 'all',
+ text: 'All'
+ }]);
+ scope.group_by_choices = scope.ec2_group_by;
+ $('#s2id_group_by').select2('data', []);
+ $('#source_form').addClass('squeeze');
+ } else if (scope.source.value === 'gce') {
+ scope.source_region_choices = scope.gce_regions;
+ //$('#s2id_group_source_regions').select2('data', []);
+ $('#s2id_source_source_regions').select2('data', [{
+ id: 'all',
+ text: 'All'
+ }]);
+ $('#source_form').addClass('squeeze');
+ } else if (scope.source.value === 'azure') {
+ scope.source_region_choices = scope.azure_regions;
+ //$('#s2id_group_source_regions').select2('data', []);
+ $('#s2id_source_source_regions').select2('data', [{
+ id: 'all',
+ text: 'All'
+ }]);
+ $('#source_form').addClass('squeeze');
+ }
+ if(scope.source.value==="custom"){
+ // need to filter the possible custom scripts by the organization defined for the current inventory
+ invUrl = GetBasePath('inventory_scripts') + '?organization='+scope.$parent.inventory.organization;
+ LookUpInit({
+ url: invUrl,
+ scope: scope,
+ form: form,
+ hdr: "Select Custom Inventory",
+ list: CustomInventoryList,
+ field: 'source_script',
+ input_type: 'radio'
+ });
+ scope.extra_vars = (Empty(scope.source_vars)) ? "---" : scope.source_vars;
+ ParseTypeChange({ scope: scope, variable: 'extra_vars', parse_variable: form.fields.extra_vars.parseTypeName,
+ field_id: 'source_extra_vars', onReady: callback });
+ }
+ if(scope.source.value==="vmware"){
+ scope.inventory_variables = (Empty(scope.source_vars)) ? "---" : scope.source_vars;
+ ParseTypeChange({ scope: scope, variable: 'inventory_variables', parse_variable: form.fields.inventory_variables.parseTypeName,
+ field_id: 'source_inventory_variables', onReady: callback });
+ }
+ if (scope.source.value === 'rax' || scope.source.value === 'ec2'|| scope.source.value==='gce' || scope.source.value === 'azure' || scope.source.value === 'vmware') {
+ kind = (scope.source.value === 'rax') ? 'rax' : (scope.source.value==='gce') ? 'gce' : (scope.source.value==='azure') ? 'azure' : (scope.source.value === 'vmware') ? 'vmware' : 'aws' ;
+ url = GetBasePath('credentials') + '?cloud=true&kind=' + kind;
+ LookUpInit({
+ url: url,
+ scope: scope,
+ form: form,
+ list: CredentialList,
+ field: 'credential',
+ input_type: "radio"
+ });
+ if ($('#group_tabs .active a').text() === 'Source' && (scope.source.value === 'ec2' )) {
+ callback = function(){ Wait('stop'); };
+ Wait('start');
+ scope.source_vars = (Empty(scope.source_vars)) ? "---" : scope.source_vars;
+ ParseTypeChange({ scope: scope, variable: 'source_vars', parse_variable: form.fields.source_vars.parseTypeName,
+ field_id: 'source_source_vars', onReady: callback });
+ }
+ }
+ }
+ };
+ }
])
/**
@@ -334,82 +336,82 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GroupsCancelUpdate', ['Empty', 'Rest', 'ProcessErrors', 'Alert', 'Wait', 'Find',
- function (Empty, Rest, ProcessErrors, Alert, Wait, Find) {
- return function (params) {
+ function (Empty, Rest, ProcessErrors, Alert, Wait, Find) {
+ return function (params) {
- var scope = params.scope,
- id = params.id,
- group = params.group;
+ var scope = params.scope,
+ id = params.id,
+ group = params.group;
- if (scope.removeCancelUpdate) {
- scope.removeCancelUpdate();
- }
- scope.removeCancelUpdate = scope.$on('CancelUpdate', function (e, url) {
- // Cancel the update process
- Rest.setUrl(url);
- Rest.post()
- .success(function () {
- Wait('stop');
- //Alert('Inventory Sync Cancelled', 'Request to cancel the sync process was submitted to the task manger. ' +
- // 'Click the button to monitor the status.', 'alert-info');
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. POST status: ' + status
- });
- });
- });
+ if (scope.removeCancelUpdate) {
+ scope.removeCancelUpdate();
+ }
+ scope.removeCancelUpdate = scope.$on('CancelUpdate', function (e, url) {
+ // Cancel the update process
+ Rest.setUrl(url);
+ Rest.post()
+ .success(function () {
+ Wait('stop');
+ //Alert('Inventory Sync Cancelled', 'Request to cancel the sync process was submitted to the task manger. ' +
+ // 'Click the button to monitor the status.', 'alert-info');
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. POST status: ' + status
+ });
+ });
+ });
- if (scope.removeCheckCancel) {
- scope.removeCheckCancel();
- }
- scope.removeCheckCancel = scope.$on('CheckCancel', function (e, last_update, current_update) {
- // Check that we have access to cancelling an update
- var url = (current_update) ? current_update : last_update;
- url += 'cancel/';
- Rest.setUrl(url);
- Rest.get()
- .success(function (data) {
- if (data.can_cancel) {
- scope.$emit('CancelUpdate', url);
- //} else {
- // Wait('stop');
- // Alert('Cancel Inventory Sync', 'The sync process completed. Click the button to view ' +
- // 'the latest status.', 'alert-info');
- }
- else {
- Wait('stop');
- }
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. GET status: ' + status
- });
- });
- });
+ if (scope.removeCheckCancel) {
+ scope.removeCheckCancel();
+ }
+ scope.removeCheckCancel = scope.$on('CheckCancel', function (e, last_update, current_update) {
+ // Check that we have access to cancelling an update
+ var url = (current_update) ? current_update : last_update;
+ url += 'cancel/';
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function (data) {
+ if (data.can_cancel) {
+ scope.$emit('CancelUpdate', url);
+ //} else {
+ // Wait('stop');
+ // Alert('Cancel Inventory Sync', 'The sync process completed. Click the button to view ' +
+ // 'the latest status.', 'alert-info');
+ }
+ else {
+ Wait('stop');
+ }
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. GET status: ' + status
+ });
+ });
+ });
- // Cancel the update process
- if (Empty(group)) {
- group = Find({ list: scope.groups, key: 'id', val: id });
- scope.selected_group_id = group.id;
- }
+ // Cancel the update process
+ if (Empty(group)) {
+ group = Find({ list: scope.groups, key: 'id', val: id });
+ scope.selected_group_id = group.id;
+ }
- if (group && (group.status === 'running' || group.status === 'pending')) {
- // We found the group, and there is a running update
- Wait('start');
- Rest.setUrl(group.related.inventory_source);
- Rest.get()
- .success(function (data) {
- scope.$emit('CheckCancel', data.related.last_update, data.related.current_update);
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + group.related.inventory_source + ' failed. GET status: ' + status
- });
- });
- }
- };
- }
+ if (group && (group.status === 'running' || group.status === 'pending')) {
+ // We found the group, and there is a running update
+ Wait('start');
+ Rest.setUrl(group.related.inventory_source);
+ Rest.get()
+ .success(function (data) {
+ scope.$emit('CheckCancel', data.related.last_update, data.related.current_update);
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + group.related.inventory_source + ' failed. GET status: ' + status
+ });
+ });
+ }
+ };
+ }
])
/**
@@ -418,107 +420,107 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GroupsScheduleListInit', ['GroupsScheduleEdit', 'SchedulesList', 'GenerateList', 'SearchInit', 'PaginateInit', 'Rest',
-'PageRangeSetup', 'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetBasePath', 'SchedulesListInit',
- function(GroupsScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find,
- ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
- return function(params) {
- var schedule_scope = params.scope,
- url = params.url,
- list;
+ 'PageRangeSetup', 'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetBasePath', 'SchedulesListInit',
+ function(GroupsScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find,
+ ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
+ return function(params) {
+ var schedule_scope = params.scope,
+ url = params.url,
+ list;
- // Clean up
- $('#schedules-list').hide().empty();
- $('#schedules-form-container').hide();
- $('#schedules-form').empty();
- $('.tooltip').each(function () {
- $(this).remove();
- });
- $('.popover').each(function () {
- $(this).remove();
- });
+ // Clean up
+ $('#schedules-list').hide().empty();
+ $('#schedules-form-container').hide();
+ $('#schedules-form').empty();
+ $('.tooltip').each(function () {
+ $(this).remove();
+ });
+ $('.popover').each(function () {
+ $(this).remove();
+ });
- // Add schedules list
- list = angular.copy(SchedulesList);
- delete list.fields.dtend;
- delete list.actions.stream;
- list.well = false;
- GenerateList.inject(list, {
- mode: 'edit',
- id: 'schedules-list',
- breadCrumbs: false,
- searchSize: 'col-lg-6 col-md-5 col-sm-5 col-xs-5',
- scope: schedule_scope
- });
+ // Add schedules list
+ list = angular.copy(SchedulesList);
+ delete list.fields.dtend;
+ delete list.actions.stream;
+ list.well = false;
+ GenerateList.inject(list, {
+ mode: 'edit',
+ id: 'schedules-list',
+ breadCrumbs: false,
+ searchSize: 'col-lg-6 col-md-5 col-sm-5 col-xs-5',
+ scope: schedule_scope
+ });
- $('#schedules-list').show();
+ $('#schedules-list').show();
- // Removing screws up /home/groups page
- // if (schedule_scope.removePostRefresh) {
- // schedule_scope.removePostRefresh();
- //}
- schedule_scope.removePostRefresh = schedule_scope.$on('PostRefresh', function() {
- SchedulesListInit({
- scope: schedule_scope,
- list: list,
- choices: null
- });
- });
- SearchInit({
- scope: schedule_scope,
- set: 'schedules',
- list: SchedulesList,
- url: url
- });
- PaginateInit({
- scope: schedule_scope,
- list: SchedulesList,
- url: url,
- pageSize: 5
- });
- schedule_scope.search(list.iterator);
+ // Removing screws up /home/groups page
+ // if (schedule_scope.removePostRefresh) {
+ // schedule_scope.removePostRefresh();
+ //}
+ schedule_scope.removePostRefresh = schedule_scope.$on('PostRefresh', function() {
+ SchedulesListInit({
+ scope: schedule_scope,
+ list: list,
+ choices: null
+ });
+ });
+ SearchInit({
+ scope: schedule_scope,
+ set: 'schedules',
+ list: SchedulesList,
+ url: url
+ });
+ PaginateInit({
+ scope: schedule_scope,
+ list: SchedulesList,
+ url: url,
+ pageSize: 5
+ });
+ schedule_scope.search(list.iterator);
- schedule_scope.refreshSchedules = function() {
- schedule_scope.search(list.iterator);
- };
+ schedule_scope.refreshSchedules = function() {
+ schedule_scope.search(list.iterator);
+ };
- schedule_scope.editSchedule = function(id) {
- GroupsScheduleEdit({ scope: schedule_scope, mode: 'edit', url: GetBasePath('schedules') + id + '/' });
- };
+ schedule_scope.editSchedule = function(id) {
+ GroupsScheduleEdit({ scope: schedule_scope, mode: 'edit', url: GetBasePath('schedules') + id + '/' });
+ };
- schedule_scope.addSchedule = function() {
- GroupsScheduleEdit({ scope: schedule_scope, mode: 'add', url: url });
- };
+ schedule_scope.addSchedule = function() {
+ GroupsScheduleEdit({ scope: schedule_scope, mode: 'add', url: url });
+ };
- if (schedule_scope.removeSchedulesRefresh) {
- schedule_scope.removeSchedulesRefresh();
- }
- schedule_scope.removeSchedulesRefresh = schedule_scope.$on('SchedulesRefresh', function() {
- schedule_scope.search(list.iterator);
- });
+ if (schedule_scope.removeSchedulesRefresh) {
+ schedule_scope.removeSchedulesRefresh();
+ }
+ schedule_scope.removeSchedulesRefresh = schedule_scope.$on('SchedulesRefresh', function() {
+ schedule_scope.search(list.iterator);
+ });
- schedule_scope.toggleSchedule = function(event, id) {
- try {
- $(event.target).tooltip('hide');
- }
- catch(e) {
- // ignore
- }
- ToggleSchedule({
- scope: schedule_scope,
- id: id,
- callback: 'SchedulesRefresh'
- });
- };
+ schedule_scope.toggleSchedule = function(event, id) {
+ try {
+ $(event.target).tooltip('hide');
+ }
+ catch(e) {
+ // ignore
+ }
+ ToggleSchedule({
+ scope: schedule_scope,
+ id: id,
+ callback: 'SchedulesRefresh'
+ });
+ };
- schedule_scope.deleteSchedule = function(id) {
- DeleteSchedule({
- scope: schedule_scope,
- id: id,
- callback: 'SchedulesRefresh'
- });
- };
- };
- }
+ schedule_scope.deleteSchedule = function(id) {
+ DeleteSchedule({
+ scope: schedule_scope,
+ id: id,
+ callback: 'SchedulesRefresh'
+ });
+ };
+ };
+ }
])
/**
@@ -528,12 +530,12 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*/
.factory('SetSchedulesInnerDialogSize', [
function() {
- return function() {
- var height = $('#group-modal-dialog').outerHeight() - $('#group_tabs').outerHeight() - 25;
- height = height - 110 - $('#schedules-buttons').outerHeight();
- $('#schedules-form-container-body').height(height);
- };
- }
+ return function() {
+ var height = $('#group-modal-dialog').outerHeight() - $('#group_tabs').outerHeight() - 25;
+ height = height - 110 - $('#schedules-buttons').outerHeight();
+ $('#schedules-form-container-body').height(height);
+ };
+}
])
/**
@@ -542,150 +544,150 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GroupsScheduleEdit', ['$compile','SchedulerInit', 'Rest', 'Wait', 'SetSchedulesInnerDialogSize', 'SchedulePost', 'ProcessErrors',
- function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, ProcessErrors) {
- return function(params) {
- var parent_scope = params.scope,
- mode = params.mode, // 'add' or 'edit'
- url = params.url,
- scope = parent_scope.$new(),
- schedule = {},
- scheduler,
- target,
- showForm,
- list,
- detail,
- restoreList,
- container,
- elem;
+ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, ProcessErrors) {
+ return function(params) {
+ var parent_scope = params.scope,
+ mode = params.mode, // 'add' or 'edit'
+ url = params.url,
+ scope = parent_scope.$new(),
+ schedule = {},
+ scheduler,
+ target,
+ showForm,
+ list,
+ detail,
+ restoreList,
+ container,
+ elem;
- Wait('start');
- detail = $('#schedules-detail').hide();
- list = $('#schedules-list');
- target = $('#schedules-form');
- container = $('#schedules-form-container');
- // Clean up any lingering stuff
- container.hide();
- target.empty();
- $('.tooltip').each(function () {
- $(this).remove();
- });
- $('.popover').each(function () {
- $(this).remove();
- });
+ Wait('start');
+ detail = $('#schedules-detail').hide();
+ list = $('#schedules-list');
+ target = $('#schedules-form');
+ container = $('#schedules-form-container');
+ // Clean up any lingering stuff
+ container.hide();
+ target.empty();
+ $('.tooltip').each(function () {
+ $(this).remove();
+ });
+ $('.popover').each(function () {
+ $(this).remove();
+ });
- elem = angular.element(document.getElementById('schedules-form-container'));
- $compile(elem)(scope);
+ elem = angular.element(document.getElementById('schedules-form-container'));
+ $compile(elem)(scope);
- if (scope.removeScheduleReady) {
- scope.removeScheduleReady();
- }
- scope.removeScheduleReady = scope.$on('ScheduleReady', function() {
- // Insert the scheduler widget into the hidden div
- scheduler = SchedulerInit({ scope: scope, requireFutureStartTime: false });
- scheduler.inject('schedules-form', false);
- scheduler.injectDetail('schedules-detail', false);
- scheduler.clear();
- scope.formShowing = true;
- scope.showRRuleDetail = false;
- scope.schedulesTitle = (mode === 'edit') ? 'Edit Schedule' : 'Create Schedule';
+ if (scope.removeScheduleReady) {
+ scope.removeScheduleReady();
+ }
+ scope.removeScheduleReady = scope.$on('ScheduleReady', function() {
+ // Insert the scheduler widget into the hidden div
+ scheduler = SchedulerInit({ scope: scope, requireFutureStartTime: false });
+ scheduler.inject('schedules-form', false);
+ scheduler.injectDetail('schedules-detail', false);
+ scheduler.clear();
+ scope.formShowing = true;
+ scope.showRRuleDetail = false;
+ scope.schedulesTitle = (mode === 'edit') ? 'Edit Schedule' : 'Create Schedule';
- // display the scheduler widget
- showForm = function() {
- Wait('stop');
- $('#schedules-overlay').width($('#schedules-tab')
- .width()).height($('#schedules-tab').height()).show();
- container.width($('#schedules-tab').width() - 18);
- SetSchedulesInnerDialogSize();
- container.show('slide', { direction: 'left' }, 300);
- $('#group-save-button').prop('disabled', true);
- target.show();
- if (mode === 'edit') {
- scope.$apply(function() {
- scheduler.setRRule(schedule.rrule);
- scheduler.setName(schedule.name);
- });
- }
- };
- setTimeout(function() { showForm(); }, 1000);
- });
+ // display the scheduler widget
+ showForm = function() {
+ Wait('stop');
+ $('#schedules-overlay').width($('#schedules-tab')
+ .width()).height($('#schedules-tab').height()).show();
+ container.width($('#schedules-tab').width() - 18);
+ SetSchedulesInnerDialogSize();
+ container.show('slide', { direction: 'left' }, 300);
+ $('#group-save-button').prop('disabled', true);
+ target.show();
+ if (mode === 'edit') {
+ scope.$apply(function() {
+ scheduler.setRRule(schedule.rrule);
+ scheduler.setName(schedule.name);
+ });
+ }
+ };
+ setTimeout(function() { showForm(); }, 1000);
+ });
- restoreList = function() {
- $('#group-save-button').prop('disabled', false);
- list.show('slide', { direction: 'right' }, 500);
- $('#schedules-overlay').width($('#schedules-tab').width()).height($('#schedules-tab').height()).hide();
- parent_scope.refreshSchedules();
- };
+ restoreList = function() {
+ $('#group-save-button').prop('disabled', false);
+ list.show('slide', { direction: 'right' }, 500);
+ $('#schedules-overlay').width($('#schedules-tab').width()).height($('#schedules-tab').height()).hide();
+ parent_scope.refreshSchedules();
+ };
- scope.showScheduleDetail = function() {
- if (scope.formShowing) {
- if (scheduler.isValid()) {
- detail.width($('#schedules-form').width()).height($('#schedules-form').height());
- target.hide();
- detail.show();
- scope.formShowing = false;
- }
- }
- else {
- detail.hide();
- target.show();
- scope.formShowing = true;
- }
- };
+ scope.showScheduleDetail = function() {
+ if (scope.formShowing) {
+ if (scheduler.isValid()) {
+ detail.width($('#schedules-form').width()).height($('#schedules-form').height());
+ target.hide();
+ detail.show();
+ scope.formShowing = false;
+ }
+ }
+ else {
+ detail.hide();
+ target.show();
+ scope.formShowing = true;
+ }
+ };
- if (scope.removeScheduleSaved) {
- scope.removeScheduleSaved();
- }
- scope.removeScheduleSaved = scope.$on('ScheduleSaved', function() {
- Wait('stop');
- container.hide('slide', { direction: 'right' }, 500, restoreList);
- scope.$destroy();
- });
+ if (scope.removeScheduleSaved) {
+ scope.removeScheduleSaved();
+ }
+ scope.removeScheduleSaved = scope.$on('ScheduleSaved', function() {
+ Wait('stop');
+ container.hide('slide', { direction: 'right' }, 500, restoreList);
+ scope.$destroy();
+ });
- scope.saveScheduleForm = function() {
- if (scheduler.isValid()) {
- scope.schedulerIsValid = true;
- SchedulePost({
- scope: scope,
- url: url,
- scheduler: scheduler,
- callback: 'ScheduleSaved',
- mode: mode,
- schedule: schedule
- });
- }
- else {
- scope.schedulerIsValid = false;
- }
- };
+ scope.saveScheduleForm = function() {
+ if (scheduler.isValid()) {
+ scope.schedulerIsValid = true;
+ SchedulePost({
+ scope: scope,
+ url: url,
+ scheduler: scheduler,
+ callback: 'ScheduleSaved',
+ mode: mode,
+ schedule: schedule
+ });
+ }
+ else {
+ scope.schedulerIsValid = false;
+ }
+ };
- scope.cancelScheduleForm = function() {
- container.hide('slide', { direction: 'right' }, 500, restoreList);
- scope.$destroy();
- };
+ scope.cancelScheduleForm = function() {
+ container.hide('slide', { direction: 'right' }, 500, restoreList);
+ scope.$destroy();
+ };
- if (mode === 'edit') {
- // Get the existing record
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- schedule = data;
- if (!/DTSTART/.test(schedule.rrule)) {
- schedule.rrule += ";DTSTART=" + schedule.dtstart.replace(/\.\d+Z$/,'Z');
- }
- schedule.rrule = schedule.rrule.replace(/ RRULE:/,';');
- schedule.rrule = schedule.rrule.replace(/DTSTART:/,'DTSTART=');
- scope.$emit('ScheduleReady');
- })
- .error(function(data,status){
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to get: ' + url + ' GET returned: ' + status });
- });
- }
- else {
- scope.$emit('ScheduleReady');
- }
- };
- }
+ if (mode === 'edit') {
+ // Get the existing record
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ schedule = data;
+ if (!/DTSTART/.test(schedule.rrule)) {
+ schedule.rrule += ";DTSTART=" + schedule.dtstart.replace(/\.\d+Z$/,'Z');
+ }
+ schedule.rrule = schedule.rrule.replace(/ RRULE:/,';');
+ schedule.rrule = schedule.rrule.replace(/DTSTART:/,'DTSTART=');
+ scope.$emit('ScheduleReady');
+ })
+ .error(function(data,status){
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to get: ' + url + ' GET returned: ' + status });
+ });
+ }
+ else {
+ scope.$emit('ScheduleReady');
+ }
+ };
+ }
])
/**
@@ -694,724 +696,724 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GroupsEdit', ['$rootScope', '$location', '$log', '$routeParams', '$compile', 'Rest', 'Alert', 'GroupForm', 'GenerateForm',
-'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate',
-'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find', 'WatchInventoryWindowResize',
-'ParseVariableString', 'ToJSON', 'GroupsScheduleListInit', 'SourceForm', 'SetSchedulesInnerDialogSize',
- function ($rootScope, $location, $log, $routeParams, $compile, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
- GetBasePath, SetNodeName, ParseTypeChange, GetSourceTypeOptions, InventoryUpdate, LookUpInit, Empty, Wait,
- GetChoices, UpdateGroup, SourceChange, Find, WatchInventoryWindowResize, ParseVariableString, ToJSON, GroupsScheduleListInit,
- SourceForm, SetSchedulesInnerDialogSize) {
- return function (params) {
+ 'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate',
+ 'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find', 'WatchInventoryWindowResize',
+ 'ParseVariableString', 'ToJSON', 'GroupsScheduleListInit', 'SourceForm', 'SetSchedulesInnerDialogSize',
+ function ($rootScope, $location, $log, $routeParams, $compile, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
+ GetBasePath, SetNodeName, ParseTypeChange, GetSourceTypeOptions, InventoryUpdate, LookUpInit, Empty, Wait,
+ GetChoices, UpdateGroup, SourceChange, Find, WatchInventoryWindowResize, ParseVariableString, ToJSON, GroupsScheduleListInit,
+ SourceForm, SetSchedulesInnerDialogSize) {
+ return function (params) {
- var parent_scope = params.scope,
- group_id = params.group_id,
- mode = params.mode, // 'add' or 'edit'
- inventory_id = params.inventory_id,
- generator = GenerateForm,
- group_created = false,
- defaultUrl,
- master = {},
- choicesReady,
- modal_scope = parent_scope.$new(),
- properties_scope = parent_scope.$new(),
- sources_scope = parent_scope.$new(),
- elem, x, y, ww, wh, maxrows,
- group,
- schedules_url = '';
+ var parent_scope = params.scope,
+ group_id = params.group_id,
+ mode = params.mode, // 'add' or 'edit'
+ inventory_id = params.inventory_id,
+ generator = GenerateForm,
+ group_created = false,
+ defaultUrl,
+ master = {},
+ choicesReady,
+ modal_scope = parent_scope.$new(),
+ properties_scope = parent_scope.$new(),
+ sources_scope = parent_scope.$new(),
+ elem, x, y, ww, wh, maxrows,
+ group,
+ schedules_url = '';
- if (mode === 'edit') {
- defaultUrl = GetBasePath('groups') + group_id + '/';
- }
- else {
- defaultUrl = (group_id !== null) ? GetBasePath('groups') + group_id + '/children/' :
- GetBasePath('inventory') + inventory_id + '/groups/';
- }
+ if (mode === 'edit') {
+ defaultUrl = GetBasePath('groups') + group_id + '/';
+ }
+ else {
+ defaultUrl = (group_id !== null) ? GetBasePath('groups') + group_id + '/children/' :
+ GetBasePath('inventory') + inventory_id + '/groups/';
+ }
- $('#properties-tab').empty();
- $('#sources-tab').empty();
- $('#schedules-list').empty();
- $('#schedules-form').empty();
- $('#schedules-detail').empty();
+ $('#properties-tab').empty();
+ $('#sources-tab').empty();
+ $('#schedules-list').empty();
+ $('#schedules-form').empty();
+ $('#schedules-detail').empty();
- elem = document.getElementById('group-modal-dialog');
- $compile(elem)(modal_scope);
+ elem = document.getElementById('group-modal-dialog');
+ $compile(elem)(modal_scope);
- generator.inject(GroupForm, { mode: 'edit', id: 'properties-tab', breadCrumbs: false, related: false, scope: properties_scope });
- generator.inject(SourceForm, { mode: 'edit', id: 'sources-tab', breadCrumbs: false, related: false, scope: sources_scope });
+ generator.inject(GroupForm, { mode: 'edit', id: 'properties-tab', breadCrumbs: false, related: false, scope: properties_scope });
+ generator.inject(SourceForm, { mode: 'edit', id: 'sources-tab', breadCrumbs: false, related: false, scope: sources_scope });
- //generator.reset();
+ //generator.reset();
- GetSourceTypeOptions({ scope: sources_scope, variable: 'source_type_options' });
- sources_scope.source = SourceForm.fields.source['default'];
- sources_scope.sourcePathRequired = false;
- sources_scope[SourceForm.fields.source_vars.parseTypeName] = 'yaml';
- sources_scope.update_cache_timeout = 0;
- properties_scope.parseType = 'yaml';
+ GetSourceTypeOptions({ scope: sources_scope, variable: 'source_type_options' });
+ sources_scope.source = SourceForm.fields.source['default'];
+ sources_scope.sourcePathRequired = false;
+ sources_scope[SourceForm.fields.source_vars.parseTypeName] = 'yaml';
+ sources_scope.update_cache_timeout = 0;
+ properties_scope.parseType = 'yaml';
- function waitStop() { Wait('stop'); }
+ function waitStop() { Wait('stop'); }
- // Attempt to create the largest textarea field that will fit on the window. Minimum
- // height is 6 rows, so on short windows you will see vertical scrolling
- function textareaResize(textareaID) {
- var textArea, formHeight, model, windowHeight, offset, rows;
- textArea = $('#' + textareaID);
- if (properties_scope.codeMirror) {
- model = textArea.attr('ng-model');
- properties_scope[model] = properties_scope.codeMirror.getValue();
- properties_scope.codeMirror.destroy();
- }
- textArea.attr('rows', 1);
- formHeight = $('#group_form').height();
- windowHeight = $('#group-modal-dialog').height() - 20; //leave a margin of 20px
- offset = Math.floor(windowHeight - formHeight);
- rows = Math.floor(offset / 24);
- rows = (rows < 6) ? 6 : rows;
- textArea.attr('rows', rows);
- while(rows > 6 && $('#group_form').height() > $('#group-modal-dialog').height()) {
- rows--;
- textArea.attr('rows', rows);
- }
- ParseTypeChange({ scope: properties_scope, field_id: textareaID, onReady: waitStop });
- }
+ // Attempt to create the largest textarea field that will fit on the window. Minimum
+ // height is 6 rows, so on short windows you will see vertical scrolling
+ function textareaResize(textareaID) {
+ var textArea, formHeight, model, windowHeight, offset, rows;
+ textArea = $('#' + textareaID);
+ if (properties_scope.codeMirror) {
+ model = textArea.attr('ng-model');
+ properties_scope[model] = properties_scope.codeMirror.getValue();
+ properties_scope.codeMirror.destroy();
+ }
+ textArea.attr('rows', 1);
+ formHeight = $('#group_form').height();
+ windowHeight = $('#group-modal-dialog').height() - 20; //leave a margin of 20px
+ offset = Math.floor(windowHeight - formHeight);
+ rows = Math.floor(offset / 24);
+ rows = (rows < 6) ? 6 : rows;
+ textArea.attr('rows', rows);
+ while(rows > 6 && $('#group_form').height() > $('#group-modal-dialog').height()) {
+ rows--;
+ textArea.attr('rows', rows);
+ }
+ ParseTypeChange({ scope: properties_scope, field_id: textareaID, onReady: waitStop });
+ }
- // Set modal dimensions based on viewport width
- ww = $(document).width();
- wh = $('body').height();
- if (ww > 1199) {
- // desktop
- x = 675;
- y = (800 > wh) ? wh - 15 : 800;
- maxrows = 18;
- } else if (ww <= 1199 && ww >= 768) {
- x = 550;
- y = (770 > wh) ? wh - 15 : 770;
- maxrows = 12;
- } else {
- x = (ww - 20);
- y = (770 > wh) ? wh - 15 : 770;
- maxrows = 10;
- }
+ // Set modal dimensions based on viewport width
+ ww = $(document).width();
+ wh = $('body').height();
+ if (ww > 1199) {
+ // desktop
+ x = 675;
+ y = (800 > wh) ? wh - 15 : 800;
+ maxrows = 18;
+ } else if (ww <= 1199 && ww >= 768) {
+ x = 550;
+ y = (770 > wh) ? wh - 15 : 770;
+ maxrows = 12;
+ } else {
+ x = (ww - 20);
+ y = (770 > wh) ? wh - 15 : 770;
+ maxrows = 10;
+ }
- // Create the modal
- $('#group-modal-dialog').dialog({
- buttons: {
- 'Cancel': function() {
- modal_scope.cancelModal();
- },
- 'Save': function () {
- modal_scope.saveGroup();
- }
- },
- modal: true,
- width: x,
- height: y,
- autoOpen: false,
- minWidth: 440,
- title: (mode === 'edit') ? 'Edit Group' : 'Add Group',
- closeOnEscape: false,
- create: function () {
- $('.ui-dialog[aria-describedby="group-modal-dialog"]').find('.ui-dialog-titlebar button').empty().attr({'class': 'close'}).text('x');
- $('.ui-dialog[aria-describedby="group-modal-dialog"]').find('.ui-dialog-buttonset button').each(function () {
- var c, h, i, l;
- l = $(this).text();
- if (l === 'Cancel') {
- h = "fa-times";
- c = "btn btn-default";
- i = "group-close-button";
- $(this).attr({
- 'class': c,
- 'id': i
- }).html(" Cancel");
- } else if (l === 'Save') {
- h = "fa-check";
- c = "btn btn-primary";
- i = "group-save-button";
- $(this).attr({
- 'class': c,
- 'id': i
- }).html(" Save");
- }
- });
- },
- resizeStop: function () {
- // for some reason, after resizing dialog the form and fields (the content) doesn't expand to 100%
- var dialog = $('.ui-dialog[aria-describedby="group-modal-dialog"]'),
- titleHeight = dialog.find('.ui-dialog-titlebar').outerHeight(),
- buttonHeight = dialog.find('.ui-dialog-buttonpane').outerHeight(),
- content = dialog.find('#group-modal-dialog'),
- w;
- content.width(dialog.width() - 28);
- content.css({ height: (dialog.height() - titleHeight - buttonHeight - 10) });
+ // Create the modal
+ $('#group-modal-dialog').dialog({
+ buttons: {
+ 'Cancel': function() {
+ modal_scope.cancelModal();
+ },
+ 'Save': function () {
+ modal_scope.saveGroup();
+ }
+ },
+ modal: true,
+ width: x,
+ height: y,
+ autoOpen: false,
+ minWidth: 440,
+ title: (mode === 'edit') ? 'Edit Group' : 'Add Group',
+ closeOnEscape: false,
+ create: function () {
+ $('.ui-dialog[aria-describedby="group-modal-dialog"]').find('.ui-dialog-titlebar button').empty().attr({'class': 'close'}).text('x');
+ $('.ui-dialog[aria-describedby="group-modal-dialog"]').find('.ui-dialog-buttonset button').each(function () {
+ var c, h, i, l;
+ l = $(this).text();
+ if (l === 'Cancel') {
+ h = "fa-times";
+ c = "btn btn-default";
+ i = "group-close-button";
+ $(this).attr({
+ 'class': c,
+ 'id': i
+ }).html(" Cancel");
+ } else if (l === 'Save') {
+ h = "fa-check";
+ c = "btn btn-primary";
+ i = "group-save-button";
+ $(this).attr({
+ 'class': c,
+ 'id': i
+ }).html(" Save");
+ }
+ });
+ },
+ resizeStop: function () {
+ // for some reason, after resizing dialog the form and fields (the content) doesn't expand to 100%
+ var dialog = $('.ui-dialog[aria-describedby="group-modal-dialog"]'),
+ titleHeight = dialog.find('.ui-dialog-titlebar').outerHeight(),
+ buttonHeight = dialog.find('.ui-dialog-buttonpane').outerHeight(),
+ content = dialog.find('#group-modal-dialog'),
+ w;
+ content.width(dialog.width() - 28);
+ content.css({ height: (dialog.height() - titleHeight - buttonHeight - 10) });
- if ($('#group_tabs .active a').text() === 'Properties') {
- textareaResize('group_variables', properties_scope);
- }
- else if ($('#group_tabs .active a').text() === 'Schedule') {
- w = $('#group_tabs').width() - 18;
- $('#schedules-overlay').width(w);
- $('#schedules-form-container').width(w);
- SetSchedulesInnerDialogSize();
- }
- },
- close: function () {
- // Destroy on close
- $('.tooltip').each(function () {
- // Remove any lingering tooltip elements
- $(this).remove();
- });
- $('.popover').each(function () {
- // remove lingering popover
elements
- $(this).remove();
- });
- if (properties_scope.codeMirror) {
- properties_scope.codeMirror.destroy();
- }
- if (sources_scope.codeMirror) {
- sources_scope.codeMirror.destroy();
- }
- $('#properties-tab').empty();
- $('#sources-tab').empty();
- $('#schedules-list').empty();
- $('#schedules-form').empty();
- $('#schedules-detail').empty();
- $('#group-modal-dialog').hide();
- $('#group-modal-dialog').dialog('destroy');
- modal_scope.cancelModal();
- },
- open: function () {
- $('#group_name').focus();
- Wait('stop');
- }
- });
+ if ($('#group_tabs .active a').text() === 'Properties') {
+ textareaResize('group_variables', properties_scope);
+ }
+ else if ($('#group_tabs .active a').text() === 'Schedule') {
+ w = $('#group_tabs').width() - 18;
+ $('#schedules-overlay').width(w);
+ $('#schedules-form-container').width(w);
+ SetSchedulesInnerDialogSize();
+ }
+ },
+ close: function () {
+ // Destroy on close
+ $('.tooltip').each(function () {
+ // Remove any lingering tooltip
elements
+ $(this).remove();
+ });
+ $('.popover').each(function () {
+ // remove lingering popover
elements
+ $(this).remove();
+ });
+ if (properties_scope.codeMirror) {
+ properties_scope.codeMirror.destroy();
+ }
+ if (sources_scope.codeMirror) {
+ sources_scope.codeMirror.destroy();
+ }
+ $('#properties-tab').empty();
+ $('#sources-tab').empty();
+ $('#schedules-list').empty();
+ $('#schedules-form').empty();
+ $('#schedules-detail').empty();
+ $('#group-modal-dialog').hide();
+ $('#group-modal-dialog').dialog('destroy');
+ modal_scope.cancelModal();
+ },
+ open: function () {
+ $('#group_name').focus();
+ Wait('stop');
+ }
+ });
- $('#group_tabs a[data-toggle="tab"]').on('show.bs.tab', function (e) {
- if ($(e.target).text() === 'Properties') {
- Wait('start');
- setTimeout(function(){ textareaResize('group_variables'); }, 300);
- }
- else if ($(e.target).text() === 'Source') {
- if (sources_scope.source && (sources_scope.source.value === 'ec2')) {
- Wait('start');
- ParseTypeChange({ scope: sources_scope, variable: 'source_vars', parse_variable: SourceForm.fields.source_vars.parseTypeName,
- field_id: 'source_source_vars', onReady: waitStop });
- } else if (sources_scope.source && (sources_scope.source.value === 'vmware')) {
- Wait('start');
- ParseTypeChange({ scope: sources_scope, variable: 'inventory_variables', parse_variable: SourceForm.fields.inventory_variables.parseTypeName,
- field_id: 'source_inventory_variables', onReady: waitStop });
- }
- else if (sources_scope.source && (sources_scope.source.value === 'custom')) {
- Wait('start');
- ParseTypeChange({ scope: sources_scope, variable: 'extra_vars', parse_variable: SourceForm.fields.extra_vars.parseTypeName,
- field_id: 'source_extra_vars', onReady: waitStop });
- }
- }
- else if ($(e.target).text() === 'Schedule') {
- $('#schedules-overlay').hide();
- }
- });
+ $('#group_tabs a[data-toggle="tab"]').on('show.bs.tab', function (e) {
+ if ($(e.target).text() === 'Properties') {
+ Wait('start');
+ setTimeout(function(){ textareaResize('group_variables'); }, 300);
+ }
+ else if ($(e.target).text() === 'Source') {
+ if (sources_scope.source && (sources_scope.source.value === 'ec2')) {
+ Wait('start');
+ ParseTypeChange({ scope: sources_scope, variable: 'source_vars', parse_variable: SourceForm.fields.source_vars.parseTypeName,
+ field_id: 'source_source_vars', onReady: waitStop });
+ } else if (sources_scope.source && (sources_scope.source.value === 'vmware')) {
+ Wait('start');
+ ParseTypeChange({ scope: sources_scope, variable: 'inventory_variables', parse_variable: SourceForm.fields.inventory_variables.parseTypeName,
+ field_id: 'source_inventory_variables', onReady: waitStop });
+ }
+ else if (sources_scope.source && (sources_scope.source.value === 'custom')) {
+ Wait('start');
+ ParseTypeChange({ scope: sources_scope, variable: 'extra_vars', parse_variable: SourceForm.fields.extra_vars.parseTypeName,
+ field_id: 'source_extra_vars', onReady: waitStop });
+ }
+ }
+ else if ($(e.target).text() === 'Schedule') {
+ $('#schedules-overlay').hide();
+ }
+ });
- if (modal_scope.groupVariablesLoadedRemove) {
- modal_scope.groupVariablesLoadedRemove();
- }
- modal_scope.groupVariablesLoadedRemove = modal_scope.$on('groupVariablesLoaded', function () {
- modal_scope.showSourceTab = (mode === 'edit' && group.has_inventory_sources && Empty(group.summary_fields.inventory_source.source) && sources_scope.source.value!=='manual') ? false : true;
- modal_scope.showSchedulesTab = (mode === 'edit' && sources_scope.source && sources_scope.source.value!=='manual') ? true : false;
- if (mode === 'edit' && modal_scope.showSourceTab) {
- // the use has access to the source tab, so they may create a schedule
- GroupsScheduleListInit({ scope: modal_scope, url: schedules_url });
- }
- $('#group_tabs a:first').tab('show');
- Wait('start');
- $('#group-modal-dialog').dialog('open');
- setTimeout(function() { textareaResize('group_variables', properties_scope); }, 300);
- });
+ if (modal_scope.groupVariablesLoadedRemove) {
+ modal_scope.groupVariablesLoadedRemove();
+ }
+ modal_scope.groupVariablesLoadedRemove = modal_scope.$on('groupVariablesLoaded', function () {
+ modal_scope.showSourceTab = (mode === 'edit' && group.has_inventory_sources && Empty(group.summary_fields.inventory_source.source) && sources_scope.source.value!=='manual') ? false : true;
+ modal_scope.showSchedulesTab = (mode === 'edit' && sources_scope.source && sources_scope.source.value!=='manual') ? true : false;
+ if (mode === 'edit' && modal_scope.showSourceTab) {
+ // the use has access to the source tab, so they may create a schedule
+ GroupsScheduleListInit({ scope: modal_scope, url: schedules_url });
+ }
+ $('#group_tabs a:first').tab('show');
+ Wait('start');
+ $('#group-modal-dialog').dialog('open');
+ setTimeout(function() { textareaResize('group_variables', properties_scope); }, 300);
+ });
- // After the group record is loaded, retrieve related data.
- // jt-- i'm changing this to act sequentially: first load properties, then sources, then schedule
- // I accomplished this by adding "LoadSourceData" which will run the source retrieval code after the property
- // variables are set.
- if (modal_scope.groupLoadedRemove) {
- modal_scope.groupLoadedRemove();
- }
- modal_scope.groupLoadedRemove = modal_scope.$on('groupLoaded', function () {
- if (properties_scope.variable_url) {
- // get group variables
- Rest.setUrl(properties_scope.variable_url);
- Rest.get()
- .success(function (data) {
- properties_scope.variables = ParseVariableString(data);
- master.variables = properties_scope.variables;
- modal_scope.$emit('LoadSourceData');
- //modal_scope.$emit('groupVariablesLoaded'); jt- this needs to get called after sources are loaded
- })
- .error(function (data, status) {
- properties_scope.variables = null;
- ProcessErrors(modal_scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve group variables. GET returned status: ' + status });
- });
- } else {
- properties_scope.variables = "---";
- master.variables = properties_scope.variables;
- modal_scope.$emit('LoadSourceData');
- //properties_scope.$emit('groupVariablesLoaded');
- }
- });
+ // After the group record is loaded, retrieve related data.
+ // jt-- i'm changing this to act sequentially: first load properties, then sources, then schedule
+ // I accomplished this by adding "LoadSourceData" which will run the source retrieval code after the property
+ // variables are set.
+ if (modal_scope.groupLoadedRemove) {
+ modal_scope.groupLoadedRemove();
+ }
+ modal_scope.groupLoadedRemove = modal_scope.$on('groupLoaded', function () {
+ if (properties_scope.variable_url) {
+ // get group variables
+ Rest.setUrl(properties_scope.variable_url);
+ Rest.get()
+ .success(function (data) {
+ properties_scope.variables = ParseVariableString(data);
+ master.variables = properties_scope.variables;
+ modal_scope.$emit('LoadSourceData');
+ //modal_scope.$emit('groupVariablesLoaded'); jt- this needs to get called after sources are loaded
+ })
+ .error(function (data, status) {
+ properties_scope.variables = null;
+ ProcessErrors(modal_scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve group variables. GET returned status: ' + status });
+ });
+ } else {
+ properties_scope.variables = "---";
+ master.variables = properties_scope.variables;
+ modal_scope.$emit('LoadSourceData');
+ //properties_scope.$emit('groupVariablesLoaded');
+ }
+ });
- // JT -- this gets called after the properties & properties variables are loaded, and is emitted from (groupLoaded)
- if (modal_scope.removeLoadSourceData) {
- modal_scope.removeLoadSourceData();
- }
- modal_scope.removeLoadSourceData = modal_scope.$on('LoadSourceData', function () {
- if (sources_scope.source_url) {
- // get source data
- Rest.setUrl(sources_scope.source_url);
- Rest.get()
- .success(function (data) {
- var fld, i, j, flag, found, set, opts, list, form;
- form = SourceForm;
- for (fld in form.fields) {
- if (fld === 'checkbox_group') {
- for (i = 0; i < form.fields[fld].fields.length; i++) {
- flag = form.fields[fld].fields[i];
- if (data[flag.name] !== undefined) {
- sources_scope[flag.name] = data[flag.name];
- master[flag.name] = sources_scope[flag.name];
- }
- }
- }
- if (fld === 'source') {
- found = false;
- data.source = (data.source === "" ) ? "manual" : data.source;
- for (i = 0; i < sources_scope.source_type_options.length; i++) {
- if (sources_scope.source_type_options[i].value === data.source) {
- sources_scope.source = sources_scope.source_type_options[i];
- found = true;
- }
- }
- if (!found || sources_scope.source.value === "manual") {
- sources_scope.groupUpdateHide = true;
- } else {
- sources_scope.groupUpdateHide = false;
- }
- master.source = sources_scope.source;
- } else if (fld === 'source_vars') {
- // Parse source_vars, converting to YAML.
- sources_scope.source_vars = ParseVariableString(data.source_vars);
- master.source_vars = sources_scope.variables;
- }
- // else if(fld === "source_script"){
- // sources_scope[fld] = data
- // }
+ // JT -- this gets called after the properties & properties variables are loaded, and is emitted from (groupLoaded)
+ if (modal_scope.removeLoadSourceData) {
+ modal_scope.removeLoadSourceData();
+ }
+ modal_scope.removeLoadSourceData = modal_scope.$on('LoadSourceData', function () {
+ if (sources_scope.source_url) {
+ // get source data
+ Rest.setUrl(sources_scope.source_url);
+ Rest.get()
+ .success(function (data) {
+ var fld, i, j, flag, found, set, opts, list, form;
+ form = SourceForm;
+ for (fld in form.fields) {
+ if (fld === 'checkbox_group') {
+ for (i = 0; i < form.fields[fld].fields.length; i++) {
+ flag = form.fields[fld].fields[i];
+ if (data[flag.name] !== undefined) {
+ sources_scope[flag.name] = data[flag.name];
+ master[flag.name] = sources_scope[flag.name];
+ }
+ }
+ }
+ if (fld === 'source') {
+ found = false;
+ data.source = (data.source === "" ) ? "manual" : data.source;
+ for (i = 0; i < sources_scope.source_type_options.length; i++) {
+ if (sources_scope.source_type_options[i].value === data.source) {
+ sources_scope.source = sources_scope.source_type_options[i];
+ found = true;
+ }
+ }
+ if (!found || sources_scope.source.value === "manual") {
+ sources_scope.groupUpdateHide = true;
+ } else {
+ sources_scope.groupUpdateHide = false;
+ }
+ master.source = sources_scope.source;
+ } else if (fld === 'source_vars') {
+ // Parse source_vars, converting to YAML.
+ sources_scope.source_vars = ParseVariableString(data.source_vars);
+ master.source_vars = sources_scope.variables;
+ }
+ // else if(fld === "source_script"){
+ // sources_scope[fld] = data
+ // }
- else if (data[fld] !== undefined) {
- sources_scope[fld] = data[fld];
- master[fld] = sources_scope[fld];
- }
+ else if (data[fld] !== undefined) {
+ sources_scope[fld] = data[fld];
+ master[fld] = sources_scope[fld];
+ }
- if (form.fields[fld].sourceModel && data.summary_fields &&
- data.summary_fields[form.fields[fld].sourceModel]) {
- sources_scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
- data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
- master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
- data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
- }
- }
+ if (form.fields[fld].sourceModel && data.summary_fields &&
+ data.summary_fields[form.fields[fld].sourceModel]) {
+ sources_scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
+ data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
+ master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
+ data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
+ }
+ }
- sources_scope.sourceChange(); //set defaults that rely on source value
+ sources_scope.sourceChange(); //set defaults that rely on source value
- if (data.source_regions) {
- if (data.source === 'ec2' || data.source === 'rax') {
- set = (data.source === 'ec2') ? sources_scope.ec2_regions : sources_scope.rax_regions;
- opts = [];
- list = data.source_regions.split(',');
- for (i = 0; i < list.length; i++) {
- for (j = 0; j < set.length; j++) {
- if (list[i] === set[j].value) {
- opts.push({
- id: set[j].value,
- text: set[j].label
- });
- }
- }
- }
- master.source_regions = opts;
- $('#s2id_source_source_regions').select2('data', opts);
- }
- } else {
- // If empty, default to all
- master.source_regions = [{
- id: 'all',
- text: 'All'
- }];
- $('#s2id_source_source_regions').select2('data', master.source_regions);
- }
- if (data.group_by && data.source === 'ec2') {
- set = sources_scope.ec2_group_by;
- opts = [];
- list = data.group_by.split(',');
- for (i = 0; i < list.length; i++) {
- for (j = 0; j < set.length; j++) {
- if (list[i] === set[j].value) {
- opts.push({
- id: set[j].value,
- text: set[j].label
- });
- }
- }
- }
- master.group_by = opts;
- $('#s2id_source_group_by').select2('data', opts);
- }
- sources_scope.group_update_url = data.related.update;
- modal_scope.$emit('groupVariablesLoaded'); // JT-- "groupVariablesLoaded" is where the schedule info is loaded, so I make a call after the sources_scope.source has been loaded
- //Wait('stop');
- })
- .error(function (data, status) {
- sources_scope.source = "";
- ProcessErrors(modal_scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve inventory source. GET status: ' + status });
- });
- }
- else {
- modal_scope.$emit('groupVariablesLoaded'); // JT-- "groupVariablesLoaded" is where the schedule info is loaded, so I make a call after the sources_scope.source has been loaded
- }
- });
+ if (data.source_regions) {
+ if (data.source === 'ec2' || data.source === 'rax') {
+ set = (data.source === 'ec2') ? sources_scope.ec2_regions : sources_scope.rax_regions;
+ opts = [];
+ list = data.source_regions.split(',');
+ for (i = 0; i < list.length; i++) {
+ for (j = 0; j < set.length; j++) {
+ if (list[i] === set[j].value) {
+ opts.push({
+ id: set[j].value,
+ text: set[j].label
+ });
+ }
+ }
+ }
+ master.source_regions = opts;
+ $('#s2id_source_source_regions').select2('data', opts);
+ }
+ } else {
+ // If empty, default to all
+ master.source_regions = [{
+ id: 'all',
+ text: 'All'
+ }];
+ $('#s2id_source_source_regions').select2('data', master.source_regions);
+ }
+ if (data.group_by && data.source === 'ec2') {
+ set = sources_scope.ec2_group_by;
+ opts = [];
+ list = data.group_by.split(',');
+ for (i = 0; i < list.length; i++) {
+ for (j = 0; j < set.length; j++) {
+ if (list[i] === set[j].value) {
+ opts.push({
+ id: set[j].value,
+ text: set[j].label
+ });
+ }
+ }
+ }
+ master.group_by = opts;
+ $('#s2id_source_group_by').select2('data', opts);
+ }
+ sources_scope.group_update_url = data.related.update;
+ modal_scope.$emit('groupVariablesLoaded'); // JT-- "groupVariablesLoaded" is where the schedule info is loaded, so I make a call after the sources_scope.source has been loaded
+ //Wait('stop');
+ })
+ .error(function (data, status) {
+ sources_scope.source = "";
+ ProcessErrors(modal_scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve inventory source. GET status: ' + status });
+ });
+ }
+ else {
+ modal_scope.$emit('groupVariablesLoaded'); // JT-- "groupVariablesLoaded" is where the schedule info is loaded, so I make a call after the sources_scope.source has been loaded
+ }
+ });
- if (sources_scope.removeScopeSourceTypeOptionsReady) {
- sources_scope.removeScopeSourceTypeOptionsReady();
- }
- sources_scope.removeScopeSourceTypeOptionsReady = sources_scope.$on('sourceTypeOptionsReady', function() {
- if (mode === 'add') {
- sources_scope.source = Find({
- list: sources_scope.source_type_options,
- key: 'value',
- val: ''
- });
- modal_scope.showSchedulesTab = false;
- }
- });
+ if (sources_scope.removeScopeSourceTypeOptionsReady) {
+ sources_scope.removeScopeSourceTypeOptionsReady();
+ }
+ sources_scope.removeScopeSourceTypeOptionsReady = sources_scope.$on('sourceTypeOptionsReady', function() {
+ if (mode === 'add') {
+ sources_scope.source = Find({
+ list: sources_scope.source_type_options,
+ key: 'value',
+ val: ''
+ });
+ modal_scope.showSchedulesTab = false;
+ }
+ });
- if (modal_scope.removeChoicesComplete) {
- modal_scope.removeChoicesComplete();
- }
- modal_scope.removeChoicesComplete = modal_scope.$on('choicesCompleteGroup', function () {
- // Retrieve detail record and prepopulate the form
- Rest.setUrl(defaultUrl);
- Rest.get()
- .success(function (data) {
- group = data;
- for (var fld in GroupForm.fields) {
- if (data[fld]) {
- properties_scope[fld] = data[fld];
- master[fld] = properties_scope[fld];
- }
- }
- schedules_url = data.related.inventory_source + 'schedules/';
- properties_scope.variable_url = data.related.variable_data;
- sources_scope.source_url = data.related.inventory_source;
- modal_scope.$emit('groupLoaded');
- })
- .error(function (data, status) {
- ProcessErrors(modal_scope, data, status, { hdr: 'Error!',
- msg: 'Failed to retrieve group: ' + defaultUrl + '. GET status: ' + status });
- });
- });
+ if (modal_scope.removeChoicesComplete) {
+ modal_scope.removeChoicesComplete();
+ }
+ modal_scope.removeChoicesComplete = modal_scope.$on('choicesCompleteGroup', function () {
+ // Retrieve detail record and prepopulate the form
+ Rest.setUrl(defaultUrl);
+ Rest.get()
+ .success(function (data) {
+ group = data;
+ for (var fld in GroupForm.fields) {
+ if (data[fld]) {
+ properties_scope[fld] = data[fld];
+ master[fld] = properties_scope[fld];
+ }
+ }
+ schedules_url = data.related.inventory_source + 'schedules/';
+ properties_scope.variable_url = data.related.variable_data;
+ sources_scope.source_url = data.related.inventory_source;
+ modal_scope.$emit('groupLoaded');
+ })
+ .error(function (data, status) {
+ ProcessErrors(modal_scope, data, status, { hdr: 'Error!',
+ msg: 'Failed to retrieve group: ' + defaultUrl + '. GET status: ' + status });
+ });
+ });
- choicesReady = 0;
+ choicesReady = 0;
- if (sources_scope.removeChoicesReady) {
- sources_scope.removeChoicesReady();
- }
- sources_scope.removeChoicesReady = sources_scope.$on('choicesReadyGroup', function () {
- choicesReady++;
- if (choicesReady === 2) {
- if (mode === 'edit') {
- modal_scope.$emit('choicesCompleteGroup');
- }
- else {
- properties_scope.variables = "---";
- master.variables = properties_scope.variables;
- modal_scope.$emit('groupVariablesLoaded');
- }
- }
- });
+ if (sources_scope.removeChoicesReady) {
+ sources_scope.removeChoicesReady();
+ }
+ sources_scope.removeChoicesReady = sources_scope.$on('choicesReadyGroup', function () {
+ choicesReady++;
+ if (choicesReady === 2) {
+ if (mode === 'edit') {
+ modal_scope.$emit('choicesCompleteGroup');
+ }
+ else {
+ properties_scope.variables = "---";
+ master.variables = properties_scope.variables;
+ modal_scope.$emit('groupVariablesLoaded');
+ }
+ }
+ });
- // Load options for source regions
- GetChoices({
- scope: sources_scope,
- url: GetBasePath('inventory_sources'),
- field: 'source_regions',
- variable: 'rax_regions',
- choice_name: 'rax_region_choices',
- callback: 'choicesReadyGroup'
- });
+ // Load options for source regions
+ GetChoices({
+ scope: sources_scope,
+ url: GetBasePath('inventory_sources'),
+ field: 'source_regions',
+ variable: 'rax_regions',
+ choice_name: 'rax_region_choices',
+ callback: 'choicesReadyGroup'
+ });
- GetChoices({
- scope: sources_scope,
- url: GetBasePath('inventory_sources'),
- field: 'source_regions',
- variable: 'ec2_regions',
- choice_name: 'ec2_region_choices',
- callback: 'choicesReadyGroup'
- });
+ GetChoices({
+ scope: sources_scope,
+ url: GetBasePath('inventory_sources'),
+ field: 'source_regions',
+ variable: 'ec2_regions',
+ choice_name: 'ec2_region_choices',
+ callback: 'choicesReadyGroup'
+ });
- GetChoices({
- scope: sources_scope,
- url: GetBasePath('inventory_sources'),
- field: 'source_regions',
- variable: 'gce_regions',
- choice_name: 'gce_region_choices',
- callback: 'choicesReadyGroup'
- });
+ GetChoices({
+ scope: sources_scope,
+ url: GetBasePath('inventory_sources'),
+ field: 'source_regions',
+ variable: 'gce_regions',
+ choice_name: 'gce_region_choices',
+ callback: 'choicesReadyGroup'
+ });
- GetChoices({
- scope: sources_scope,
- url: GetBasePath('inventory_sources'),
- field: 'source_regions',
- variable: 'azure_regions',
- choice_name: 'azure_region_choices',
- callback: 'choicesReadyGroup'
- });
+ GetChoices({
+ scope: sources_scope,
+ url: GetBasePath('inventory_sources'),
+ field: 'source_regions',
+ variable: 'azure_regions',
+ choice_name: 'azure_region_choices',
+ callback: 'choicesReadyGroup'
+ });
- // Load options for group_by
- GetChoices({
- scope: sources_scope,
- url: GetBasePath('inventory_sources'),
- field: 'group_by',
- variable: 'ec2_group_by',
- choice_name: 'ec2_group_by_choices',
- callback: 'choicesReadyGroup'
- });
+ // Load options for group_by
+ GetChoices({
+ scope: sources_scope,
+ url: GetBasePath('inventory_sources'),
+ field: 'group_by',
+ variable: 'ec2_group_by',
+ choice_name: 'ec2_group_by_choices',
+ callback: 'choicesReadyGroup'
+ });
- Wait('start');
+ Wait('start');
- if (parent_scope.removeAddTreeRefreshed) {
- parent_scope.removeAddTreeRefreshed();
- }
- parent_scope.removeAddTreeRefreshed = parent_scope.$on('GroupTreeRefreshed', function() {
- // Clean up
- Wait('stop');
- WatchInventoryWindowResize();
- if (modal_scope.searchCleanUp) {
- modal_scope.searchCleanup();
- }
- try {
- $('#group-modal-dialog').dialog('close');
- }
- catch(e) {
- // ignore
- }
- });
+ if (parent_scope.removeAddTreeRefreshed) {
+ parent_scope.removeAddTreeRefreshed();
+ }
+ parent_scope.removeAddTreeRefreshed = parent_scope.$on('GroupTreeRefreshed', function() {
+ // Clean up
+ Wait('stop');
+ WatchInventoryWindowResize();
+ if (modal_scope.searchCleanUp) {
+ modal_scope.searchCleanup();
+ }
+ try {
+ $('#group-modal-dialog').dialog('close');
+ }
+ catch(e) {
+ // ignore
+ }
+ });
- if (modal_scope.removeSaveComplete) {
- modal_scope.removeSaveComplete();
- }
- modal_scope.removeSaveComplete = modal_scope.$on('SaveComplete', function (e, error) {
- if (!error) {
- modal_scope.cancelModal();
- }
- });
+ if (modal_scope.removeSaveComplete) {
+ modal_scope.removeSaveComplete();
+ }
+ modal_scope.removeSaveComplete = modal_scope.$on('SaveComplete', function (e, error) {
+ if (!error) {
+ modal_scope.cancelModal();
+ }
+ });
- if (modal_scope.removeFormSaveSuccess) {
- modal_scope.removeFormSaveSuccess();
- }
- modal_scope.removeFormSaveSuccess = modal_scope.$on('formSaveSuccess', function () {
+ if (modal_scope.removeFormSaveSuccess) {
+ modal_scope.removeFormSaveSuccess();
+ }
+ modal_scope.removeFormSaveSuccess = modal_scope.$on('formSaveSuccess', function () {
- // Source data gets stored separately from the group. Validate and store Source
- // related fields, then call SaveComplete to wrap things up.
+ // Source data gets stored separately from the group. Validate and store Source
+ // related fields, then call SaveComplete to wrap things up.
- var parseError = false,
- regions, r, i,
- group_by,
- data = {
- group: group_id,
- source: ((sources_scope.source && sources_scope.source.value!=='manual') ? sources_scope.source.value : ''),
- source_path: sources_scope.source_path,
- credential: sources_scope.credential,
- overwrite: sources_scope.overwrite,
- overwrite_vars: sources_scope.overwrite_vars,
- source_script: sources_scope.source_script,
- update_on_launch: sources_scope.update_on_launch,
- update_cache_timeout: (sources_scope.update_cache_timeout || 0)
- };
+ var parseError = false,
+ regions, r, i,
+ group_by,
+ data = {
+ group: group_id,
+ source: ((sources_scope.source && sources_scope.source.value!=='manual') ? sources_scope.source.value : ''),
+ source_path: sources_scope.source_path,
+ credential: sources_scope.credential,
+ overwrite: sources_scope.overwrite,
+ overwrite_vars: sources_scope.overwrite_vars,
+ source_script: sources_scope.source_script,
+ update_on_launch: sources_scope.update_on_launch,
+ update_cache_timeout: (sources_scope.update_cache_timeout || 0)
+ };
- // Create a string out of selected list of regions
- regions = $('#s2id_source_source_regions').select2("data");
- r = [];
- for (i = 0; i < regions.length; i++) {
- r.push(regions[i].id);
- }
- data.source_regions = r.join();
+ // Create a string out of selected list of regions
+ regions = $('#s2id_source_source_regions').select2("data");
+ r = [];
+ for (i = 0; i < regions.length; i++) {
+ r.push(regions[i].id);
+ }
+ data.source_regions = r.join();
- if (sources_scope.source && (sources_scope.source.value === 'ec2')) {
- data.instance_filters = sources_scope.instance_filters;
- // Create a string out of selected list of regions
- group_by = $('#s2id_source_group_by').select2("data");
- r = [];
- for (i = 0; i < group_by.length; i++) {
- r.push(group_by[i].id);
- }
- data.group_by = r.join();
- }
+ if (sources_scope.source && (sources_scope.source.value === 'ec2')) {
+ data.instance_filters = sources_scope.instance_filters;
+ // Create a string out of selected list of regions
+ group_by = $('#s2id_source_group_by').select2("data");
+ r = [];
+ for (i = 0; i < group_by.length; i++) {
+ r.push(group_by[i].id);
+ }
+ data.group_by = r.join();
+ }
- if (sources_scope.source && (sources_scope.source.value === 'ec2' )) {
- // for ec2, validate variable data
- data.source_vars = ToJSON(sources_scope.envParseType, sources_scope.source_vars, true);
- }
+ if (sources_scope.source && (sources_scope.source.value === 'ec2' )) {
+ // for ec2, validate variable data
+ data.source_vars = ToJSON(sources_scope.envParseType, sources_scope.source_vars, true);
+ }
- if (sources_scope.source && (sources_scope.source.value === 'custom')) {
- data.source_vars = ToJSON(sources_scope.envParseType, sources_scope.extra_vars, true);
- }
+ if (sources_scope.source && (sources_scope.source.value === 'custom')) {
+ data.source_vars = ToJSON(sources_scope.envParseType, sources_scope.extra_vars, true);
+ }
- if (sources_scope.source && (sources_scope.source.value === 'vmware')) {
- data.source_vars = ToJSON(sources_scope.envParseType, sources_scope.inventory_variables, true);
- }
+ if (sources_scope.source && (sources_scope.source.value === 'vmware')) {
+ data.source_vars = ToJSON(sources_scope.envParseType, sources_scope.inventory_variables, true);
+ }
- // the API doesn't expect the credential to be passed with a custom inv script
- if(sources_scope.source && sources_scope.source.value === 'custom'){
- delete(data.credential);
- }
+ // the API doesn't expect the credential to be passed with a custom inv script
+ if(sources_scope.source && sources_scope.source.value === 'custom'){
+ delete(data.credential);
+ }
- if (!parseError) {
- Rest.setUrl(sources_scope.source_url);
- Rest.put(data)
- .success(function () {
- modal_scope.$emit('SaveComplete', false);
- })
- .error(function (data, status) {
- $('#group_tabs a:eq(1)').tab('show');
- ProcessErrors(sources_scope, data, status, SourceForm, { hdr: 'Error!',
- msg: 'Failed to update group inventory source. PUT status: ' + status });
- });
- }
- });
+ if (!parseError) {
+ Rest.setUrl(sources_scope.source_url);
+ Rest.put(data)
+ .success(function () {
+ modal_scope.$emit('SaveComplete', false);
+ })
+ .error(function (data, status) {
+ $('#group_tabs a:eq(1)').tab('show');
+ ProcessErrors(sources_scope, data, status, SourceForm, { hdr: 'Error!',
+ msg: 'Failed to update group inventory source. PUT status: ' + status });
+ });
+ }
+ });
- if (modal_scope.removeUpdateVariables) {
- modal_scope.removeUpdateVariables();
- }
- modal_scope.removeUpdateVariables = modal_scope.$on('updateVariables', function(e, data, url) {
- Rest.setUrl(url);
- Rest.put(data)
- .success(function () {
- modal_scope.$emit('formSaveSuccess');
- })
- .error(function (data, status) {
- $('#group_tabs a:eq(0)').tab('show');
- ProcessErrors(modal_scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to update group variables. PUT status: ' + status });
- });
- });
+ if (modal_scope.removeUpdateVariables) {
+ modal_scope.removeUpdateVariables();
+ }
+ modal_scope.removeUpdateVariables = modal_scope.$on('updateVariables', function(e, data, url) {
+ Rest.setUrl(url);
+ Rest.put(data)
+ .success(function () {
+ modal_scope.$emit('formSaveSuccess');
+ })
+ .error(function (data, status) {
+ $('#group_tabs a:eq(0)').tab('show');
+ ProcessErrors(modal_scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to update group variables. PUT status: ' + status });
+ });
+ });
- // Cancel
- modal_scope.cancelModal = function () {
- try {
- $('#group-modal-dialog').dialog('close');
- }
- catch(e) {
- //ignore
- }
- if (modal_scope.searchCleanup) {
- modal_scope.searchCleanup();
- }
- if (parent_scope.restoreSearch) {
- parent_scope.restoreSearch();
- }
- else {
- Wait('stop');
- }
- };
+ // Cancel
+ modal_scope.cancelModal = function () {
+ try {
+ $('#group-modal-dialog').dialog('close');
+ }
+ catch(e) {
+ //ignore
+ }
+ if (modal_scope.searchCleanup) {
+ modal_scope.searchCleanup();
+ }
+ if (parent_scope.restoreSearch) {
+ parent_scope.restoreSearch();
+ }
+ else {
+ Wait('stop');
+ }
+ };
- // Save
- modal_scope.saveGroup = function () {
- Wait('start');
- var fld, data, json_data;
+ // Save
+ modal_scope.saveGroup = function () {
+ Wait('start');
+ var fld, data, json_data;
- try {
+ try {
- json_data = ToJSON(properties_scope.parseType, properties_scope.variables);
+ json_data = ToJSON(properties_scope.parseType, properties_scope.variables);
- data = {};
- for (fld in GroupForm.fields) {
- if (fld !== 'variables') {
- data[fld] = properties_scope[fld];
- }
- }
+ data = {};
+ for (fld in GroupForm.fields) {
+ if (fld !== 'variables') {
+ data[fld] = properties_scope[fld];
+ }
+ }
- data.inventory = inventory_id;
+ data.inventory = inventory_id;
- Rest.setUrl(defaultUrl);
- if (mode === 'edit' || (mode === 'add' && group_created)) {
- Rest.put(data)
- .success(function () {
- if (properties_scope.variables) {
- modal_scope.$emit('updateVariables', json_data, properties_scope.variable_url);
- }
- else {
- modal_scope.$emit('formSaveSuccess');
- }
- })
- .error(function (data, status) {
- $('#group_tabs a:eq(0)').tab('show');
- ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!',
- msg: 'Failed to update group: ' + group_id + '. PUT status: ' + status
- });
- });
- }
- else {
- Rest.post(data)
- .success(function (data) {
- group_created = true;
- group_id = data.id;
- sources_scope.source_url = data.related.inventory_source;
- if (properties_scope.variables) {
- modal_scope.$emit('updateVariables', json_data, data.related.variable_data);
- }
- else {
- modal_scope.$emit('formSaveSuccess');
- }
- })
- .error(function (data, status) {
- $('#group_tabs a:eq(0)').tab('show');
- ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!',
- msg: 'Failed to create group: ' + group_id + '. POST status: ' + status
- });
- });
- }
- }
- catch(e) {
- // ignore. ToJSON will have already alerted the user
- }
- };
+ Rest.setUrl(defaultUrl);
+ if (mode === 'edit' || (mode === 'add' && group_created)) {
+ Rest.put(data)
+ .success(function () {
+ if (properties_scope.variables) {
+ modal_scope.$emit('updateVariables', json_data, properties_scope.variable_url);
+ }
+ else {
+ modal_scope.$emit('formSaveSuccess');
+ }
+ })
+ .error(function (data, status) {
+ $('#group_tabs a:eq(0)').tab('show');
+ ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!',
+ msg: 'Failed to update group: ' + group_id + '. PUT status: ' + status
+ });
+ });
+ }
+ else {
+ Rest.post(data)
+ .success(function (data) {
+ group_created = true;
+ group_id = data.id;
+ sources_scope.source_url = data.related.inventory_source;
+ if (properties_scope.variables) {
+ modal_scope.$emit('updateVariables', json_data, data.related.variable_data);
+ }
+ else {
+ modal_scope.$emit('formSaveSuccess');
+ }
+ })
+ .error(function (data, status) {
+ $('#group_tabs a:eq(0)').tab('show');
+ ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!',
+ msg: 'Failed to create group: ' + group_id + '. POST status: ' + status
+ });
+ });
+ }
+ }
+ catch(e) {
+ // ignore. ToJSON will have already alerted the user
+ }
+ };
- // Start the update process
- modal_scope.updateGroup = function () {
- if (sources_scope.source === "manual" || sources_scope.source === null) {
- Alert('Missing Configuration', 'The selected group is not configured for updates. You must first edit the group, provide Source settings, ' +
- 'and then run an update.', 'alert-info');
- } else if (sources_scope.status === 'updating') {
- Alert('Update in Progress', 'The inventory update process is currently running for group
' +
- sources_scope.summary_fields.group.name + ' . Use the Refresh button to monitor the status.', 'alert-info');
- } else {
- InventoryUpdate({
- scope: parent_scope,
- group_id: group_id,
- url: properties_scope.group_update_url,
- group_name: properties_scope.name,
- group_source: sources_scope.source.value
- });
- }
- };
+ // Start the update process
+ modal_scope.updateGroup = function () {
+ if (sources_scope.source === "manual" || sources_scope.source === null) {
+ Alert('Missing Configuration', 'The selected group is not configured for updates. You must first edit the group, provide Source settings, ' +
+ 'and then run an update.', 'alert-info');
+ } else if (sources_scope.status === 'updating') {
+ Alert('Update in Progress', 'The inventory update process is currently running for group
' +
+ sources_scope.summary_fields.group.name + ' . Use the Refresh button to monitor the status.', 'alert-info');
+ } else {
+ InventoryUpdate({
+ scope: parent_scope,
+ group_id: group_id,
+ url: properties_scope.group_update_url,
+ group_name: properties_scope.name,
+ group_source: sources_scope.source.value
+ });
+ }
+ };
- // Change the lookup and regions when the source changes
- sources_scope.sourceChange = function () {
- parent_scope.showSchedulesTab = (mode === 'edit' && sources_scope.source && sources_scope.source.value!=="manual") ? true : false;
- SourceChange({ scope: sources_scope, form: SourceForm });
- };
+ // Change the lookup and regions when the source changes
+ sources_scope.sourceChange = function () {
+ parent_scope.showSchedulesTab = (mode === 'edit' && sources_scope.source && sources_scope.source.value!=="manual") ? true : false;
+ SourceChange({ scope: sources_scope, form: SourceForm });
+ };
- };
- }
+ };
+ }
])
/**
@@ -1420,237 +1422,237 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GroupsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm',
-'Prompt', 'ProcessErrors', 'GetBasePath', 'Wait', 'BuildTree', 'Find', 'CreateDialog',
- function ($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
- GetBasePath, Wait, BuildTree, Find, CreateDialog) {
- return function (params) {
+ 'Prompt', 'ProcessErrors', 'GetBasePath', 'Wait', 'BuildTree', 'Find', 'CreateDialog',
+ function ($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
+ GetBasePath, Wait, BuildTree, Find, CreateDialog) {
+ return function (params) {
- var scope = params.scope,
- group_id = params.group_id,
- node = Find({ list: scope.groups, key: 'id', val: group_id }),
- hosts = [],
- groups = [],
- childCount = 0,
- buttonSet;
+ var scope = params.scope,
+ group_id = params.group_id,
+ node = Find({ list: scope.groups, key: 'id', val: group_id }),
+ hosts = [],
+ groups = [],
+ childCount = 0,
+ buttonSet;
- scope.deleteOption = "preserve-all";
+ scope.deleteOption = "preserve-all";
- scope.helpText = "
Delete Deletes groups and hosts associated with the group being deleted. " +
- "If a group or host is associated with other groups, it will still exist within those groups. Otherwise, " +
- "the associated groups and hosts will no longer appear in the inventory. \n" +
- "Promote Groups and hosts associated with the group being removed will be " +
- "promoted one level. Note: groups already associated with other groups cannot be promoted to the top level of the " +
- "tree. \n";
- buttonSet = [{
- label: "Cancel",
- onClick: function() {
- scope.cancel();
- },
- icon: "fa-times",
- "class": "btn btn-default",
- "id": "group-delete-cancel-button"
- },{
- label: "Delete",
- onClick: function() {
- scope.performDelete();
- },
- icon: "fa-check",
- "class": "btn btn-primary",
- "id": "group-delete-ok-button"
- }];
+ scope.helpText = "
Delete Deletes groups and hosts associated with the group being deleted. " +
+ "If a group or host is associated with other groups, it will still exist within those groups. Otherwise, " +
+ "the associated groups and hosts will no longer appear in the inventory. \n" +
+ "Promote Groups and hosts associated with the group being removed will be " +
+ "promoted one level. Note: groups already associated with other groups cannot be promoted to the top level of the " +
+ "tree. \n";
+ buttonSet = [{
+ label: "Cancel",
+ onClick: function() {
+ scope.cancel();
+ },
+ icon: "fa-times",
+ "class": "btn btn-default",
+ "id": "group-delete-cancel-button"
+ },{
+ label: "Delete",
+ onClick: function() {
+ scope.performDelete();
+ },
+ icon: "fa-check",
+ "class": "btn btn-primary",
+ "id": "group-delete-ok-button"
+ }];
- if (scope.removeDeleteDialogReady) {
- scope.removeDeleteDialogReady();
- }
+ if (scope.removeDeleteDialogReady) {
+ scope.removeDeleteDialogReady();
+ }
- scope.removeDeleteDialogReady = scope.$on('DeleteDialogReady', function() {
- Wait('stop');
- $('#group-delete-dialog').dialog('open');
- });
+ scope.removeDeleteDialogReady = scope.$on('DeleteDialogReady', function() {
+ Wait('stop');
+ $('#group-delete-dialog').dialog('open');
+ });
- if (scope.removeShowDeleteDialog) {
- scope.removeShowDeleteDialog();
- }
+ if (scope.removeShowDeleteDialog) {
+ scope.removeShowDeleteDialog();
+ }
- scope.removeShowDeleteDialog = scope.$on('ShowDeleteDialog', function() {
- scope.group_name = node.name;
- scope.groupsCount = groups.length;
- scope.hostsCount = hosts.length;
- CreateDialog({
- id: 'group-delete-dialog',
- scope: scope,
- buttons: buttonSet,
- width: 650,
- height: 350,
- minWidth: 500,
- title: 'Delete Group',
- callback: 'DeleteDialogReady'
- });
- });
+ scope.removeShowDeleteDialog = scope.$on('ShowDeleteDialog', function() {
+ scope.group_name = node.name;
+ scope.groupsCount = groups.length;
+ scope.hostsCount = hosts.length;
+ CreateDialog({
+ id: 'group-delete-dialog',
+ scope: scope,
+ buttons: buttonSet,
+ width: 650,
+ height: 350,
+ minWidth: 500,
+ title: 'Delete Group',
+ callback: 'DeleteDialogReady'
+ });
+ });
- if (scope.removeChildrenReady) {
- scope.removeChildrenReady();
- }
+ if (scope.removeChildrenReady) {
+ scope.removeChildrenReady();
+ }
- scope.removeChildrenReady = scope.$on('ChildrenReady', function() {
- childCount++;
- if (childCount === 2) {
- scope.$emit('ShowDeleteDialog');
- }
- });
+ scope.removeChildrenReady = scope.$on('ChildrenReady', function() {
+ childCount++;
+ if (childCount === 2) {
+ scope.$emit('ShowDeleteDialog');
+ }
+ });
- Wait('start');
+ Wait('start');
- // this function is used to make sure that we get all of the groups/hosts,
- // not just the first page
- scope.next_iterator = function(next_url, type) {
- Rest.setUrl(next_url);
- Rest.get()
- .success(function(data) {
- if (data.count) {
- if (type === "groups") {
- data.results.forEach(function(group) {
- groups.push(group);
- });
- }
- else if (type === "hosts") {
- data.results.forEach(function(host) {
- hosts.push(host);
- });
- }
- }
+ // this function is used to make sure that we get all of the groups/hosts,
+ // not just the first page
+ scope.next_iterator = function(next_url, type) {
+ Rest.setUrl(next_url);
+ Rest.get()
+ .success(function(data) {
+ if (data.count) {
+ if (type === "groups") {
+ data.results.forEach(function(group) {
+ groups.push(group);
+ });
+ }
+ else if (type === "hosts") {
+ data.results.forEach(function(host) {
+ hosts.push(host);
+ });
+ }
+ }
- if (data.next) {
- if (type === "groups") {
- scope.next_iterator(data.next, "groups");
- } else if (type === "hosts") {
- scope.next_iterator(data.next, "hosts");
- }
- }
- else {
- scope.$emit('ChildrenReady');
- }
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve related groups. GET returned: ' + status
- });
- });
- };
+ if (data.next) {
+ if (type === "groups") {
+ scope.next_iterator(data.next, "groups");
+ } else if (type === "hosts") {
+ scope.next_iterator(data.next, "hosts");
+ }
+ }
+ else {
+ scope.$emit('ChildrenReady');
+ }
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve related groups. GET returned: ' + status
+ });
+ });
+ };
- if (node.related.children) {
- Rest.setUrl(node.related.children);
- Rest.get()
- .success(function(data) {
- if (data.count) {
- data.results.forEach(function(group) {
- groups.push(group);
- });
- }
+ if (node.related.children) {
+ Rest.setUrl(node.related.children);
+ Rest.get()
+ .success(function(data) {
+ if (data.count) {
+ data.results.forEach(function(group) {
+ groups.push(group);
+ });
+ }
- if (data.next) {
- scope.next_iterator(data.next, "groups");
- } else {
- scope.$emit('ChildrenReady');
- }
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve related groups. GET returned: ' + status
- });
- });
- }
- else {
- scope.$emit('ChildrenReady');
- }
+ if (data.next) {
+ scope.next_iterator(data.next, "groups");
+ } else {
+ scope.$emit('ChildrenReady');
+ }
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve related groups. GET returned: ' + status
+ });
+ });
+ }
+ else {
+ scope.$emit('ChildrenReady');
+ }
- if (node.related.all_hosts) {
- Rest.setUrl(node.related.all_hosts);
- Rest.get()
- .success( function(data) {
- if (data.count) {
- data.results.forEach(function(host) {
- hosts.push(host);
- });
- }
- if (data.next) {
- scope.next_iterator(data.next, "hosts");
- } else {
- scope.$emit('ChildrenReady');
- }
- })
- .error( function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to retrieve related hosts. GET returned: ' + status
- });
- });
- }
- else {
- scope.$emit('ChildrenReady');
- }
+ if (node.related.all_hosts) {
+ Rest.setUrl(node.related.all_hosts);
+ Rest.get()
+ .success( function(data) {
+ if (data.count) {
+ data.results.forEach(function(host) {
+ hosts.push(host);
+ });
+ }
+ if (data.next) {
+ scope.next_iterator(data.next, "hosts");
+ } else {
+ scope.$emit('ChildrenReady');
+ }
+ })
+ .error( function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to retrieve related hosts. GET returned: ' + status
+ });
+ });
+ }
+ else {
+ scope.$emit('ChildrenReady');
+ }
- if (scope.removeDisassociateGroup) {
- scope.removeDisassociateGroup();
- }
+ if (scope.removeDisassociateGroup) {
+ scope.removeDisassociateGroup();
+ }
- scope.removeDisassociateGroup = scope.$on('DisassociateGroup', function() {
- var data, url;
- if (!scope.selected_group_id) {
- url = GetBasePath('inventory') + scope.inventory.id + '/groups/';
- data = { id: node.id, disassociate: 1 };
- }
- else {
- url = GetBasePath('groups') + node.id + '/children/';
- data = { disassociate: 1 };
- }
+ scope.removeDisassociateGroup = scope.$on('DisassociateGroup', function() {
+ var data, url;
+ if (!scope.selected_group_id) {
+ url = GetBasePath('inventory') + scope.inventory.id + '/groups/';
+ data = { id: node.id, disassociate: 1 };
+ }
+ else {
+ url = GetBasePath('groups') + node.id + '/children/';
+ data = { disassociate: 1 };
+ }
- Rest.setUrl(url);
- Rest.post(data)
- .success(function () {
- scope.$emit('GroupDeleteCompleted'); // Signal a group refresh to start
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. POST returned: ' + status
- });
- });
- });
+ Rest.setUrl(url);
+ Rest.post(data)
+ .success(function () {
+ scope.$emit('GroupDeleteCompleted'); // Signal a group refresh to start
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. POST returned: ' + status
+ });
+ });
+ });
- if (scope.removeDeleteGroup) {
- scope.removeDeleteGroup();
- }
+ if (scope.removeDeleteGroup) {
+ scope.removeDeleteGroup();
+ }
- scope.removeDeleteGroup = scope.$on('DeleteGroup', function() {
- var url = GetBasePath('groups') + node.id + '/';
- Rest.setUrl(url);
- Rest.destroy()
- .success( function() {
- scope.$emit('GroupDeleteCompleted'); // Signal a group refresh to start
- })
- .error( function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. DELETE returned: ' + status
- });
- });
- });
+ scope.removeDeleteGroup = scope.$on('DeleteGroup', function() {
+ var url = GetBasePath('groups') + node.id + '/';
+ Rest.setUrl(url);
+ Rest.destroy()
+ .success( function() {
+ scope.$emit('GroupDeleteCompleted'); // Signal a group refresh to start
+ })
+ .error( function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. DELETE returned: ' + status
+ });
+ });
+ });
- scope.cancel = function() {
- $('#group-delete-dialog').dialog('close');
- };
+ scope.cancel = function() {
+ $('#group-delete-dialog').dialog('close');
+ };
- scope.performDelete = function() {
- $('#group-delete-dialog').dialog('close');
- Wait('start');
- if (scope.deleteOption === 'delete-all' || (scope.groupsCount === 0 && scope.hostsCount === 0)) {
- // If user chooses Delete or there are no children, send DELETE request
- scope.$emit('DeleteGroup');
- }
- else {
- scope.$emit('DisassociateGroup');
- }
- };
- };
- }
+ scope.performDelete = function() {
+ $('#group-delete-dialog').dialog('close');
+ Wait('start');
+ if (scope.deleteOption === 'delete-all' || (scope.groupsCount === 0 && scope.hostsCount === 0)) {
+ // If user chooses Delete or there are no children, send DELETE request
+ scope.$emit('DeleteGroup');
+ }
+ else {
+ scope.$emit('DisassociateGroup');
+ }
+ };
+ };
+ }
])
/**
@@ -1659,26 +1661,26 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GetRootGroups', ['Rest', 'ProcessErrors', 'GetBasePath',
- function(Rest, ProcessErrors, GetBasePath) {
- return function(params) {
- var scope = params.scope,
- inventory_id = params.inventory_id,
- //group_id = params.group_id,
- callback = params.callback,
- url;
+ function(Rest, ProcessErrors, GetBasePath) {
+ return function(params) {
+ var scope = params.scope,
+ inventory_id = params.inventory_id,
+ //group_id = params.group_id,
+ callback = params.callback,
+ url;
- url = GetBasePath('inventory') + inventory_id + '/root_groups/';
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- scope.$emit(callback, data.results);
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. GET returned: ' + status });
- });
- };
- }
+ url = GetBasePath('inventory') + inventory_id + '/root_groups/';
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ scope.$emit(callback, data.results);
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. GET returned: ' + status });
+ });
+ };
+ }
])
/**
@@ -1687,301 +1689,301 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('GroupsCopy', ['$compile', 'Rest', 'ProcessErrors', 'CreateDialog', 'GetBasePath', 'Wait', 'GenerateList', 'GroupList', 'SearchInit',
-'PaginateInit', 'GetRootGroups',
- function($compile, Rest, ProcessErrors, CreateDialog, GetBasePath, Wait, GenerateList, GroupList, SearchInit, PaginateInit, GetRootGroups) {
- return function(params) {
+ 'PaginateInit', 'GetRootGroups',
+ function($compile, Rest, ProcessErrors, CreateDialog, GetBasePath, Wait, GenerateList, GroupList, SearchInit, PaginateInit, GetRootGroups) {
+ return function(params) {
- var group_id = params.group_id,
- parent_scope = params.scope,
- scope = parent_scope.$new(),
- parent_group = parent_scope.selected_group_id,
- buttonSet, url, group;
+ var group_id = params.group_id,
+ parent_scope = params.scope,
+ scope = parent_scope.$new(),
+ parent_group = parent_scope.selected_group_id,
+ buttonSet, url, group;
- buttonSet = [{
- label: "Cancel",
- onClick: function() {
- scope.cancel();
- },
- icon: "fa-times",
- "class": "btn btn-default",
- "id": "group-copy-cancel-button"
- },{
- label: "OK",
- onClick: function() {
- scope.performCopy();
- },
- icon: "fa-check",
- "class": "btn btn-primary",
- "id": "group-copy-ok-button"
- }];
+ buttonSet = [{
+ label: "Cancel",
+ onClick: function() {
+ scope.cancel();
+ },
+ icon: "fa-times",
+ "class": "btn btn-default",
+ "id": "group-copy-cancel-button"
+ },{
+ label: "OK",
+ onClick: function() {
+ scope.performCopy();
+ },
+ icon: "fa-check",
+ "class": "btn btn-primary",
+ "id": "group-copy-ok-button"
+ }];
- if (scope.removeGroupsCopyPostRefresh) {
- scope.removeGroupsCopyPostRefresh();
- }
- scope.removeGroupCopyPostRefresh = scope.$on('PostRefresh', function() {
- scope.copy_groups.forEach(function(row, i) {
- scope.copy_groups[i].checked = '0';
- });
- Wait('stop');
- $('#group-copy-dialog').dialog('open');
- $('#group-copy-ok-button').attr('disabled','disabled');
+ if (scope.removeGroupsCopyPostRefresh) {
+ scope.removeGroupsCopyPostRefresh();
+ }
+ scope.removeGroupCopyPostRefresh = scope.$on('PostRefresh', function() {
+ scope.copy_groups.forEach(function(row, i) {
+ scope.copy_groups[i].checked = '0';
+ });
+ Wait('stop');
+ $('#group-copy-dialog').dialog('open');
+ $('#group-copy-ok-button').attr('disabled','disabled');
- // prevent backspace from navigation when not in input or textarea field
- $(document).on("keydown", function (e) {
- if (e.which === 8 && !$(e.target).is('input[type="text"], textarea')) {
- e.preventDefault();
- }
- });
+ // prevent backspace from navigation when not in input or textarea field
+ $(document).on("keydown", function (e) {
+ if (e.which === 8 && !$(e.target).is('input[type="text"], textarea')) {
+ e.preventDefault();
+ }
+ });
- });
+ });
- if (scope.removeCopyDialogReady) {
- scope.removeCopyDialogReady();
- }
- scope.removeCopyDialogReady = scope.$on('CopyDialogReady', function() {
- var url = GetBasePath('inventory') + parent_scope.inventory.id + '/groups/';
- url += (parent_group) ? '?not__id__in=' + group_id + ',' + parent_group : '?not__id=' + group_id;
- GenerateList.inject(GroupList, {
- mode: 'lookup',
- id: 'copy-select-container',
- scope: scope
- //,
- //instructions: instructions
- });
- SearchInit({
- scope: scope,
- set: GroupList.name,
- list: GroupList,
- url: url
- });
- PaginateInit({
- scope: scope,
- list: GroupList,
- url: url,
- mode: 'lookup'
- });
- scope.search(GroupList.iterator);
- });
+ if (scope.removeCopyDialogReady) {
+ scope.removeCopyDialogReady();
+ }
+ scope.removeCopyDialogReady = scope.$on('CopyDialogReady', function() {
+ var url = GetBasePath('inventory') + parent_scope.inventory.id + '/groups/';
+ url += (parent_group) ? '?not__id__in=' + group_id + ',' + parent_group : '?not__id=' + group_id;
+ GenerateList.inject(GroupList, {
+ mode: 'lookup',
+ id: 'copy-select-container',
+ scope: scope
+ //,
+ //instructions: instructions
+ });
+ SearchInit({
+ scope: scope,
+ set: GroupList.name,
+ list: GroupList,
+ url: url
+ });
+ PaginateInit({
+ scope: scope,
+ list: GroupList,
+ url: url,
+ mode: 'lookup'
+ });
+ scope.search(GroupList.iterator);
+ });
- if (scope.removeShowDialog) {
- scope.removeShowDialog();
- }
- scope.removeShowDialog = scope.$on('ShowDialog', function() {
- var d;
- scope.name = group.name;
- scope.copy_choice = "copy";
- d = angular.element(document.getElementById('group-copy-dialog'));
- $compile(d)(scope);
+ if (scope.removeShowDialog) {
+ scope.removeShowDialog();
+ }
+ scope.removeShowDialog = scope.$on('ShowDialog', function() {
+ var d;
+ scope.name = group.name;
+ scope.copy_choice = "copy";
+ d = angular.element(document.getElementById('group-copy-dialog'));
+ $compile(d)(scope);
- CreateDialog({
- id: 'group-copy-dialog',
- scope: scope,
- buttons: buttonSet,
- width: 650,
- height: 650,
- minWidth: 600,
- title: 'Copy or Move Group',
- callback: 'CopyDialogReady',
- onClose: function() {
- scope.cancel();
- }
- });
- });
+ CreateDialog({
+ id: 'group-copy-dialog',
+ scope: scope,
+ buttons: buttonSet,
+ width: 650,
+ height: 650,
+ minWidth: 600,
+ title: 'Copy or Move Group',
+ callback: 'CopyDialogReady',
+ onClose: function() {
+ scope.cancel();
+ }
+ });
+ });
- if (scope.removeRootGroupsReady) {
- scope.removeRootGroupsReady();
- }
- scope.removeRootGroupsReady = scope.$on('RootGroupsReady', function(e, root_groups) {
- scope.offer_root_group = true;
- scope.use_root_group = false;
- root_groups.every(function(row) {
- if (row.id === group_id) {
- scope.offer_root_group = false;
- return false;
- }
- return true;
- });
- url = GetBasePath('groups') + group_id + '/';
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- group = data;
- scope.$emit('ShowDialog');
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. GET returned: ' + status });
- });
- });
+ if (scope.removeRootGroupsReady) {
+ scope.removeRootGroupsReady();
+ }
+ scope.removeRootGroupsReady = scope.$on('RootGroupsReady', function(e, root_groups) {
+ scope.offer_root_group = true;
+ scope.use_root_group = false;
+ root_groups.every(function(row) {
+ if (row.id === group_id) {
+ scope.offer_root_group = false;
+ return false;
+ }
+ return true;
+ });
+ url = GetBasePath('groups') + group_id + '/';
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ group = data;
+ scope.$emit('ShowDialog');
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. GET returned: ' + status });
+ });
+ });
- Wait('start');
+ Wait('start');
- GetRootGroups({
- scope: scope,
- group_id: group_id,
- inventory_id: parent_scope.inventory.id,
- callback: 'RootGroupsReady'
- });
+ GetRootGroups({
+ scope: scope,
+ group_id: group_id,
+ inventory_id: parent_scope.inventory.id,
+ callback: 'RootGroupsReady'
+ });
- scope.cancel = function() {
- $(document).off("keydown");
- try {
- $('#group-copy-dialog').dialog('close');
- }
- catch(e) {
- // ignore
- }
- scope.searchCleanup();
- parent_scope.restoreSearch();
- scope.$destroy();
- };
+ scope.cancel = function() {
+ $(document).off("keydown");
+ try {
+ $('#group-copy-dialog').dialog('close');
+ }
+ catch(e) {
+ // ignore
+ }
+ scope.searchCleanup();
+ parent_scope.restoreSearch();
+ scope.$destroy();
+ };
- scope['toggle_' + GroupList.iterator] = function (id) {
- var count = 0,
- list = GroupList;
- scope[list.name].forEach( function(row, i) {
- if (row.id === id) {
- if (row.checked === '0') {
- scope[list.name][i].checked = '1';
- scope[list.name][i].success_class = 'success';
- }
- else {
- scope[list.name][i].checked = '0';
- scope[list.name][i].success_class = '';
- }
- } else {
- scope[list.name][i].checked = '0';
- scope[list.name][i].success_class = '';
- }
- });
- // Check if any rows are checked
- scope[list.name].forEach(function(row) {
- if (row.checked === '1') {
- count++;
- }
- });
- if (count === 0) {
- $('#group-copy-ok-button').attr('disabled','disabled');
- }
- else {
- $('#group-copy-ok-button').removeAttr('disabled');
- }
- };
+ scope['toggle_' + GroupList.iterator] = function (id) {
+ var count = 0,
+ list = GroupList;
+ scope[list.name].forEach( function(row, i) {
+ if (row.id === id) {
+ if (row.checked === '0') {
+ scope[list.name][i].checked = '1';
+ scope[list.name][i].success_class = 'success';
+ }
+ else {
+ scope[list.name][i].checked = '0';
+ scope[list.name][i].success_class = '';
+ }
+ } else {
+ scope[list.name][i].checked = '0';
+ scope[list.name][i].success_class = '';
+ }
+ });
+ // Check if any rows are checked
+ scope[list.name].forEach(function(row) {
+ if (row.checked === '1') {
+ count++;
+ }
+ });
+ if (count === 0) {
+ $('#group-copy-ok-button').attr('disabled','disabled');
+ }
+ else {
+ $('#group-copy-ok-button').removeAttr('disabled');
+ }
+ };
- scope.toggleUseRootGroup = function() {
- var list = GroupList;
- //console.log("scope.use_root_group: " + scope.use_root_group);
- if (scope.use_root_group) {
- $('#group-copy-ok-button').removeAttr('disabled');
- }
- else {
- // check for group selection
- $('#group-copy-ok-button').attr('disabled','disabled');
- scope[list.name].every(function(row) {
- if (row.checked === '1') {
- $('#group-copy-ok-button').removeAttr('disabled');
- return false;
- }
- return true;
- });
- }
- };
+ scope.toggleUseRootGroup = function() {
+ var list = GroupList;
+ //console.log("scope.use_root_group: " + scope.use_root_group);
+ if (scope.use_root_group) {
+ $('#group-copy-ok-button').removeAttr('disabled');
+ }
+ else {
+ // check for group selection
+ $('#group-copy-ok-button').attr('disabled','disabled');
+ scope[list.name].every(function(row) {
+ if (row.checked === '1') {
+ $('#group-copy-ok-button').removeAttr('disabled');
+ return false;
+ }
+ return true;
+ });
+ }
+ };
- scope.performCopy = function() {
- var list = GroupList,
- target,
- url;
+ scope.performCopy = function() {
+ var list = GroupList,
+ target,
+ url;
- Wait('start');
+ Wait('start');
- if (scope.use_root_group) {
- target = null;
- }
- else {
- scope[list.name].every(function(row) {
- if (row.checked === '1') {
- target = row;
- return false;
- }
- return true;
- });
- }
+ if (scope.use_root_group) {
+ target = null;
+ }
+ else {
+ scope[list.name].every(function(row) {
+ if (row.checked === '1') {
+ target = row;
+ return false;
+ }
+ return true;
+ });
+ }
- if (scope.copy_choice === 'move') {
- // Respond to move
+ if (scope.copy_choice === 'move') {
+ // Respond to move
- // disassociate the group from the original parent
- if (scope.removeGroupRemove) {
- scope.removeGroupRemove();
- }
- scope.removeGroupRemove = scope.$on('RemoveGroup', function () {
- if (parent_group > 0) {
- // Only remove a group from a parent when the parent is a group and not the inventory root
- url = GetBasePath('groups') + parent_group + '/children/';
- Rest.setUrl(url);
- Rest.post({ id: group.id, disassociate: 1 })
- .success(function () {
- scope.cancel();
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to remove ' + group.name + ' from group ' + parent_group + '. POST returned: ' + status });
- });
- } else {
- scope.cancel();
- }
- });
+ // disassociate the group from the original parent
+ if (scope.removeGroupRemove) {
+ scope.removeGroupRemove();
+ }
+ scope.removeGroupRemove = scope.$on('RemoveGroup', function () {
+ if (parent_group > 0) {
+ // Only remove a group from a parent when the parent is a group and not the inventory root
+ url = GetBasePath('groups') + parent_group + '/children/';
+ Rest.setUrl(url);
+ Rest.post({ id: group.id, disassociate: 1 })
+ .success(function () {
+ scope.cancel();
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to remove ' + group.name + ' from group ' + parent_group + '. POST returned: ' + status });
+ });
+ } else {
+ scope.cancel();
+ }
+ });
- // add the new group to the target
- url = (target) ?
- GetBasePath('groups') + target.id + '/children/' :
- GetBasePath('inventory') + parent_scope.inventory.id + '/groups/';
- group = {
- id: group.id,
- name: group.name,
- description: group.description,
- inventory: parent_scope.inventory.id
- };
- Rest.setUrl(url);
- Rest.post(group)
- .success(function () {
- scope.$emit('RemoveGroup');
- })
- .error(function (data, status) {
- var target_name = (target) ? target.name : 'inventory';
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to add ' + group.name + ' to ' + target_name + '. POST returned: ' + status });
- });
- }
- else {
- // Respond to copy by adding the new group to the target
- url = (target) ?
- GetBasePath('groups') + target.id + '/children/' :
- GetBasePath('inventory') + parent_scope.inventory.id + '/groups/';
+ // add the new group to the target
+ url = (target) ?
+ GetBasePath('groups') + target.id + '/children/' :
+ GetBasePath('inventory') + parent_scope.inventory.id + '/groups/';
+ group = {
+ id: group.id,
+ name: group.name,
+ description: group.description,
+ inventory: parent_scope.inventory.id
+ };
+ Rest.setUrl(url);
+ Rest.post(group)
+ .success(function () {
+ scope.$emit('RemoveGroup');
+ })
+ .error(function (data, status) {
+ var target_name = (target) ? target.name : 'inventory';
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to add ' + group.name + ' to ' + target_name + '. POST returned: ' + status });
+ });
+ }
+ else {
+ // Respond to copy by adding the new group to the target
+ url = (target) ?
+ GetBasePath('groups') + target.id + '/children/' :
+ GetBasePath('inventory') + parent_scope.inventory.id + '/groups/';
- group = {
- id: group.id,
- name: group.name,
- description: group.description,
- inventory: parent_scope.inventory.id
- };
+ group = {
+ id: group.id,
+ name: group.name,
+ description: group.description,
+ inventory: parent_scope.inventory.id
+ };
- Rest.setUrl(url);
- Rest.post(group)
- .success(function () {
- scope.cancel();
- })
- .error(function (data, status) {
- var target_name = (target) ? target.name : 'inventory';
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to add ' + group.name + ' to ' + target_name + '. POST returned: ' + status
- });
- });
- }
- };
+ Rest.setUrl(url);
+ Rest.post(group)
+ .success(function () {
+ scope.cancel();
+ })
+ .error(function (data, status) {
+ var target_name = (target) ? target.name : 'inventory';
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to add ' + group.name + ' to ' + target_name + '. POST returned: ' + status
+ });
+ });
+ }
+ };
- };
- }
+ };
+ }
])
/**
@@ -1990,134 +1992,134 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
*
*/
.factory('ShowUpdateStatus', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm',
-'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'InventoryStatusForm', 'Wait',
- function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath,
- FormatDate, InventoryStatusForm, Wait) {
- return function (params) {
+ 'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'InventoryStatusForm', 'Wait',
+ function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath,
+ FormatDate, InventoryStatusForm, Wait) {
+ return function (params) {
- var group_name = params.group_name,
- last_update = params.last_update,
- generator = GenerateForm,
- form = InventoryStatusForm,
- license_error = params.license_error,
- maxrows, html, scope, ww, wh, x, y;
+ var group_name = params.group_name,
+ last_update = params.last_update,
+ generator = GenerateForm,
+ form = InventoryStatusForm,
+ license_error = params.license_error,
+ maxrows, html, scope, ww, wh, x, y;
- function calcRows(content) {
- var n, rows;
- n = content.match(/\n/g);
- rows = (n) ? n.length : 1;
- return (rows > maxrows) ? maxrows : rows;
- }
+ function calcRows(content) {
+ var n, rows;
+ n = content.match(/\n/g);
+ rows = (n) ? n.length : 1;
+ return (rows > maxrows) ? maxrows : rows;
+ }
- if (last_update === undefined || last_update === null || last_update === '') {
- Wait('stop');
- Alert('Missing Configuration', 'The selected group is not configured for inventory sync. ' +
- 'Edit the group and provide Source information.', 'alert-info');
- } else {
- html = "
\n";
+ if (last_update === undefined || last_update === null || last_update === '') {
+ Wait('stop');
+ Alert('Missing Configuration', 'The selected group is not configured for inventory sync. ' +
+ 'Edit the group and provide Source information.', 'alert-info');
+ } else {
+ html = "
\n";
- $('#inventory-modal-container').empty().append(html);
- scope = generator.inject(form, {
- mode: 'edit',
- id: 'form-container',
- breadCrumbs: false,
- related: false
- });
+ $('#inventory-modal-container').empty().append(html);
+ scope = generator.inject(form, {
+ mode: 'edit',
+ id: 'form-container',
+ breadCrumbs: false,
+ related: false
+ });
- // Set modal dimensions based on viewport width
- ww = $(document).width();
- wh = $('body').height();
- if (ww > 1199) {
- // desktop
- x = 675;
- y = (750 > wh) ? wh - 20 : 750;
- maxrows = 18;
- } else if (ww <= 1199 && ww >= 768) {
- x = 550;
- y = (620 > wh) ? wh - 15 : 620;
- maxrows = 12;
- } else {
- x = (ww - 20);
- y = (500 > wh) ? wh : 500;
- maxrows = 10;
- }
+ // Set modal dimensions based on viewport width
+ ww = $(document).width();
+ wh = $('body').height();
+ if (ww > 1199) {
+ // desktop
+ x = 675;
+ y = (750 > wh) ? wh - 20 : 750;
+ maxrows = 18;
+ } else if (ww <= 1199 && ww >= 768) {
+ x = 550;
+ y = (620 > wh) ? wh - 15 : 620;
+ maxrows = 12;
+ } else {
+ x = (ww - 20);
+ y = (500 > wh) ? wh : 500;
+ maxrows = 10;
+ }
- // Create the modal
- $('#status-modal-dialog').dialog({
- buttons: {
- "OK": function () {
- $(this).dialog("close");
- }
- },
- modal: true,
- width: x,
- height: y,
- autoOpen: false,
- create: function () {
- // fix the close button
- $('.ui-dialog[aria-describedby="status-modal-dialog"]').find('.ui-dialog-titlebar button')
- .empty().attr({
- 'class': 'close'
- }).text('x');
- // fix the OK button
- $('.ui-dialog[aria-describedby="status-modal-dialog"]').find('.ui-dialog-buttonset button:first')
- .attr({
- 'class': 'btn btn-primary'
- });
- },
- resizeStop: function () {
- // for some reason, after resizing dialog the form and fields (the content) doesn't expand to 100%
- var dialog = $('.ui-dialog[aria-describedby="status-modal-dialog"]'),
- content = dialog.find('#status-modal-dialog');
- content.width(dialog.width() - 28);
- },
- close: function () {
- // Destroy on close
- $('.tooltip').each(function () {
- // Remove any lingering tooltip
elements
- $(this).remove();
- });
- $('.popover').each(function () {
- // remove lingering popover
elements
- $(this).remove();
- });
- $('#status-modal-dialog').dialog('destroy');
- $('#inventory-modal-container').empty();
- //WatchInventoryWindowResize();
- },
- open: function () {
- Wait('stop');
- }
- });
+ // Create the modal
+ $('#status-modal-dialog').dialog({
+ buttons: {
+ "OK": function () {
+ $(this).dialog("close");
+ }
+ },
+ modal: true,
+ width: x,
+ height: y,
+ autoOpen: false,
+ create: function () {
+ // fix the close button
+ $('.ui-dialog[aria-describedby="status-modal-dialog"]').find('.ui-dialog-titlebar button')
+ .empty().attr({
+ 'class': 'close'
+ }).text('x');
+ // fix the OK button
+ $('.ui-dialog[aria-describedby="status-modal-dialog"]').find('.ui-dialog-buttonset button:first')
+ .attr({
+ 'class': 'btn btn-primary'
+ });
+ },
+ resizeStop: function () {
+ // for some reason, after resizing dialog the form and fields (the content) doesn't expand to 100%
+ var dialog = $('.ui-dialog[aria-describedby="status-modal-dialog"]'),
+ content = dialog.find('#status-modal-dialog');
+ content.width(dialog.width() - 28);
+ },
+ close: function () {
+ // Destroy on close
+ $('.tooltip').each(function () {
+ // Remove any lingering tooltip
elements
+ $(this).remove();
+ });
+ $('.popover').each(function () {
+ // remove lingering popover
elements
+ $(this).remove();
+ });
+ $('#status-modal-dialog').dialog('destroy');
+ $('#inventory-modal-container').empty();
+ //WatchInventoryWindowResize();
+ },
+ open: function () {
+ Wait('stop');
+ }
+ });
- Rest.setUrl(last_update);
- Rest.get()
- .success(function (data) {
- for (var fld in form.fields) {
- if (data[fld]) {
- if (fld === 'created') {
- scope[fld] = FormatDate(new Date(data[fld]));
- } else {
- scope[fld] = data[fld];
- }
- }
- }
- scope.license_error = license_error;
- scope.status_rows = calcRows(data.status);
- scope.stdout_rows = calcRows(data.result_stdout);
- scope.traceback_rows = calcRows(data.result_traceback);
- $('#status-modal-dialog').dialog('open');
- })
- .error(function (data, status) {
- $('#form-modal').modal("hide");
- ProcessErrors(scope, data, status, null, {
- hdr: 'Error!',
- msg: 'Failed to retrieve last update: ' + last_update + '. GET status: ' + status
- });
- });
- }
+ Rest.setUrl(last_update);
+ Rest.get()
+ .success(function (data) {
+ for (var fld in form.fields) {
+ if (data[fld]) {
+ if (fld === 'created') {
+ scope[fld] = FormatDate(new Date(data[fld]));
+ } else {
+ scope[fld] = data[fld];
+ }
+ }
+ }
+ scope.license_error = license_error;
+ scope.status_rows = calcRows(data.status);
+ scope.stdout_rows = calcRows(data.result_stdout);
+ scope.traceback_rows = calcRows(data.result_traceback);
+ $('#status-modal-dialog').dialog('open');
+ })
+ .error(function (data, status) {
+ $('#form-modal').modal("hide");
+ ProcessErrors(scope, data, status, null, {
+ hdr: 'Error!',
+ msg: 'Failed to retrieve last update: ' + last_update + '. GET status: ' + status
+ });
+ });
+ }
- };
- }
+ };
+ }
]);
diff --git a/awx/ui/static/js/helpers/HostEventsViewer.js b/awx/ui/static/js/helpers/HostEventsViewer.js
index cbc8152bd9..6e035df035 100644
--- a/awx/ui/static/js/helpers/HostEventsViewer.js
+++ b/awx/ui/static/js/helpers/HostEventsViewer.js
@@ -12,278 +12,278 @@
* @description view a list of events for a given job and host
*/
+export default
+ angular.module('HostEventsViewerHelper', ['ModalDialog', 'Utilities', 'EventViewerHelper'])
-angular.module('HostEventsViewerHelper', ['ModalDialog', 'Utilities', 'EventViewerHelper'])
+ .factory('HostEventsViewer', ['$log', '$compile', 'CreateDialog', 'Wait', 'GetBasePath', 'Empty', 'GetEvents', 'EventViewer',
+ function($log, $compile, CreateDialog, Wait, GetBasePath, Empty, GetEvents, EventViewer) {
+ return function(params) {
+ var parent_scope = params.scope,
+ scope = parent_scope.$new(true),
+ job_id = params.job_id,
+ url = params.url,
+ title = params.title, //optional
+ fixHeight, buildTable,
+ lastID, setStatus, buildRow, status;
- .factory('HostEventsViewer', ['$log', '$compile', 'CreateDialog', 'Wait', 'GetBasePath', 'Empty', 'GetEvents', 'EventViewer',
- function($log, $compile, CreateDialog, Wait, GetBasePath, Empty, GetEvents, EventViewer) {
- return function(params) {
- var parent_scope = params.scope,
- scope = parent_scope.$new(true),
- job_id = params.job_id,
- url = params.url,
- title = params.title, //optional
- fixHeight, buildTable,
- lastID, setStatus, buildRow, status;
-
- // initialize the status dropdown
- scope.host_events_status_options = [
- { value: "all", name: "All" },
- { value: "changed", name: "Changed" },
- { value: "failed", name: "Failed" },
- { value: "ok", name: "OK" },
- { value: "unreachable", name: "Unreachable" }
- ];
- scope.host_events_search_name = params.name;
- status = (params.status) ? params.status : 'all';
- scope.host_events_status_options.every(function(opt, idx) {
- if (opt.value === status) {
- scope.host_events_search_status = scope.host_events_status_options[idx];
- return false;
- }
- return true;
- });
- if (!scope.host_events_search_status) {
- scope.host_events_search_status = scope.host_events_status_options[0];
- }
-
- $log.debug('job_id: ' + job_id + ' url: ' + url + ' title: ' + title + ' name: ' + name + ' status: ' + status);
-
- scope.eventsSearchActive = (scope.host_events_search_name) ? true : false;
-
- if (scope.removeModalReady) {
- scope.removeModalReady();
- }
- scope.removeModalReady = scope.$on('ModalReady', function() {
- scope.hostViewSearching = false;
- $('#host-events-modal-dialog').dialog('open');
- });
-
- if (scope.removeJobReady) {
- scope.removeJobReady();
- }
- scope.removeEventReady = scope.$on('EventsReady', function(e, data, maxID) {
- var elem, html;
-
- lastID = maxID;
- html = buildTable(data);
- $('#host-events').html(html);
- elem = angular.element(document.getElementById('host-events-modal-dialog'));
- $compile(elem)(scope);
-
- CreateDialog({
- scope: scope,
- width: 675,
- height: 600,
- minWidth: 450,
- callback: 'ModalReady',
- id: 'host-events-modal-dialog',
- onResizeStop: fixHeight,
- title: ( (title) ? title : 'Host Events' ),
- onClose: function() {
- try {
- scope.$destroy();
- }
- catch(e) {
- //ignore
- }
- },
- onOpen: function() {
- fixHeight();
+ // initialize the status dropdown
+ scope.host_events_status_options = [
+ { value: "all", name: "All" },
+ { value: "changed", name: "Changed" },
+ { value: "failed", name: "Failed" },
+ { value: "ok", name: "OK" },
+ { value: "unreachable", name: "Unreachable" }
+ ];
+ scope.host_events_search_name = params.name;
+ status = (params.status) ? params.status : 'all';
+ scope.host_events_status_options.every(function(opt, idx) {
+ if (opt.value === status) {
+ scope.host_events_search_status = scope.host_events_status_options[idx];
+ return false;
}
+ return true;
});
- });
-
- if (scope.removeRefreshHTML) {
- scope.removeRefreshHTML();
- }
- scope.removeRefreshHTML = scope.$on('RefreshHTML', function(e, data) {
- var elem, html = buildTable(data);
- $('#host-events').html(html);
- scope.hostViewSearching = false;
- elem = angular.element(document.getElementById('host-events'));
- $compile(elem)(scope);
- });
-
- setStatus = function(result) {
- var msg = '', status = 'ok', status_text = 'OK';
- if (!result.task && result.event_data && result.event_data.res && result.event_data.res.ansible_facts) {
- result.task = "Gathering Facts";
+ if (!scope.host_events_search_status) {
+ scope.host_events_search_status = scope.host_events_status_options[0];
}
- if (result.event === "runner_on_no_hosts") {
- msg = "No hosts remaining";
- }
- if (result.event === 'runner_on_unreachable') {
- status = 'unreachable';
- status_text = 'Unreachable';
- }
- else if (result.failed) {
- status = 'failed';
- status_text = 'Failed';
- }
- else if (result.changed) {
- status = 'changed';
- status_text = 'Changed';
- }
- if (result.event_data.res && result.event_data.res.msg) {
- msg = result.event_data.res.msg;
- }
- result.msg = msg;
- result.status = status;
- result.status_text = status_text;
- return result;
- };
- buildRow = function(res) {
- var html = '';
- html += "
\n";
- html += " " + res.status_text + " \n";
- html += "" + res.host_name + " \n";
- html += "" + res.play + " \n";
- html += "" + res.task + " \n";
- html += " ";
- return html;
- };
+ $log.debug('job_id: ' + job_id + ' url: ' + url + ' title: ' + title + ' name: ' + name + ' status: ' + status);
- buildTable = function(data) {
- var html = "
\n";
- html += "\n";
- data.results.forEach(function(result) {
- var res = setStatus(result);
- html += buildRow(res);
- });
- html += " \n";
- html += "
\n";
- return html;
- };
-
- fixHeight = function() {
- var available_height = $('#host-events-modal-dialog').height() - $('#host-events-modal-dialog #search-form').height() - $('#host-events-modal-dialog #fixed-table-header').height();
- $('#host-events').height(available_height);
- $log.debug('set height to: ' + available_height);
- // Check width and reset search fields
- if ($('#host-events-modal-dialog').width() <= 450) {
- $('#host-events-modal-dialog #status-field').css({'margin-left': '7px'});
- }
- else {
- $('#host-events-modal-dialog #status-field').css({'margin-left': '15px'});
- }
- };
-
- GetEvents({
- url: url,
- scope: scope,
- callback: 'EventsReady'
- });
-
- scope.modalOK = function() {
- $('#host-events-modal-dialog').dialog('close');
- scope.$destroy();
- };
-
- scope.searchEvents = function() {
scope.eventsSearchActive = (scope.host_events_search_name) ? true : false;
- GetEvents({
- scope: scope,
- url: url,
- callback: 'RefreshHTML'
- });
- };
- scope.searchEventKeyPress = function(e) {
- if (e.keyCode === 13) {
- scope.searchEvents();
+ if (scope.removeModalReady) {
+ scope.removeModalReady();
}
- };
-
- scope.showDetails = function(id) {
- EventViewer({
- scope: parent_scope,
- url: GetBasePath('jobs') + job_id + '/job_events/?id=' + id,
+ scope.removeModalReady = scope.$on('ModalReady', function() {
+ scope.hostViewSearching = false;
+ $('#host-events-modal-dialog').dialog('open');
});
- };
- if (scope.removeEventsScrollDownBuild) {
- scope.removeEventsScrollDownBuild();
- }
- scope.removeEventsScrollDownBuild = scope.$on('EventScrollDownBuild', function(e, data, maxID) {
- var elem, html = '';
- lastID = maxID;
- data.results.forEach(function(result) {
- var res = setStatus(result);
- html += buildRow(res);
+ if (scope.removeJobReady) {
+ scope.removeJobReady();
+ }
+ scope.removeEventReady = scope.$on('EventsReady', function(e, data, maxID) {
+ var elem, html;
+
+ lastID = maxID;
+ html = buildTable(data);
+ $('#host-events').html(html);
+ elem = angular.element(document.getElementById('host-events-modal-dialog'));
+ $compile(elem)(scope);
+
+ CreateDialog({
+ scope: scope,
+ width: 675,
+ height: 600,
+ minWidth: 450,
+ callback: 'ModalReady',
+ id: 'host-events-modal-dialog',
+ onResizeStop: fixHeight,
+ title: ( (title) ? title : 'Host Events' ),
+ onClose: function() {
+ try {
+ scope.$destroy();
+ }
+ catch(e) {
+ //ignore
+ }
+ },
+ onOpen: function() {
+ fixHeight();
+ }
+ });
});
- if (html) {
- $('#host-events table tbody').append(html);
+
+ if (scope.removeRefreshHTML) {
+ scope.removeRefreshHTML();
+ }
+ scope.removeRefreshHTML = scope.$on('RefreshHTML', function(e, data) {
+ var elem, html = buildTable(data);
+ $('#host-events').html(html);
+ scope.hostViewSearching = false;
elem = angular.element(document.getElementById('host-events'));
$compile(elem)(scope);
- }
- });
-
- scope.hostEventsScrollDown = function() {
- GetEvents({
- scope: scope,
- url: url,
- gt: lastID,
- callback: 'EventScrollDownBuild'
});
- };
- };
- }])
-
- .factory('GetEvents', ['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
- return function(params) {
- var url = params.url,
- scope = params.scope,
- gt = params.gt,
- callback = params.callback;
-
- if (scope.host_events_search_name) {
- url += '?host_name=' + scope.host_events_search_name;
- }
- else {
- url += '?host_name__isnull=false';
- }
-
- if (scope.host_events_search_status.value === 'changed') {
- url += '&event__icontains=runner&changed=true';
- }
- else if (scope.host_events_search_status.value === 'failed') {
- url += '&event__icontains=runner&failed=true';
- }
- else if (scope.host_events_search_status.value === 'ok') {
- url += '&event=runner_on_ok&changed=false';
- }
- else if (scope.host_events_search_status.value === 'unreachable') {
- url += '&event=runner_on_unreachable';
- }
- else if (scope.host_events_search_status.value === 'all') {
- url += '&event__icontains=runner¬__event=runner_on_skipped';
- }
-
- if (gt) {
- // used for endless scroll
- url += '&id__gt=' + gt;
- }
-
- url += '&page_size=50&order=id';
-
- scope.hostViewSearching = true;
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- var lastID;
- scope.hostViewSearching = false;
- if (data.results.length > 0) {
- lastID = data.results[data.results.length - 1].id;
+ setStatus = function(result) {
+ var msg = '', status = 'ok', status_text = 'OK';
+ if (!result.task && result.event_data && result.event_data.res && result.event_data.res.ansible_facts) {
+ result.task = "Gathering Facts";
}
- scope.$emit(callback, data, lastID);
- })
- .error(function(data, status) {
- scope.hostViewSearching = false;
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to get events ' + url + '. GET returned: ' + status });
+ if (result.event === "runner_on_no_hosts") {
+ msg = "No hosts remaining";
+ }
+ if (result.event === 'runner_on_unreachable') {
+ status = 'unreachable';
+ status_text = 'Unreachable';
+ }
+ else if (result.failed) {
+ status = 'failed';
+ status_text = 'Failed';
+ }
+ else if (result.changed) {
+ status = 'changed';
+ status_text = 'Changed';
+ }
+ if (result.event_data.res && result.event_data.res.msg) {
+ msg = result.event_data.res.msg;
+ }
+ result.msg = msg;
+ result.status = status;
+ result.status_text = status_text;
+ return result;
+ };
+
+ buildRow = function(res) {
+ var html = '';
+ html += "
\n";
+ html += " " + res.status_text + " \n";
+ html += "" + res.host_name + " \n";
+ html += "" + res.play + " \n";
+ html += "" + res.task + " \n";
+ html += " ";
+ return html;
+ };
+
+ buildTable = function(data) {
+ var html = "
\n";
+ html += "\n";
+ data.results.forEach(function(result) {
+ var res = setStatus(result);
+ html += buildRow(res);
+ });
+ html += " \n";
+ html += "
\n";
+ return html;
+ };
+
+ fixHeight = function() {
+ var available_height = $('#host-events-modal-dialog').height() - $('#host-events-modal-dialog #search-form').height() - $('#host-events-modal-dialog #fixed-table-header').height();
+ $('#host-events').height(available_height);
+ $log.debug('set height to: ' + available_height);
+ // Check width and reset search fields
+ if ($('#host-events-modal-dialog').width() <= 450) {
+ $('#host-events-modal-dialog #status-field').css({'margin-left': '7px'});
+ }
+ else {
+ $('#host-events-modal-dialog #status-field').css({'margin-left': '15px'});
+ }
+ };
+
+ GetEvents({
+ url: url,
+ scope: scope,
+ callback: 'EventsReady'
});
- };
- }]);
+
+ scope.modalOK = function() {
+ $('#host-events-modal-dialog').dialog('close');
+ scope.$destroy();
+ };
+
+ scope.searchEvents = function() {
+ scope.eventsSearchActive = (scope.host_events_search_name) ? true : false;
+ GetEvents({
+ scope: scope,
+ url: url,
+ callback: 'RefreshHTML'
+ });
+ };
+
+ scope.searchEventKeyPress = function(e) {
+ if (e.keyCode === 13) {
+ scope.searchEvents();
+ }
+ };
+
+ scope.showDetails = function(id) {
+ EventViewer({
+ scope: parent_scope,
+ url: GetBasePath('jobs') + job_id + '/job_events/?id=' + id,
+ });
+ };
+
+ if (scope.removeEventsScrollDownBuild) {
+ scope.removeEventsScrollDownBuild();
+ }
+ scope.removeEventsScrollDownBuild = scope.$on('EventScrollDownBuild', function(e, data, maxID) {
+ var elem, html = '';
+ lastID = maxID;
+ data.results.forEach(function(result) {
+ var res = setStatus(result);
+ html += buildRow(res);
+ });
+ if (html) {
+ $('#host-events table tbody').append(html);
+ elem = angular.element(document.getElementById('host-events'));
+ $compile(elem)(scope);
+ }
+ });
+
+ scope.hostEventsScrollDown = function() {
+ GetEvents({
+ scope: scope,
+ url: url,
+ gt: lastID,
+ callback: 'EventScrollDownBuild'
+ });
+ };
+
+ };
+ }])
+
+ .factory('GetEvents', ['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
+ return function(params) {
+ var url = params.url,
+ scope = params.scope,
+ gt = params.gt,
+ callback = params.callback;
+
+ if (scope.host_events_search_name) {
+ url += '?host_name=' + scope.host_events_search_name;
+ }
+ else {
+ url += '?host_name__isnull=false';
+ }
+
+ if (scope.host_events_search_status.value === 'changed') {
+ url += '&event__icontains=runner&changed=true';
+ }
+ else if (scope.host_events_search_status.value === 'failed') {
+ url += '&event__icontains=runner&failed=true';
+ }
+ else if (scope.host_events_search_status.value === 'ok') {
+ url += '&event=runner_on_ok&changed=false';
+ }
+ else if (scope.host_events_search_status.value === 'unreachable') {
+ url += '&event=runner_on_unreachable';
+ }
+ else if (scope.host_events_search_status.value === 'all') {
+ url += '&event__icontains=runner¬__event=runner_on_skipped';
+ }
+
+ if (gt) {
+ // used for endless scroll
+ url += '&id__gt=' + gt;
+ }
+
+ url += '&page_size=50&order=id';
+
+ scope.hostViewSearching = true;
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ var lastID;
+ scope.hostViewSearching = false;
+ if (data.results.length > 0) {
+ lastID = data.results[data.results.length - 1].id;
+ }
+ scope.$emit(callback, data, lastID);
+ })
+ .error(function(data, status) {
+ scope.hostViewSearching = false;
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to get events ' + url + '. GET returned: ' + status });
+ });
+ };
+ }]);
diff --git a/awx/ui/static/js/helpers/Hosts.js b/awx/ui/static/js/helpers/Hosts.js
index 3d69b860d9..280e398599 100644
--- a/awx/ui/static/js/helpers/Hosts.js
+++ b/awx/ui/static/js/helpers/Hosts.js
@@ -8,20 +8,21 @@
*/
/* jshint loopfunc: true */
- /**
+/**
* @ngdoc function
* @name helpers.function:Hosts
* @description Routines that handle host add/edit/delete on the Inventory detail page.
-*/
-
+ */
+'use strict';
+export default
angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'HostListDefinition',
- 'SearchHelper', 'PaginationHelpers', 'ListGenerator', 'AuthService', 'HostsHelper',
- 'InventoryHelper', 'RelatedSearchHelper', 'InventoryFormDefinition', 'SelectionHelper',
- 'HostGroupsFormDefinition', 'VariablesHelper', 'ModalDialog', 'LogViewerHelper',
- 'GroupListDefinition'
- ])
+ 'SearchHelper', 'PaginationHelpers', 'ListGenerator', 'AuthService', 'HostsHelper',
+ 'InventoryHelper', 'RelatedSearchHelper', 'InventoryFormDefinition', 'SelectionHelper',
+ 'HostGroupsFormDefinition', 'VariablesHelper', 'ModalDialog', 'LogViewerHelper',
+ 'GroupListDefinition'
+])
.factory('SetEnabledMsg', [ function() {
return function(host) {
@@ -65,8 +66,8 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
return function(params) {
var scope = params.scope,
- host = params.host,
- i, html, title;
+ host = params.host,
+ i, html, title;
function ellipsis(a) {
if (a.length > 25) {
@@ -96,9 +97,9 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
// build html table of job status info
jobs = host.summary_fields.recent_jobs.sort(
function(a,b) {
- // reverse numerical order
- return -1 * (a - b);
- });
+ // reverse numerical order
+ return -1 * (a - b);
+ });
title = "Recent Jobs";
html = "
\n";
html += "\n";
@@ -161,7 +162,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
.factory('ViewJob', ['LogViewer', 'GetBasePath', function(LogViewer, GetBasePath) {
return function(params) {
var scope = params.scope,
- id = params.id;
+ id = params.id;
LogViewer({
scope: scope,
url: GetBasePath('jobs') + id + '/'
@@ -170,1143 +171,1138 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
}])
.factory('HostsReload', [ '$routeParams', 'Empty', 'InventoryHosts', 'GetBasePath', 'SearchInit', 'PaginateInit', 'Wait',
- 'SetHostStatus', 'SetStatus', 'ApplyEllipsis', 'SetContainerHeights', 'GetHostContainerRows',
-function($routeParams, Empty, InventoryHosts, GetBasePath, SearchInit, PaginateInit, Wait, SetHostStatus, SetStatus,
- ApplyEllipsis, SetContainerHeights) {
- return function(params) {
-
- var scope = params.scope,
- parent_scope = params.parent_scope,
- group_id = params.group_id,
- inventory_id = params.inventory_id,
- list = InventoryHosts,
- pageSize = (params.pageSize) ? params.pageSize : 20,
-
- url = ( !Empty(group_id) ) ? GetBasePath('groups') + group_id + '/all_hosts/' :
- GetBasePath('inventory') + inventory_id + '/hosts/';
-
- scope.search_place_holder='Search ' + scope.selected_group_name;
-
- if (scope.removeHostsReloadPostRefresh) {
- scope.removeHostsReloadPostRefresh();
- }
- scope.removeHostsReloadPostRefresh = scope.$on('PostRefresh', function(e, set) {
- if (set === 'hosts') {
- for (var i=0; i < scope.hosts.length; i++) {
- //Set tooltip for host enabled flag
- scope.hosts[i].enabled_flag = scope.hosts[i].enabled;
- }
- SetStatus({ scope: scope });
- setTimeout(function() { ApplyEllipsis('#hosts_table .host-name a'); }, 2500);
- Wait('stop');
- if (parent_scope) {
- parent_scope.$emit('HostReloadComplete');
- }
- }
- });
-
- // Size containers based on viewport
- SetContainerHeights({ scope: scope, reloadHosts: false });
-
- SearchInit({ scope: scope, set: 'hosts', list: list, url: url });
- PaginateInit({ scope: scope, list: list, url: url, pageSize: pageSize });
-
- if ($routeParams.host_name) {
- scope[list.iterator + 'InputDisable'] = false;
- scope[list.iterator + 'SearchValue'] = $routeParams.host_name;
- scope[list.iterator + 'SearchField'] = 'name';
- scope[list.iterator + 'SearchFieldLabel'] = list.fields.name.label;
- scope[list.iterator + 'SearchSelectValue'] = null;
- }
-
- if (scope.show_failures) {
- scope[list.iterator + 'InputDisable'] = true;
- scope[list.iterator + 'SearchValue'] = 'true';
- scope[list.iterator + 'SearchField'] = 'has_active_failures';
- scope[list.iterator + 'SearchFieldLabel'] = list.fields.has_active_failures.label;
- scope[list.iterator + 'SearchSelectValue'] = { value: 1 };
- }
- scope.search(list.iterator, null, true);
- };
-}])
-
-.factory('InjectHosts', ['GenerateList', 'InventoryHosts', 'HostsReload',
-function(GenerateList, InventoryHosts, HostsReload) {
- return function(params) {
-
- var group_scope = params.group_scope,
- host_scope = params.host_scope,
- inventory_id = params.inventory_id,
- group_id = params.group_id,
- pageSize = params.pageSize,
- generator = GenerateList;
-
- // Inject the list html
- generator.inject(InventoryHosts, { scope: host_scope, mode: 'edit', id: 'hosts-container', breadCrumbs: false, searchSize: 'col-lg-6 col-md-6 col-sm-6' });
-
- // Load data
- HostsReload({ scope: host_scope, group_id: group_id, inventory_id: inventory_id, parent_scope: group_scope, pageSize: pageSize });
- };
-}])
-
-.factory('ToggleHostEnabled', [ 'GetBasePath', 'Rest', 'Wait', 'ProcessErrors', 'Alert', 'Find', 'SetEnabledMsg',
-function(GetBasePath, Rest, Wait, ProcessErrors, Alert, Find, SetEnabledMsg) {
- return function(params) {
-
- var id = params.host_id,
- external_source = params.external_source,
- parent_scope = params.parent_scope,
- host_scope = params.host_scope,
- host;
-
- function setMsg(host) {
- host.enabled = (host.enabled) ? false : true;
- host.enabled_flag = host.enabled;
- SetEnabledMsg(host);
- }
-
- if (!external_source) {
- // Host is not managed by an external source
- Wait('start');
- host = Find({ list: host_scope.hosts, key: 'id', val: id });
- setMsg(host);
-
- Rest.setUrl(GetBasePath('hosts') + id + '/');
- Rest.put(host)
- .success( function() {
- Wait('stop');
- })
- .error( function(data, status) {
- // Flip the enabled flag back
- setMsg(host);
- ProcessErrors(parent_scope, data, status, null,
- { hdr: 'Error!', msg: 'Failed to update host. PUT returned status: ' + status });
- });
- }
- else {
- Alert('Action Not Allowed', 'This host is managed by an external cloud source. Disable it at the external source, ' +
- 'then run an inventory sync to update Tower with the new status.', 'alert-info');
- }
- };
-}])
-
-.factory('HostsList', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
- 'Prompt', 'SearchInit', 'PaginateInit', 'ProcessErrors', 'GetBasePath', 'HostsAdd', 'HostsReload', 'SelectionInit',
-function($rootScope, $location, $log, $routeParams, Rest, Alert, HostList, GenerateList, Prompt, SearchInit,
- PaginateInit, ProcessErrors, GetBasePath, HostsAdd, HostsReload, SelectionInit) {
- return function(params) {
-
- var inventory_id = params.inventory_id,
- group_id = params.group_id,
- list = HostList,
- generator = GenerateList,
- defaultUrl, scope;
-
- list.iterator = 'subhost'; //Override the iterator and name so the scope of the modal dialog
- list.name = 'subhosts'; //will not conflict with the parent scope
-
-
-
- scope = generator.inject(list, {
- id: 'form-modal-body',
- mode: 'select',
- breadCrumbs: false,
- selectButton: false
- });
-
- defaultUrl = GetBasePath('inventory') + inventory_id + '/hosts/?not__groups__id=' + scope.group_id;
-
- scope.formModalActionLabel = 'Select';
- scope.formModalHeader = 'Add Existing Hosts';
- scope.formModalCancelShow = true;
-
- SelectionInit({ scope: scope, list: list, url: GetBasePath('groups') + group_id + '/hosts/' });
-
- if (scope.removeModalClosed) {
- scope.removeModalClosed();
- }
- scope.removeModalClosed = scope.$on('modalClosed', function() {
- // if the modal closed, assume something got changed and reload the host list
- HostsReload(params);
- });
-
- $('.popover').popover('hide'); //remove any lingering pop-overs
- $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
- $('#form-modal').modal({ backdrop: 'static', keyboard: false });
-
- SearchInit({ scope: scope, set: 'subhosts', list: list, url: defaultUrl });
- PaginateInit({ scope: scope, list: list, url: defaultUrl, mode: 'lookup' });
- scope.search(list.iterator);
-
- if (!scope.$$phase) {
- scope.$digest();
- }
-
- scope.createHost = function() {
- $('#form-modal').modal('hide');
- HostsAdd({ scope: params.scope, inventory_id: inventory_id, group_id: group_id });
- };
-
- };
-}])
-
-
-.factory('HostsCreate', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostForm', 'GenerateForm',
- 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange', 'Wait', 'ToJSON',
-function($rootScope, $location, $log, $routeParams, Rest, Alert, HostForm, GenerateForm, Prompt, ProcessErrors,
- GetBasePath, HostsReload, ParseTypeChange, Wait, ToJSON) {
- return function(params) {
-
- var parent_scope = params.scope,
- inventory_id = parent_scope.inventory_id,
- group_id = parent_scope.selected_group_id,
- defaultUrl = GetBasePath('groups') + group_id + '/hosts/',
- form = HostForm,
- generator = GenerateForm,
- scope = generator.inject(form, {mode: 'add', modal: true, related: false}),
- master={};
-
- scope.formModalActionLabel = 'Save';
- scope.formModalHeader = 'Create New Host';
- scope.formModalCancelShow = true;
-
- scope.parseType = 'yaml';
- ParseTypeChange({ scope: scope, field_id: 'host_variables' });
-
- if (scope.removeHostsReload) {
- scope.removeHostsReload();
- }
- scope.removeHostsReload = scope.$on('hostsReload', function() {
- HostsReload(params);
- });
-
- $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
- //$('#form-modal').unbind('hidden');
- //$('#form-modal').on('hidden', function () { scope.$emit('hostsReload'); });
-
- generator.reset();
- master={};
-
- if (!scope.$$phase) {
- scope.$digest();
- }
-
- if (scope.removeHostSaveComplete) {
- scope.removeHostSaveComplete();
- }
- scope.removeHostSaveComplete = scope.$on('HostSaveComplete', function() {
- Wait('stop');
- $('#form-modal').modal('hide');
-
- HostsReload({
- scope: parent_scope,
- group_id: parent_scope.selected_group_id,
- tree_id: parent_scope.selected_tree_id,
- inventory_id: parent_scope.inventory_id
- });
-
- //WatchInventoryWindowResize();
- });
-
- // Save
- scope.formModalAction = function() {
-
- Wait('start');
-
- var fld, data={};
- scope.formModalActionDisabled = true;
- data.variables = ToJSON(scope.parseType, scope.variables, true);
- for (fld in form.fields) {
- if (fld !== 'variables') {
- data[fld] = scope[fld];
- }
- }
- data.inventory = inventory_id;
-
- Rest.setUrl(defaultUrl);
- Rest.post(data)
- .success( function() {
- scope.$emit('HostSaveComplete');
- })
- .error( function(data, status) {
- Wait('stop');
- scope.formModalActionDisabled = false;
- ProcessErrors(scope, data, status, form,
- { hdr: 'Error!', msg: 'Failed to add new host. POST returned status: ' + status });
- });
- };
-
- // Cancel
- scope.formReset = function() {
- // Defaults
- generator.reset();
- };
-
- scope.cancelModal = function() {
- // WatchInventoryWindowResize();
- };
-
- };
-}])
-
-
-.factory('HostsEdit', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostForm', 'GenerateForm',
- 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange', 'Wait', 'Find', 'SetStatus', 'ApplyEllipsis',
- 'ToJSON', 'ParseVariableString', 'CreateDialog', 'TextareaResize',
-function($rootScope, $location, $log, $routeParams, Rest, Alert, HostForm, GenerateForm, Prompt, ProcessErrors,
- GetBasePath, HostsReload, ParseTypeChange, Wait, Find, SetStatus, ApplyEllipsis, ToJSON,
- ParseVariableString, CreateDialog, TextareaResize) {
- return function(params) {
-
- var parent_scope = params.host_scope,
- group_scope = params.group_scope,
- host_id = params.host_id,
- inventory_id = params.inventory_id,
- mode = params.mode, // 'add' or 'edit'
- selected_group_id = params.selected_group_id,
- generator = GenerateForm,
- form = HostForm,
- defaultUrl,
- scope = parent_scope.$new(),
- master = {},
- relatedSets = {},
- buttons, url;
-
- generator.inject(HostForm, { mode: 'edit', id: 'host-modal-dialog', breadCrumbs: false, related: false, scope: scope });
- generator.reset();
-
- buttons = [{
- label: "Cancel",
- onClick: function() {
- scope.cancelModal();
- },
- icon: "fa-times",
- "class": "btn btn-default",
- "id": "host-cancel-button"
- },{
- label: "Save",
- onClick: function() {
- scope.saveModal();
- },
- icon: "fa-check",
- "class": "btn btn-primary",
- "id": "host-save-button"
- }];
-
- CreateDialog({
- scope: scope,
- buttons: buttons,
- width: 675,
- height: 750,
- minWidth: 400,
- title: 'Host Properties',
- id: 'host-modal-dialog',
- clonseOnEscape: false,
- onClose: function() {
- Wait('stop');
- scope.codeMirror.destroy();
- $('#host-modal-dialog').empty();
- },
- onResizeStop: function() {
- TextareaResize({
- scope: scope,
- textareaId: 'host_variables',
- modalId: 'host-modal-dialog',
- formId: 'host_form'
- });
- },
- beforeDestroy: function() {
- if (scope.codeMirror) {
- scope.codeMirror.destroy();
- }
- $('#host-modal-dialog').empty();
- },
- onOpen: function() {
- $('#host_name').focus();
- },
- callback: 'HostEditDialogReady'
- });
-
- scope.parseType = 'yaml';
-
- if (scope.hostVariablesLoadedRemove) {
- scope.hostVariablesLoadedRemove();
- }
- scope.hostVariablesLoadedRemove = scope.$on('hostVariablesLoaded', function() {
- $('#host-modal-dialog').dialog('open');
- setTimeout(function() {
- TextareaResize({
- scope: scope,
- textareaId: 'host_variables',
- modalId: 'host-modal-dialog',
- formId: 'host_form',
- parse: true
- });
- }, 300);
- //ParseTypeChange({ scope: scope, field_id: 'host_variables', onReady: callback });
- });
-
- if (scope.hostLoadedRemove) {
- scope.hostLoadedRemove();
- }
- scope.hostLoadedRemove = scope.$on('hostLoaded', function() {
- // Retrieve host variables
- if (scope.variable_url) {
- Rest.setUrl(scope.variable_url);
- Rest.get()
- .success( function(data) {
- scope.variables = ParseVariableString(data);
- scope.$emit('hostVariablesLoaded');
- })
- .error( function(data, status) {
- scope.variables = null;
- ProcessErrors(scope, data, status, form,
- { hdr: 'Error!', msg: 'Failed to retrieve host variables. GET returned status: ' + status });
- });
- }
- else {
- scope.variables = "---";
- scope.$emit('hostVariablesLoaded');
- }
- master.variables = scope.variables;
- });
-
- Wait('start');
-
- // Retrieve detail record and prepopulate the form
- if (mode === 'edit') {
- defaultUrl = GetBasePath('hosts') + host_id + '/';
- Rest.setUrl(defaultUrl);
- Rest.get()
- .success( function(data) {
- var set, fld, related;
- for (fld in form.fields) {
- if (data[fld]) {
- scope[fld] = data[fld];
- master[fld] = scope[fld];
- }
- }
- related = data.related;
- for (set in form.related) {
- if (related[set]) {
- relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
- }
- }
- scope.variable_url = data.related.variable_data;
- scope.has_inventory_sources = data.has_inventory_sources;
- scope.$emit('hostLoaded');
- })
- .error( function(data, status) {
- ProcessErrors(parent_scope, data, status, form,
- { hdr: 'Error!', msg: 'Failed to retrieve host: ' + host_id + '. GET returned status: ' + status });
- });
- }
- else {
- // Add mode
- url = GetBasePath('groups') + selected_group_id + '/';
- Rest.setUrl(url);
- Rest.get()
- .success( function(data) {
- scope.has_inventory_sources = data.has_inventory_sources;
- scope.enabled = true;
- scope.variables = '---';
- defaultUrl = data.related.hosts;
- scope.$emit('hostVariablesLoaded');
- })
- .error( function(data, status) {
- ProcessErrors(parent_scope, data, status, form,
- { hdr: 'Error!', msg: 'Failed to retrieve group: ' + selected_group_id + '. GET returned status: ' + status });
- });
- }
-
- if (scope.removeSaveCompleted) {
- scope.removeSaveCompleted();
- }
- scope.removeSaveCompleted = scope.$on('saveCompleted', function() {
- try {
- $('#host-modal-dialog').dialog('close');
- }
- catch(err) {
- // ignore
- }
- if (group_scope && group_scope.refreshHosts) {
- group_scope.refreshHosts();
- }
- if (parent_scope.refreshHosts) {
- parent_scope.refreshHosts();
- }
- scope.$destroy();
- });
-
- // Save changes to the parent
- scope.saveModal = function() {
-
- Wait('start');
- var fld, data={};
-
- try {
- data.variables = ToJSON(scope.parseType, scope.variables, true);
- for (fld in form.fields) {
- data[fld] = scope[fld];
- }
- data.inventory = inventory_id;
- Rest.setUrl(defaultUrl);
- if (mode === 'edit') {
- Rest.put(data)
- .success( function() {
- scope.$emit('saveCompleted');
- })
- .error( function(data, status) {
- ProcessErrors(scope, data, status, form,
- { hdr: 'Error!', msg: 'Failed to update host: ' + host_id + '. PUT returned status: ' + status });
- });
- }
- else {
- Rest.post(data)
- .success( function() {
- scope.$emit('saveCompleted');
- })
- .error( function(data, status) {
- ProcessErrors(scope, data, status, form,
- { hdr: 'Error!', msg: 'Failed to create host. POST returned status: ' + status });
- });
- }
- }
- catch(e) {
- // ignore. ToJSON will have already alerted the user
- }
- };
-
- // Cancel
- scope.formReset = function() {
- generator.reset();
- for (var fld in master) {
- scope[fld] = master[fld];
- }
- scope.parseType = 'yaml';
- };
-
- scope.cancelModal = function() {
- try {
- $('#host-modal-dialog').dialog('close');
- }
- catch(err) {
- // ignore
- }
- scope.$destroy();
- };
-
- };
-}])
-
-
-.factory('HostsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'Wait',
-function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload, Wait) {
- return function(params) {
- // Remove the selected host from the current group by disassociating
-
- var action_to_take, body,
- scope = params.parent_scope,
- host_id = params.host_id,
- host_name = params.host_name,
- group,
- url_list = [];
-
- if (scope.selected_group_id) {
- //group = Find({ list: parent_scope.groups, key: 'id', val: parent_scope.selected_group_id });
- //getChildren(group.id);
- url_list.push(GetBasePath('groups') + scope.selected_group_id + '/hosts/');
- }
- else {
- url_list.push(GetBasePath('inventory') + scope.inventory.id + '/hosts/');
- }
-
- if (scope.removeHostsReload) {
- scope.removeHostsReload();
- }
- scope.removeHostsReload = scope.$on('hostsReload', function() {
- $('#prompt-modal').modal('hide');
- scope.refreshHosts();
- });
-
- $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('stop'); });
-
- action_to_take = function() {
- var count=0, i;
-
- Wait('start');
-
- if (scope.removeHostRemoved) {
- scope.removeHostRemoved();
- }
- scope.removeHostRemoved = scope.$on('hostRemoved', function(){
- count++;
- if (count === url_list.length) {
- Wait('start');
- scope.$emit('hostsReload');
- }
- });
-
- for(i=0; i < url_list.length; i++) {
- Rest.setUrl(url_list[i]);
- Rest.post({ id: host_id, disassociate: 1 })
- .success( function() {
- scope.$emit('hostRemoved');
- })
- .error( function(data, status) {
- ProcessErrors(scope, data, status, null,
- { hdr: 'Error!', msg: 'Attempt to delete ' + host_name + ' failed. DELETE returned status: ' + status });
- });
- }
- };
-
- body = (group) ? 'Are you sure you want to remove host ' + host_name + ' from group ' + group.name + '?' +
- ' It will still be part of the inventory and available in All Hosts.
' :
- 'Are you sure you want to permanently delete host ' + host_name + ' from the inventory?
';
- Prompt({ hdr: 'Delete Host', body: body, action: action_to_take, 'class': 'btn-danger' });
-
- };
-}])
-
-.factory('HostsCopy', ['$compile', 'Rest', 'ProcessErrors', 'CreateDialog', 'GetBasePath', 'Wait', 'GenerateList', 'GroupList', 'SearchInit',
- 'PaginateInit',
- function($compile, Rest, ProcessErrors, CreateDialog, GetBasePath, Wait, GenerateList, GroupList, SearchInit, PaginateInit) {
- return function(params) {
-
- var host_id = params.host_id,
- group_scope = params.group_scope,
- parent_scope = params.host_scope,
- parent_group = group_scope.selected_group_id,
- scope = parent_scope.$new(),
- buttonSet, url, host;
-
- buttonSet = [{
- label: "Cancel",
- onClick: function() {
- scope.cancel();
- },
- icon: "fa-times",
- "class": "btn btn-default",
- "id": "host-copy-cancel-button"
- },{
- label: "OK",
- onClick: function() {
- scope.performCopy();
- },
- icon: "fa-check",
- "class": "btn btn-primary",
- "id": "host-copy-ok-button"
- }];
-
- if (scope.removeHostCopyPostRefresh) {
- scope.removeHostCopyPostRefresh();
- }
- scope.removeHostCopyPostRefresh = scope.$on('PostRefresh', function() {
- scope.copy_groups.forEach(function(row, i) {
- scope.copy_groups[i].checked = '0';
- });
- Wait('stop');
- $('#host-copy-dialog').dialog('open');
- $('#host-copy-ok-button').attr('disabled','disabled');
-
- // prevent backspace from navigation when not in input or textarea field
- $(document).on("keydown", function (e) {
- if (e.which === 8 && !$(e.target).is('input[type="text"], textarea')) {
- e.preventDefault();
- }
- });
- });
-
- if (scope.removeHostCopyDialogReady) {
- scope.removeHostCopyDialogReady();
- }
- scope.removeCopyDialogReady = scope.$on('HostCopyDialogReady', function() {
- var url = GetBasePath('inventory') + group_scope.inventory.id + '/groups/';
- GenerateList.inject(GroupList, {
- mode: 'lookup',
- id: 'copy-host-select-container',
- scope: scope
- //,
- //instructions: instructions
- });
- SearchInit({
- scope: scope,
- set: GroupList.name,
- list: GroupList,
- url: url
- });
- PaginateInit({
- scope: scope,
- list: GroupList,
- url: url,
- mode: 'lookup'
- });
- scope.search(GroupList.iterator, null, true, false);
- });
-
- if (scope.removeShowDialog) {
- scope.removeShowDialog();
- }
- scope.removeShowDialog = scope.$on('ShowDialog', function() {
- var d;
- scope.name = host.name;
- scope.copy_choice = "copy";
- d = angular.element(document.getElementById('host-copy-dialog'));
- $compile(d)(scope);
- CreateDialog({
- id: 'host-copy-dialog',
- scope: scope,
- buttons: buttonSet,
- width: 650,
- height: 650,
- minWidth: 600,
- title: 'Copy or Move Host',
- callback: 'HostCopyDialogReady',
- onClose: function() {
- scope.cancel();
- }
- });
- });
-
- Wait('start');
-
- url = GetBasePath('hosts') + host_id + '/';
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- host = data;
- scope.$emit('ShowDialog');
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + ' failed. GET returned: ' + status });
- });
-
-
- scope.cancel = function() {
- $(document).off("keydown");
- try {
- $('#host-copy-dialog').dialog('close');
- }
- catch(e) {
- // ignore
- }
- scope.searchCleanup();
- group_scope.restoreSearch(); // Restore all parent search stuff and refresh hosts and groups lists
- scope.$destroy();
- };
-
- scope['toggle_' + GroupList.iterator] = function (id) {
- var count = 0,
- list = GroupList;
- scope[list.name].forEach( function(row, i) {
- if (row.id === id) {
- if (row.checked === '0') {
- scope[list.name][i].checked = '1';
- scope[list.name][i].success_class = 'success';
- }
- else {
- scope[list.name][i].checked = '0';
- scope[list.name][i].success_class = '';
- }
- } else {
- scope[list.name][i].checked = '0';
- scope[list.name][i].success_class = '';
- }
- });
- // Check if any rows are checked
- scope[list.name].forEach(function(row) {
- if (row.checked === '1') {
- count++;
- }
- });
- if (count === 0) {
- $('#host-copy-ok-button').attr('disabled','disabled');
- }
- else {
- $('#host-copy-ok-button').removeAttr('disabled');
- }
- };
-
- scope.performCopy = function() {
- var list = GroupList,
- target,
- url;
-
- Wait('start');
-
- if (scope.use_root_group) {
- target = null;
- }
- else {
- scope[list.name].every(function(row) {
- if (row.checked === '1') {
- target = row;
- return false;
- }
- return true;
- });
- }
-
- if (scope.copy_choice === 'move') {
- // Respond to move
-
- // disassociate the host from the original parent
- if (scope.removeHostRemove) {
- scope.removeHostRemove();
- }
- scope.removeHostRemove = scope.$on('RemoveHost', function () {
- if (parent_group > 0) {
- // Only remove a host from a parent when the parent is a group and not the inventory root
- url = GetBasePath('groups') + parent_group + '/hosts/';
- Rest.setUrl(url);
- Rest.post({ id: host.id, disassociate: 1 })
- .success(function () {
- scope.cancel();
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to remove ' + host.name + ' from group ' + parent_group + '. POST returned: ' + status });
- });
- } else {
- scope.cancel();
- }
- });
-
- // add the new host to the target
- url = GetBasePath('groups') + target.id + '/hosts/';
- Rest.setUrl(url);
- Rest.post(host)
- .success(function () {
- scope.$emit('RemoveHost');
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to add ' + host.name + ' to ' + target.name + '. POST returned: ' + status });
- });
- }
- else {
- // Respond to copy by adding the new host to the target
- url = GetBasePath('groups') + target.id + '/hosts/';
- Rest.setUrl(url);
- Rest.post(host)
- .success(function () {
- scope.cancel();
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed to add ' + host.name + ' to ' + target.name + '. POST returned: ' + status
- });
- });
- }
- };
-
-
- };
-}])
-
-.factory('EditHostGroups', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm', 'Prompt',
- 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange', 'Wait',
-function($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath, HostsReload,
- ParseTypeChange, Wait) {
- return function(params) {
-
- var host_id = params.host_id,
- inventory_id = params.inventory_id,
- generator = GenerateForm,
- actions = [],
- i, html, defaultUrl, scope, postAction;
-
- html = "\n";
- html += "
\n";
- html += "Available Groups: \n";
- html += " \n";
- html += "
\n";
- html += "
\n";
- html += "Belongs to Groups: \n";
- html += " \n";
- html += "
\n";
- html += "
\n";
- html += "\n";
- html += "
\n";
- html += "
" +
- " \n";
- html += "
" +
- " \n";
- html += "
(move selected groups)
\n";
- html += "
\n";
- html += "
\n";
-
- defaultUrl = GetBasePath('hosts') + host_id + '/';
- scope = generator.inject(null, { mode: 'edit', modal: true, related: false, html: html });
-
- for (i=0; i < scope.hosts.length; i++) {
- if (scope.hosts[i].id === host_id) {
- scope.host = scope.hosts[i];
- }
- }
-
- scope.selectedGroups = null;
- scope.assignedGroups = null;
- scope.leftButtonDisabled = true;
- scope.rightButtonDisabled = true;
-
- scope.formModalActionLabel = 'Save';
- //scope.formModalHeader = 'Host Groups';
- scope.formModalHeader = scope.host.name + ' - Groups ';
- scope.formModalCancelShow = true;
- scope.formModalActionDisabled = true;
-
- $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
-
- if (scope.hostGroupChangeRemove) {
- scope.hostGroupChangeRemove();
- }
- scope.hostGroupChangeRemove = scope.$on('hostGroupChange', function() {
- actions.pop();
- if (actions.length === 0) {
- postAction = function() {
- setTimeout(function() { Wait('stop'); }, 500);
- };
- HostsReload({ scope: scope, inventory_id: inventory_id, group_id: scope.group_id , action: postAction });
- }
- });
-
- // Save changes
- scope.formModalAction = function() {
- var i, j, found;
-
- $('#form-modal').modal('hide');
- Wait('start');
-
- // removed host from deleted groups
- for (i=0; i < scope.original_groups.length; i++) {
- found = false;
- for (j=0; j < scope.host_groups.length; j++) {
- if (scope.original_groups[i].id === scope.host_groups[j].id) {
- found = true;
- }
- }
- if (!found) {
- // group was removed
- actions.push({ group_id: scope.original_groups[i].id , action: 'delete' });
- Rest.setUrl(GetBasePath('groups') + scope.original_groups[i].id + '/hosts/');
- Rest.post({ id: host_id, disassociate: 1 })
- .success( function() {
- scope.$emit('hostGroupChange');
- })
- .error( function(data, status) {
- scope.$emit('hostGroupChange');
- ProcessErrors(scope, data, status, null,
- { hdr: 'Error!', msg: 'Attempt to remove host from group ' + scope.original_groups[i].name +
- ' failed. POST returned status: ' + status });
- });
- }
- }
-
- // add host to new groups
- for (i=0; i < scope.host_groups.length; i++) {
- found = false;
- for (j=0; j < scope.original_groups.length; j++) {
- if (scope.original_groups[j].id === scope.host_groups[i].id) {
- found = true;
- }
- }
- if (!found) {
- // group was added
- actions.push({ group_id: scope.host_groups[i].id , action: 'add' });
- Rest.setUrl(GetBasePath('groups') + scope.host_groups[i].id + '/hosts/');
- Rest.post(scope.host)
- .success( function() {
- scope.$emit('hostGroupChange');
- })
- .error( function(data, status) {
- scope.$emit('hostGroupChange');
- ProcessErrors(scope, data, status, null,
- { hdr: 'Error!', msg: 'Attempt to add host to group ' + scope.host_groups[i].name +
- ' failed. POST returned status: ' + status });
- });
- }
- }
- };
-
- scope.leftChange = function() {
- // Select/deselect on available groups list
- if (scope.selectedGroups !== null && scope.selectedGroups.length > 0) {
- scope.assignedGroups = null;
- scope.leftButtonDisabled = true;
- scope.rightButtonDisabled = false;
- }
- else {
- scope.rightButtonDisabled = true;
- }
- };
-
- scope.rightChange = function() {
- // Select/deselect made on host groups list
- if (scope.assignedGroups !== null && scope.assignedGroups.length > 0) {
- scope.selectedGroups = null;
- scope.leftButtonDisabled = false;
- scope.rightButtonDisabled = true;
- }
- else {
- scope.leftButtonDisabled = true;
- }
- };
-
- scope.moveLeft = function() {
- // Remove selected groups from the list of assigned groups
-
- var i, j, found, placed;
-
- for (i=0; i < scope.assignedGroups.length; i++){
- for (j=0 ; j < scope.host_groups.length; j++) {
- if (scope.host_groups[j].id === scope.assignedGroups[i].id) {
- scope.host_groups.splice(j,1);
- break;
- }
- }
- }
- for (i=0; i < scope.assignedGroups.length; i++){
- found = false;
- for (j=0; j < scope.available_groups.length && !found; j++){
- if (scope.available_groups[j].id === scope.assignedGroups[i].id) {
- found=true;
- }
- }
- if (!found) {
- placed = false;
- for (j=0; j < scope.available_groups.length && !placed; j++){
- if (j === 0 && scope.assignedGroups[i].name.toLowerCase() < scope.available_groups[j].name.toLowerCase()) {
- // prepend to the beginning of the array
- placed=true;
- scope.available_groups.unshift(scope.assignedGroups[i]);
- }
- else if (j + 1 < scope.available_groups.length) {
- if (scope.assignedGroups[i].name.toLowerCase() > scope.available_groups[j].name.toLowerCase() &&
- scope.assignedGroups[i].name.toLowerCase() < scope.available_groups[j + 1].name.toLowerCase() ) {
- // insert into the middle of the array
- placed = true;
- scope.available_groups.splice(j + 1, 0, scope.assignedGroups[i]);
- }
- }
- }
- if (!placed) {
- // append to the end of the array
- scope.available_groups.push(scope.assignedGroups[i]);
- }
- }
- }
- scope.assignedGroups = null;
- scope.leftButtonDisabled = true;
- scope.rightButtonDisabled = true;
- scope.formModalActionDisabled = false;
- };
-
- scope.moveRight = function() {
- // Remove selected groups from list of available groups
-
- var i, j, found, placed;
-
- for (i=0; i < scope.selectedGroups.length; i++){
- for (j=0 ; j < scope.available_groups.length; j++) {
- if (scope.available_groups[j].id === scope.selectedGroups[i].id) {
- scope.available_groups.splice(j,1);
- break;
- }
- }
- }
- for (i=0; i < scope.selectedGroups.length; i++){
- found = false;
- for (j=0; j < scope.host_groups.length && !found; j++){
- if (scope.host_groups[j].id === scope.selectedGroups[i].id) {
- found=true;
- }
- }
- if (!found) {
- placed = false;
- for (j=0; j < scope.host_groups.length && !placed; j++) {
- if (j === 0 && scope.selectedGroups[i].name.toLowerCase() < scope.host_groups[j].name.toLowerCase()) {
- // prepend to the beginning of the array
- placed=true;
- scope.host_groups.unshift(scope.selectedGroups[i]);
- }
- else if (j + 1 < scope.host_groups.length) {
- if (scope.selectedGroups[i].name.toLowerCase() > scope.host_groups[j].name.toLowerCase() &&
- scope.selectedGroups[i].name.toLowerCase() < scope.host_groups[j + 1].name.toLowerCase() ) {
- // insert into the middle of the array
- placed = true;
- scope.host_groups.splice(j + 1, 0, scope.selectedGroups[i]);
- }
- }
- }
- if (!placed) {
- // append to the end of the array
- scope.host_groups.push(scope.selectedGroups[i]);
- }
- }
- }
- scope.selectedGroups = null;
- scope.leftButtonDisabled = true;
- scope.rightButtonDisabled = true;
- scope.formModalActionDisabled = false;
- };
-
-
- // Load the host's current list of groups
- scope.host_groups = [];
- scope.original_groups = [];
- scope.available_groups = [];
- Rest.setUrl(scope.host.related.groups + '?order_by=name');
- Rest.get()
- .success( function(data) {
- var i, j, found;
- for (i=0; i < data.results.length; i++) {
- scope.host_groups.push({
- id: data.results[i].id,
- name: data.results[i].name,
- description: data.results[i].description
- });
- scope.original_groups.push({
- id: data.results[i].id,
- name: data.results[i].name,
- description: data.results[i].description
- });
- }
- for (i=0; i < scope.inventory_groups.length; i++) {
- found = false;
- for (j=0; j < scope.host_groups.length; j++) {
- if (scope.inventory_groups[i].id === scope.host_groups[j].id) {
- found = true;
- }
- }
- if (!found) {
- scope.available_groups.push(scope.inventory_groups[i]);
- }
- }
- })
- .error( function(data, status) {
- ProcessErrors(scope, data, status, null,
- { hdr: 'Error!', msg: 'Failed to get current groups for host: ' + host_id + '. GET returned: ' + status });
- });
-
- if (scope.removeHostsReload) {
- scope.removeHostsReload();
- }
- scope.removeHostsReload = scope.$on('hostsReload', function() {
- HostsReload(params);
- });
-
- if (!scope.$$phase) {
- scope.$digest();
- }
- };
-}]);
-
-
-
-
-
+ 'SetHostStatus', 'SetStatus', 'ApplyEllipsis', 'SetContainerHeights', 'GetHostContainerRows',
+ function($routeParams, Empty, InventoryHosts, GetBasePath, SearchInit, PaginateInit, Wait, SetHostStatus, SetStatus,
+ ApplyEllipsis, SetContainerHeights) {
+ return function(params) {
+
+ var scope = params.scope,
+ parent_scope = params.parent_scope,
+ group_id = params.group_id,
+ inventory_id = params.inventory_id,
+ list = InventoryHosts,
+ pageSize = (params.pageSize) ? params.pageSize : 20,
+
+ url = ( !Empty(group_id) ) ? GetBasePath('groups') + group_id + '/all_hosts/' :
+ GetBasePath('inventory') + inventory_id + '/hosts/';
+
+ scope.search_place_holder='Search ' + scope.selected_group_name;
+
+ if (scope.removeHostsReloadPostRefresh) {
+ scope.removeHostsReloadPostRefresh();
+ }
+ scope.removeHostsReloadPostRefresh = scope.$on('PostRefresh', function(e, set) {
+ if (set === 'hosts') {
+ for (var i=0; i < scope.hosts.length; i++) {
+ //Set tooltip for host enabled flag
+ scope.hosts[i].enabled_flag = scope.hosts[i].enabled;
+ }
+ SetStatus({ scope: scope });
+ setTimeout(function() { ApplyEllipsis('#hosts_table .host-name a'); }, 2500);
+ Wait('stop');
+ if (parent_scope) {
+ parent_scope.$emit('HostReloadComplete');
+ }
+ }
+ });
+
+ // Size containers based on viewport
+ SetContainerHeights({ scope: scope, reloadHosts: false });
+
+ SearchInit({ scope: scope, set: 'hosts', list: list, url: url });
+ PaginateInit({ scope: scope, list: list, url: url, pageSize: pageSize });
+
+ if ($routeParams.host_name) {
+ scope[list.iterator + 'InputDisable'] = false;
+ scope[list.iterator + 'SearchValue'] = $routeParams.host_name;
+ scope[list.iterator + 'SearchField'] = 'name';
+ scope[list.iterator + 'SearchFieldLabel'] = list.fields.name.label;
+ scope[list.iterator + 'SearchSelectValue'] = null;
+ }
+
+ if (scope.show_failures) {
+ scope[list.iterator + 'InputDisable'] = true;
+ scope[list.iterator + 'SearchValue'] = 'true';
+ scope[list.iterator + 'SearchField'] = 'has_active_failures';
+ scope[list.iterator + 'SearchFieldLabel'] = list.fields.has_active_failures.label;
+ scope[list.iterator + 'SearchSelectValue'] = { value: 1 };
+ }
+ scope.search(list.iterator, null, true);
+ };
+ }])
+
+ .factory('InjectHosts', ['GenerateList', 'InventoryHosts', 'HostsReload',
+ function(GenerateList, InventoryHosts, HostsReload) {
+ return function(params) {
+
+ var group_scope = params.group_scope,
+ host_scope = params.host_scope,
+ inventory_id = params.inventory_id,
+ group_id = params.group_id,
+ pageSize = params.pageSize,
+ generator = GenerateList;
+
+ // Inject the list html
+ generator.inject(InventoryHosts, { scope: host_scope, mode: 'edit', id: 'hosts-container', breadCrumbs: false, searchSize: 'col-lg-6 col-md-6 col-sm-6' });
+
+ // Load data
+ HostsReload({ scope: host_scope, group_id: group_id, inventory_id: inventory_id, parent_scope: group_scope, pageSize: pageSize });
+ };
+ }])
+
+ .factory('ToggleHostEnabled', [ 'GetBasePath', 'Rest', 'Wait', 'ProcessErrors', 'Alert', 'Find', 'SetEnabledMsg',
+ function(GetBasePath, Rest, Wait, ProcessErrors, Alert, Find, SetEnabledMsg) {
+ return function(params) {
+
+ var id = params.host_id,
+ external_source = params.external_source,
+ parent_scope = params.parent_scope,
+ host_scope = params.host_scope,
+ host;
+
+ function setMsg(host) {
+ host.enabled = (host.enabled) ? false : true;
+ host.enabled_flag = host.enabled;
+ SetEnabledMsg(host);
+ }
+
+ if (!external_source) {
+ // Host is not managed by an external source
+ Wait('start');
+ host = Find({ list: host_scope.hosts, key: 'id', val: id });
+ setMsg(host);
+
+ Rest.setUrl(GetBasePath('hosts') + id + '/');
+ Rest.put(host)
+ .success( function() {
+ Wait('stop');
+ })
+ .error( function(data, status) {
+ // Flip the enabled flag back
+ setMsg(host);
+ ProcessErrors(parent_scope, data, status, null,
+ { hdr: 'Error!', msg: 'Failed to update host. PUT returned status: ' + status });
+ });
+ }
+ else {
+ Alert('Action Not Allowed', 'This host is managed by an external cloud source. Disable it at the external source, ' +
+ 'then run an inventory sync to update Tower with the new status.', 'alert-info');
+ }
+ };
+ }])
+
+ .factory('HostsList', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
+ 'Prompt', 'SearchInit', 'PaginateInit', 'ProcessErrors', 'GetBasePath', 'HostsAdd', 'HostsReload', 'SelectionInit',
+ function($rootScope, $location, $log, $routeParams, Rest, Alert, HostList, GenerateList, Prompt, SearchInit,
+ PaginateInit, ProcessErrors, GetBasePath, HostsAdd, HostsReload, SelectionInit) {
+ return function(params) {
+
+ var inventory_id = params.inventory_id,
+ group_id = params.group_id,
+ list = HostList,
+ generator = GenerateList,
+ defaultUrl, scope;
+
+ list.iterator = 'subhost'; //Override the iterator and name so the scope of the modal dialog
+ list.name = 'subhosts'; //will not conflict with the parent scope
+
+
+
+ scope = generator.inject(list, {
+ id: 'form-modal-body',
+ mode: 'select',
+ breadCrumbs: false,
+ selectButton: false
+ });
+
+ defaultUrl = GetBasePath('inventory') + inventory_id + '/hosts/?not__groups__id=' + scope.group_id;
+
+ scope.formModalActionLabel = 'Select';
+ scope.formModalHeader = 'Add Existing Hosts';
+ scope.formModalCancelShow = true;
+
+ SelectionInit({ scope: scope, list: list, url: GetBasePath('groups') + group_id + '/hosts/' });
+
+ if (scope.removeModalClosed) {
+ scope.removeModalClosed();
+ }
+ scope.removeModalClosed = scope.$on('modalClosed', function() {
+ // if the modal closed, assume something got changed and reload the host list
+ HostsReload(params);
+ });
+
+ $('.popover').popover('hide'); //remove any lingering pop-overs
+ $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
+ $('#form-modal').modal({ backdrop: 'static', keyboard: false });
+
+ SearchInit({ scope: scope, set: 'subhosts', list: list, url: defaultUrl });
+ PaginateInit({ scope: scope, list: list, url: defaultUrl, mode: 'lookup' });
+ scope.search(list.iterator);
+
+ if (!scope.$$phase) {
+ scope.$digest();
+ }
+
+ scope.createHost = function() {
+ $('#form-modal').modal('hide');
+ HostsAdd({ scope: params.scope, inventory_id: inventory_id, group_id: group_id });
+ };
+
+ };
+ }])
+
+
+ .factory('HostsCreate', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostForm', 'GenerateForm',
+ 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange', 'Wait', 'ToJSON',
+ function($rootScope, $location, $log, $routeParams, Rest, Alert, HostForm, GenerateForm, Prompt, ProcessErrors,
+ GetBasePath, HostsReload, ParseTypeChange, Wait, ToJSON) {
+ return function(params) {
+
+ var parent_scope = params.scope,
+ inventory_id = parent_scope.inventory_id,
+ group_id = parent_scope.selected_group_id,
+ defaultUrl = GetBasePath('groups') + group_id + '/hosts/',
+ form = HostForm,
+ generator = GenerateForm,
+ scope = generator.inject(form, {mode: 'add', modal: true, related: false}),
+ master={};
+
+ scope.formModalActionLabel = 'Save';
+ scope.formModalHeader = 'Create New Host';
+ scope.formModalCancelShow = true;
+
+ scope.parseType = 'yaml';
+ ParseTypeChange({ scope: scope, field_id: 'host_variables' });
+
+ if (scope.removeHostsReload) {
+ scope.removeHostsReload();
+ }
+ scope.removeHostsReload = scope.$on('hostsReload', function() {
+ HostsReload(params);
+ });
+
+ $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
+ //$('#form-modal').unbind('hidden');
+ //$('#form-modal').on('hidden', function () { scope.$emit('hostsReload'); });
+
+ generator.reset();
+ master={};
+
+ if (!scope.$$phase) {
+ scope.$digest();
+ }
+
+ if (scope.removeHostSaveComplete) {
+ scope.removeHostSaveComplete();
+ }
+ scope.removeHostSaveComplete = scope.$on('HostSaveComplete', function() {
+ Wait('stop');
+ $('#form-modal').modal('hide');
+
+ HostsReload({
+ scope: parent_scope,
+ group_id: parent_scope.selected_group_id,
+ tree_id: parent_scope.selected_tree_id,
+ inventory_id: parent_scope.inventory_id
+ });
+
+ //WatchInventoryWindowResize();
+ });
+
+ // Save
+ scope.formModalAction = function() {
+
+ Wait('start');
+
+ var fld, data={};
+ scope.formModalActionDisabled = true;
+ data.variables = ToJSON(scope.parseType, scope.variables, true);
+ for (fld in form.fields) {
+ if (fld !== 'variables') {
+ data[fld] = scope[fld];
+ }
+ }
+ data.inventory = inventory_id;
+
+ Rest.setUrl(defaultUrl);
+ Rest.post(data)
+ .success( function() {
+ scope.$emit('HostSaveComplete');
+ })
+ .error( function(data, status) {
+ Wait('stop');
+ scope.formModalActionDisabled = false;
+ ProcessErrors(scope, data, status, form,
+ { hdr: 'Error!', msg: 'Failed to add new host. POST returned status: ' + status });
+ });
+ };
+
+ // Cancel
+ scope.formReset = function() {
+ // Defaults
+ generator.reset();
+ };
+
+ scope.cancelModal = function() {
+ // WatchInventoryWindowResize();
+ };
+
+ };
+ }])
+
+
+ .factory('HostsEdit', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostForm', 'GenerateForm',
+ 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange', 'Wait', 'Find', 'SetStatus', 'ApplyEllipsis',
+ 'ToJSON', 'ParseVariableString', 'CreateDialog', 'TextareaResize',
+ function($rootScope, $location, $log, $routeParams, Rest, Alert, HostForm, GenerateForm, Prompt, ProcessErrors,
+ GetBasePath, HostsReload, ParseTypeChange, Wait, Find, SetStatus, ApplyEllipsis, ToJSON,
+ ParseVariableString, CreateDialog, TextareaResize) {
+ return function(params) {
+
+ var parent_scope = params.host_scope,
+ group_scope = params.group_scope,
+ host_id = params.host_id,
+ inventory_id = params.inventory_id,
+ mode = params.mode, // 'add' or 'edit'
+ selected_group_id = params.selected_group_id,
+ generator = GenerateForm,
+ form = HostForm,
+ defaultUrl,
+ scope = parent_scope.$new(),
+ master = {},
+ relatedSets = {},
+ buttons, url;
+
+ generator.inject(HostForm, { mode: 'edit', id: 'host-modal-dialog', breadCrumbs: false, related: false, scope: scope });
+ generator.reset();
+
+ buttons = [{
+ label: "Cancel",
+ onClick: function() {
+ scope.cancelModal();
+ },
+ icon: "fa-times",
+ "class": "btn btn-default",
+ "id": "host-cancel-button"
+ },{
+ label: "Save",
+ onClick: function() {
+ scope.saveModal();
+ },
+ icon: "fa-check",
+ "class": "btn btn-primary",
+ "id": "host-save-button"
+ }];
+
+ CreateDialog({
+ scope: scope,
+ buttons: buttons,
+ width: 675,
+ height: 750,
+ minWidth: 400,
+ title: 'Host Properties',
+ id: 'host-modal-dialog',
+ clonseOnEscape: false,
+ onClose: function() {
+ Wait('stop');
+ scope.codeMirror.destroy();
+ $('#host-modal-dialog').empty();
+ },
+ onResizeStop: function() {
+ TextareaResize({
+ scope: scope,
+ textareaId: 'host_variables',
+ modalId: 'host-modal-dialog',
+ formId: 'host_form'
+ });
+ },
+ beforeDestroy: function() {
+ if (scope.codeMirror) {
+ scope.codeMirror.destroy();
+ }
+ $('#host-modal-dialog').empty();
+ },
+ onOpen: function() {
+ $('#host_name').focus();
+ },
+ callback: 'HostEditDialogReady'
+ });
+
+ scope.parseType = 'yaml';
+
+ if (scope.hostVariablesLoadedRemove) {
+ scope.hostVariablesLoadedRemove();
+ }
+ scope.hostVariablesLoadedRemove = scope.$on('hostVariablesLoaded', function() {
+ $('#host-modal-dialog').dialog('open');
+ setTimeout(function() {
+ TextareaResize({
+ scope: scope,
+ textareaId: 'host_variables',
+ modalId: 'host-modal-dialog',
+ formId: 'host_form',
+ parse: true
+ });
+ }, 300);
+ //ParseTypeChange({ scope: scope, field_id: 'host_variables', onReady: callback });
+ });
+
+ if (scope.hostLoadedRemove) {
+ scope.hostLoadedRemove();
+ }
+ scope.hostLoadedRemove = scope.$on('hostLoaded', function() {
+ // Retrieve host variables
+ if (scope.variable_url) {
+ Rest.setUrl(scope.variable_url);
+ Rest.get()
+ .success( function(data) {
+ scope.variables = ParseVariableString(data);
+ scope.$emit('hostVariablesLoaded');
+ })
+ .error( function(data, status) {
+ scope.variables = null;
+ ProcessErrors(scope, data, status, form,
+ { hdr: 'Error!', msg: 'Failed to retrieve host variables. GET returned status: ' + status });
+ });
+ }
+ else {
+ scope.variables = "---";
+ scope.$emit('hostVariablesLoaded');
+ }
+ master.variables = scope.variables;
+ });
+
+ Wait('start');
+
+ // Retrieve detail record and prepopulate the form
+ if (mode === 'edit') {
+ defaultUrl = GetBasePath('hosts') + host_id + '/';
+ Rest.setUrl(defaultUrl);
+ Rest.get()
+ .success( function(data) {
+ var set, fld, related;
+ for (fld in form.fields) {
+ if (data[fld]) {
+ scope[fld] = data[fld];
+ master[fld] = scope[fld];
+ }
+ }
+ related = data.related;
+ for (set in form.related) {
+ if (related[set]) {
+ relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
+ }
+ }
+ scope.variable_url = data.related.variable_data;
+ scope.has_inventory_sources = data.has_inventory_sources;
+ scope.$emit('hostLoaded');
+ })
+ .error( function(data, status) {
+ ProcessErrors(parent_scope, data, status, form,
+ { hdr: 'Error!', msg: 'Failed to retrieve host: ' + host_id + '. GET returned status: ' + status });
+ });
+ }
+ else {
+ // Add mode
+ url = GetBasePath('groups') + selected_group_id + '/';
+ Rest.setUrl(url);
+ Rest.get()
+ .success( function(data) {
+ scope.has_inventory_sources = data.has_inventory_sources;
+ scope.enabled = true;
+ scope.variables = '---';
+ defaultUrl = data.related.hosts;
+ scope.$emit('hostVariablesLoaded');
+ })
+ .error( function(data, status) {
+ ProcessErrors(parent_scope, data, status, form,
+ { hdr: 'Error!', msg: 'Failed to retrieve group: ' + selected_group_id + '. GET returned status: ' + status });
+ });
+ }
+
+ if (scope.removeSaveCompleted) {
+ scope.removeSaveCompleted();
+ }
+ scope.removeSaveCompleted = scope.$on('saveCompleted', function() {
+ try {
+ $('#host-modal-dialog').dialog('close');
+ }
+ catch(err) {
+ // ignore
+ }
+ if (group_scope && group_scope.refreshHosts) {
+ group_scope.refreshHosts();
+ }
+ if (parent_scope.refreshHosts) {
+ parent_scope.refreshHosts();
+ }
+ scope.$destroy();
+ });
+
+ // Save changes to the parent
+ scope.saveModal = function() {
+
+ Wait('start');
+ var fld, data={};
+
+ try {
+ data.variables = ToJSON(scope.parseType, scope.variables, true);
+ for (fld in form.fields) {
+ data[fld] = scope[fld];
+ }
+ data.inventory = inventory_id;
+ Rest.setUrl(defaultUrl);
+ if (mode === 'edit') {
+ Rest.put(data)
+ .success( function() {
+ scope.$emit('saveCompleted');
+ })
+ .error( function(data, status) {
+ ProcessErrors(scope, data, status, form,
+ { hdr: 'Error!', msg: 'Failed to update host: ' + host_id + '. PUT returned status: ' + status });
+ });
+ }
+ else {
+ Rest.post(data)
+ .success( function() {
+ scope.$emit('saveCompleted');
+ })
+ .error( function(data, status) {
+ ProcessErrors(scope, data, status, form,
+ { hdr: 'Error!', msg: 'Failed to create host. POST returned status: ' + status });
+ });
+ }
+ }
+ catch(e) {
+ // ignore. ToJSON will have already alerted the user
+ }
+ };
+
+ // Cancel
+ scope.formReset = function() {
+ generator.reset();
+ for (var fld in master) {
+ scope[fld] = master[fld];
+ }
+ scope.parseType = 'yaml';
+ };
+
+ scope.cancelModal = function() {
+ try {
+ $('#host-modal-dialog').dialog('close');
+ }
+ catch(err) {
+ // ignore
+ }
+ scope.$destroy();
+ };
+
+ };
+ }])
+
+
+ .factory('HostsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'Wait',
+ function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload, Wait) {
+ return function(params) {
+ // Remove the selected host from the current group by disassociating
+
+ var action_to_take, body,
+ scope = params.parent_scope,
+ host_id = params.host_id,
+ host_name = params.host_name,
+ group,
+ url_list = [];
+
+ if (scope.selected_group_id) {
+ //group = Find({ list: parent_scope.groups, key: 'id', val: parent_scope.selected_group_id });
+ //getChildren(group.id);
+ url_list.push(GetBasePath('groups') + scope.selected_group_id + '/hosts/');
+ }
+ else {
+ url_list.push(GetBasePath('inventory') + scope.inventory.id + '/hosts/');
+ }
+
+ if (scope.removeHostsReload) {
+ scope.removeHostsReload();
+ }
+ scope.removeHostsReload = scope.$on('hostsReload', function() {
+ $('#prompt-modal').modal('hide');
+ scope.refreshHosts();
+ });
+
+ $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('stop'); });
+
+ action_to_take = function() {
+ var count=0, i;
+
+ Wait('start');
+
+ if (scope.removeHostRemoved) {
+ scope.removeHostRemoved();
+ }
+ scope.removeHostRemoved = scope.$on('hostRemoved', function(){
+ count++;
+ if (count === url_list.length) {
+ Wait('start');
+ scope.$emit('hostsReload');
+ }
+ });
+
+ for(i=0; i < url_list.length; i++) {
+ Rest.setUrl(url_list[i]);
+ Rest.post({ id: host_id, disassociate: 1 })
+ .success( function() {
+ scope.$emit('hostRemoved');
+ })
+ .error( function(data, status) {
+ ProcessErrors(scope, data, status, null,
+ { hdr: 'Error!', msg: 'Attempt to delete ' + host_name + ' failed. DELETE returned status: ' + status });
+ });
+ }
+ };
+
+ body = (group) ? 'Are you sure you want to remove host ' + host_name + ' from group ' + group.name + '?' +
+ ' It will still be part of the inventory and available in All Hosts.
' :
+ 'Are you sure you want to permanently delete host ' + host_name + ' from the inventory?
';
+ Prompt({ hdr: 'Delete Host', body: body, action: action_to_take, 'class': 'btn-danger' });
+
+ };
+ }])
+
+ .factory('HostsCopy', ['$compile', 'Rest', 'ProcessErrors', 'CreateDialog', 'GetBasePath', 'Wait', 'GenerateList', 'GroupList', 'SearchInit',
+ 'PaginateInit',
+ function($compile, Rest, ProcessErrors, CreateDialog, GetBasePath, Wait, GenerateList, GroupList, SearchInit, PaginateInit) {
+ return function(params) {
+
+ var host_id = params.host_id,
+ group_scope = params.group_scope,
+ parent_scope = params.host_scope,
+ parent_group = group_scope.selected_group_id,
+ scope = parent_scope.$new(),
+ buttonSet, url, host;
+
+ buttonSet = [{
+ label: "Cancel",
+ onClick: function() {
+ scope.cancel();
+ },
+ icon: "fa-times",
+ "class": "btn btn-default",
+ "id": "host-copy-cancel-button"
+ },{
+ label: "OK",
+ onClick: function() {
+ scope.performCopy();
+ },
+ icon: "fa-check",
+ "class": "btn btn-primary",
+ "id": "host-copy-ok-button"
+ }];
+
+ if (scope.removeHostCopyPostRefresh) {
+ scope.removeHostCopyPostRefresh();
+ }
+ scope.removeHostCopyPostRefresh = scope.$on('PostRefresh', function() {
+ scope.copy_groups.forEach(function(row, i) {
+ scope.copy_groups[i].checked = '0';
+ });
+ Wait('stop');
+ $('#host-copy-dialog').dialog('open');
+ $('#host-copy-ok-button').attr('disabled','disabled');
+
+ // prevent backspace from navigation when not in input or textarea field
+ $(document).on("keydown", function (e) {
+ if (e.which === 8 && !$(e.target).is('input[type="text"], textarea')) {
+ e.preventDefault();
+ }
+ });
+ });
+
+ if (scope.removeHostCopyDialogReady) {
+ scope.removeHostCopyDialogReady();
+ }
+ scope.removeCopyDialogReady = scope.$on('HostCopyDialogReady', function() {
+ var url = GetBasePath('inventory') + group_scope.inventory.id + '/groups/';
+ GenerateList.inject(GroupList, {
+ mode: 'lookup',
+ id: 'copy-host-select-container',
+ scope: scope
+ //,
+ //instructions: instructions
+ });
+ SearchInit({
+ scope: scope,
+ set: GroupList.name,
+ list: GroupList,
+ url: url
+ });
+ PaginateInit({
+ scope: scope,
+ list: GroupList,
+ url: url,
+ mode: 'lookup'
+ });
+ scope.search(GroupList.iterator, null, true, false);
+ });
+
+ if (scope.removeShowDialog) {
+ scope.removeShowDialog();
+ }
+ scope.removeShowDialog = scope.$on('ShowDialog', function() {
+ var d;
+ scope.name = host.name;
+ scope.copy_choice = "copy";
+ d = angular.element(document.getElementById('host-copy-dialog'));
+ $compile(d)(scope);
+ CreateDialog({
+ id: 'host-copy-dialog',
+ scope: scope,
+ buttons: buttonSet,
+ width: 650,
+ height: 650,
+ minWidth: 600,
+ title: 'Copy or Move Host',
+ callback: 'HostCopyDialogReady',
+ onClose: function() {
+ scope.cancel();
+ }
+ });
+ });
+
+ Wait('start');
+
+ url = GetBasePath('hosts') + host_id + '/';
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ host = data;
+ scope.$emit('ShowDialog');
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. GET returned: ' + status });
+ });
+
+
+ scope.cancel = function() {
+ $(document).off("keydown");
+ try {
+ $('#host-copy-dialog').dialog('close');
+ }
+ catch(e) {
+ // ignore
+ }
+ scope.searchCleanup();
+ group_scope.restoreSearch(); // Restore all parent search stuff and refresh hosts and groups lists
+ scope.$destroy();
+ };
+
+ scope['toggle_' + GroupList.iterator] = function (id) {
+ var count = 0,
+ list = GroupList;
+ scope[list.name].forEach( function(row, i) {
+ if (row.id === id) {
+ if (row.checked === '0') {
+ scope[list.name][i].checked = '1';
+ scope[list.name][i].success_class = 'success';
+ }
+ else {
+ scope[list.name][i].checked = '0';
+ scope[list.name][i].success_class = '';
+ }
+ } else {
+ scope[list.name][i].checked = '0';
+ scope[list.name][i].success_class = '';
+ }
+ });
+ // Check if any rows are checked
+ scope[list.name].forEach(function(row) {
+ if (row.checked === '1') {
+ count++;
+ }
+ });
+ if (count === 0) {
+ $('#host-copy-ok-button').attr('disabled','disabled');
+ }
+ else {
+ $('#host-copy-ok-button').removeAttr('disabled');
+ }
+ };
+
+ scope.performCopy = function() {
+ var list = GroupList,
+ target,
+ url;
+
+ Wait('start');
+
+ if (scope.use_root_group) {
+ target = null;
+ }
+ else {
+ scope[list.name].every(function(row) {
+ if (row.checked === '1') {
+ target = row;
+ return false;
+ }
+ return true;
+ });
+ }
+
+ if (scope.copy_choice === 'move') {
+ // Respond to move
+
+ // disassociate the host from the original parent
+ if (scope.removeHostRemove) {
+ scope.removeHostRemove();
+ }
+ scope.removeHostRemove = scope.$on('RemoveHost', function () {
+ if (parent_group > 0) {
+ // Only remove a host from a parent when the parent is a group and not the inventory root
+ url = GetBasePath('groups') + parent_group + '/hosts/';
+ Rest.setUrl(url);
+ Rest.post({ id: host.id, disassociate: 1 })
+ .success(function () {
+ scope.cancel();
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to remove ' + host.name + ' from group ' + parent_group + '. POST returned: ' + status });
+ });
+ } else {
+ scope.cancel();
+ }
+ });
+
+ // add the new host to the target
+ url = GetBasePath('groups') + target.id + '/hosts/';
+ Rest.setUrl(url);
+ Rest.post(host)
+ .success(function () {
+ scope.$emit('RemoveHost');
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to add ' + host.name + ' to ' + target.name + '. POST returned: ' + status });
+ });
+ }
+ else {
+ // Respond to copy by adding the new host to the target
+ url = GetBasePath('groups') + target.id + '/hosts/';
+ Rest.setUrl(url);
+ Rest.post(host)
+ .success(function () {
+ scope.cancel();
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Failed to add ' + host.name + ' to ' + target.name + '. POST returned: ' + status
+ });
+ });
+ }
+ };
+
+
+ };
+ }])
+
+ .factory('EditHostGroups', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm', 'Prompt',
+ 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange', 'Wait',
+ function($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath, HostsReload,
+ ParseTypeChange, Wait) {
+ return function(params) {
+
+ var host_id = params.host_id,
+ inventory_id = params.inventory_id,
+ generator = GenerateForm,
+ actions = [],
+ i, html, defaultUrl, scope, postAction;
+
+ html = "\n";
+ html += "
\n";
+ html += "Available Groups: \n";
+ html += " \n";
+ html += "
\n";
+ html += "
\n";
+ html += "Belongs to Groups: \n";
+ html += " \n";
+ html += "
\n";
+ html += "
\n";
+ html += "\n";
+ html += "
\n";
+ html += "
" +
+ " \n";
+ html += "
" +
+ " \n";
+ html += "
(move selected groups)
\n";
+ html += "
\n";
+ html += "
\n";
+
+ defaultUrl = GetBasePath('hosts') + host_id + '/';
+ scope = generator.inject(null, { mode: 'edit', modal: true, related: false, html: html });
+
+ for (i=0; i < scope.hosts.length; i++) {
+ if (scope.hosts[i].id === host_id) {
+ scope.host = scope.hosts[i];
+ }
+ }
+
+ scope.selectedGroups = null;
+ scope.assignedGroups = null;
+ scope.leftButtonDisabled = true;
+ scope.rightButtonDisabled = true;
+
+ scope.formModalActionLabel = 'Save';
+ //scope.formModalHeader = 'Host Groups';
+ scope.formModalHeader = scope.host.name + ' - Groups ';
+ scope.formModalCancelShow = true;
+ scope.formModalActionDisabled = true;
+
+ $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
+
+ if (scope.hostGroupChangeRemove) {
+ scope.hostGroupChangeRemove();
+ }
+ scope.hostGroupChangeRemove = scope.$on('hostGroupChange', function() {
+ actions.pop();
+ if (actions.length === 0) {
+ postAction = function() {
+ setTimeout(function() { Wait('stop'); }, 500);
+ };
+ HostsReload({ scope: scope, inventory_id: inventory_id, group_id: scope.group_id , action: postAction });
+ }
+ });
+
+ // Save changes
+ scope.formModalAction = function() {
+ var i, j, found;
+
+ $('#form-modal').modal('hide');
+ Wait('start');
+
+ // removed host from deleted groups
+ for (i=0; i < scope.original_groups.length; i++) {
+ found = false;
+ for (j=0; j < scope.host_groups.length; j++) {
+ if (scope.original_groups[i].id === scope.host_groups[j].id) {
+ found = true;
+ }
+ }
+ if (!found) {
+ // group was removed
+ actions.push({ group_id: scope.original_groups[i].id , action: 'delete' });
+ Rest.setUrl(GetBasePath('groups') + scope.original_groups[i].id + '/hosts/');
+ Rest.post({ id: host_id, disassociate: 1 })
+ .success( function() {
+ scope.$emit('hostGroupChange');
+ })
+ .error( function(data, status) {
+ scope.$emit('hostGroupChange');
+ ProcessErrors(scope, data, status, null,
+ { hdr: 'Error!', msg: 'Attempt to remove host from group ' + scope.original_groups[i].name +
+ ' failed. POST returned status: ' + status });
+ });
+ }
+ }
+
+ // add host to new groups
+ for (i=0; i < scope.host_groups.length; i++) {
+ found = false;
+ for (j=0; j < scope.original_groups.length; j++) {
+ if (scope.original_groups[j].id === scope.host_groups[i].id) {
+ found = true;
+ }
+ }
+ if (!found) {
+ // group was added
+ actions.push({ group_id: scope.host_groups[i].id , action: 'add' });
+ Rest.setUrl(GetBasePath('groups') + scope.host_groups[i].id + '/hosts/');
+ Rest.post(scope.host)
+ .success( function() {
+ scope.$emit('hostGroupChange');
+ })
+ .error( function(data, status) {
+ scope.$emit('hostGroupChange');
+ ProcessErrors(scope, data, status, null,
+ { hdr: 'Error!', msg: 'Attempt to add host to group ' + scope.host_groups[i].name +
+ ' failed. POST returned status: ' + status });
+ });
+ }
+ }
+ };
+
+ scope.leftChange = function() {
+ // Select/deselect on available groups list
+ if (scope.selectedGroups !== null && scope.selectedGroups.length > 0) {
+ scope.assignedGroups = null;
+ scope.leftButtonDisabled = true;
+ scope.rightButtonDisabled = false;
+ }
+ else {
+ scope.rightButtonDisabled = true;
+ }
+ };
+
+ scope.rightChange = function() {
+ // Select/deselect made on host groups list
+ if (scope.assignedGroups !== null && scope.assignedGroups.length > 0) {
+ scope.selectedGroups = null;
+ scope.leftButtonDisabled = false;
+ scope.rightButtonDisabled = true;
+ }
+ else {
+ scope.leftButtonDisabled = true;
+ }
+ };
+
+ scope.moveLeft = function() {
+ // Remove selected groups from the list of assigned groups
+
+ var i, j, found, placed;
+
+ for (i=0; i < scope.assignedGroups.length; i++){
+ for (j=0 ; j < scope.host_groups.length; j++) {
+ if (scope.host_groups[j].id === scope.assignedGroups[i].id) {
+ scope.host_groups.splice(j,1);
+ break;
+ }
+ }
+ }
+ for (i=0; i < scope.assignedGroups.length; i++){
+ found = false;
+ for (j=0; j < scope.available_groups.length && !found; j++){
+ if (scope.available_groups[j].id === scope.assignedGroups[i].id) {
+ found=true;
+ }
+ }
+ if (!found) {
+ placed = false;
+ for (j=0; j < scope.available_groups.length && !placed; j++){
+ if (j === 0 && scope.assignedGroups[i].name.toLowerCase() < scope.available_groups[j].name.toLowerCase()) {
+ // prepend to the beginning of the array
+ placed=true;
+ scope.available_groups.unshift(scope.assignedGroups[i]);
+ }
+ else if (j + 1 < scope.available_groups.length) {
+ if (scope.assignedGroups[i].name.toLowerCase() > scope.available_groups[j].name.toLowerCase() &&
+ scope.assignedGroups[i].name.toLowerCase() < scope.available_groups[j + 1].name.toLowerCase() ) {
+ // insert into the middle of the array
+ placed = true;
+ scope.available_groups.splice(j + 1, 0, scope.assignedGroups[i]);
+ }
+ }
+ }
+ if (!placed) {
+ // append to the end of the array
+ scope.available_groups.push(scope.assignedGroups[i]);
+ }
+ }
+ }
+ scope.assignedGroups = null;
+ scope.leftButtonDisabled = true;
+ scope.rightButtonDisabled = true;
+ scope.formModalActionDisabled = false;
+ };
+
+ scope.moveRight = function() {
+ // Remove selected groups from list of available groups
+
+ var i, j, found, placed;
+
+ for (i=0; i < scope.selectedGroups.length; i++){
+ for (j=0 ; j < scope.available_groups.length; j++) {
+ if (scope.available_groups[j].id === scope.selectedGroups[i].id) {
+ scope.available_groups.splice(j,1);
+ break;
+ }
+ }
+ }
+ for (i=0; i < scope.selectedGroups.length; i++){
+ found = false;
+ for (j=0; j < scope.host_groups.length && !found; j++){
+ if (scope.host_groups[j].id === scope.selectedGroups[i].id) {
+ found=true;
+ }
+ }
+ if (!found) {
+ placed = false;
+ for (j=0; j < scope.host_groups.length && !placed; j++) {
+ if (j === 0 && scope.selectedGroups[i].name.toLowerCase() < scope.host_groups[j].name.toLowerCase()) {
+ // prepend to the beginning of the array
+ placed=true;
+ scope.host_groups.unshift(scope.selectedGroups[i]);
+ }
+ else if (j + 1 < scope.host_groups.length) {
+ if (scope.selectedGroups[i].name.toLowerCase() > scope.host_groups[j].name.toLowerCase() &&
+ scope.selectedGroups[i].name.toLowerCase() < scope.host_groups[j + 1].name.toLowerCase() ) {
+ // insert into the middle of the array
+ placed = true;
+ scope.host_groups.splice(j + 1, 0, scope.selectedGroups[i]);
+ }
+ }
+ }
+ if (!placed) {
+ // append to the end of the array
+ scope.host_groups.push(scope.selectedGroups[i]);
+ }
+ }
+ }
+ scope.selectedGroups = null;
+ scope.leftButtonDisabled = true;
+ scope.rightButtonDisabled = true;
+ scope.formModalActionDisabled = false;
+ };
+
+
+ // Load the host's current list of groups
+ scope.host_groups = [];
+ scope.original_groups = [];
+ scope.available_groups = [];
+ Rest.setUrl(scope.host.related.groups + '?order_by=name');
+ Rest.get()
+ .success( function(data) {
+ var i, j, found;
+ for (i=0; i < data.results.length; i++) {
+ scope.host_groups.push({
+ id: data.results[i].id,
+ name: data.results[i].name,
+ description: data.results[i].description
+ });
+ scope.original_groups.push({
+ id: data.results[i].id,
+ name: data.results[i].name,
+ description: data.results[i].description
+ });
+ }
+ for (i=0; i < scope.inventory_groups.length; i++) {
+ found = false;
+ for (j=0; j < scope.host_groups.length; j++) {
+ if (scope.inventory_groups[i].id === scope.host_groups[j].id) {
+ found = true;
+ }
+ }
+ if (!found) {
+ scope.available_groups.push(scope.inventory_groups[i]);
+ }
+ }
+ })
+ .error( function(data, status) {
+ ProcessErrors(scope, data, status, null,
+ { hdr: 'Error!', msg: 'Failed to get current groups for host: ' + host_id + '. GET returned: ' + status });
+ });
+
+ if (scope.removeHostsReload) {
+ scope.removeHostsReload();
+ }
+ scope.removeHostsReload = scope.$on('hostsReload', function() {
+ HostsReload(params);
+ });
+
+ if (!scope.$$phase) {
+ scope.$digest();
+ }
+ };
+ }]);
diff --git a/awx/ui/static/js/helpers/JobDetail.js b/awx/ui/static/js/helpers/JobDetail.js
index 180b572452..3603302f45 100644
--- a/awx/ui/static/js/helpers/JobDetail.js
+++ b/awx/ui/static/js/helpers/JobDetail.js
@@ -38,829 +38,710 @@
*/
+export default
+ angular.module('JobDetailHelper', ['Utilities', 'RestServices', 'ModalDialog'])
-angular.module('JobDetailHelper', ['Utilities', 'RestServices', 'ModalDialog'])
+ .factory('DigestEvent', ['$rootScope', '$log', 'UpdatePlayStatus', 'UpdateHostStatus', 'AddHostResult',
+ 'GetElapsed', 'UpdateTaskStatus', 'DrawGraph', 'LoadHostSummary', 'JobIsFinished', 'AddNewTask', 'AddNewPlay',
+ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, GetElapsed,
+ UpdateTaskStatus, DrawGraph, LoadHostSummary, JobIsFinished, AddNewTask, AddNewPlay) {
+ return function(params) {
-.factory('DigestEvent', ['$rootScope', '$log', 'UpdatePlayStatus', 'UpdateHostStatus', 'AddHostResult',
- 'GetElapsed', 'UpdateTaskStatus', 'DrawGraph', 'LoadHostSummary', 'JobIsFinished', 'AddNewTask', 'AddNewPlay',
-function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, GetElapsed,
- UpdateTaskStatus, DrawGraph, LoadHostSummary, JobIsFinished, AddNewTask, AddNewPlay) {
- return function(params) {
+ var scope = params.scope,
+ event = params.event,
+ msg;
- var scope = params.scope,
- event = params.event,
- msg;
+ $log.debug('processing event: ' + event.id);
+ $log.debug(event);
- $log.debug('processing event: ' + event.id);
- $log.debug(event);
-
- function getMsg(event) {
- var msg = '';
- if (event.event_data && event.event_data.res) {
- if (typeof event.event_data.res === 'object') {
- msg = event.event_data.res.msg;
- } else {
- msg = event.event_data.res;
+ function getMsg(event) {
+ var msg = '';
+ if (event.event_data && event.event_data.res) {
+ if (typeof event.event_data.res === 'object') {
+ msg = event.event_data.res.msg;
+ } else {
+ msg = event.event_data.res;
+ }
}
+ return msg;
}
- return msg;
- }
- switch (event.event) {
- case 'playbook_on_start':
- if (!JobIsFinished(scope)) {
- scope.job_status.started = event.created;
- scope.job_status.status = 'running';
- }
- break;
+ switch (event.event) {
+ case 'playbook_on_start':
+ if (!JobIsFinished(scope)) {
+ scope.job_status.started = event.created;
+ scope.job_status.status = 'running';
+ }
+ break;
- case 'playbook_on_play_start':
- AddNewPlay({ scope: scope, event: event });
- break;
+ case 'playbook_on_play_start':
+ AddNewPlay({ scope: scope, event: event });
+ break;
- case 'playbook_on_setup':
- AddNewTask({ scope: scope, event: event });
- break;
+ case 'playbook_on_setup':
+ AddNewTask({ scope: scope, event: event });
+ break;
- case 'playbook_on_task_start':
- AddNewTask({ scope: scope, event: event });
- break;
+ case 'playbook_on_task_start':
+ AddNewTask({ scope: scope, event: event });
+ break;
- case 'runner_on_ok':
- case 'runner_on_async_ok':
- msg = getMsg(event);
- UpdateHostStatus({
- scope: scope,
- name: event.host_name,
- host_id: event.host,
- task_id: event.parent,
- status: ( (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful' ),
- id: event.id,
- created: event.created,
- modified: event.modified,
- message: msg,
- counter: event.counter,
- item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
- });
- break;
+ case 'runner_on_ok':
+ case 'runner_on_async_ok':
+ msg = getMsg(event);
+ UpdateHostStatus({
+ scope: scope,
+ name: event.host_name,
+ host_id: event.host,
+ task_id: event.parent,
+ status: ( (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful' ),
+ id: event.id,
+ created: event.created,
+ modified: event.modified,
+ message: msg,
+ counter: event.counter,
+ item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
+ });
+ break;
- case 'playbook_on_no_hosts_matched':
- UpdatePlayStatus({
- scope: scope,
- play_id: event.parent,
- failed: false,
- changed: false,
- modified: event.modified,
- no_hosts: true
- });
- break;
+ case 'playbook_on_no_hosts_matched':
+ UpdatePlayStatus({
+ scope: scope,
+ play_id: event.parent,
+ failed: false,
+ changed: false,
+ modified: event.modified,
+ no_hosts: true
+ });
+ break;
- case 'runner_on_unreachable':
- msg = getMsg(event);
- UpdateHostStatus({
- scope: scope,
- name: event.host_name,
- host_id: event.host,
- task_id: event.parent,
- status: 'unreachable',
- id: event.id,
- created: event.created,
- modified: event.modified,
- message: msg,
- counter: event.counter,
- item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
- });
- break;
+ case 'runner_on_unreachable':
+ msg = getMsg(event);
+ UpdateHostStatus({
+ scope: scope,
+ name: event.host_name,
+ host_id: event.host,
+ task_id: event.parent,
+ status: 'unreachable',
+ id: event.id,
+ created: event.created,
+ modified: event.modified,
+ message: msg,
+ counter: event.counter,
+ item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
+ });
+ break;
- case 'runner_on_error':
- case 'runner_on_async_failed':
- msg = getMsg(event);
- UpdateHostStatus({
- scope: scope,
- name: event.host_name,
- host_id: event.host,
- task_id: event.parent,
- status: 'failed',
- id: event.id,
- created: event.created,
- modified: event.modified,
- message: msg,
- counter: event.counter,
- item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
- });
- break;
+ case 'runner_on_error':
+ case 'runner_on_async_failed':
+ msg = getMsg(event);
+ UpdateHostStatus({
+ scope: scope,
+ name: event.host_name,
+ host_id: event.host,
+ task_id: event.parent,
+ status: 'failed',
+ id: event.id,
+ created: event.created,
+ modified: event.modified,
+ message: msg,
+ counter: event.counter,
+ item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
+ });
+ break;
- case 'runner_on_no_hosts':
- UpdateTaskStatus({
- scope: scope,
- failed: event.failed,
- changed: event.changed,
- task_id: event.parent,
- modified: event.modified,
- no_hosts: true
- });
- break;
+ case 'runner_on_no_hosts':
+ UpdateTaskStatus({
+ scope: scope,
+ failed: event.failed,
+ changed: event.changed,
+ task_id: event.parent,
+ modified: event.modified,
+ no_hosts: true
+ });
+ break;
- case 'runner_on_skipped':
- msg = getMsg(event);
- UpdateHostStatus({
- scope: scope,
- name: event.host_name,
- host_id: event.host,
- task_id: event.parent,
- status: 'skipped',
- id: event.id,
- created: event.created,
- modified: event.modified,
- message: msg,
- counter: event.counter,
- item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
- });
- }
- };
-}])
-
-.factory('JobIsFinished', [ function() {
- return function(scope) {
- return (scope.job_status.status === 'failed' || scope.job_status.status === 'canceled' ||
- scope.job_status.status === 'error' || scope.job_status.status === 'successful');
- };
-}])
-
-.factory('GetElapsed', [ function() {
- return function(params) {
- var start = params.start,
- end = params.end,
- dt1, dt2, sec, hours, min;
- dt1 = new Date(start);
- dt2 = new Date(end);
- if ( dt2.getTime() !== dt1.getTime() ) {
- sec = Math.floor( (dt2.getTime() - dt1.getTime()) / 1000 );
- hours = Math.floor(sec / 3600);
- sec = sec - (hours * 3600);
- if (('' + hours).length < 2) {
- hours = ('00' + hours).substr(-2, 2);
+ case 'runner_on_skipped':
+ msg = getMsg(event);
+ UpdateHostStatus({
+ scope: scope,
+ name: event.host_name,
+ host_id: event.host,
+ task_id: event.parent,
+ status: 'skipped',
+ id: event.id,
+ created: event.created,
+ modified: event.modified,
+ message: msg,
+ counter: event.counter,
+ item: (event.event_data && event.event_data.res) ? event.event_data.res.item : ''
+ });
}
- min = Math.floor(sec / 60);
- sec = sec - (min * 60);
- min = ('00' + min).substr(-2,2);
- sec = ('00' + sec).substr(-2,2);
- return hours + ':' + min + ':' + sec;
- }
- else {
- return '00:00:00';
- }
- };
-}])
-
-.factory('SetActivePlay', [ function() {
- return function(params) {
- //find the most recent task in the list of 'active' tasks
-
- var scope = params.scope,
- activeList = [],
- newActivePlay,
- key;
-
- for (key in scope.jobData.plays) {
- if (scope.jobData.plays[key].taskCount > 0) {
- activeList.push(key);
- }
- }
-
- if (activeList.length > 0) {
- newActivePlay = scope.jobData.plays[activeList[activeList.length - 1]].id;
- if (newActivePlay && scope.activePlay && newActivePlay !== scope.activePlay) {
- scope.jobData.plays[scope.activePlay].tasks = {};
- scope.jobData.plays[scope.activePlay].playActiveClass = '';
- scope.activeTask = null;
- }
- if (newActivePlay) {
- scope.activePlay = newActivePlay;
- scope.jobData.plays[scope.activePlay].playActiveClass = 'active';
- }
- }
- };
-}])
-
-.factory('SetActiveTask', [ function() {
- return function(params) {
- //find the most recent task in the list of 'active' tasks
- var scope = params.scope,
- key,
- newActiveTask,
- activeList = [];
-
- for (key in scope.jobData.plays[scope.activePlay].tasks) {
- if (scope.jobData.plays[scope.activePlay].tasks[key].reportedHosts > 0 || scope.jobData.plays[scope.activePlay].tasks[key].status === 'no-matching-hosts') {
- activeList.push(key);
- }
- }
-
- if (activeList.length > 0) {
- newActiveTask = scope.jobData.plays[scope.activePlay].tasks[activeList[activeList.length - 1]].id;
- if (newActiveTask && scope.activeTask && newActiveTask !== scope.activeTask) {
- if (scope.activeTask && scope.jobData.plays[scope.activePlay].tasks[scope.activeTask] !== undefined) {
- scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].taskActiveClass = '';
- scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].hostResults = {};
- }
- }
- if (newActiveTask) {
- scope.activeTask = newActiveTask;
- scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].taskActiveClass = 'active';
- }
- }
- };
-}])
-
-.factory('AddNewPlay', ['SetActivePlay', function(SetActivePlay) {
- return function(params) {
- var scope = params.scope,
- event = params.event,
- status, status_text;
-
- status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
- status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
-
- scope.jobData.plays[event.id] = {
- id: event.id,
- name: event.play,
- created: event.created,
- status: status,
- status_text: status_text,
- elapsed: '00:00:00',
- hostCount: 0,
- taskCount: 0,
- fistTask: null,
- unreachableCount: 0,
- status_tip: "Event ID: " + event.id + " Status: " + status_text,
- tasks: {}
};
+ }])
- SetActivePlay({ scope: scope });
- };
-}])
-
-.factory('AddNewTask', ['DrawGraph', 'UpdatePlayStatus', 'SetActivePlay', 'SetActiveTask', function(DrawGraph, UpdatePlayStatus, SetActivePlay, SetActiveTask) {
- return function(params) {
- var scope = params.scope,
- event = params.event,
- status, status_text;
-
- status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
- status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
-
- scope.jobData.plays[event.parent].tasks[event.id] = {
- id: event.id,
- play_id: event.parent,
- name: (event.task) ? event.task : event.event_display,
- status: status,
- status_text: status_text,
- status_tip: "Event ID: " + event.id + " Status: " + status_text,
- created: event.created,
- modified: event.modified,
- hostCount: (scope.jobData.plays[event.parent]) ? scope.jobData.plays[event.parent].hostCount : 0,
- reportedHosts: 0,
- successfulCount: 0,
- failedCount: 0,
- changedCount: 0,
- skippedCount: 0,
- unreachableCount: 0,
- successfulStyle: { display: 'none'},
- failedStyle: { display: 'none' },
- changedStyle: { display: 'none' },
- skippedStyle: { display: 'none' },
- unreachableStyle: { display: 'none' },
- hostResults: {}
+ .factory('JobIsFinished', [ function() {
+ return function(scope) {
+ return (scope.job_status.status === 'failed' || scope.job_status.status === 'canceled' ||
+ scope.job_status.status === 'error' || scope.job_status.status === 'successful');
};
+ }])
- if (scope.jobData.plays[event.parent].firstTask === undefined || scope.jobData.plays[event.parent].firstTask === null) {
- scope.jobData.plays[event.parent].firstTask = event.id;
- }
- scope.jobData.plays[event.parent].taskCount++;
-
- SetActivePlay({ scope: scope });
-
- SetActiveTask({ scope: scope });
-
- UpdatePlayStatus({
- scope: scope,
- play_id: event.parent,
- failed: event.failed,
- changed: event.changed,
- modified: event.modified
- });
- };
-}])
-
-.factory('UpdateJobStatus', ['GetElapsed', 'Empty', 'JobIsFinished', function(GetElapsed, Empty, JobIsFinished) {
- return function(params) {
- var scope = params.scope,
- failed = params.failed,
- modified = params.modified,
- started = params.started;
-
- if (failed && scope.job_status.status !== 'failed' && scope.job_status.status !== 'error' &&
- scope.job_status.status !== 'canceled') {
- scope.job_status.status = 'failed';
- }
- if (JobIsFinished(scope) && !Empty(modified)) {
- scope.job_status.finished = modified;
- }
- if (!Empty(started) && Empty(scope.job_status.started)) {
- scope.job_status.started = started;
- }
- if (!Empty(scope.job_status.finished) && !Empty(scope.job_status.started)) {
- scope.job_status.elapsed = GetElapsed({
- start: scope.job_status.started,
- end: scope.job_status.finished
- });
- }
- };
-}])
-
-// Update the status of a play
-.factory('UpdatePlayStatus', ['GetElapsed', 'UpdateJobStatus', function(GetElapsed, UpdateJobStatus) {
- return function(params) {
- var scope = params.scope,
- failed = params.failed,
- changed = params.changed,
- id = params.play_id,
- modified = params.modified,
- no_hosts = params.no_hosts,
- play;
-
- if (scope.jobData.plays[id] !== undefined) {
- play = scope.jobData.plays[id];
- if (failed) {
- play.status = 'failed';
- play.status_text = 'Failed';
+ .factory('GetElapsed', [ function() {
+ return function(params) {
+ var start = params.start,
+ end = params.end,
+ dt1, dt2, sec, hours, min;
+ dt1 = new Date(start);
+ dt2 = new Date(end);
+ if ( dt2.getTime() !== dt1.getTime() ) {
+ sec = Math.floor( (dt2.getTime() - dt1.getTime()) / 1000 );
+ hours = Math.floor(sec / 3600);
+ sec = sec - (hours * 3600);
+ if (('' + hours).length < 2) {
+ hours = ('00' + hours).substr(-2, 2);
+ }
+ min = Math.floor(sec / 60);
+ sec = sec - (min * 60);
+ min = ('00' + min).substr(-2,2);
+ sec = ('00' + sec).substr(-2,2);
+ return hours + ':' + min + ':' + sec;
}
- else if (play.status !== 'changed' && play.status !== 'failed') {
- // once the status becomes 'changed' or 'failed' don't modify it
- if (no_hosts) {
- play.status = 'no-matching-hosts';
- play.status_text = 'No matching hosts';
- } else {
- play.status = (changed) ? 'changed' : (failed) ? 'failed' : 'successful';
- play.status_text = (changed) ? 'Changed' : (failed) ? 'Failed' : 'OK';
+ else {
+ return '00:00:00';
+ }
+ };
+ }])
+
+ .factory('SetActivePlay', [ function() {
+ return function(params) {
+ //find the most recent task in the list of 'active' tasks
+
+ var scope = params.scope,
+ activeList = [],
+ newActivePlay,
+ key;
+
+ for (key in scope.jobData.plays) {
+ if (scope.jobData.plays[key].taskCount > 0) {
+ activeList.push(key);
}
}
- play.taskCount = (play.taskCount > 0) ? play.taskCount : 1; // set to a minimum of 1 to force drawing
- play.status_tip = "Event ID: " + play.id + " Status: " + play.status_text;
- play.finished = modified;
- play.elapsed = GetElapsed({
- start: play.created,
- end: modified
- });
- //play.status_text = (status_text) ? status_text : play.status;
- }
- UpdateJobStatus({
- scope: scope,
- failed: null,
- modified: modified
- });
- };
-}])
-
-.factory('UpdateTaskStatus', ['UpdatePlayStatus', 'GetElapsed', function(UpdatePlayStatus, GetElapsed) {
- return function(params) {
- var scope = params.scope,
- failed = params.failed,
- changed = params.changed,
- id = params.task_id,
- modified = params.modified,
- no_hosts = params.no_hosts,
- play, task;
-
- // find the task in our hierarchy
- for (play in scope.jobData.plays) {
- if (scope.jobData.plays[play].tasks[id]) {
- task = scope.jobData.plays[play].tasks[id];
- }
- }
-
- if (task) {
- if (no_hosts){
- task.status = 'no-matching-hosts';
- task.status_text = 'No matching hosts';
- }
- else if (failed) {
- task.status = 'failed';
- task.status_text = 'Failed';
- }
- else if (task.status !== 'changed' && task.status !== 'failed') {
- // once the status becomes 'changed' or 'failed' don't modify it
- task.status = (failed) ? 'failed' : (changed) ? 'changed' : 'successful';
- task.status_text = (failed) ? 'Failed' : (changed) ? 'Changed' : 'OK';
- }
- task.status_tip = "Event ID: " + task.id + " Status: " + task.status_text;
- task.finished = params.modified;
- task.elapsed = GetElapsed({
- start: task.created,
- end: modified
- });
-
- UpdatePlayStatus({
- scope: scope,
- failed: failed,
- changed: changed,
- play_id: task.play_id,
- modified: modified,
- no_hosts: no_hosts
- });
- }
- };
-}])
-
-// Each time a runner event is received update host summary totals and the parent task
-.factory('UpdateHostStatus', ['UpdateTaskStatus', 'AddHostResult', function(UpdateTaskStatus, AddHostResult) {
- return function(params) {
- var scope = params.scope,
- status = params.status, // successful, changed, unreachable, failed, skipped
- name = params.name,
- event_id = params.id,
- host_id = params.host_id,
- task_id = params.task_id,
- modified = params.modified,
- created = params.created,
- msg = params.message,
- item = params.item,
- counter = params.counter,
- h, host;
-
- /*
- scope.host_summary.ok += (status === 'successful') ? 1 : 0;
- scope.host_summary.changed += (status === 'changed') ? 1 : 0;
- scope.host_summary.unreachable += (status === 'unreachable') ? 1 : 0;
- scope.host_summary.failed += (status === 'failed') ? 1 : 0;
- scope.host_summary.total = scope.host_summary.ok + scope.host_summary.changed + scope.host_summary.unreachable +
- scope.host_summary.failed;
- */
-
- if (scope.jobData.hostSummaries[name] !== undefined) {
- scope.jobData.hostSummaries[name].ok += (status === 'successful') ? 1 : 0;
- scope.jobData.hostSummaries[name].changed += (status === 'changed') ? 1 : 0;
- scope.jobData.hostSummaries[name].unreachable += (status === 'unreachable') ? 1 : 0;
- scope.jobData.hostSummaries[name].failed += (status === 'failed') ? 1 : 0;
- if (status === 'failed' || status === 'unreachable') {
- scope.jobData.hostSummaries[name].status = 'failed';
- }
- }
- else {
- scope.jobData.hostSummaries[name] = {
- id: name,
- name: name,
- ok: (status === 'successful') ? 1 : 0,
- changed: (status === 'changed') ? 1 : 0,
- unreachable: (status === 'unreachable') ? 1 : 0,
- failed: (status === 'failed') ? 1 : 0,
- status: (status === 'failed' || status === 'unreachable') ? 'failed' : 'successful'
- };
- }
-
- scope.host_summary.ok = 0;
- scope.host_summary.changed = 0;
- scope.host_summary.unreachable = 0;
- scope.host_summary.failed = 0;
- for (h in scope.jobData.hostSummaries) {
- host = scope.jobData.hostSummaries[h];
- if (host.ok > 0 && host.failed === 0 && host.unreachable === 0 && host.changed === 0) {
- scope.host_summary.ok++;
- }
- if (host.changed > 0 && host.failed === 0 && host.unreachable === 0) {
- scope.host_summary.changed++;
- }
- if (host.failed > 0) {
- scope.host_summary.failed++;
- }
- if (host.unreachable > 0) {
- scope.host_summary.unreachable++;
- }
- }
- scope.host_summary.total = scope.host_summary.ok + scope.host_summary.changed + scope.host_summary.unreachable +
- scope.host_summary.failed;
-
- UpdateTaskStatus({
- scope: scope,
- task_id: task_id,
- failed: ((status === 'failed' || status === 'unreachable') ? true :false),
- changed: ((status === 'changed') ? true : false),
- modified: modified
- });
-
- AddHostResult({
- scope: scope,
- task_id: task_id,
- host_id: host_id,
- event_id: event_id,
- status: status,
- name: name,
- created: created,
- counter: counter,
- message: msg,
- item: item
- });
- };
-}])
-
-// Add a new host result
-.factory('AddHostResult', ['SetTaskStyles', 'SetActivePlay', 'SetActiveTask', function(SetTaskStyles, SetActivePlay, SetActiveTask) {
- return function(params) {
- var scope = params.scope,
- task_id = params.task_id,
- host_id = params.host_id,
- event_id = params.event_id,
- status = params.status,
- created = params.created,
- counter = params.counter,
- name = params.name,
- msg = params.message,
- item = params.item,
- status_text = '',
- task, play, play_id;
-
- switch(status) {
- case "successful":
- status_text = 'OK';
- break;
- case "changed":
- status_text = "Changed";
- break;
- case "failed":
- status_text = "Failed";
- break;
- case "unreachable":
- status_text = "Unreachable";
- break;
- case "skipped":
- status_text = "Skipped";
- }
-
- if (typeof item === "object") {
- item = JSON.stringify(item);
- }
-
- for (play in scope.jobData.plays) {
- for (task in scope.jobData.plays[play].tasks) {
- if (parseInt(task,10) === parseInt(task_id,10)) {
- play_id = parseInt(play,10);
+ if (activeList.length > 0) {
+ newActivePlay = scope.jobData.plays[activeList[activeList.length - 1]].id;
+ if (newActivePlay && scope.activePlay && newActivePlay !== scope.activePlay) {
+ scope.jobData.plays[scope.activePlay].tasks = {};
+ scope.jobData.plays[scope.activePlay].playActiveClass = '';
+ scope.activeTask = null;
+ }
+ if (newActivePlay) {
+ scope.activePlay = newActivePlay;
+ scope.jobData.plays[scope.activePlay].playActiveClass = 'active';
}
}
- }
+ };
+ }])
- if (play_id) {
- scope.jobData.plays[play_id].tasks[task_id].hostResults[event_id] = {
- id: event_id,
+ .factory('SetActiveTask', [ function() {
+ return function(params) {
+ //find the most recent task in the list of 'active' tasks
+ var scope = params.scope,
+ key,
+ newActiveTask,
+ activeList = [];
+
+ for (key in scope.jobData.plays[scope.activePlay].tasks) {
+ if (scope.jobData.plays[scope.activePlay].tasks[key].reportedHosts > 0 || scope.jobData.plays[scope.activePlay].tasks[key].status === 'no-matching-hosts') {
+ activeList.push(key);
+ }
+ }
+
+ if (activeList.length > 0) {
+ newActiveTask = scope.jobData.plays[scope.activePlay].tasks[activeList[activeList.length - 1]].id;
+ if (newActiveTask && scope.activeTask && newActiveTask !== scope.activeTask) {
+ if (scope.activeTask && scope.jobData.plays[scope.activePlay].tasks[scope.activeTask] !== undefined) {
+ scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].taskActiveClass = '';
+ scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].hostResults = {};
+ }
+ }
+ if (newActiveTask) {
+ scope.activeTask = newActiveTask;
+ scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].taskActiveClass = 'active';
+ }
+ }
+ };
+ }])
+
+ .factory('AddNewPlay', ['SetActivePlay', function(SetActivePlay) {
+ return function(params) {
+ var scope = params.scope,
+ event = params.event,
+ status, status_text;
+
+ status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
+ status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
+
+ scope.jobData.plays[event.id] = {
+ id: event.id,
+ name: event.play,
+ created: event.created,
status: status,
status_text: status_text,
- host_id: host_id,
- task_id: task_id,
- name: name,
- created: created,
- counter: counter,
- msg: msg,
- item: item
+ elapsed: '00:00:00',
+ hostCount: 0,
+ taskCount: 0,
+ fistTask: null,
+ unreachableCount: 0,
+ status_tip: "Event ID: " + event.id + " Status: " + status_text,
+ tasks: {}
};
- // increment the unreachable count on the play
- if (status === 'unreachable') {
- scope.jobData.plays[play_id].unreachableCount++;
+ SetActivePlay({ scope: scope });
+ };
+ }])
+
+ .factory('AddNewTask', ['DrawGraph', 'UpdatePlayStatus', 'SetActivePlay', 'SetActiveTask', function(DrawGraph, UpdatePlayStatus, SetActivePlay, SetActiveTask) {
+ return function(params) {
+ var scope = params.scope,
+ event = params.event,
+ status, status_text;
+
+ status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
+ status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
+
+ scope.jobData.plays[event.parent].tasks[event.id] = {
+ id: event.id,
+ play_id: event.parent,
+ name: (event.task) ? event.task : event.event_display,
+ status: status,
+ status_text: status_text,
+ status_tip: "Event ID: " + event.id + " Status: " + status_text,
+ created: event.created,
+ modified: event.modified,
+ hostCount: (scope.jobData.plays[event.parent]) ? scope.jobData.plays[event.parent].hostCount : 0,
+ reportedHosts: 0,
+ successfulCount: 0,
+ failedCount: 0,
+ changedCount: 0,
+ skippedCount: 0,
+ unreachableCount: 0,
+ successfulStyle: { display: 'none'},
+ failedStyle: { display: 'none' },
+ changedStyle: { display: 'none' },
+ skippedStyle: { display: 'none' },
+ unreachableStyle: { display: 'none' },
+ hostResults: {}
+ };
+
+ if (scope.jobData.plays[event.parent].firstTask === undefined || scope.jobData.plays[event.parent].firstTask === null) {
+ scope.jobData.plays[event.parent].firstTask = event.id;
}
-
- // update the task status bar
- task = scope.jobData.plays[play_id].tasks[task_id];
-
- if (task_id === scope.jobData.plays[play_id].firstTask) {
- scope.jobData.plays[play_id].hostCount++;
- task.hostCount++;
- }
-
- task.reportedHosts += 1;
- task.failedCount += (status === 'failed') ? 1 : 0;
- task.changedCount += (status === 'changed') ? 1 : 0;
- task.successfulCount += (status === 'successful') ? 1 : 0;
- task.skippedCount += (status === 'skipped') ? 1 : 0;
- task.unreachableCount += (status === 'unreachable') ? 1 : 0;
-
- SetTaskStyles({
- task: task
- });
+ scope.jobData.plays[event.parent].taskCount++;
SetActivePlay({ scope: scope });
SetActiveTask({ scope: scope });
- }
- };
-}])
-.factory('SetTaskStyles', [ function() {
- return function(params) {
- var task = params.task,
- diff;
-
- task.missingCount = task.hostCount - (task.failedCount + task.changedCount + task.skippedCount + task.successfulCount + task.unreachableCount);
- task.missingPct = (task.hostCount > 0) ? Math.ceil((100 * (task.missingCount / task.hostCount))) : 0;
- task.failedPct = (task.hostCount > 0) ? Math.ceil((100 * (task.failedCount / task.hostCount))) : 0;
- task.changedPct = (task.hostCount > 0) ? Math.ceil((100 * (task.changedCount / task.hostCount))) : 0;
- task.skippedPct = (task.hostCount > 0) ? Math.ceil((100 * (task.skippedCount / task.hostCount))) : 0;
- task.successfulPct = (task.hostCount > 0) ? Math.ceil((100 * (task.successfulCount / task.hostCount))) : 0;
- task.unreachablePct = (task.hostCount > 0) ? Math.ceil((100 * (task.unreachableCount / task.hostCount))) : 0;
-
- // cap % at 100
- task.missingPct = (task.missingPct > 100) ? 100 : task.missingPct;
- task.failedPct = (task.failedPct > 100) ? 100 : task.failedPct;
- task.changedPct = (task.changedPct > 100) ? 100 : task.changedPct;
- task.skippedPct = (task.skippedPct > 100) ? 100 : task.skippedPct;
- task.successfulPct = ( task.successfulPct > 100) ? 100 : task.successfulPct;
- task.unreachablePct = (task.unreachablePct > 100) ? 100 : task.unreachablePct;
-
- diff = (task.failedPct + task.changedPct + task.skippedPct + task.successfulPct + task.unreachablePct + task.missingPct) - 100;
- if (diff > 0) {
- if (task.failedPct > diff) {
- task.failedPct = task.failedPct - diff;
- }
- else if (task.changedPct > diff) {
- task.changedPct = task.changedPct - diff;
- }
- else if (task.skippedPct > diff) {
- task.skippedPct = task.skippedPct - diff;
- }
- else if (task.successfulPct > diff) {
- task.successfulPct = task.successfulPct - diff;
- }
- else if (task.unreachablePct > diff) {
- task.unreachablePct = task.unreachablePct - diff;
- }
- else if (task.missingPct > diff) {
- task.missingPct = task.missingPct - diff;
- }
- }
- task.successfulStyle = (task.successfulPct > 0) ? { 'display': 'inline-block', 'width': task.successfulPct + "%" } : { 'display': 'none' };
- task.changedStyle = (task.changedPct > 0) ? { 'display': 'inline-block', 'width': task.changedPct + "%" } : { 'display': 'none' };
- task.skippedStyle = (task.skippedPct > 0) ? { 'display': 'inline-block', 'width': task.skippedPct + "%" } : { 'display': 'none' };
- task.failedStyle = (task.failedPct > 0) ? { 'display': 'inline-block', 'width': task.failedPct + "%" } : { 'display': 'none' };
- task.unreachableStyle = (task.unreachablePct > 0) ? { 'display': 'inline-block', 'width': task.unreachablePct + "%" } : { 'display': 'none' };
- task.missingStyle = (task.missingPct > 0) ? { 'display': 'inline-block', 'width': task.missingPct + "%" } : { 'display': 'none' };
- };
-}])
-
-.factory('LoadPlays', ['Rest', 'ProcessErrors', 'GetElapsed', 'SelectPlay', 'JobIsFinished',
- function(Rest, ProcessErrors, GetElapsed, SelectPlay, JobIsFinished) {
- return function(params) {
- var scope = params.scope,
- callback = params.callback,
- url;
-
- scope.plays = [];
-
- url = scope.job.url + 'job_plays/?page_size=' + scope.playsMaxRows + '&order=id';
- url += (scope.search_play_name) ? '&play__icontains=' + scope.search_play_name : '';
- url += (scope.search_play_status === 'failed') ? '&failed=true' : '';
- scope.playsLoading = true;
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- scope.next_plays = data.next;
- scope.plays = [];
- data.results.forEach(function(event, idx) {
- var status, status_text, start, end, elapsed;
-
- status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
- status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
- start = event.started;
-
- if (idx < data.results.length - 1) {
- // end date = starting date of the next event
- end = data.results[idx + 1].started;
- }
- else if (JobIsFinished(scope)) {
- // this is the last play and the job already finished
- end = scope.job_status.finished;
- }
- if (end) {
- elapsed = GetElapsed({
- start: start,
- end: end
- });
- }
- else {
- elapsed = '00:00:00';
- }
-
- scope.plays.push({
- id: event.id,
- name: event.play,
- created: start,
- finished: end,
- status: status,
- status_text: status_text,
- status_tip: "Event ID: " + event.id + " Status: " + status_text,
- elapsed: elapsed,
- hostCount: 0,
- fistTask: null,
- playActiveClass: '',
- unreachableCount: (event.unreachable_count) ? event.unreachable_count : 0,
- });
- });
-
- // set the active task
- SelectPlay({
- scope: scope,
- id: (scope.plays.length > 0) ? scope.plays[0].id : null,
- callback: callback
- });
- scope.playsLoading = false;
- })
- .error(function(data) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + '. GET returned: ' + status });
+ UpdatePlayStatus({
+ scope: scope,
+ play_id: event.parent,
+ failed: event.failed,
+ changed: event.changed,
+ modified: event.modified
});
- };
-}])
+ };
+ }])
-// Call when the selected Play needs to change
-.factory('SelectPlay', ['LoadTasks', function(LoadTasks) {
- return function(params) {
- var scope = params.scope,
- id = params.id,
- callback = params.callback;
+ .factory('UpdateJobStatus', ['GetElapsed', 'Empty', 'JobIsFinished', function(GetElapsed, Empty, JobIsFinished) {
+ return function(params) {
+ var scope = params.scope,
+ failed = params.failed,
+ modified = params.modified,
+ started = params.started;
- scope.selectedPlay = id;
- scope.plays.forEach(function(play, idx) {
- if (play.id === scope.selectedPlay) {
- scope.plays[idx].playActiveClass = 'active';
+ if (failed && scope.job_status.status !== 'failed' && scope.job_status.status !== 'error' &&
+ scope.job_status.status !== 'canceled') {
+ scope.job_status.status = 'failed';
+ }
+ if (JobIsFinished(scope) && !Empty(modified)) {
+ scope.job_status.finished = modified;
+ }
+ if (!Empty(started) && Empty(scope.job_status.started)) {
+ scope.job_status.started = started;
+ }
+ if (!Empty(scope.job_status.finished) && !Empty(scope.job_status.started)) {
+ scope.job_status.elapsed = GetElapsed({
+ start: scope.job_status.started,
+ end: scope.job_status.finished
+ });
+ }
+ };
+ }])
+
+ // Update the status of a play
+ .factory('UpdatePlayStatus', ['GetElapsed', 'UpdateJobStatus', function(GetElapsed, UpdateJobStatus) {
+ return function(params) {
+ var scope = params.scope,
+ failed = params.failed,
+ changed = params.changed,
+ id = params.play_id,
+ modified = params.modified,
+ no_hosts = params.no_hosts,
+ play;
+
+ if (scope.jobData.plays[id] !== undefined) {
+ play = scope.jobData.plays[id];
+ if (failed) {
+ play.status = 'failed';
+ play.status_text = 'Failed';
+ }
+ else if (play.status !== 'changed' && play.status !== 'failed') {
+ // once the status becomes 'changed' or 'failed' don't modify it
+ if (no_hosts) {
+ play.status = 'no-matching-hosts';
+ play.status_text = 'No matching hosts';
+ } else {
+ play.status = (changed) ? 'changed' : (failed) ? 'failed' : 'successful';
+ play.status_text = (changed) ? 'Changed' : (failed) ? 'Failed' : 'OK';
+ }
+ }
+ play.taskCount = (play.taskCount > 0) ? play.taskCount : 1; // set to a minimum of 1 to force drawing
+ play.status_tip = "Event ID: " + play.id + " Status: " + play.status_text;
+ play.finished = modified;
+ play.elapsed = GetElapsed({
+ start: play.created,
+ end: modified
+ });
+ //play.status_text = (status_text) ? status_text : play.status;
+ }
+
+ UpdateJobStatus({
+ scope: scope,
+ failed: null,
+ modified: modified
+ });
+ };
+ }])
+
+ .factory('UpdateTaskStatus', ['UpdatePlayStatus', 'GetElapsed', function(UpdatePlayStatus, GetElapsed) {
+ return function(params) {
+ var scope = params.scope,
+ failed = params.failed,
+ changed = params.changed,
+ id = params.task_id,
+ modified = params.modified,
+ no_hosts = params.no_hosts,
+ play, task;
+
+ // find the task in our hierarchy
+ for (play in scope.jobData.plays) {
+ if (scope.jobData.plays[play].tasks[id]) {
+ task = scope.jobData.plays[play].tasks[id];
+ }
+ }
+
+ if (task) {
+ if (no_hosts){
+ task.status = 'no-matching-hosts';
+ task.status_text = 'No matching hosts';
+ }
+ else if (failed) {
+ task.status = 'failed';
+ task.status_text = 'Failed';
+ }
+ else if (task.status !== 'changed' && task.status !== 'failed') {
+ // once the status becomes 'changed' or 'failed' don't modify it
+ task.status = (failed) ? 'failed' : (changed) ? 'changed' : 'successful';
+ task.status_text = (failed) ? 'Failed' : (changed) ? 'Changed' : 'OK';
+ }
+ task.status_tip = "Event ID: " + task.id + " Status: " + task.status_text;
+ task.finished = params.modified;
+ task.elapsed = GetElapsed({
+ start: task.created,
+ end: modified
+ });
+
+ UpdatePlayStatus({
+ scope: scope,
+ failed: failed,
+ changed: changed,
+ play_id: task.play_id,
+ modified: modified,
+ no_hosts: no_hosts
+ });
+ }
+ };
+ }])
+
+ // Each time a runner event is received update host summary totals and the parent task
+ .factory('UpdateHostStatus', ['UpdateTaskStatus', 'AddHostResult', function(UpdateTaskStatus, AddHostResult) {
+ return function(params) {
+ var scope = params.scope,
+ status = params.status, // successful, changed, unreachable, failed, skipped
+ name = params.name,
+ event_id = params.id,
+ host_id = params.host_id,
+ task_id = params.task_id,
+ modified = params.modified,
+ created = params.created,
+ msg = params.message,
+ item = params.item,
+ counter = params.counter,
+ h, host;
+
+ /*
+ scope.host_summary.ok += (status === 'successful') ? 1 : 0;
+ scope.host_summary.changed += (status === 'changed') ? 1 : 0;
+ scope.host_summary.unreachable += (status === 'unreachable') ? 1 : 0;
+ scope.host_summary.failed += (status === 'failed') ? 1 : 0;
+ scope.host_summary.total = scope.host_summary.ok + scope.host_summary.changed + scope.host_summary.unreachable +
+ scope.host_summary.failed;
+ */
+
+ if (scope.jobData.hostSummaries[name] !== undefined) {
+ scope.jobData.hostSummaries[name].ok += (status === 'successful') ? 1 : 0;
+ scope.jobData.hostSummaries[name].changed += (status === 'changed') ? 1 : 0;
+ scope.jobData.hostSummaries[name].unreachable += (status === 'unreachable') ? 1 : 0;
+ scope.jobData.hostSummaries[name].failed += (status === 'failed') ? 1 : 0;
+ if (status === 'failed' || status === 'unreachable') {
+ scope.jobData.hostSummaries[name].status = 'failed';
+ }
}
else {
- scope.plays[idx].playActiveClass = '';
+ scope.jobData.hostSummaries[name] = {
+ id: name,
+ name: name,
+ ok: (status === 'successful') ? 1 : 0,
+ changed: (status === 'changed') ? 1 : 0,
+ unreachable: (status === 'unreachable') ? 1 : 0,
+ failed: (status === 'failed') ? 1 : 0,
+ status: (status === 'failed' || status === 'unreachable') ? 'failed' : 'successful'
+ };
}
- });
- LoadTasks({
- scope: scope,
- callback: callback,
- clear: true
- });
-
- };
-}])
-
-.factory('LoadTasks', ['Rest', 'ProcessErrors', 'GetElapsed', 'SelectTask', 'SetTaskStyles', function(Rest, ProcessErrors, GetElapsed, SelectTask, SetTaskStyles) {
- return function(params) {
- var scope = params.scope,
- callback = params.callback,
- url, play;
-
- scope.tasks = [];
-
- if (scope.selectedPlay) {
- url = scope.job.url + 'job_tasks/?event_id=' + scope.selectedPlay;
- url += (scope.search_task_name) ? '&task__icontains=' + scope.search_task_name : '';
- url += (scope.search_task_status === 'failed') ? '&failed=true' : '';
- url += '&page_size=' + scope.tasksMaxRows + '&order=id';
-
- scope.plays.every(function(p, idx) {
- if (p.id === scope.selectedPlay) {
- play = scope.plays[idx];
- return false;
+ scope.host_summary.ok = 0;
+ scope.host_summary.changed = 0;
+ scope.host_summary.unreachable = 0;
+ scope.host_summary.failed = 0;
+ for (h in scope.jobData.hostSummaries) {
+ host = scope.jobData.hostSummaries[h];
+ if (host.ok > 0 && host.failed === 0 && host.unreachable === 0 && host.changed === 0) {
+ scope.host_summary.ok++;
}
- return true;
+ if (host.changed > 0 && host.failed === 0 && host.unreachable === 0) {
+ scope.host_summary.changed++;
+ }
+ if (host.failed > 0) {
+ scope.host_summary.failed++;
+ }
+ if (host.unreachable > 0) {
+ scope.host_summary.unreachable++;
+ }
+ }
+ scope.host_summary.total = scope.host_summary.ok + scope.host_summary.changed + scope.host_summary.unreachable +
+ scope.host_summary.failed;
+
+ UpdateTaskStatus({
+ scope: scope,
+ task_id: task_id,
+ failed: ((status === 'failed' || status === 'unreachable') ? true :false),
+ changed: ((status === 'changed') ? true : false),
+ modified: modified
});
- scope.tasksLoading = true;
+ AddHostResult({
+ scope: scope,
+ task_id: task_id,
+ host_id: host_id,
+ event_id: event_id,
+ status: status,
+ name: name,
+ created: created,
+ counter: counter,
+ message: msg,
+ item: item
+ });
+ };
+ }])
+ // Add a new host result
+ .factory('AddHostResult', ['SetTaskStyles', 'SetActivePlay', 'SetActiveTask', function(SetTaskStyles, SetActivePlay, SetActiveTask) {
+ return function(params) {
+ var scope = params.scope,
+ task_id = params.task_id,
+ host_id = params.host_id,
+ event_id = params.event_id,
+ status = params.status,
+ created = params.created,
+ counter = params.counter,
+ name = params.name,
+ msg = params.message,
+ item = params.item,
+ status_text = '',
+ task, play, play_id;
+
+ switch(status) {
+ case "successful":
+ status_text = 'OK';
+ break;
+ case "changed":
+ status_text = "Changed";
+ break;
+ case "failed":
+ status_text = "Failed";
+ break;
+ case "unreachable":
+ status_text = "Unreachable";
+ break;
+ case "skipped":
+ status_text = "Skipped";
+ }
+
+ if (typeof item === "object") {
+ item = JSON.stringify(item);
+ }
+
+ for (play in scope.jobData.plays) {
+ for (task in scope.jobData.plays[play].tasks) {
+ if (parseInt(task,10) === parseInt(task_id,10)) {
+ play_id = parseInt(play,10);
+ }
+ }
+ }
+
+ if (play_id) {
+ scope.jobData.plays[play_id].tasks[task_id].hostResults[event_id] = {
+ id: event_id,
+ status: status,
+ status_text: status_text,
+ host_id: host_id,
+ task_id: task_id,
+ name: name,
+ created: created,
+ counter: counter,
+ msg: msg,
+ item: item
+ };
+
+ // increment the unreachable count on the play
+ if (status === 'unreachable') {
+ scope.jobData.plays[play_id].unreachableCount++;
+ }
+
+ // update the task status bar
+ task = scope.jobData.plays[play_id].tasks[task_id];
+
+ if (task_id === scope.jobData.plays[play_id].firstTask) {
+ scope.jobData.plays[play_id].hostCount++;
+ task.hostCount++;
+ }
+
+ task.reportedHosts += 1;
+ task.failedCount += (status === 'failed') ? 1 : 0;
+ task.changedCount += (status === 'changed') ? 1 : 0;
+ task.successfulCount += (status === 'successful') ? 1 : 0;
+ task.skippedCount += (status === 'skipped') ? 1 : 0;
+ task.unreachableCount += (status === 'unreachable') ? 1 : 0;
+
+ SetTaskStyles({
+ task: task
+ });
+
+ SetActivePlay({ scope: scope });
+
+ SetActiveTask({ scope: scope });
+ }
+ };
+ }])
+
+ .factory('SetTaskStyles', [ function() {
+ return function(params) {
+ var task = params.task,
+ diff;
+
+ task.missingCount = task.hostCount - (task.failedCount + task.changedCount + task.skippedCount + task.successfulCount + task.unreachableCount);
+ task.missingPct = (task.hostCount > 0) ? Math.ceil((100 * (task.missingCount / task.hostCount))) : 0;
+ task.failedPct = (task.hostCount > 0) ? Math.ceil((100 * (task.failedCount / task.hostCount))) : 0;
+ task.changedPct = (task.hostCount > 0) ? Math.ceil((100 * (task.changedCount / task.hostCount))) : 0;
+ task.skippedPct = (task.hostCount > 0) ? Math.ceil((100 * (task.skippedCount / task.hostCount))) : 0;
+ task.successfulPct = (task.hostCount > 0) ? Math.ceil((100 * (task.successfulCount / task.hostCount))) : 0;
+ task.unreachablePct = (task.hostCount > 0) ? Math.ceil((100 * (task.unreachableCount / task.hostCount))) : 0;
+
+ // cap % at 100
+ task.missingPct = (task.missingPct > 100) ? 100 : task.missingPct;
+ task.failedPct = (task.failedPct > 100) ? 100 : task.failedPct;
+ task.changedPct = (task.changedPct > 100) ? 100 : task.changedPct;
+ task.skippedPct = (task.skippedPct > 100) ? 100 : task.skippedPct;
+ task.successfulPct = ( task.successfulPct > 100) ? 100 : task.successfulPct;
+ task.unreachablePct = (task.unreachablePct > 100) ? 100 : task.unreachablePct;
+
+ diff = (task.failedPct + task.changedPct + task.skippedPct + task.successfulPct + task.unreachablePct + task.missingPct) - 100;
+ if (diff > 0) {
+ if (task.failedPct > diff) {
+ task.failedPct = task.failedPct - diff;
+ }
+ else if (task.changedPct > diff) {
+ task.changedPct = task.changedPct - diff;
+ }
+ else if (task.skippedPct > diff) {
+ task.skippedPct = task.skippedPct - diff;
+ }
+ else if (task.successfulPct > diff) {
+ task.successfulPct = task.successfulPct - diff;
+ }
+ else if (task.unreachablePct > diff) {
+ task.unreachablePct = task.unreachablePct - diff;
+ }
+ else if (task.missingPct > diff) {
+ task.missingPct = task.missingPct - diff;
+ }
+ }
+ task.successfulStyle = (task.successfulPct > 0) ? { 'display': 'inline-block', 'width': task.successfulPct + "%" } : { 'display': 'none' };
+ task.changedStyle = (task.changedPct > 0) ? { 'display': 'inline-block', 'width': task.changedPct + "%" } : { 'display': 'none' };
+ task.skippedStyle = (task.skippedPct > 0) ? { 'display': 'inline-block', 'width': task.skippedPct + "%" } : { 'display': 'none' };
+ task.failedStyle = (task.failedPct > 0) ? { 'display': 'inline-block', 'width': task.failedPct + "%" } : { 'display': 'none' };
+ task.unreachableStyle = (task.unreachablePct > 0) ? { 'display': 'inline-block', 'width': task.unreachablePct + "%" } : { 'display': 'none' };
+ task.missingStyle = (task.missingPct > 0) ? { 'display': 'inline-block', 'width': task.missingPct + "%" } : { 'display': 'none' };
+ };
+ }])
+
+ .factory('LoadPlays', ['Rest', 'ProcessErrors', 'GetElapsed', 'SelectPlay', 'JobIsFinished',
+ function(Rest, ProcessErrors, GetElapsed, SelectPlay, JobIsFinished) {
+ return function(params) {
+ var scope = params.scope,
+ callback = params.callback,
+ url;
+
+ scope.plays = [];
+
+ url = scope.job.url + 'job_plays/?page_size=' + scope.playsMaxRows + '&order=id';
+ url += (scope.search_play_name) ? '&play__icontains=' + scope.search_play_name : '';
+ url += (scope.search_play_status === 'failed') ? '&failed=true' : '';
+ scope.playsLoading = true;
Rest.setUrl(url);
Rest.get()
.success(function(data) {
- scope.next_tasks = data.next;
- scope.tasks = [];
+ scope.next_plays = data.next;
+ scope.plays = [];
data.results.forEach(function(event, idx) {
- var end, elapsed, status, status_text;
+ var status, status_text, start, end, elapsed;
- if (play.firstTask === undefined || play.firstTask === null) {
- play.firstTask = event.id;
- play.hostCount = (event.host_count) ? event.host_count : 0;
- }
+ status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
+ status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
+ start = event.started;
if (idx < data.results.length - 1) {
// end date = starting date of the next event
- end = data.results[idx + 1].created;
+ end = data.results[idx + 1].started;
}
- else {
- // no next event (task), get the end time of the play
- scope.plays.every(function(play) {
- if (play.id === scope.selectedPlay) {
- end = play.finished;
- return false;
- }
- return true;
- });
+ else if (JobIsFinished(scope)) {
+ // this is the last play and the job already finished
+ end = scope.job_status.finished;
}
-
if (end) {
elapsed = GetElapsed({
- start: event.created,
+ start: start,
end: end
});
}
@@ -868,172 +749,350 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
elapsed = '00:00:00';
}
- status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
- status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
-
- scope.tasks.push({
+ scope.plays.push({
id: event.id,
- play_id: scope.selectedPlay,
- name: event.name,
+ name: event.play,
+ created: start,
+ finished: end,
status: status,
status_text: status_text,
status_tip: "Event ID: " + event.id + " Status: " + status_text,
- created: event.created,
- modified: event.modified,
- finished: end,
elapsed: elapsed,
- hostCount: (event.host_count) ? event.host_count : 0,
- reportedHosts: (event.reported_hosts) ? event.reported_hosts : 0,
- successfulCount: (event.successful_count) ? event.successful_count : 0,
- failedCount: (event.failed_count) ? event.failed_count : 0,
- changedCount: (event.changed_count) ? event.changed_count : 0,
- skippedCount: (event.skipped_count) ? event.skipped_count : 0,
+ hostCount: 0,
+ fistTask: null,
+ playActiveClass: '',
unreachableCount: (event.unreachable_count) ? event.unreachable_count : 0,
- taskActiveClass: ''
- });
-
- if (play.firstTask !== event.id) {
- // this is not the first task
- scope.tasks[scope.tasks.length - 1].hostCount = play.hostCount;
- }
-
- SetTaskStyles({
- task: scope.tasks[scope.tasks.length - 1]
});
});
// set the active task
- SelectTask({
+ SelectPlay({
scope: scope,
- id: (scope.tasks.length > 0) ? scope.tasks[0].id : null,
+ id: (scope.plays.length > 0) ? scope.plays[0].id : null,
callback: callback
});
-
- scope.tasksLoading = false;
-
+ scope.playsLoading = false;
})
.error(function(data) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + '. GET returned: ' + status });
});
- }
- else {
- SelectTask({
- scope: scope,
- id: null,
- callback: callback
+ };
+ }])
+
+ // Call when the selected Play needs to change
+ .factory('SelectPlay', ['LoadTasks', function(LoadTasks) {
+ return function(params) {
+ var scope = params.scope,
+ id = params.id,
+ callback = params.callback;
+
+ scope.selectedPlay = id;
+ scope.plays.forEach(function(play, idx) {
+ if (play.id === scope.selectedPlay) {
+ scope.plays[idx].playActiveClass = 'active';
+ }
+ else {
+ scope.plays[idx].playActiveClass = '';
+ }
});
- }
- };
-}])
-// Call when the selected task needs to change
-.factory('SelectTask', ['LoadHosts', function(LoadHosts) {
- return function(params) {
- var scope = params.scope,
- id = params.id,
- callback = params.callback;
+ LoadTasks({
+ scope: scope,
+ callback: callback,
+ clear: true
+ });
- scope.selectedTask = id;
- scope.tasks.forEach(function(task, idx) {
- if (task.id === scope.selectedTask) {
- scope.tasks[idx].taskActiveClass = 'active';
+ };
+ }])
+
+ .factory('LoadTasks', ['Rest', 'ProcessErrors', 'GetElapsed', 'SelectTask', 'SetTaskStyles', function(Rest, ProcessErrors, GetElapsed, SelectTask, SetTaskStyles) {
+ return function(params) {
+ var scope = params.scope,
+ callback = params.callback,
+ url, play;
+
+ scope.tasks = [];
+
+ if (scope.selectedPlay) {
+ url = scope.job.url + 'job_tasks/?event_id=' + scope.selectedPlay;
+ url += (scope.search_task_name) ? '&task__icontains=' + scope.search_task_name : '';
+ url += (scope.search_task_status === 'failed') ? '&failed=true' : '';
+ url += '&page_size=' + scope.tasksMaxRows + '&order=id';
+
+ scope.plays.every(function(p, idx) {
+ if (p.id === scope.selectedPlay) {
+ play = scope.plays[idx];
+ return false;
+ }
+ return true;
+ });
+
+ scope.tasksLoading = true;
+
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ scope.next_tasks = data.next;
+ scope.tasks = [];
+ data.results.forEach(function(event, idx) {
+ var end, elapsed, status, status_text;
+
+ if (play.firstTask === undefined || play.firstTask === null) {
+ play.firstTask = event.id;
+ play.hostCount = (event.host_count) ? event.host_count : 0;
+ }
+
+ if (idx < data.results.length - 1) {
+ // end date = starting date of the next event
+ end = data.results[idx + 1].created;
+ }
+ else {
+ // no next event (task), get the end time of the play
+ scope.plays.every(function(play) {
+ if (play.id === scope.selectedPlay) {
+ end = play.finished;
+ return false;
+ }
+ return true;
+ });
+ }
+
+ if (end) {
+ elapsed = GetElapsed({
+ start: event.created,
+ end: end
+ });
+ }
+ else {
+ elapsed = '00:00:00';
+ }
+
+ status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
+ status_text = (event.failed) ? 'Failed' : (event.changed) ? 'Changed' : 'OK';
+
+ scope.tasks.push({
+ id: event.id,
+ play_id: scope.selectedPlay,
+ name: event.name,
+ status: status,
+ status_text: status_text,
+ status_tip: "Event ID: " + event.id + " Status: " + status_text,
+ created: event.created,
+ modified: event.modified,
+ finished: end,
+ elapsed: elapsed,
+ hostCount: (event.host_count) ? event.host_count : 0,
+ reportedHosts: (event.reported_hosts) ? event.reported_hosts : 0,
+ successfulCount: (event.successful_count) ? event.successful_count : 0,
+ failedCount: (event.failed_count) ? event.failed_count : 0,
+ changedCount: (event.changed_count) ? event.changed_count : 0,
+ skippedCount: (event.skipped_count) ? event.skipped_count : 0,
+ unreachableCount: (event.unreachable_count) ? event.unreachable_count : 0,
+ taskActiveClass: ''
+ });
+
+ if (play.firstTask !== event.id) {
+ // this is not the first task
+ scope.tasks[scope.tasks.length - 1].hostCount = play.hostCount;
+ }
+
+ SetTaskStyles({
+ task: scope.tasks[scope.tasks.length - 1]
+ });
+ });
+
+ // set the active task
+ SelectTask({
+ scope: scope,
+ id: (scope.tasks.length > 0) ? scope.tasks[0].id : null,
+ callback: callback
+ });
+
+ scope.tasksLoading = false;
+
+ })
+ .error(function(data) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + '. GET returned: ' + status });
+ });
}
else {
- scope.tasks[idx].taskActiveClass = '';
+ SelectTask({
+ scope: scope,
+ id: null,
+ callback: callback
+ });
}
- });
+ };
+ }])
- LoadHosts({
- scope: scope,
- callback: callback,
- clear: true
- });
- };
-}])
+ // Call when the selected task needs to change
+ .factory('SelectTask', ['LoadHosts', function(LoadHosts) {
+ return function(params) {
+ var scope = params.scope,
+ id = params.id,
+ callback = params.callback;
-// Refresh the list of hosts
-.factory('LoadHosts', ['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
- return function(params) {
- var scope = params.scope,
- callback = params.callback,
- url;
+ scope.selectedTask = id;
+ scope.tasks.forEach(function(task, idx) {
+ if (task.id === scope.selectedTask) {
+ scope.tasks[idx].taskActiveClass = 'active';
+ }
+ else {
+ scope.tasks[idx].taskActiveClass = '';
+ }
+ });
- scope.hostResults = [];
+ LoadHosts({
+ scope: scope,
+ callback: callback,
+ clear: true
+ });
+ };
+ }])
+
+ // Refresh the list of hosts
+ .factory('LoadHosts', ['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
+ return function(params) {
+ var scope = params.scope,
+ callback = params.callback,
+ url;
+
+ scope.hostResults = [];
+
+ if (scope.selectedTask) {
+ // If we have a selected task, then get the list of hosts
+ url = scope.job.related.job_events + '?parent=' + scope.selectedTask + '&';
+ url += (scope.search_host_name) ? 'host__name__icontains=' + scope.search_host_name + '&' : '';
+ url += (scope.search_host_status === 'failed') ? 'failed=true&' : '';
+ url += 'event__startswith=runner&page_size=' + scope.hostResultsMaxRows + '&order=host_name,counter';
+ scope.hostResultsLoading = true;
+ Rest.setUrl(url);
+ Rest.get()
+ .success(function(data) {
+ scope.next_host_results = data.next;
+ scope.hostResults = [];
+ data.results.forEach(function(event) {
+ var status, status_text, item, msg;
+ if (event.event === "runner_on_skipped") {
+ status = 'skipped';
+ }
+ else if (event.event === "runner_on_unreachable") {
+ status = 'unreachable';
+ }
+ else {
+ status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
+ }
+ switch(status) {
+ case "successful":
+ status_text = 'OK';
+ break;
+ case "changed":
+ status_text = "Changed";
+ break;
+ case "failed":
+ status_text = "Failed";
+ break;
+ case "unreachable":
+ status_text = "Unreachable";
+ break;
+ case "skipped":
+ status_text = "Skipped";
+ }
+
+ if (event.event_data && event.event_data.res) {
+ item = event.event_data.res.item;
+ if (typeof item === "object") {
+ item = JSON.stringify(item);
+ item = item.replace(/\"/g,'').replace(/:/g,': ').replace(/,/g,', ');
+ }
+ }
+
+ msg = '';
+ if (event.event_data && event.event_data.res) {
+ if (typeof event.event_data.res === 'object') {
+ msg = event.event_data.res.msg;
+ } else {
+ msg = event.event_data.res;
+ }
+ }
+
+ if (event.event !== "runner_on_no_hosts") {
+ scope.hostResults.push({
+ id: event.id,
+ status: status,
+ status_text: status_text,
+ host_id: event.host,
+ task_id: event.parent,
+ name: event.event_data.host,
+ created: event.created,
+ msg: msg,
+ item: item
+ });
+ }
+ });
+
+ scope.hostResultsLoading = false;
+
+ if (callback) {
+ scope.$emit(callback);
+ }
+ })
+ .error(function(data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + '. GET returned: ' + status });
+ });
+ }
+ else {
+ if (callback) {
+ scope.$emit(callback);
+ }
+ //$('#hosts-table-detail').mCustomScrollbar("update");
+ }
+ };
+ }])
+
+ // Refresh the list of hosts in the hosts summary section
+ .factory('ReloadHostSummaryList', ['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
+ return function(params) {
+ var scope = params.scope,
+ callback = params.callback,
+ url;
+
+ url = scope.job.related.job_host_summaries + '?';
+ url += (scope.search_host_summary_name) ? 'host_name__icontains=' + scope.search_host_summary_name + '&': '';
+ url += (scope.search_host_summary_status === 'failed') ? 'failed=true&' : '';
+ url += '&page_size=' + scope.hostSummariesMaxRows + '&order=host_name';
+
+ scope.hosts = [];
+ scope.hostSummariesLoading = true;
- if (scope.selectedTask) {
- // If we have a selected task, then get the list of hosts
- url = scope.job.related.job_events + '?parent=' + scope.selectedTask + '&';
- url += (scope.search_host_name) ? 'host__name__icontains=' + scope.search_host_name + '&' : '';
- url += (scope.search_host_status === 'failed') ? 'failed=true&' : '';
- url += 'event__startswith=runner&page_size=' + scope.hostResultsMaxRows + '&order=host_name,counter';
- scope.hostResultsLoading = true;
Rest.setUrl(url);
Rest.get()
.success(function(data) {
- scope.next_host_results = data.next;
- scope.hostResults = [];
+ scope.next_host_summaries = data.next;
+ scope.hosts = [];
data.results.forEach(function(event) {
- var status, status_text, item, msg;
- if (event.event === "runner_on_skipped") {
- status = 'skipped';
- }
- else if (event.event === "runner_on_unreachable") {
- status = 'unreachable';
+ var name;
+ if (event.host_name) {
+ name = event.host_name;
}
else {
- status = (event.failed) ? 'failed' : (event.changed) ? 'changed' : 'successful';
- }
- switch(status) {
- case "successful":
- status_text = 'OK';
- break;
- case "changed":
- status_text = "Changed";
- break;
- case "failed":
- status_text = "Failed";
- break;
- case "unreachable":
- status_text = "Unreachable";
- break;
- case "skipped":
- status_text = "Skipped";
- }
-
- if (event.event_data && event.event_data.res) {
- item = event.event_data.res.item;
- if (typeof item === "object") {
- item = JSON.stringify(item);
- item = item.replace(/\"/g,'').replace(/:/g,': ').replace(/,/g,', ');
- }
- }
-
- msg = '';
- if (event.event_data && event.event_data.res) {
- if (typeof event.event_data.res === 'object') {
- msg = event.event_data.res.msg;
- } else {
- msg = event.event_data.res;
- }
- }
-
- if (event.event !== "runner_on_no_hosts") {
- scope.hostResults.push({
- id: event.id,
- status: status,
- status_text: status_text,
- host_id: event.host,
- task_id: event.parent,
- name: event.event_data.host,
- created: event.created,
- msg: msg,
- item: item
- });
+ name = "";
}
+ scope.hosts.push({
+ id: name,
+ name: event.host_name,
+ ok: event.ok,
+ changed: event.changed,
+ unreachable: event.dark,
+ failed: event.failures,
+ status: (event.failed) ? 'failed' : 'successful'
+ });
});
- scope.hostResultsLoading = false;
+ scope.hostSummariesLoading = false;
if (callback) {
scope.$emit(callback);
@@ -1043,266 +1102,130 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + '. GET returned: ' + status });
});
- }
- else {
- if (callback) {
- scope.$emit(callback);
+ };
+ }])
+
+ .factory('LoadHostSummary', [ function() {
+ return function(params) {
+ var scope = params.scope,
+ data = params.data,
+ host;
+ scope.host_summary.ok = 0;
+ for (host in data.ok) {
+ if (!data.changed[host] && !data.dark[host] && !data.failures[host]) {
+ scope.host_summary.ok += 1;
+ }
}
- //$('#hosts-table-detail').mCustomScrollbar("update");
- }
- };
-}])
+ scope.host_summary.changed = 0;
+ for (host in data.changed) {
+ if (!data.dark[host] && !data.failures[host]) {
+ scope.host_summary.changed += 1;
+ }
+ }
+ scope.host_summary.unreachable = 0;
+ for (host in data.dark) {
+ scope.host_summary.unreachable += 1;
+ }
+ scope.host_summary.failed = 0;
+ for (host in data.failures) {
+ scope.host_summary.failed += 1;
+ }
+ scope.host_summary.total = scope.host_summary.ok + scope.host_summary.changed +
+ scope.host_summary.unreachable + scope.host_summary.failed;
+ };
+ }])
-// Refresh the list of hosts in the hosts summary section
-.factory('ReloadHostSummaryList', ['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
- return function(params) {
- var scope = params.scope,
- callback = params.callback,
- url;
+ .factory('DrawGraph', [ function() {
+ return function(params) {
+ var scope = params.scope,
+ resize = params.resize,
+ width, height, svg_height, svg_width, svg_radius, svg, graph_data = [];
- url = scope.job.related.job_host_summaries + '?';
- url += (scope.search_host_summary_name) ? 'host_name__icontains=' + scope.search_host_summary_name + '&': '';
- url += (scope.search_host_summary_status === 'failed') ? 'failed=true&' : '';
- url += '&page_size=' + scope.hostSummariesMaxRows + '&order=host_name';
-
- scope.hosts = [];
- scope.hostSummariesLoading = true;
-
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- scope.next_host_summaries = data.next;
- scope.hosts = [];
- data.results.forEach(function(event) {
- var name;
- if (event.host_name) {
- name = event.host_name;
- }
- else {
- name = "";
- }
- scope.hosts.push({
- id: name,
- name: event.host_name,
- ok: event.ok,
- changed: event.changed,
- unreachable: event.dark,
- failed: event.failures,
- status: (event.failed) ? 'failed' : 'successful'
- });
+ // Ready the data
+ if (scope.host_summary.ok) {
+ graph_data.push({
+ label: 'OK',
+ value: (scope.host_summary.ok === scope.host_summary.total) ? 1 : scope.host_summary.ok,
+ color: '#00aa00'
});
+ }
+ if (scope.host_summary.changed) {
+ graph_data.push({
+ label: 'Changed',
+ value: (scope.host_summary.changed === scope.host_summary.total) ? 1 : scope.host_summary.changed,
+ color: '#FF9900'
+ });
+ }
+ if (scope.host_summary.unreachable) {
+ graph_data.push({
+ label: 'Unreachable',
+ value: (scope.host_summary.unreachable === scope.host_summary.total) ? 1 : scope.host_summary.unreachable,
+ color: '#FF0000'
+ });
+ }
+ if (scope.host_summary.failed) {
+ graph_data.push({
+ label: 'Failed',
+ value: (scope.host_summary.failed === scope.host_summary.total) ? 1 : scope.host_summary.failed,
+ color: '#aa0000'
+ });
+ }
- scope.hostSummariesLoading = false;
-
- if (callback) {
- scope.$emit(callback);
+ // Adjust the size
+ width = $('#job-summary-container .job_well').width();
+ height = $('#job-summary-container .job_well').height() - $('#summary-well-top-section').height() - $('#graph-section .header').outerHeight() - 15;
+ svg_radius = Math.min(width, height);
+ svg_width = width;
+ svg_height = height;
+ if (svg_height > 0 && svg_width > 0) {
+ if (!resize && $('#graph-section svg').length > 0) {
+ Donut3D.transition("completedHostsDonut", graph_data, Math.floor(svg_radius * 0.50), Math.floor(svg_radius * 0.25), 18, 0.4);
}
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Call to ' + url + '. GET returned: ' + status });
- });
- };
-}])
-
-.factory('LoadHostSummary', [ function() {
- return function(params) {
- var scope = params.scope,
- data = params.data,
- host;
- scope.host_summary.ok = 0;
- for (host in data.ok) {
- if (!data.changed[host] && !data.dark[host] && !data.failures[host]) {
- scope.host_summary.ok += 1;
- }
- }
- scope.host_summary.changed = 0;
- for (host in data.changed) {
- if (!data.dark[host] && !data.failures[host]) {
- scope.host_summary.changed += 1;
- }
- }
- scope.host_summary.unreachable = 0;
- for (host in data.dark) {
- scope.host_summary.unreachable += 1;
- }
- scope.host_summary.failed = 0;
- for (host in data.failures) {
- scope.host_summary.failed += 1;
- }
- scope.host_summary.total = scope.host_summary.ok + scope.host_summary.changed +
- scope.host_summary.unreachable + scope.host_summary.failed;
- };
-}])
-
-.factory('DrawGraph', [ function() {
- return function(params) {
- var scope = params.scope,
- resize = params.resize,
- width, height, svg_height, svg_width, svg_radius, svg, graph_data = [];
-
- // Ready the data
- if (scope.host_summary.ok) {
- graph_data.push({
- label: 'OK',
- value: (scope.host_summary.ok === scope.host_summary.total) ? 1 : scope.host_summary.ok,
- color: '#00aa00'
- });
- }
- if (scope.host_summary.changed) {
- graph_data.push({
- label: 'Changed',
- value: (scope.host_summary.changed === scope.host_summary.total) ? 1 : scope.host_summary.changed,
- color: '#FF9900'
- });
- }
- if (scope.host_summary.unreachable) {
- graph_data.push({
- label: 'Unreachable',
- value: (scope.host_summary.unreachable === scope.host_summary.total) ? 1 : scope.host_summary.unreachable,
- color: '#FF0000'
- });
- }
- if (scope.host_summary.failed) {
- graph_data.push({
- label: 'Failed',
- value: (scope.host_summary.failed === scope.host_summary.total) ? 1 : scope.host_summary.failed,
- color: '#aa0000'
- });
- }
-
- // Adjust the size
- width = $('#job-summary-container .job_well').width();
- height = $('#job-summary-container .job_well').height() - $('#summary-well-top-section').height() - $('#graph-section .header').outerHeight() - 15;
- svg_radius = Math.min(width, height);
- svg_width = width;
- svg_height = height;
- if (svg_height > 0 && svg_width > 0) {
- if (!resize && $('#graph-section svg').length > 0) {
- Donut3D.transition("completedHostsDonut", graph_data, Math.floor(svg_radius * 0.50), Math.floor(svg_radius * 0.25), 18, 0.4);
- }
- else {
- if ($('#graph-section svg').length > 0) {
- $('#graph-section svg').remove();
+ else {
+ if ($('#graph-section svg').length > 0) {
+ $('#graph-section svg').remove();
+ }
+ svg = d3.select("#graph-section").append("svg").attr("width", svg_width).attr("height", svg_height);
+ svg.append("g").attr("id","completedHostsDonut");
+ Donut3D.draw("completedHostsDonut", graph_data, Math.floor(svg_width / 2), Math.floor(svg_height / 2), Math.floor(svg_radius * 0.50), Math.floor(svg_radius * 0.25), 18, 0.4);
+ $('#graph-section .header .legend').show();
}
- svg = d3.select("#graph-section").append("svg").attr("width", svg_width).attr("height", svg_height);
- svg.append("g").attr("id","completedHostsDonut");
- Donut3D.draw("completedHostsDonut", graph_data, Math.floor(svg_width / 2), Math.floor(svg_height / 2), Math.floor(svg_radius * 0.50), Math.floor(svg_radius * 0.25), 18, 0.4);
- $('#graph-section .header .legend').show();
}
- }
- };
-}])
+ };
+ }])
-.factory('DrawPlays', [function() {
- return function(params) {
- var scope = params.scope,
- idx = 0,
- result = [],
- newKeys = [],
- plays = JSON.parse(JSON.stringify(scope.jobData.plays)),
- filteredListX = [],
- filteredListA = [],
- filteredListB = [],
- key,
- keys;
+ .factory('DrawPlays', [function() {
+ return function(params) {
+ var scope = params.scope,
+ idx = 0,
+ result = [],
+ newKeys = [],
+ plays = JSON.parse(JSON.stringify(scope.jobData.plays)),
+ filteredListX = [],
+ filteredListA = [],
+ filteredListB = [],
+ key,
+ keys;
- function listSort(a,b) {
- if (parseInt(a,10) < parseInt(b,10)) {
- return -1;
+ function listSort(a,b) {
+ if (parseInt(a,10) < parseInt(b,10)) {
+ return -1;
+ }
+ if (parseInt(a,10) > parseInt(b,10)) {
+ return 1;
+ }
+ return 0;
}
- if (parseInt(a,10) > parseInt(b,10)) {
- return 1;
- }
- return 0;
- }
- // Only draw plays that are in the 'active' list
- for (key in plays) {
- if (plays[key].taskCount > 0) {
- filteredListX[key] = plays[key];
- }
- }
- if (scope.search_play_name) {
+ // Only draw plays that are in the 'active' list
for (key in plays) {
- if (filteredListX[key].name.indexOf(scope.search_play_name) > 0) {
- filteredListA[key] = filteredListX[key];
+ if (plays[key].taskCount > 0) {
+ filteredListX[key] = plays[key];
}
}
- }
- else {
- filteredListA = filteredListX;
- }
-
- if (scope.search_play_status === 'failed') {
- for (key in filteredListA) {
- if (filteredListA[key].status === 'failed') {
- filteredListB[key] = plays[key];
- }
- }
- }
- else {
- filteredListB = filteredListA;
- }
-
- keys = Object.keys(filteredListB);
- keys.sort(function(a,b) { return listSort(a,b); }).reverse();
- for (idx=0; idx < scope.playsMaxRows && idx < keys.length; idx++) {
- newKeys.push(keys[idx]);
- }
- newKeys.sort(function(a,b) { return listSort(a,b); });
- idx = 0;
- while (idx < newKeys.length) {
- result.push(filteredListB[newKeys[idx]]);
- idx++;
- }
- setTimeout( function() {
- scope.$apply( function() {
- scope.plays = result;
- scope.selectedPlay = scope.activePlay;
- if (scope.liveEventProcessing) {
- $('#plays-table-detail').scrollTop($('#plays-table-detail').prop("scrollHeight"));
- }
- });
- });
- };
-}])
-
-.factory('DrawTasks', [ function() {
- return function(params) {
- var scope = params.scope,
- result = [],
- filteredListX = [],
- filteredListA = [],
- filteredListB = [],
- idx, key, keys, newKeys, tasks, t;
-
- function listSort(a,b) {
- if (parseInt(a,10) < parseInt(b,10)) {
- return -1;
- }
- if (parseInt(a,10) > parseInt(b,10)) {
- return 1;
- }
- return 0;
- }
-
- if (scope.activePlay && scope.jobData.plays[scope.activePlay]) {
-
- tasks = JSON.parse(JSON.stringify(scope.jobData.plays[scope.activePlay].tasks));
-
- // Only draw tasks that are in the 'active' list
- for (key in tasks) {
- t = tasks[key];
- if (t.reportedHosts > 0 || t.hostCount > 0 || t.successfulCount >0 || t.failedCount > 0 ||
- t.changedCount > 0 || t.skippedCount > 0 || t.unreachableCount > 0) {
- filteredListX[key] = tasks[key];
- }
- }
-
- if (scope.search_task_name) {
- for (key in filteredListX) {
- if (filteredListX[key].name.indexOf(scope.search_task_name) > 0) {
+ if (scope.search_play_name) {
+ for (key in plays) {
+ if (filteredListX[key].name.indexOf(scope.search_play_name) > 0) {
filteredListA[key] = filteredListX[key];
}
}
@@ -1311,10 +1234,10 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
filteredListA = filteredListX;
}
- if (scope.search_task_status === 'failed') {
+ if (scope.search_play_status === 'failed') {
for (key in filteredListA) {
if (filteredListA[key].status === 'failed') {
- filteredListB[key] = tasks[key];
+ filteredListB[key] = plays[key];
}
}
}
@@ -1324,8 +1247,7 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
keys = Object.keys(filteredListB);
keys.sort(function(a,b) { return listSort(a,b); }).reverse();
- newKeys = [];
- for (idx=0; result.length < scope.tasksMaxRows && idx < keys.length; idx++) {
+ for (idx=0; idx < scope.playsMaxRows && idx < keys.length; idx++) {
newKeys.push(keys[idx]);
}
newKeys.sort(function(a,b) { return listSort(a,b); });
@@ -1334,178 +1256,256 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
result.push(filteredListB[newKeys[idx]]);
idx++;
}
- }
-
- setTimeout( function() {
- scope.$apply( function() {
- scope.tasks = result;
- scope.selectedTask = scope.activeTask;
- if (scope.liveEventProcessing) {
- $('#tasks-table-detail').scrollTop($('#tasks-table-detail').prop("scrollHeight"));
- }
+ setTimeout( function() {
+ scope.$apply( function() {
+ scope.plays = result;
+ scope.selectedPlay = scope.activePlay;
+ if (scope.liveEventProcessing) {
+ $('#plays-table-detail').scrollTop($('#plays-table-detail').prop("scrollHeight"));
+ }
+ });
});
- });
+ };
+ }])
- };
-}])
+ .factory('DrawTasks', [ function() {
+ return function(params) {
+ var scope = params.scope,
+ result = [],
+ filteredListX = [],
+ filteredListA = [],
+ filteredListB = [],
+ idx, key, keys, newKeys, tasks, t;
-.factory('DrawHostResults', [ function() {
- return function(params) {
- var scope = params.scope,
- result = [],
- filteredListA = [],
- filteredListB = [],
- idx = 0,
- hostResults,
- key,
- keys;
+ function listSort(a,b) {
+ if (parseInt(a,10) < parseInt(b,10)) {
+ return -1;
+ }
+ if (parseInt(a,10) > parseInt(b,10)) {
+ return 1;
+ }
+ return 0;
+ }
- if (scope.activePlay && scope.activeTask && scope.jobData.plays[scope.activePlay] &&
- scope.jobData.plays[scope.activePlay].tasks[scope.activeTask]) {
+ if (scope.activePlay && scope.jobData.plays[scope.activePlay]) {
- hostResults = JSON.parse(JSON.stringify(scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].hostResults));
+ tasks = JSON.parse(JSON.stringify(scope.jobData.plays[scope.activePlay].tasks));
- if (scope.search_host_name) {
- for (key in hostResults) {
- if (hostResults[key].name.indexOf(scope.search_host_name) > 0) {
- filteredListA[key] = hostResults[key];
+ // Only draw tasks that are in the 'active' list
+ for (key in tasks) {
+ t = tasks[key];
+ if (t.reportedHosts > 0 || t.hostCount > 0 || t.successfulCount >0 || t.failedCount > 0 ||
+ t.changedCount > 0 || t.skippedCount > 0 || t.unreachableCount > 0) {
+ filteredListX[key] = tasks[key];
}
}
- }
- else {
- filteredListA = hostResults;
- }
- if (scope.search_host_status === 'failed' || scope.search_host_status === 'unreachable') {
- for (key in filteredListA) {
- if (filteredListA[key].status === 'failed') {
- filteredListB[key] = filteredListA[key];
+ if (scope.search_task_name) {
+ for (key in filteredListX) {
+ if (filteredListX[key].name.indexOf(scope.search_task_name) > 0) {
+ filteredListA[key] = filteredListX[key];
+ }
}
}
+ else {
+ filteredListA = filteredListX;
+ }
+
+ if (scope.search_task_status === 'failed') {
+ for (key in filteredListA) {
+ if (filteredListA[key].status === 'failed') {
+ filteredListB[key] = tasks[key];
+ }
+ }
+ }
+ else {
+ filteredListB = filteredListA;
+ }
+
+ keys = Object.keys(filteredListB);
+ keys.sort(function(a,b) { return listSort(a,b); }).reverse();
+ newKeys = [];
+ for (idx=0; result.length < scope.tasksMaxRows && idx < keys.length; idx++) {
+ newKeys.push(keys[idx]);
+ }
+ newKeys.sort(function(a,b) { return listSort(a,b); });
+ idx = 0;
+ while (idx < newKeys.length) {
+ result.push(filteredListB[newKeys[idx]]);
+ idx++;
+ }
}
- else {
- filteredListB = filteredListA;
+
+ setTimeout( function() {
+ scope.$apply( function() {
+ scope.tasks = result;
+ scope.selectedTask = scope.activeTask;
+ if (scope.liveEventProcessing) {
+ $('#tasks-table-detail').scrollTop($('#tasks-table-detail').prop("scrollHeight"));
+ }
+ });
+ });
+
+ };
+ }])
+
+ .factory('DrawHostResults', [ function() {
+ return function(params) {
+ var scope = params.scope,
+ result = [],
+ filteredListA = [],
+ filteredListB = [],
+ idx = 0,
+ hostResults,
+ key,
+ keys;
+
+ if (scope.activePlay && scope.activeTask && scope.jobData.plays[scope.activePlay] &&
+ scope.jobData.plays[scope.activePlay].tasks[scope.activeTask]) {
+
+ hostResults = JSON.parse(JSON.stringify(scope.jobData.plays[scope.activePlay].tasks[scope.activeTask].hostResults));
+
+ if (scope.search_host_name) {
+ for (key in hostResults) {
+ if (hostResults[key].name.indexOf(scope.search_host_name) > 0) {
+ filteredListA[key] = hostResults[key];
+ }
+ }
+ }
+ else {
+ filteredListA = hostResults;
+ }
+
+ if (scope.search_host_status === 'failed' || scope.search_host_status === 'unreachable') {
+ for (key in filteredListA) {
+ if (filteredListA[key].status === 'failed') {
+ filteredListB[key] = filteredListA[key];
+ }
+ }
+ }
+ else {
+ filteredListB = filteredListA;
+ }
+ keys = Object.keys(filteredListB);
+ keys.sort(function compare(a, b) {
+ if (filteredListB[a].name === filteredListB[b].name) {
+ if (filteredListB[a].counter < filteredListB[b].counter) {
+ return -1;
+ }
+ if (filteredListB[a].counter >filteredListB[b].counter) {
+ return 1;
+ }
+ } else {
+ if (filteredListB[a].name < filteredListB[b].name) {
+ return -1;
+ }
+ if (filteredListB[a].name > filteredListB[b].name) {
+ return 1;
+ }
+ }
+ // a must be equal to b
+ return 0;
+ });
+ while (idx < keys.length && result.length < scope.hostResultsMaxRows) {
+ result.push(filteredListB[keys[idx]]);
+ idx++;
+ }
}
- keys = Object.keys(filteredListB);
- keys.sort(function compare(a, b) {
- if (filteredListB[a].name === filteredListB[b].name) {
- if (filteredListB[a].counter < filteredListB[b].counter) {
- return -1;
+
+ setTimeout( function() {
+ scope.$apply( function() {
+ scope.hostResults = result;
+ if (scope.liveEventProcessing) {
+ $('#hosts-table-detail').scrollTop($('#hosts-table-detail').prop("scrollHeight"));
}
- if (filteredListB[a].counter >filteredListB[b].counter) {
- return 1;
+ });
+ });
+
+ };
+ }])
+
+ .factory('DrawHostSummaries', [ function() {
+ return function(params) {
+ var scope = params.scope,
+ result = [],
+ filteredListA = [],
+ filteredListB = [],
+ idx = 0,
+ hostSummaries,
+ key,
+ keys = Object.keys(scope.jobData.hostSummaries);
+ if (keys.length > 0) {
+ hostSummaries = JSON.parse(JSON.stringify(scope.jobData.hostSummaries));
+ if (scope.search_host_summary_name) {
+ for (key in hostSummaries) {
+ if (hostSummaries[key].name.indexOf(scope.search_host_summary_name) > 0) {
+ filteredListA[key] = hostSummaries[key];
+ }
}
- } else {
- if (filteredListB[a].name < filteredListB[b].name) {
- return -1;
+ }
+ else {
+ filteredListA = hostSummaries;
+ }
+
+ if (scope.search_host_summary_status === 'failed') {
+ for (key in filteredListA) {
+ if (filteredListA[key].status === 'failed' || filteredListA[key].status === 'unreachable') {
+ filteredListB[key] = filteredListA[key];
+ }
}
+ }
+ else {
+ filteredListB = filteredListA;
+ }
+
+ keys = Object.keys(filteredListB);
+
+ keys.sort(function(a,b) {
if (filteredListB[a].name > filteredListB[b].name) {
return 1;
}
- }
- // a must be equal to b
- return 0;
- });
- while (idx < keys.length && result.length < scope.hostResultsMaxRows) {
- result.push(filteredListB[keys[idx]]);
- idx++;
- }
- }
-
- setTimeout( function() {
- scope.$apply( function() {
- scope.hostResults = result;
- if (scope.liveEventProcessing) {
- $('#hosts-table-detail').scrollTop($('#hosts-table-detail').prop("scrollHeight"));
- }
- });
- });
-
- };
-}])
-
-.factory('DrawHostSummaries', [ function() {
- return function(params) {
- var scope = params.scope,
- result = [],
- filteredListA = [],
- filteredListB = [],
- idx = 0,
- hostSummaries,
- key,
- keys = Object.keys(scope.jobData.hostSummaries);
- if (keys.length > 0) {
- hostSummaries = JSON.parse(JSON.stringify(scope.jobData.hostSummaries));
- if (scope.search_host_summary_name) {
- for (key in hostSummaries) {
- if (hostSummaries[key].name.indexOf(scope.search_host_summary_name) > 0) {
- filteredListA[key] = hostSummaries[key];
+ if (filteredListB[a].name < filteredListB[b].name) {
+ return -1;
}
- }
- }
- else {
- filteredListA = hostSummaries;
- }
+ // a must be equal to b
+ return 0;
+ });
- if (scope.search_host_summary_status === 'failed') {
- for (key in filteredListA) {
- if (filteredListA[key].status === 'failed' || filteredListA[key].status === 'unreachable') {
- filteredListB[key] = filteredListA[key];
- }
+ while (idx < keys.length && result.length < scope.hostSummariesMaxRows) {
+ result.push(filteredListB[keys[idx]]);
+ idx++;
}
}
- else {
- filteredListB = filteredListA;
- }
-
- keys = Object.keys(filteredListB);
-
- keys.sort(function(a,b) {
- if (filteredListB[a].name > filteredListB[b].name) {
- return 1;
- }
- if (filteredListB[a].name < filteredListB[b].name) {
- return -1;
- }
- // a must be equal to b
- return 0;
+ setTimeout( function() {
+ scope.$apply( function() {
+ scope.hosts = result;
+ });
});
+ };
+ }])
- while (idx < keys.length && result.length < scope.hostSummariesMaxRows) {
- result.push(filteredListB[keys[idx]]);
- idx++;
+ .factory('UpdateDOM', ['DrawPlays', 'DrawTasks', 'DrawHostResults', 'DrawHostSummaries', 'DrawGraph',
+ function(DrawPlays, DrawTasks, DrawHostResults, DrawHostSummaries, DrawGraph) {
+ return function(params) {
+ var scope = params.scope;
+
+ if (!scope.pauseLiveEvents) {
+ DrawPlays({ scope: scope });
+ DrawTasks({ scope: scope });
+ DrawHostResults({ scope: scope });
}
- }
- setTimeout( function() {
- scope.$apply( function() {
- scope.hosts = result;
- });
- });
- };
-}])
-.factory('UpdateDOM', ['DrawPlays', 'DrawTasks', 'DrawHostResults', 'DrawHostSummaries', 'DrawGraph',
- function(DrawPlays, DrawTasks, DrawHostResults, DrawHostSummaries, DrawGraph) {
- return function(params) {
- var scope = params.scope;
+ DrawHostSummaries({ scope: scope });
- if (!scope.pauseLiveEvents) {
- DrawPlays({ scope: scope });
- DrawTasks({ scope: scope });
- DrawHostResults({ scope: scope });
- }
+ setTimeout(function() {
+ scope.playsLoading = false;
+ scope.tasksLoading = false;
+ scope.hostResultsLoading = false;
+ scope.LoadHostSummaries = false;
+ },100);
- DrawHostSummaries({ scope: scope });
-
- setTimeout(function() {
- scope.playsLoading = false;
- scope.tasksLoading = false;
- scope.hostResultsLoading = false;
- scope.LoadHostSummaries = false;
- },100);
-
- if (scope.host_summary.total > 0) {
- DrawGraph({ scope: scope, resize: true });
- }
- };
-}]);
+ if (scope.host_summary.total > 0) {
+ DrawGraph({ scope: scope, resize: true });
+ }
+ };
+ }]);
diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js
index 60ee289df1..0b08ba998e 100644
--- a/awx/ui/static/js/helpers/JobSubmission.js
+++ b/awx/ui/static/js/helpers/JobSubmission.js
@@ -4,1024 +4,1025 @@
* JobSubmission.js
*
*/
- /**
- * @ngdoc function
- * @name helpers.function:JobSubmission
- * @description
+/**
+* @ngdoc function
+* @name helpers.function:JobSubmission
+* @description
*/
+'use strict';
-
+export default
angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'CredentialFormDefinition', 'CredentialsListDefinition',
- 'LookUpHelper', 'JobSubmissionHelper', 'JobTemplateFormDefinition', 'ModalDialog', 'FormGenerator', 'JobVarsPromptFormDefinition'])
-
-.factory('LaunchJob', ['Rest', 'Wait', 'ProcessErrors', 'ToJSON', 'Empty', 'GetBasePath',
- function(Rest, Wait, ProcessErrors, ToJSON, Empty, GetBasePath) {
- return function(params) {
- var scope = params.scope,
- callback = params.callback || 'JobLaunched',
- job_launch_data = {},
- url = params.url,
- vars_url = GetBasePath('job_templates')+scope.job_template_id + '/',
- // fld,
- extra_vars;
-
- //found it easier to assume that there will be extra vars, and then check for a blank object at the end
- job_launch_data.extra_vars = {};
-
- //gather the extra vars from the job template if survey is enabled and prompt for vars is false
- if (scope.removeGetExtraVars) {
- scope.removeGetExtraVars();
- }
- scope.removeGetExtraVars = scope.$on('GetExtraVars', function() {
-
- Rest.setUrl(vars_url);
- Rest.get()
- .success(function (data) {
- if(!Empty(data.extra_vars)){
- data.extra_vars = ToJSON('json', data.extra_vars, false);
- $.each(data.extra_vars, function(key,value){
- job_launch_data.extra_vars[key] = value;
- });
- }
- scope.$emit('BuildData');
- })
- .error(function (data, status) {
- ProcessErrors(scope, data, status, { hdr: 'Error!',
- msg: 'Failed to retrieve job template extra variables.' });
- });
- });
-
- //build the data object to be sent to the job launch endpoint. Any variables gathered from the survey and the extra variables text editor are inserted into the extra_vars dict of the job_launch_data
- if (scope.removeBuildData) {
- scope.removeBuildData();
- }
- scope.removeBuildData = scope.$on('BuildData', function() {
- if(!Empty(scope.passwords_needed_to_start) && scope.passwords_needed_to_start.length>0){
- scope.passwords.forEach(function(password) {
- job_launch_data[password] = scope[password];
- scope.passwords_needed_to_start.push(password+'_confirm'); // i'm pushing these values into this array for use during the survey taker parsing
- });
- }
- if(scope.prompt_for_vars===true){
- extra_vars = ToJSON(scope.parseType, scope.extra_vars, false);
- if(!Empty(extra_vars)){
- $.each(extra_vars, function(key,value){
- job_launch_data.extra_vars[key] = value;
- });
- }
-
- }
- if(scope.survey_enabled===true){
- for (var fld in scope.job_launch_form){
- //grab only survey question fields, including those that are zero or a blank answer (for optional questions)
- if((scope[fld] || scope[fld] === 0 || scope[fld]==="") && scope.passwords_needed_to_start.indexOf(fld) === -1 && fld !== 'extra_vars'){
- job_launch_data.extra_vars[fld] = scope[fld];
- }
- }
- }
-
- // include the credential used if the user was prompted to choose a cred
- if(!Empty(scope.credential)){
- job_launch_data.credential_id = scope.credential;
- }
-
- // If the extra_vars dict is empty, we don't want to include it if we didn't prompt for anything.
- if(jQuery.isEmptyObject(job_launch_data.extra_vars)===true && scope.prompt_for_vars===false){
- delete job_launch_data.extra_vars;
- }
-
- Rest.setUrl(url);
- Rest.post(job_launch_data)
- .success(function(data) {
- Wait('stop');
- if(!$('#password-modal').is(':hidden')){
- $('#password-modal').dialog('close');
- }
- scope.$emit(callback, data);
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!',
- msg: 'Failed updating job ' + scope.job_template_id + ' with variables. POST returned: ' + status });
- });
- });
-
- // if the user has a survey and does not have 'prompt for vars' selected, then we want to
- // include the extra vars from the job template in the job launch. so first check for these conditions
- // and then overlay any survey vars over those.
- if(scope.prompt_for_vars===false && scope.survey_enabled===true){
- scope.$emit('GetExtraVars');
- }
- else {
- scope.$emit('BuildData');
- }
-
-
- };
- }])
-
-.factory('PromptForCredential', ['$location', 'Wait', 'GetBasePath', 'LookUpInit', 'JobTemplateForm', 'CredentialList', 'Rest', 'Prompt', 'ProcessErrors',
-function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList, Rest, Prompt, ProcessErrors) {
- return function(params) {
-
- var scope = params.scope,
- callback = params.callback || 'CredentialReady',
- selectionMade;
-
- Wait('stop');
- scope.credential = '';
-
- if (scope.removeShowLookupDialog) {
- scope.removeShowLookupDialog();
- }
- scope.removeShowLookupDialog = scope.$on('ShowLookupDialog', function() {
- selectionMade = function () {
- scope.$emit(callback, scope.credential);
- };
-
- LookUpInit({
- url: GetBasePath('credentials') + '?kind=ssh',
- scope: scope,
- form: JobTemplateForm(),
- current_item: null,
- list: CredentialList,
- field: 'credential',
- hdr: 'Credential Required',
- instructions: "Launching this job requires a machine credential. Please select your machine credential now or Cancel to quit.",
- postAction: selectionMade,
- input_type: 'radio'
- });
- scope.lookUpCredential();
- });
-
- if (scope.removeAlertNoCredentials) {
- scope.removeAlertNoCredentials();
- }
- scope.removeAlertNoCredentials = scope.$on('AlertNoCredentials', function() {
- var action = function () {
- $('#prompt-modal').modal('hide');
- $location.url('/credentials/add');
- };
-
- Prompt({
- hdr: 'Machine Credential Required',
- body: "