Commit fc8d4c70 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Alessio Caiazza

Add scheduled job dropdown to pipelines list

parent 786ae683
...@@ -370,3 +370,23 @@ window.gl.utils = { ...@@ -370,3 +370,23 @@ window.gl.utils = {
getTimeago, getTimeago,
localTimeAgo, localTimeAgo,
}; };
/**
* Formats milliseconds as timestamp (e.g. 01:02:03).
*
* @param milliseconds
* @returns {string}
*/
export const formatTime = milliseconds => {
const remainingSeconds = Math.floor(milliseconds / 1000) % 60;
const remainingMinutes = Math.floor(milliseconds / 1000 / 60) % 60;
const remainingHours = Math.floor(milliseconds / 1000 / 60 / 60);
let formattedTime = '';
if (remainingHours < 10) formattedTime += '0';
formattedTime += `${remainingHours}:`;
if (remainingMinutes < 10) formattedTime += '0';
formattedTime += `${remainingMinutes}:`;
if (remainingSeconds < 10) formattedTime += '0';
formattedTime += remainingSeconds;
return formattedTime;
};
<script> <script>
import { formatTime } from '~/lib/utils/datetime_utility';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import icon from '../../vue_shared/components/icon.vue'; import icon from '../../vue_shared/components/icon.vue';
import tooltip from '../../vue_shared/directives/tooltip'; import tooltip from '../../vue_shared/directives/tooltip';
...@@ -35,6 +36,11 @@ export default { ...@@ -35,6 +36,11 @@ export default {
return !action.playable; return !action.playable;
}, },
remainingTime(action) {
const remainingMilliseconds = new Date(action.scheduled_at).getTime() - Date.now();
return formatTime(remainingMilliseconds);
},
}, },
}; };
</script> </script>
...@@ -63,8 +69,8 @@ export default { ...@@ -63,8 +69,8 @@ export default {
<ul class="dropdown-menu dropdown-menu-right"> <ul class="dropdown-menu dropdown-menu-right">
<li <li
v-for="(action, i) in actions" v-for="action in actions"
:key="i" :key="action.path"
> >
<button <button
:class="{ disabled: isActionDisabled(action) }" :class="{ disabled: isActionDisabled(action) }"
...@@ -74,6 +80,13 @@ export default { ...@@ -74,6 +80,13 @@ export default {
@click="onClickAction(action.path)" @click="onClickAction(action.path)"
> >
{{ action.name }} {{ action.name }}
<span
v-if="action.scheduled_at"
class="pull-right"
>
<icon name="clock" />
{{ remainingTime(action) }}
</span>
</button> </button>
</li> </li>
</ul> </ul>
......
...@@ -59,6 +59,9 @@ export default { ...@@ -59,6 +59,9 @@ export default {
}; };
}, },
computed: { computed: {
actions() {
return [...this.pipeline.details.manual_actions, ...this.pipeline.details.scheduled_actions];
},
/** /**
* If provided, returns the commit tag. * If provided, returns the commit tag.
* Needed to render the commit component column. * Needed to render the commit component column.
...@@ -321,8 +324,8 @@ export default { ...@@ -321,8 +324,8 @@ export default {
> >
<div class="btn-group table-action-buttons"> <div class="btn-group table-action-buttons">
<pipelines-actions-component <pipelines-actions-component
v-if="pipeline.details.manual_actions.length" v-if="actions.length > 0"
:actions="pipeline.details.manual_actions" :actions="actions"
/> />
<pipelines-artifacts-component <pipelines-artifacts-component
......
...@@ -6,9 +6,7 @@ describe('Date time utils', () => { ...@@ -6,9 +6,7 @@ describe('Date time utils', () => {
const date = new Date(); const date = new Date();
date.setFullYear(date.getFullYear() - 1); date.setFullYear(date.getFullYear() - 1);
expect( expect(datetimeUtility.timeFor(date)).toBe('Past due');
datetimeUtility.timeFor(date),
).toBe('Past due');
}); });
it('returns remaining time when in the future', () => { it('returns remaining time when in the future', () => {
...@@ -19,9 +17,7 @@ describe('Date time utils', () => { ...@@ -19,9 +17,7 @@ describe('Date time utils', () => {
// short of a full year, timeFor will return '11 months remaining' // short of a full year, timeFor will return '11 months remaining'
date.setDate(date.getDate() + 1); date.setDate(date.getDate() + 1);
expect( expect(datetimeUtility.timeFor(date)).toBe('1 year remaining');
datetimeUtility.timeFor(date),
).toBe('1 year remaining');
}); });
}); });
...@@ -168,3 +164,20 @@ describe('getTimeframeWindowFrom', () => { ...@@ -168,3 +164,20 @@ describe('getTimeframeWindowFrom', () => {
}); });
}); });
}); });
describe('formatTime', () => {
const expectedTimestamps = [
[0, '00:00:00'],
[1000, '00:00:01'],
[42000, '00:00:42'],
[121000, '00:02:01'],
[10921000, '03:02:01'],
[108000000, '30:00:00'],
];
expectedTimestamps.forEach(([milliseconds, expectedTimestamp]) => {
it(`formats ${milliseconds}ms as ${expectedTimestamp}`, () => {
expect(datetimeUtility.formatTime(milliseconds)).toBe(expectedTimestamp);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment