From b10dc6d4ff3e464a9578dcc2700d064c24305f0c Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Tue, 27 Mar 2018 12:39:30 -0400 Subject: [PATCH] wip - integrate adhoc and workflow --- .../features/output/details.directive.js | 37 +++++++++------ .../features/output/index.controller.js | 7 +-- awx/ui/client/features/output/index.js | 34 +++++++------- awx/ui/client/features/output/index.view.html | 2 +- .../client/features/output/stats.directive.js | 5 +-- .../client/features/output/stats.partial.html | 45 +++++++++++++++++-- .../relaunchButton.component.js | 6 ++- awx/ui/client/lib/models/AdHocCommand.js | 5 +++ .../src/shared/socket/socket.service.js | 2 +- .../workflow-chart.directive.js | 6 +-- 10 files changed, 103 insertions(+), 46 deletions(-) diff --git a/awx/ui/client/features/output/details.directive.js b/awx/ui/client/features/output/details.directive.js index 22c66d12cc..7f36ee84e6 100644 --- a/awx/ui/client/features/output/details.directive.js +++ b/awx/ui/client/features/output/details.directive.js @@ -12,6 +12,8 @@ let resource; let strings; let wait; +let vm; + function mapChoices (choices) { if (!choices) return {}; return Object.assign(...choices.map(([k, v]) => ({ [k]: v }))); @@ -33,7 +35,7 @@ function getStatusDetails (status) { return { label, icon, value }; } -function getStartTimeDetails (started) { +function getStartDetails (started) { const unfiltered = started || resource.model.get('started'); const label = 'Started'; @@ -49,7 +51,7 @@ function getStartTimeDetails (started) { return { label, value }; } -function getFinishTimeDetails (finished) { +function getFinishDetails (finished) { const unfiltered = finished || resource.model.get('finished'); const label = 'Finished'; @@ -416,6 +418,17 @@ function cancelJob () { function deleteJob () {} +function handleSocketEvent (data) { + const project = resource.model.get('project'); + + if (resource.model.get('id') === data.unified_job_id) { + vm.status = getStatusDetails(data.status); + } else if (project && (project === data.project_id)) { + vm.project.update = vm.project.update || {}; + vm.project.update.status = data.status; + } +}; + function AtDetailsController ( _$http_, _$filter_, @@ -427,7 +440,7 @@ function AtDetailsController ( ParseTypeChange, ParseVariableString, ) { - const vm = this || {}; + vm = this || {}; $http = _$http_; $filter = _$filter_; @@ -444,8 +457,8 @@ function AtDetailsController ( resource = $scope.resource; // eslint-disable-line prefer-destructuring vm.status = getStatusDetails(); - vm.started = getStartTimeDetails(); - vm.finished = getFinishTimeDetails(); + vm.started = getStartDetails(); + vm.finished = getFinishDetails(); vm.jobType = getJobTypeDetails(); vm.jobTemplate = getJobTemplateDetails(); vm.sourceWorkflowJob = getSourceWorkflowJobDetails(); @@ -488,13 +501,10 @@ function AtDetailsController ( vm.deleteJob = deleteJob; vm.toggleLabels = toggleLabels; - const observe = (key, transform) => { - $scope.$watch(key, value => { vm[key] = transform(value); }); - }; + $scope.$watch('started', value => { vm.started = getStartDetails(value); }); + $scope.$watch('finished', value => { vm.finished = getFinishDetails(value); }); - observe('finished', getFinishTimeDetails); - observe('status', getStatusDetails); - observe('started', getStartTimeDetails); + $scope.$on(resource.ws.status, (e, data) => handleSocketEvent(data)); }; } @@ -525,10 +535,9 @@ function atDetails () { link: atDetailsLink, controller: AtDetailsController, scope: { - resource: '=', - status: '=', - started: '=', finished: '=', + started: '=', + resource: '=', }, }; } diff --git a/awx/ui/client/features/output/index.controller.js b/awx/ui/client/features/output/index.controller.js index 45581b876e..df2a06034c 100644 --- a/awx/ui/client/features/output/index.controller.js +++ b/awx/ui/client/features/output/index.controller.js @@ -84,12 +84,14 @@ function JobsIndexController ( eventCounter = null; statsEvent = resource.stats; + // Panel Title + vm.title = resource.model.get('name'); + // Status Bar vm.status = { stats: statsEvent, elapsed: resource.model.get('elapsed'), running: Boolean(resource.model.get('started')) && !resource.model.get('finished'), - title: resource.model.get('name'), plays: null, tasks: null, }; @@ -99,7 +101,6 @@ function JobsIndexController ( resource, started: resource.model.get('started'), finished: resource.model.get('finished'), - status: resource.model.get('status'), }; render.requestAnimationFrame(() => init(!vm.status.running)); @@ -143,7 +144,7 @@ function init (pageMode) { } }); - $scope.$on(resource.ws.namespace, handleSocketEvent); + $scope.$on(resource.ws.events, handleSocketEvent); if (pageMode) { next(); diff --git a/awx/ui/client/features/output/index.js b/awx/ui/client/features/output/index.js index ec1e756f69..62155aed1e 100644 --- a/awx/ui/client/features/output/index.js +++ b/awx/ui/client/features/output/index.js @@ -32,6 +32,7 @@ function resolveResource ( Wait ) { const { id, type, job_event_search } = $stateParams; // eslint-disable-line camelcase + const { name, key } = getWebSocketResource(type); let Resource; let related = 'events'; @@ -50,9 +51,9 @@ function resolveResource ( case 'system': Resource = SystemJob; break; - case 'workflow': - Resource = WorkflowJob; - break; + // case 'workflow': + // todo: integrate workflow chart components into this view + // break; default: // Redirect return null; @@ -87,7 +88,8 @@ function resolveResource ( model, related, ws: { - namespace: `${WS_PREFIX}-${getWebSocketResource(type).key}-${id}` + events: `${WS_PREFIX}-${key}-${id}`, + status: `${WS_PREFIX}-${name}`, }, page: { cache: PAGE_CACHE, @@ -99,22 +101,23 @@ function resolveResource ( .finally(() => Wait('stop')); } -function resolveWebSocketConnection (SocketService, $stateParams) { +function resolveWebSocketConnection ($stateParams, SocketService) { const { type, id } = $stateParams; - const resource = getWebSocketResource(type); + const { name, key } = getWebSocketResource(type); const state = { data: { socket: { groups: { - [resource.name]: ['status_changed', 'summary'], - [resource.key]: [] + [name]: ['status_changed', 'summary'], + [key]: [] } } } }; - SocketService.addStateResolve(state, id); + return SocketService.addStateResolve(state, id); + } function resolveBreadcrumb (strings) { @@ -129,19 +132,19 @@ function getWebSocketResource (type) { switch (type) { case 'system': - name = 'system_jobs'; + name = 'jobs'; key = 'system_job_events'; break; case 'project': - name = 'project_updates'; + name = 'jobs'; key = 'project_update_events'; break; case 'command': - name = 'ad_hoc_commands'; + name = 'jobs'; key = 'ad_hoc_command_events'; break; case 'inventory': - name = 'inventory_updates'; + name = 'jobs'; key = 'inventory_update_events'; break; case 'playbook': @@ -188,10 +191,10 @@ function JobsRun ($stateRegistry) { resolveBreadcrumb ], webSocketConnection: [ - 'SocketService', '$stateParams', + 'SocketService', resolveWebSocketConnection - ] + ], }, }; @@ -208,6 +211,7 @@ angular .service('JobStrings', Strings) .service('JobPageService', PageService) .service('JobScrollService', ScrollService) + .service('JobRenderService', RenderService) .service('JobEventEngine', EngineService) .directive('atDetails', DetailsDirective) .directive('atSearchKey', SearchKeyDirective) diff --git a/awx/ui/client/features/output/index.view.html b/awx/ui/client/features/output/index.view.html index 084ef7deda..4dde59725a 100644 --- a/awx/ui/client/features/output/index.view.html +++ b/awx/ui/client/features/output/index.view.html @@ -3,7 +3,6 @@ @@ -13,6 +12,7 @@
+
{{ vm.title }}
{ - const { elapsed, running, stats, title, plays, tasks } = scope; - - vm.title = title; + const { elapsed, running, stats, plays, tasks } = scope; vm.plays = plays; vm.tasks = tasks; @@ -99,7 +97,6 @@ function atStats () { elapsed: '=', running: '=', stats: '=', - title: '=', plays: '=', tasks: '=', }, diff --git a/awx/ui/client/features/output/stats.partial.html b/awx/ui/client/features/output/stats.partial.html index 6608a23262..97e12223ec 100644 --- a/awx/ui/client/features/output/stats.partial.html +++ b/awx/ui/client/features/output/stats.partial.html @@ -1,3 +1,42 @@ + +
+ plays + ... + {{ vm.plays }} + + tasks + ... + {{ vm.tasks }} + + hosts + ... + {{ vm.hosts }} + + elapsed + ... + + {{ vm.elapsed * 1000 | duration: "hh:mm:ss" }} + + + + + + + +
+
-
+ aw-tool-tip="{{ vm.tooltips.dark }}" + data-tip-watch="vm.tooltips.dark">
{ jobObj.getRelaunch({ id: vm.job.id @@ -182,7 +184,7 @@ function atRelaunchCtrl ( project.postUpdate(vm.job.project) .then((postUpdateRes) => { if (!$state.includes('jobs')) { - $state.go('scmUpdateStdout', { id: postUpdateRes.data.id }, { reload: true }); + $state.go('jobz', { id: postUpdateRes.data.id, type: 'project' }, { reload: true }); } }); } else { @@ -218,7 +220,7 @@ function atRelaunchCtrl ( id: vm.job.id }).then((launchRes) => { if (!$state.includes('jobs')) { - $state.go('adHocJobStdout', { id: launchRes.data.id }, { reload: true }); + $state.go('jobz', { id: launchRes.data.id, type: 'command' }, { reload: true }); } }); } diff --git a/awx/ui/client/lib/models/AdHocCommand.js b/awx/ui/client/lib/models/AdHocCommand.js index 9f259a929a..7bea2677ac 100644 --- a/awx/ui/client/lib/models/AdHocCommand.js +++ b/awx/ui/client/lib/models/AdHocCommand.js @@ -19,12 +19,17 @@ function postRelaunch (params) { return $http(req); } +function getStats () { + return Promise.resolve(null); +} + function AdHocCommandModel (method, resource, config) { BaseModel.call(this, 'ad_hoc_commands'); this.Constructor = AdHocCommandModel; this.postRelaunch = postRelaunch.bind(this); this.getRelaunch = getRelaunch.bind(this); + this.getStats = getStats.bind(this); return this.create(method, resource, config); } diff --git a/awx/ui/client/src/shared/socket/socket.service.js b/awx/ui/client/src/shared/socket/socket.service.js index b26dae58d7..0e50b0e671 100644 --- a/awx/ui/client/src/shared/socket/socket.service.js +++ b/awx/ui/client/src/shared/socket/socket.service.js @@ -216,7 +216,7 @@ export default // socket-enabled AND socket-disabled, and whether the $state // requires a subscribe or an unsubscribe var self = this; - socketPromise.promise.then(function(){ + return socketPromise.promise.then(function(){ if(!state.data || !state.data.socket){ _.merge(state.data, {socket: {groups: {}}}); self.unsubscribe(state); diff --git a/awx/ui/client/src/templates/workflows/workflow-chart/workflow-chart.directive.js b/awx/ui/client/src/templates/workflows/workflow-chart/workflow-chart.directive.js index 70bab1727b..7cfc754d86 100644 --- a/awx/ui/client/src/templates/workflows/workflow-chart/workflow-chart.directive.js +++ b/awx/ui/client/src/templates/workflows/workflow-chart/workflow-chart.directive.js @@ -898,13 +898,13 @@ export default ['$state','moment', '$timeout', '$window', '$filter', 'Rest', 'Ge let goToJobResults = function(job_type) { if(job_type === 'job') { - $state.go('jobResult', {id: d.job.id}); + $state.go('jobz', {id: d.job.id, type: 'playbook'}); } else if(job_type === 'inventory_update') { - $state.go('inventorySyncStdout', {id: d.job.id}); + $state.go('jobz', {id: d.job.id, type: 'inventory'}); } else if(job_type === 'project_update') { - $state.go('scmUpdateStdout', {id: d.job.id}); + $state.go('jobz', {id: d.job.id, type: 'project'}); } };