add redirect route for workflow viewer

This commit is contained in:
Jake McDermott 2018-12-14 19:20:01 -05:00
parent 9f18f8dbdb
commit a5c4350695
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7

View File

@ -1,4 +1,4 @@
function LegacyRedirect ($stateRegistry) {
function LegacyRedirect ($http, $stateRegistry) {
const destination = 'output';
const routes = [
{
@ -66,11 +66,35 @@ function LegacyRedirect ($stateRegistry) {
return { state: 'schedules.edit', params: { schedule_id, schedule_search } };
}
},
{
name: 'workflowPlaybookNodeRedirect',
url: '/workflow_node_playbook_results/:id',
redirectTo: (trans) => {
// The workflow job viewer uses this route for playbook job nodes. The provided id
// is used to lookup the corresponding unified job, which is then inspected to
// determine if we need to redirect to a split (workflow) job or a playbook job.
const { id } = trans.params();
const endpoint = '/api/v2/unified_jobs/';
return $http.get(endpoint, { params: { id } })
.then(({ data }) => {
const { results } = data;
const [obj] = results;
if (obj && obj.type === 'workflow_job') {
return { state: 'workflowResults', params: { id } };
}
return { state: destination, params: { type: 'playbook', id } };
})
.catch(() => ({ state: 'dashboard' }));
}
},
];
routes.forEach(state => $stateRegistry.register(state));
}
LegacyRedirect.$inject = ['$stateRegistry'];
LegacyRedirect.$inject = ['$http', '$stateRegistry'];
export default LegacyRedirect;