Merge pull request #1647 from jakemcdermott/fix-1534-and-713

add persistent jobs->results filtering, prior version compatibility for job urls
This commit is contained in:
Jake McDermott 2018-05-02 18:42:54 -04:00 committed by GitHub
commit 5b3bfa31df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 139 additions and 82 deletions

View File

@ -3,8 +3,7 @@
*
* All Rights Reserved
************************************************ */
const mapChoices = choices => Object
.assign(...choices.map(([k, v]) => ({ [k]: v })));
const mapChoices = choices => Object.assign(...choices.map(([k, v]) => ({ [k]: v })));
function ListJobsController (
$scope,
@ -61,37 +60,36 @@ function ListJobsController (
vm.emptyListReason = strings.get('list.NO_RUNNING');
}
vm.jobTypes = mapChoices(unifiedJob
.options('actions.GET.type.choices'));
vm.jobTypes = mapChoices(unifiedJob.options('actions.GET.type.choices'));
vm.getLink = ({ type, id }) => {
let link;
vm.getSref = ({ type, id }) => {
let sref;
switch (type) {
case 'job':
link = `/#/jobz/playbook/${id}`;
sref = `output({type: 'playbook', id: ${id}})`;
break;
case 'ad_hoc_command':
link = `/#/jobz/command/${id}`;
sref = `output({type: 'command', id: ${id}})`;
break;
case 'system_job':
link = `/#/jobz/system/${id}`;
sref = `output({type: 'system', id: ${id}})`;
break;
case 'project_update':
link = `/#/jobz/project/${id}`;
sref = `output({type: 'project', id: ${id}})`;
break;
case 'inventory_update':
link = `/#/jobz/inventory/${id}`;
sref = `output({type: 'inventory', id: ${id}})`;
break;
case 'workflow_job':
link = `/#/workflows/${id}`;
sref = `workflowResults({id: ${id}})`;
break;
default:
link = '';
sref = '';
break;
}
return link;
return sref;
};
vm.deleteJob = (job) => {

View File

@ -21,7 +21,7 @@
status="{{ job.status }}"
status-tip="Job {{job.status}}. Click for details."
header-value="{{ job.name }}"
header-link="{{ vm.getLink(job) }}"
header-state="{{ vm.getSref(job) }}"
header-tag="{{ vm.jobTypes[job.type] }}">
</at-row-item>
<div class="at-Row--inline">

View File

@ -303,7 +303,7 @@
grid-template-rows: minmax(500px, ~"calc(100vh - 140px)");
.at-Panel {
overflow-y: scroll;
overflow-y: auto;
}
}

View File

@ -227,7 +227,7 @@ function getProjectUpdateDetails (updateId) {
return null;
}
const link = `/#/jobz/project/${jobId}`;
const link = `/#/jobs/project/${jobId}`;
const tooltip = strings.get('resourceTooltips.PROJECT_UPDATE');
return { link, tooltip };
@ -510,8 +510,7 @@ function AtJobDetailsController (
_strings_,
_status_,
_wait_,
ParseTypeChange,
ParseVariableString,
_parse_,
) {
vm = this || {};
@ -520,7 +519,7 @@ function AtJobDetailsController (
$state = _$state_;
error = _error_;
parse = ParseVariableString;
parse = _parse_;
prompt = _prompt_;
strings = _strings_;
status = _status_;
@ -589,7 +588,6 @@ AtJobDetailsController.$inject = [
'JobStrings',
'JobStatusService',
'Wait',
'ParseTypeChange',
'ParseVariableString',
];

View File

@ -40,19 +40,19 @@
<div class="HostEvent-nav">
<!-- view navigation buttons -->
<button ui-sref="jobz.host-event.json" type="button"
<button ui-sref="output.host-event.json" type="button"
class="btn btn-sm btn-default HostEvent-tab"
ng-class="{'HostEvent-tab--selected' : isActiveState('jobz.host-event.json')}">
ng-class="{'HostEvent-tab--selected' : isActiveState('output.host-event.json')}">
JSON
</button>
<button ng-if="stdout" ui-sref="jobz.host-event.stdout"
<button ng-if="stdout" ui-sref="output.host-event.stdout"
type="button" class="btn btn-sm btn-default HostEvent-tab"
ng-class="{'HostEvent-tab--selected' : isActiveState('jobz.host-event.stdout')}">
ng-class="{'HostEvent-tab--selected' : isActiveState('output.host-event.stdout')}">
Standard Out
</button>
<button ng-if="stderr" ui-sref="jobz.host-event.stderr"
<button ng-if="stderr" ui-sref="output.host-event.stderr"
type="button" class="btn btn-sm btn-default HostEvent-tab"
ng-class="{'HostEvent-tab--selected' : isActiveState('jobz.host-event.stderr')}">
ng-class="{'HostEvent-tab--selected' : isActiveState('output.host-event.stderr')}">
Standard Error
</button>

View File

@ -57,7 +57,7 @@ function HostEventsController (
$scope.stdout = event[0];// eslint-disable-line prefer-destructuring
}
// instantiate Codemirror
if ($state.current.name === 'jobz.host-event.json') {
if ($state.current.name === 'output.host-event.json') {
try {
if (_.has(hostEvent.event_data, 'res')) {
initCodeMirror(
@ -73,14 +73,14 @@ function HostEventsController (
// element with id HostEvent-codemirror is not the view
// controlled by this instance of HostEventController
}
} else if ($state.current.name === 'jobz.host-event.stdout') {
} else if ($state.current.name === 'output.host-event.stdout') {
try {
resize();
} catch (err) {
// element with id HostEvent-codemirror is not the view
// controlled by this instance of HostEventController
}
} else if ($state.current.name === 'jobz.host-event.stderr') {
} else if ($state.current.name === 'output.host-event.stderr') {
try {
resize();
} catch (err) {
@ -98,11 +98,11 @@ function HostEventsController (
});
function resize () {
if ($state.current.name === 'jobz.host-event.json') {
if ($state.current.name === 'output.host-event.json') {
const editor = $('.CodeMirror')[0].CodeMirror;
const height = $('.modal-dialog').height() - $('.HostEvent-header').height() - $('.HostEvent-details').height() - $('.HostEvent-nav').height() - $('.HostEvent-controls').height() - 120;
editor.setSize('100%', height);
} else if ($state.current.name === 'jobz.host-event.stdout' || $state.current.name === 'jobz.host-event.stderr') {
} else if ($state.current.name === 'output.host-event.stdout' || $state.current.name === 'output.host-event.stderr') {
const height = $('.modal-dialog').height() - $('.HostEvent-header').height() - $('.HostEvent-details').height() - $('.HostEvent-nav').height() - $('.HostEvent-controls').height() - 120;
$('.HostEvent-stdout').width('100%');
$('.HostEvent-stdout').height(height);
@ -154,7 +154,7 @@ function HostEventsController (
// Unbind the listener so it doesn't fire when we close the modal via navigation
$('#HostEvent').off('hidden.bs.modal');
$('#HostEvent').modal('hide');
$state.go('jobz');
$state.go('output');
}
$scope.init = init;
$scope.init();

View File

@ -25,7 +25,7 @@ HostEventResolve.$inject = [
];
const hostEventModal = {
name: 'jobz.host-event',
name: 'output.host-event',
url: '/host-event/:eventId',
controller: 'HostEventsController',
templateUrl: HostEventModalTemplate,
@ -40,7 +40,7 @@ const hostEventModal = {
};
const hostEventJson = {
name: 'jobz.host-event.json',
name: 'output.host-event.json',
url: '/json',
controller: 'HostEventsController',
templateUrl: HostEventCodeMirrorTemplate,
@ -50,7 +50,7 @@ const hostEventJson = {
};
const hostEventStdout = {
name: 'jobz.host-event.stdout',
name: 'output.host-event.stdout',
url: '/stdout',
controller: 'HostEventsController',
templateUrl: HostEventStdoutTemplate,
@ -60,7 +60,7 @@ const hostEventStdout = {
};
const hostEventStderr = {
name: 'jobz.host-event.stderr',
name: 'output.host-event.stderr',
url: '/stderr',
controller: 'HostEventsController',
templateUrl: HostEventStderrTemplate,

View File

@ -8,6 +8,7 @@ import RenderService from '~features/output/render.service';
import ScrollService from '~features/output/scroll.service';
import EngineService from '~features/output/engine.service';
import StatusService from '~features/output/status.service';
import LegacyRedirect from '~features/output/legacy.route';
import DetailsDirective from '~features/output/details.directive';
import SearchDirective from '~features/output/search.directive';
@ -125,12 +126,6 @@ function resolveWebSocketConnection ($stateParams, SocketService) {
return SocketService.addStateResolve(state, id);
}
function resolveBreadcrumb (strings) {
return {
label: strings.get('state.TITLE')
};
}
function getWebSocketResource (type) {
let name;
let key;
@ -163,11 +158,15 @@ function getWebSocketResource (type) {
return { name, key };
}
function JobsRun ($stateRegistry) {
function JobsRun ($stateRegistry, strings) {
const parent = 'jobs';
const ncyBreadcrumb = { parent, label: strings.get('state.BREADCRUMB_DEFAULT') };
const state = {
name: 'jobz',
url: '/jobz/:type/:id?job_event_search',
route: '/jobz/:type/:id?job_event_search',
url: '/:type/:id?job_event_search',
name: 'output',
parent,
ncyBreadcrumb,
data: {
activityStream: false,
},
@ -179,6 +178,11 @@ function JobsRun ($stateRegistry) {
}
},
resolve: {
webSocketConnection: [
'$stateParams',
'SocketService',
resolveWebSocketConnection
],
resource: [
'JobModel',
'ProjectUpdateModel',
@ -191,14 +195,11 @@ function JobsRun ($stateRegistry) {
'Wait',
resolveResource
],
ncyBreadcrumb: [
'JobStrings',
resolveBreadcrumb
],
webSocketConnection: [
'$stateParams',
'SocketService',
resolveWebSocketConnection
breadcrumbLabel: [
'resource',
({ model }) => {
ncyBreadcrumb.label = `${model.get('id')} - ${model.get('name')}`;
}
],
},
};
@ -206,7 +207,7 @@ function JobsRun ($stateRegistry) {
$stateRegistry.register(state);
}
JobsRun.$inject = ['$stateRegistry'];
JobsRun.$inject = ['$stateRegistry', 'JobStrings'];
angular
.module(MODULE_NAME, [
@ -223,6 +224,7 @@ angular
.directive('atJobDetails', DetailsDirective)
.directive('atJobSearch', SearchDirective)
.directive('atJobStats', StatsDirective)
.run(JobsRun);
.run(JobsRun)
.run(LegacyRedirect);
export default MODULE_NAME;

View File

@ -5,7 +5,7 @@ function JobsStrings (BaseString) {
const ns = this.jobs;
ns.state = {
TITLE: t.s('JOBZ')
BREADCRUMB_DEFAULT: t.s('RESULTS'),
};
ns.status = {

View File

@ -0,0 +1,55 @@
function LegacyRedirect ($stateRegistry) {
const destination = 'output';
const routes = [
{
name: 'legacyJobResult',
url: '/jobs/:id?job_event_search',
redirectTo: (trans) => {
const {
id,
job_event_search // eslint-disable-line camelcase
} = trans.params();
return { state: destination, params: { type: 'playbook', id, job_event_search } };
}
},
{
name: 'legacyAdHocJobStdout',
url: '/ad_hoc_commands/:id',
redirectTo: (trans) => {
const { id } = trans.params();
return { state: destination, params: { type: 'command', id } };
}
},
{
name: 'legacyInventorySyncStdout',
url: '/inventory_sync/:id',
redirectTo: (trans) => {
const { id } = trans.params();
return { state: destination, params: { type: 'inventory', id } };
}
},
{
name: 'legacyManagementJobStdout',
url: '/management_jobs/:id',
redirectTo: (trans) => {
const { id } = trans.params();
return { state: destination, params: { type: 'system', id } };
}
},
{
name: 'legacyScmUpdateStdout',
url: '/scm_update/:id',
redirectTo: (trans) => {
const { id } = trans.params();
return { state: destination, params: { type: 'project', id } };
}
},
];
routes.forEach(state => $stateRegistry.register(state));
}
LegacyRedirect.$inject = ['$stateRegistry'];
export default LegacyRedirect;

View File

@ -183,7 +183,7 @@ function JobRenderService ($q, $sce, $window) {
}
if (current.isHost) {
tdEvent = `<td class="at-Stdout-event--host" ui-sref="jobz.host-event.json({eventId: ${current.id}, taskUuid: '${current.uuid}' })"><span ng-non-bindable>${content}</span></td>`;
tdEvent = `<td class="at-Stdout-event--host" ui-sref="output.host-event.json({eventId: ${current.id}, taskUuid: '${current.uuid}' })"><span ng-non-bindable>${content}</span></td>`;
}
if (current.time && current.line === ln) {

View File

@ -41,7 +41,7 @@ function atLaunchTemplateCtrl (
selectedJobTemplate
.postLaunch({ id: vm.template.id })
.then(({ data }) => {
$state.go('jobz', { id: data.job, type: 'playbook' }, { reload: true });
$state.go('output', { id: data.job, type: 'playbook' }, { reload: true });
});
} else {
const promptData = {
@ -138,7 +138,7 @@ function atLaunchTemplateCtrl (
id: vm.promptData.template,
launchData: jobLaunchData
}).then((launchRes) => {
$state.go('jobz', { id: launchRes.data.job, type: 'playbook' }, { reload: true });
$state.go('output', { id: launchRes.data.job, type: 'playbook' }, { reload: true });
}).catch(createErrorHandler('launch job template', 'POST'));
} else if (vm.promptData.templateType === 'workflow_job_template') {
workflowTemplate.create().postLaunch({

View File

@ -11,6 +11,7 @@ function atRowItem () {
badge: '@',
headerValue: '@',
headerLink: '@',
headerState: '@',
headerTag: '@',
status: '@',
statusTip: '@',

View File

@ -11,7 +11,10 @@
<div class="at-RowItem-header" ng-if="headerValue && headerLink">
<a ng-href="{{ headerLink }}">{{ headerValue }}</a>
</div>
<div class="at-RowItem-header" ng-if="headerValue && !headerLink">
<div class="at-RowItem-header" ng-if="headerValue && headerState">
<a ui-sref="{{ headerState }}" >{{ headerValue }}</a>
</div>
<div class="at-RowItem-header" ng-if="headerValue && !headerLink && !headerState">
{{ headerValue }}
</div>
<div class="at-RowItem-tag at-RowItem-tag--header" ng-if="headerTag">

View File

@ -128,7 +128,7 @@ function atRelaunchCtrl (
.then((launchRes) => {
if (!$state.is('jobs')) {
const relaunchType = launchRes.data.type === 'job' ? 'playbook' : launchRes.data.type;
$state.go('jobz', { id: launchRes.data.id, type: relaunchType }, { reload: true });
$state.go('output', { id: launchRes.data.id, type: relaunchType }, { reload: true });
}
}).catch(({ data, status, config }) => {
ProcessErrors($scope, data, status, null, {
@ -173,7 +173,7 @@ function atRelaunchCtrl (
inventorySource.postUpdate(vm.job.inventory_source)
.then((postUpdateRes) => {
if (!$state.is('jobs')) {
$state.go('jobz', { id: postUpdateRes.data.id, type: 'inventory' }, { reload: true });
$state.go('output', { id: postUpdateRes.data.id, type: 'inventory' }, { reload: true });
}
}).catch(({ data, status, config }) => {
ProcessErrors($scope, data, status, null, {
@ -197,7 +197,7 @@ function atRelaunchCtrl (
project.postUpdate(vm.job.project)
.then((postUpdateRes) => {
if (!$state.is('jobs')) {
$state.go('jobz', { id: postUpdateRes.data.id, type: 'project' }, { reload: true });
$state.go('output', { id: postUpdateRes.data.id, type: 'project' }, { reload: true });
}
}).catch(({ data, status, config }) => {
ProcessErrors($scope, data, status, null, {
@ -243,7 +243,7 @@ function atRelaunchCtrl (
id: vm.job.id
}).then((launchRes) => {
if (!$state.is('jobs')) {
$state.go('jobz', { id: launchRes.data.id, type: 'command' }, { reload: true });
$state.go('output', { id: launchRes.data.id, type: 'command' }, { reload: true });
}
}).catch(({ data, status, config }) => {
ProcessErrors($scope, data, status, null, {
@ -268,7 +268,7 @@ function atRelaunchCtrl (
relaunchData: PromptService.bundlePromptDataForRelaunch(vm.promptData)
}).then((launchRes) => {
if (!$state.is('jobs')) {
$state.go('jobz', { id: launchRes.data.job, type: 'playbook' }, { reload: true });
$state.go('output', { id: launchRes.data.job, type: 'playbook' }, { reload: true });
}
}).catch(({ data, status }) => {
ProcessErrors($scope, data, status, null, {

View File

@ -34,7 +34,7 @@ export default
if (job.type === 'workflow_job') {
detailsUrl = `/#/workflows/${job.id}`;
} else {
detailsUrl = `/#/jobz/playbook/${job.id}`;
detailsUrl = `/#/jobs/playbook/${job.id}`;
}
return {

View File

@ -241,7 +241,7 @@ function adhocController($q, $scope, $stateParams,
Rest.post(data)
.then(({data}) => {
Wait('stop');
$state.go('jobz', {id: data.id, type: 'command'});
$state.go('output', {id: data.id, type: 'command'});
})
.catch(({data, status}) => {
ProcessErrors($scope, data, status, adhocForm, {

View File

@ -23,7 +23,7 @@ export default [ '$scope', 'Empty', 'Wait', 'GetBasePath', 'Rest', 'ProcessError
};
$scope.viewJob = function(jobId) {
$state.go('jobz', { id: jobId, type: 'playbook' });
$state.go('output', { id: jobId, type: 'playbook' });
};
}

View File

@ -20,7 +20,7 @@ export default [ '$scope', 'Wait', 'Empty', 'Rest', 'ProcessErrors', '$state',
$scope.viewJob = function(url) {
// Pull the id out of the URL
var id = url.replace(/^\//, '').split('/')[3];
$state.go('jobz', { id, type: 'inventory' } );
$state.go('output', { id, type: 'inventory' } );
};
}

View File

@ -17,7 +17,7 @@ export default
// Get the ID from the correct summary field
var update_id = (data.summary_fields.current_update) ? data.summary_fields.current_update.id : data.summary_fields.last_update.id;
$state.go('jobz', { id: update_id, type: 'inventory' });
$state.go('output', { id: update_id, type: 'inventory' });
})
.catch(({data, status}) => {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',

View File

@ -89,7 +89,7 @@
.then(({data}) => {
Wait('stop');
if($location.path().replace(/^\//, '').split('/')[0] !== 'jobs') {
$state.go('jobz', { id: data.id, type: 'command' });
$state.go('output', { id: data.id, type: 'command' });
}
})
.catch(({data, status}) => {

View File

@ -150,7 +150,7 @@ export default
// use $state.go with reload: true option to re-instantiate sockets in
var goTojobResults = function(type) {
$state.go('jobz', {id: job, type}, {reload:true});
$state.go('output', {id: job, type}, {reload:true});
};
if($state.includes('jobs')) {

View File

@ -94,7 +94,7 @@ export default
Wait('stop');
$("#prompt-for-days").dialog("close");
// $("#configure-dialog").dialog('close');
$state.go('jobz', { id: data.system_job, type: 'system' }, { reload: true });
$state.go('output', { id: data.system_job, type: 'system' }, { reload: true });
})
.catch(({data, status}) => {
let template_id = $scope.job_template_id;

View File

@ -234,7 +234,7 @@ export default ['$scope', '$rootScope', '$location',
$scope.viewJob = function(url) {
// Pull the id out of the URL
var id = url.replace(/^\//, '').split('/')[3];
$state.go('jobz', { id: id, type: 'inventory' });
$state.go('output', { id: id, type: 'inventory' });
};

View File

@ -187,7 +187,7 @@ export default ['$scope', '$rootScope', '$log', '$stateParams', 'Rest', 'Alert',
// Grab the id from summary_fields
var id = (data.summary_fields.current_update) ? data.summary_fields.current_update.id : data.summary_fields.last_update.id;
$state.go('jobz', { id: id, type: 'project' });
$state.go('output', { id: id, type: 'project' });
} else {
Alert('No Updates Available', 'There is no SCM update information available for this project. An update has not yet been ' +

View File

@ -146,7 +146,7 @@ export default ['$scope', '$rootScope', '$log', 'Rest', 'Alert',
// Grab the id from summary_fields
var id = (data.summary_fields.current_update) ? data.summary_fields.current_update.id : data.summary_fields.last_update.id;
$state.go('jobz', { id: id, type: 'project'}, { reload: true });
$state.go('output', { id: id, type: 'project'}, { reload: true });
} else {
Alert(i18n._('No Updates Available'), i18n._('There is no SCM update information available for this project. An update has not yet been ' +

View File

@ -27,7 +27,7 @@ export default ['$scope', '$filter',
if (typeof $scope.templateType !== 'undefined' && $scope.templateType === 'workflow_job_template') {
detailsBaseUrl = '/#/workflows/';
} else {
detailsBaseUrl = '/#/jobz/playbook/';
detailsBaseUrl = '/#/jobs/playbook/';
}
var sparkData =

View File

@ -898,13 +898,13 @@ export default ['$state','moment', '$timeout', '$window', '$filter', 'Rest', 'Ge
let goToJobResults = function(job_type) {
if(job_type === 'job') {
$state.go('jobz', {id: d.job.id, type: 'playbook'});
$state.go('output', {id: d.job.id, type: 'playbook'});
}
else if(job_type === 'inventory_update') {
$state.go('jobz', {id: d.job.id, type: 'inventory'});
$state.go('output', {id: d.job.id, type: 'inventory'});
}
else if(job_type === 'project_update') {
$state.go('jobz', {id: d.job.id, type: 'project'});
$state.go('output', {id: d.job.id, type: 'project'});
}
};