2020-04-30 13:15:19 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { sort } from '@ember/object/computed';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { tagName } from '@ember-decorators/component';
|
|
|
|
import classic from 'ember-classic-decorator';
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class LifecycleChart extends Component {
|
|
|
|
tasks = null;
|
|
|
|
taskStates = null;
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('tasks.@each.lifecycle', 'taskStates.@each.state')
|
|
|
|
get lifecyclePhases() {
|
2020-04-30 13:15:19 +00:00
|
|
|
const tasksOrStates = this.taskStates || this.tasks;
|
|
|
|
const lifecycles = {
|
|
|
|
prestarts: [],
|
|
|
|
sidecars: [],
|
|
|
|
mains: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
tasksOrStates.forEach(taskOrState => {
|
|
|
|
const task = taskOrState.task || taskOrState;
|
|
|
|
lifecycles[`${task.lifecycleName}s`].push(taskOrState);
|
|
|
|
});
|
|
|
|
|
|
|
|
const phases = [];
|
|
|
|
|
|
|
|
if (lifecycles.prestarts.length || lifecycles.sidecars.length) {
|
|
|
|
phases.push({
|
|
|
|
name: 'Prestart',
|
|
|
|
isActive: lifecycles.prestarts.some(state => state.state === 'running'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lifecycles.sidecars.length || lifecycles.mains.length) {
|
|
|
|
phases.push({
|
|
|
|
name: 'Main',
|
|
|
|
isActive: lifecycles.mains.some(state => state.state === 'running'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return phases;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@sort('taskStates', function(a, b) {
|
2020-04-30 13:15:19 +00:00
|
|
|
return getTaskSortPrefix(a.task).localeCompare(getTaskSortPrefix(b.task));
|
2020-06-10 13:49:16 +00:00
|
|
|
})
|
|
|
|
sortedLifecycleTaskStates;
|
2020-04-30 13:15:19 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@sort('tasks', function(a, b) {
|
2020-04-30 13:15:19 +00:00
|
|
|
return getTaskSortPrefix(a).localeCompare(getTaskSortPrefix(b));
|
2020-06-10 13:49:16 +00:00
|
|
|
})
|
|
|
|
sortedLifecycleTasks;
|
|
|
|
}
|
2020-04-30 13:15:19 +00:00
|
|
|
|
|
|
|
const lifecycleNameSortPrefix = {
|
|
|
|
prestart: 0,
|
|
|
|
sidecar: 1,
|
|
|
|
main: 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
function getTaskSortPrefix(task) {
|
|
|
|
// Prestarts first, then sidecars, then mains
|
|
|
|
return `${lifecycleNameSortPrefix[task.lifecycleName]}-${task.name}`;
|
|
|
|
}
|