open-nomad/ui/app/components/job-deployments-stream.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-09-19 14:47:10 +00:00
import Ember from 'ember';
import moment from 'moment';
const { Component, computed } = Ember;
export default Component.extend({
tagName: 'ol',
classNames: ['timeline'],
deployments: computed(() => []),
2017-12-12 00:19:49 +00:00
sortedDeployments: computed('deployments.@each.versionSubmitTime', function() {
2017-09-19 14:47:10 +00:00
return this.get('deployments')
2017-12-12 00:19:49 +00:00
.sortBy('versionSubmitTime')
2017-09-19 14:47:10 +00:00
.reverse();
}),
annotatedDeployments: computed('sortedDeployments.@each.version', function() {
const deployments = this.get('sortedDeployments');
return deployments.map((deployment, index) => {
const meta = {};
if (index === 0) {
meta.showDate = true;
} else {
const previousDeployment = deployments.objectAt(index - 1);
const previousSubmitTime = previousDeployment.get('version.submitTime');
const submitTime = deployment.get('submitTime');
if (
submitTime &&
previousSubmitTime &&
moment(previousSubmitTime)
.startOf('day')
.diff(moment(submitTime).startOf('day'), 'days') > 0
) {
meta.showDate = true;
}
}
return { deployment, meta };
});
}),
});