gitlab-org--gitlab-foss/app/assets/javascripts/pipelines/components/header_component.vue

99 lines
2.2 KiB
Vue
Raw Normal View History

<script>
2018-01-04 19:18:35 -05:00
import ciHeader from '../../vue_shared/components/header_ci_component.vue';
import eventHub from '../event_hub';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
2018-01-04 19:18:35 -05:00
export default {
name: 'PipelineHeaderSection',
components: {
ciHeader,
loadingIcon,
},
2018-01-04 19:18:35 -05:00
props: {
pipeline: {
type: Object,
required: true,
},
isLoading: {
type: Boolean,
required: true,
},
},
2018-01-04 19:18:35 -05:00
data() {
return {
actions: this.getActions(),
};
},
2018-01-04 19:18:35 -05:00
computed: {
status() {
return this.pipeline.details && this.pipeline.details.status;
},
shouldRenderContent() {
return !this.isLoading && Object.keys(this.pipeline).length;
},
},
2018-01-04 19:18:35 -05:00
watch: {
pipeline() {
this.actions = this.getActions();
},
},
2018-01-04 19:18:35 -05:00
methods: {
postAction(action) {
const index = this.actions.indexOf(action);
2018-01-04 19:18:35 -05:00
this.$set(this.actions[index], 'isLoading', true);
2018-01-04 19:18:35 -05:00
eventHub.$emit('headerPostAction', action);
},
2018-01-04 19:18:35 -05:00
getActions() {
const actions = [];
2018-01-04 19:18:35 -05:00
if (this.pipeline.retry_path) {
actions.push({
label: 'Retry',
path: this.pipeline.retry_path,
cssClass: 'js-retry-button btn btn-inverted-secondary',
type: 'button',
isLoading: false,
});
}
2018-01-04 19:18:35 -05:00
if (this.pipeline.cancel_path) {
actions.push({
label: 'Cancel running',
path: this.pipeline.cancel_path,
cssClass: 'js-btn-cancel-pipeline btn btn-danger',
type: 'button',
isLoading: false,
});
}
2018-01-04 19:18:35 -05:00
return actions;
},
},
2018-01-04 19:18:35 -05:00
};
</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-06-11 05:49:47 -04:00
item-name="Pipeline"
@actionClicked="postAction"
2018-01-04 19:18:35 -05:00
/>
<loading-icon
v-if="isLoading"
2018-01-04 19:18:35 -05:00
size="2"
2018-01-16 11:22:34 -05:00
class="prepend-top-default append-bottom-default"
2018-01-04 19:18:35 -05:00
/>
</div>
</template>