From 213f6d2af1a508150f68adc72c6210faf60db689 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Thu, 30 Oct 2014 15:36:27 -0400 Subject: [PATCH] /lib/Socket.js removed disconnect code Removing some code for attempting to disconnect a socket. we found a work around from this and are no longer using this --- awx/ui/static/js/config.js | 2 +- awx/ui/static/js/controllers/Jobs.js | 2 + awx/ui/static/js/controllers/Portal.js | 53 ++++++- awx/ui/static/js/helpers/JobSubmission.js | 2 +- awx/ui/static/js/helpers/JobTemplates.js | 142 +++++++++++++++++- awx/ui/static/js/helpers/Variables.js | 31 +++- awx/ui/static/js/lists/JobTemplates.js | 11 +- awx/ui/static/js/widgets/PortalJobs.js | 41 +++-- awx/ui/static/lib/ansible/Socket.js | 39 ++--- .../static/lib/ansible/generator-helpers.js | 2 +- awx/ui/static/partials/job_templates.html | 8 + 11 files changed, 287 insertions(+), 46 deletions(-) diff --git a/awx/ui/static/js/config.js b/awx/ui/static/js/config.js index abed710242..ce064c6eba 100644 --- a/awx/ui/static/js/config.js +++ b/awx/ui/static/js/config.js @@ -19,7 +19,7 @@ tooltip_delay: {show: 500, hide: 100}, // Default number of milliseconds to delay displaying/hiding tooltips - debug_mode: false, // Enable console logging messages + debug_mode: true, // Enable console logging messages password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong. // This value controls progress bar colors: diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index 40049a8d5c..7f95a68d0b 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -79,6 +79,8 @@ function JobsListController ($rootScope, $log, $scope, $compile, $routeParams, C queued_scope.search('queued_job'); break; case 'successful': + completed_scope.search('completed_job'); + break; case 'failed': case 'error': case 'canceled': diff --git a/awx/ui/static/js/controllers/Portal.js b/awx/ui/static/js/controllers/Portal.js index 6623fc62c4..c936f7be4a 100644 --- a/awx/ui/static/js/controllers/Portal.js +++ b/awx/ui/static/js/controllers/Portal.js @@ -31,8 +31,7 @@ function PortalController($scope, $compile, $routeParams, $rootScope, $location, var html, e, - // winHeight, - // available_height, + jobs_scope, list = PortalJobTemplateList, view= GenerateList, defaultUrl = GetBasePath('job_templates'), @@ -112,12 +111,60 @@ function PortalController($scope, $compile, $routeParams, $rootScope, $location, if ($scope.removeWidgetLoaded) { $scope.removeWidgetLoaded(); } - $scope.removeWidgetLoaded = $scope.$on('WidgetLoaded', function () { + $scope.removeWidgetLoaded = $scope.$on('WidgetLoaded', function (e, label, jobscope) { + if(label==="portal_jobs"){ + jobs_scope = jobscope; + } $('.actions-column:eq(0)').text('Launch'); $('.actions-column:eq(1)').text('Details'); $('.list-well:eq(1)').css('margin-top' , '0px'); }); + // function processEvent(event) { + // switch(event.status) { + // case 'running': + // jobs_scope.search('running_job'); + // jobs_scope.search('queued_job'); + + // break; + // case 'new': + // case 'pending': + // case 'waiting': + // jobs_scope.search('queued_job'); + + // break; + // case 'successful': + // jobs_scope.search('completed_job'); + // case 'failed': + // case 'error': + // case 'canceled': + // jobs_scope.search('completed_job'); + // jobs_scope.search('running_job'); + // jobs_scope.search('queued_job'); + // } + // } + + if ($rootScope.removeJobStatusChange) { + $rootScope.removeJobStatusChange(); + } + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function() { + jobs_scope.refreshJobs(); + // if(data.status==='pending'){ + // // $scope.refresh(); + // $('#portal-jobs').empty(); + // // $rootScope.flashMessage = null; + // PortalJobsWidget({ + // scope: $scope, + // target: 'portal-jobs', + // searchSize: 'col-lg-6 col-md-6' + // }); + // } + + + //x`processEvent(data); + + }); + $scope.submitJob = function (id) { PlaybookRun({ scope: $scope, id: id }); }; diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js index 855c3c1d43..411a1d85b8 100644 --- a/awx/ui/static/js/helpers/JobSubmission.js +++ b/awx/ui/static/js/helpers/JobSubmission.js @@ -760,7 +760,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi } scope.removePlaybookLaunchFinished = scope.$on('PlaybookLaunchFinished', function(e, data) { //var base = $location.path().replace(/^\//, '').split('/')[0]; - if(scope.portalMode===false){ + if(scope.portalMode===false || scope.$parent.portalMode===false){ $location.path('/jobs/' + data.job); } diff --git a/awx/ui/static/js/helpers/JobTemplates.js b/awx/ui/static/js/helpers/JobTemplates.js index 42dbd0435d..d5a772b4e9 100644 --- a/awx/ui/static/js/helpers/JobTemplates.js +++ b/awx/ui/static/js/helpers/JobTemplates.js @@ -19,10 +19,24 @@ angular.module('JobTemplatesHelper', ['Utilities']) * Add bits to $scope for handling callback url help * */ -.factory('CallbackHelpInit', ['$location', 'GetBasePath', function($location, GetBasePath) { + +.factory('CallbackHelpInit', ['$location', 'GetBasePath', 'Rest', 'JobTemplateForm', 'GenerateForm', '$routeParams', 'LoadBreadCrumbs', 'ProcessErrors', 'ParseTypeChange', + 'ParseVariableString', 'Empty', 'LookUpInit', 'InventoryList', 'CredentialList','ProjectList', 'RelatedSearchInit', 'RelatedPaginateInit', + function($location, GetBasePath, Rest, JobTemplateForm, GenerateForm, $routeParams, LoadBreadCrumbs, ProcessErrors,ParseTypeChange, + ParseVariableString, Empty, LookUpInit, InventoryList, CredentialList, ProjectList, RelatedSearchInit, RelatedPaginateInit) { return function(params) { - var scope = params.scope; + var scope = params.scope, + defaultUrl = GetBasePath('job_templates'), + // generator = GenerateForm, + form = JobTemplateForm(), + // loadingFinishedCount = 0, + // base = $location.path().replace(/^\//, '').split('/')[0], + master = {}, + id = $routeParams.template_id, + relatedSets = {}; + // checkSCMStatus, getPlaybooks, callback, + // choicesCount = 0; // The form uses awPopOverWatch directive to 'watch' scope.callback_help for changes. Each time the // popover is activated, a function checks the value of scope.callback_help before constructing the content. @@ -56,8 +70,132 @@ angular.module('JobTemplatesHelper', ['Utilities']) scope.example_config_key = '5a8ec154832b780b9bdef1061764ae5a'; scope.example_template_id = 'N'; scope.setCallbackHelp(); + + scope.fillJobTemplate = function(){ + // id = id || $rootScope.copy.id; + // Retrieve detail record and prepopulate the form + Rest.setUrl(defaultUrl + id); + Rest.get() + .success(function (data) { + var fld, i; + LoadBreadCrumbs({ path: '/job_templates/' + id, title: data.name }); + for (fld in form.fields) { + if (fld !== 'variables' && data[fld] !== null && data[fld] !== undefined) { + if (form.fields[fld].type === 'select') { + if (scope[fld + '_options'] && scope[fld + '_options'].length > 0) { + for (i = 0; i < scope[fld + '_options'].length; i++) { + if (data[fld] === scope[fld + '_options'][i].value) { + scope[fld] = scope[fld + '_options'][i]; + } + } + } else { + scope[fld] = data[fld]; + } + } else { + scope[fld] = data[fld]; + if(fld ==='survey_enabled'){ + // $scope.$emit('EnableSurvey', fld); + $('#job_templates_survey_enabled_chbox').attr('checked', scope[fld]); + if(Empty(data.summary_fields.survey)) { + $('#job_templates_delete_survey_btn').hide(); + $('#job_templates_edit_survey_btn').hide(); + $('#job_templates_create_survey_btn').show(); + } + else{ + $('#job_templates_delete_survey_btn').show(); + $('#job_templates_edit_survey_btn').show(); + $('#job_templates_create_survey_btn').hide(); + scope.survey_exists = true; + } + } + } + master[fld] = scope[fld]; + } + if (fld === 'variables') { + // Parse extra_vars, converting to YAML. + scope.variables = ParseVariableString(data.extra_vars); + master.variables = scope.variables; + } + if (form.fields[fld].type === 'lookup' && 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] = + scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField]; + } + } + + scope.url = data.url; + + scope.ask_variables_on_launch = (data.ask_variables_on_launch) ? 'true' : 'false'; + master.ask_variables_on_launch = scope.ask_variables_on_launch; + + relatedSets = form.relatedSets(data.related); + + if (data.host_config_key) { + scope.example_config_key = data.host_config_key; + } + scope.example_template_id = id; + scope.setCallbackHelp(); + + scope.callback_url = scope.callback_server_path + ((data.related.callback) ? data.related.callback : + GetBasePath('job_templates') + id + '/callback/'); + master.callback_url = scope.callback_url; + + LookUpInit({ + scope: scope, + form: form, + current_item: data.inventory, + list: InventoryList, + field: 'inventory', + input_type: "radio" + }); + + LookUpInit({ + url: GetBasePath('credentials') + '?kind=ssh', + scope: scope, + form: form, + current_item: data.credential, + list: CredentialList, + field: 'credential', + hdr: 'Select Machine Credential', + input_type: "radio" + }); + + LookUpInit({ + scope: scope, + form: form, + current_item: data.project, + list: ProjectList, + field: 'project', + input_type: "radio" + }); + + RelatedSearchInit({ + scope: scope, + form: form, + relatedSets: relatedSets + }); + + RelatedPaginateInit({ + scope: scope, + relatedSets: relatedSets + }); + + + scope.$emit('jobTemplateLoaded', data.related.cloud_credential); + }) + .error(function (data, status) { + ProcessErrors(scope, data, status, form, { + hdr: 'Error!', + msg: 'Failed to retrieve job template: ' + $routeParams.template_id + '. GET status: ' + status + }); + }); + }; + }; + + }]); diff --git a/awx/ui/static/js/helpers/Variables.js b/awx/ui/static/js/helpers/Variables.js index c9a613b7e7..70d74161d7 100644 --- a/awx/ui/static/js/helpers/Variables.js +++ b/awx/ui/static/js/helpers/Variables.js @@ -32,6 +32,7 @@ angular.module('VariablesHelper', ['Utilities']) json_obj = JSON.parse(variables); json_obj = SortVariables(json_obj); result = jsyaml.safeDump(json_obj); + } catch (e) { $log.info('Attempt to parse extra_vars as JSON failed. Attempting to parse as YAML'); @@ -56,6 +57,7 @@ angular.module('VariablesHelper', ['Utilities']) try { json_obj = SortVariables(variables); result = jsyaml.safeDump(json_obj); + // result = variables; } catch(e3) { ProcessErrors(null, variables, e3.message, null, { hdr: 'Error!', @@ -78,7 +80,11 @@ angular.module('VariablesHelper', ['Utilities']) **/ .factory('ToJSON', ['$log', 'ProcessErrors', function($log, ProcessErrors) { return function(parseType, variables, stringify, reviver) { - var json_data, result; + var json_data, + result; + // bracketVar, + // key, + // lines, i, newVars = []; if (parseType === 'json') { try { //parse a JSON string @@ -97,7 +103,30 @@ angular.module('VariablesHelper', ['Utilities']) } } else { try { + // if(variables.indexOf('{{')>-1){ + // lines = variables.split(/\n/); + // for(i=0; i-1){ + // lines[i] = lines[i].replace('{{', '"{{'); + // // lines[i] = lines[i].replace(lines[i].lastIndexOf('}}'), '}}"'); + // lines[i] = lines[i]+'"'; + // // newVars = newVars+ lines[i]; + // newVars.push(lines[i]) + + // } + // } + // json_data = jsyaml.load(newVars.toString()); + + // bracketVar = variables.substr(variables.indexOf('{{'), variables.indexOf('}}')); + // bracketVar = bracketVar.trimRight(); + // key = variables.substr(0, variables.indexOf(':')); + // json_data = jsyaml.load(variables); + // json_data[key] = bracketVar; + // } + // else json_data = jsyaml.load(variables); + + } catch(e) { json_data = {}; diff --git a/awx/ui/static/js/lists/JobTemplates.js b/awx/ui/static/js/lists/JobTemplates.js index 83301dceea..a17314e4fa 100644 --- a/awx/ui/static/js/lists/JobTemplates.js +++ b/awx/ui/static/js/lists/JobTemplates.js @@ -64,7 +64,6 @@ angular.module('JobTemplatesListDefinition', []) ngHref: '#/job_templates/{{ job_template.id }}/schedules', awToolTip: 'Schedule future job template runs', dataPlacement: 'top', - ngHide: 'portalMode===true' }, edit: { label: 'Edit', @@ -72,7 +71,6 @@ angular.module('JobTemplatesListDefinition', []) awToolTip: 'Edit template', "class": 'btn-default btn-xs', dataPlacement: 'top', - ngHide: 'portalMode===true' }, "delete": { label: 'Delete', @@ -80,7 +78,14 @@ angular.module('JobTemplatesListDefinition', []) "class": 'btn-danger btn-xs', awToolTip: 'Delete template', dataPlacement: 'top', - ngHide: 'portalMode===true' + }, + copy: { + label: 'Copy', + ngClick: "copyJobTemplate(job_template.id, job_template.name)", + "class": 'btn-danger btn-xs', + awToolTip: 'Copy template', + dataPlacement: 'top', + } } }); diff --git a/awx/ui/static/js/widgets/PortalJobs.js b/awx/ui/static/js/widgets/PortalJobs.js index 94a3a34fa0..3b2a65c7dd 100644 --- a/awx/ui/static/js/widgets/PortalJobs.js +++ b/awx/ui/static/js/widgets/PortalJobs.js @@ -19,6 +19,9 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities']) choicesCount = 0, listCount = 0, jobs_scope = scope.$new(true), + // completed_scope = scope.$new(true), + // running_scope = scope.$new(true), + // queued_scope = scope.$new(true), // scheduled_scope = scope.$new(true), max_rows, html, e; @@ -56,7 +59,7 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities']) listCount++; if (listCount === 1) { //api_complete = true; - scope.$emit('WidgetLoaded', jobs_scope); + scope.$emit('WidgetLoaded', "portal_jobs", jobs_scope); } }); @@ -75,16 +78,36 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities']) id: 'active-jobs', url: GetBasePath('unified_jobs') + '?status__in=running,completed,failed,successful,error,canceled', pageSize: max_rows, - spinner: false + spinner: true }); - // LoadSchedulesScope({ + + // completed_scope.showJobType = true; + // LoadJobsScope({ // parent_scope: scope, - // scope: scheduled_scope, - // list: ScheduledJobsList, - // id: 'scheduled-jobs-tab', - // url: GetBasePath('schedules') + '?next_run__isnull=false', - // pageSize: max_rows, - // spinner: false + // scope: completed_scope, + // list: PortalJobsList, + // id: 'active-jobs', + // url: GetBasePath('unified_jobs') + '?or__status=successful&or__status=failed&or__status=error&or__status=canceled', + // // searchParams: search_params, + // pageSize: max_rows + // }); + + // LoadJobsScope({ + // parent_scope: scope, + // scope: running_scope, + // list: PortalJobsList, + // id: 'active-jobs', + // url: GetBasePath('unified_jobs') + '?status=running', + // pageSize: max_rows + // }); + + // LoadJobsScope({ + // parent_scope: scope, + // scope: queued_scope, + // list: PortalJobsList, + // id: 'active-jobs', + // url: GetBasePath('unified_jobs') + '?or__status=pending&or__status=waiting&or__status=new', + // pageSize: max_rows // }); $(window).resize(_.debounce(function() { diff --git a/awx/ui/static/lib/ansible/Socket.js b/awx/ui/static/lib/ansible/Socket.js index e2683cb6fc..f3c991ddc6 100644 --- a/awx/ui/static/lib/ansible/Socket.js +++ b/awx/ui/static/lib/ansible/Socket.js @@ -28,7 +28,8 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) endpoint = params.endpoint, protocol = $location.protocol(), config, socketPort, - handshakeData, url; + // handshakeData, + url; // Since some pages are opened in a new tab, we might get here before AnsibleConfig is available. // In that case, load from local storage. @@ -70,19 +71,20 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) // We have a valid session token, so attempt socket connection $log.debug('Socket connecting to: ' + url); self.scope.socket_url = url; - handshakeData = { - headers: { - 'Authorization': 'Token ' + token, - 'X-Auth-Token': 'Token ' + token - } - }; + // handshakeData = { + // headers: { + // 'Authorization': 'Token ' + token, + // 'X-Auth-Token': 'Token ' + token + // } + // } + self.socket = io.connect(url, { - // headers: - // { - // 'Authorization': 'Token ' + token, - // 'X-Auth-Token': 'Token ' + token - // }, + headers: + { + 'Authorization': 'Token ' + token, + 'X-Auth-Token': 'Token ' + token + }, 'connect timeout': 3000, 'try multiple transports': false, 'max reconneciton attemps': 3, @@ -180,19 +182,6 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) }); }); }, - disconnect: function(){ - var self = this; - $rootScope.disconnect_timer = setInterval(function(){disconnectSocket();}, 1000); - - function disconnectSocket() { - self.socket.socket.disconnect(); - window.clearInterval($rootScope.disconnect_timer); - } - // self.scope.$apply(function () { - - // }); - - }, emit: function (eventName, data, callback) { var self = this; self.socket.emit(eventName, data, function () { diff --git a/awx/ui/static/lib/ansible/generator-helpers.js b/awx/ui/static/lib/ansible/generator-helpers.js index d55cb45f01..9036ff3911 100644 --- a/awx/ui/static/lib/ansible/generator-helpers.js +++ b/awx/ui/static/lib/ansible/generator-helpers.js @@ -159,7 +159,7 @@ angular.module('GeneratorHelpers', []) icon = 'fa-list-ul'; break; case 'copy': - icon = "fa-cut"; + icon = "fa-copy"; break; } icon += (size) ? " " + size : ""; diff --git a/awx/ui/static/partials/job_templates.html b/awx/ui/static/partials/job_templates.html index 2d5e9ed45b..df51fc051c 100644 --- a/awx/ui/static/partials/job_templates.html +++ b/awx/ui/static/partials/job_templates.html @@ -3,4 +3,12 @@
+ + \ No newline at end of file