debian-mirror-gitlab/app/assets/javascripts/pipelines/components/header_component.vue

96 lines
2 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2019-02-15 15:39:39 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2018-11-08 19:23:39 +05:30
import ciHeader from '../../vue_shared/components/header_ci_component.vue';
import eventHub from '../event_hub';
2019-09-30 21:07:59 +05:30
import { __ } from '~/locale';
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
export default {
name: 'PipelineHeaderSection',
components: {
ciHeader,
2018-12-13 13:39:08 +05:30
GlLoadingIcon,
2018-11-08 19:23:39 +05:30
},
props: {
pipeline: {
type: Object,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
isLoading: {
type: Boolean,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
actions: this.getActions(),
};
},
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
computed: {
status() {
return this.pipeline.details && this.pipeline.details.status;
},
shouldRenderContent() {
return !this.isLoading && Object.keys(this.pipeline).length;
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
},
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
watch: {
pipeline() {
this.actions = this.getActions();
2018-03-17 18:26:18 +05:30
},
2018-11-08 19:23:39 +05:30
},
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
methods: {
postAction(action) {
const index = this.actions.indexOf(action);
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
this.$set(this.actions[index], 'isLoading', true);
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
eventHub.$emit('headerPostAction', action);
},
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
getActions() {
const actions = [];
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
if (this.pipeline.retry_path) {
actions.push({
2019-09-30 21:07:59 +05:30
label: __('Retry'),
2018-11-08 19:23:39 +05:30
path: this.pipeline.retry_path,
cssClass: 'js-retry-button btn btn-inverted-secondary',
type: 'button',
isLoading: false,
});
}
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
if (this.pipeline.cancel_path) {
actions.push({
2019-09-30 21:07:59 +05:30
label: __('Cancel running'),
2018-11-08 19:23:39 +05:30
path: this.pipeline.cancel_path,
cssClass: 'js-btn-cancel-pipeline btn btn-danger',
type: 'button',
isLoading: false,
});
}
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
return actions;
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
},
};
2017-09-10 17:25:29 +05:30
</script>
<template>
<div class="pipeline-header-container">
<ci-header
v-if="shouldRenderContent"
:status="status"
:item-id="pipeline.id"
:time="pipeline.created_at"
:user="pipeline.user"
:actions="actions"
2018-11-08 19:23:39 +05:30
item-name="Pipeline"
2017-09-10 17:25:29 +05:30
@actionClicked="postAction"
2018-03-17 18:26:18 +05:30
/>
2019-02-15 15:39:39 +05:30
<gl-loading-icon v-if="isLoading" :size="2" class="prepend-top-default append-bottom-default" />
2017-09-10 17:25:29 +05:30
</div>
</template>