summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/tree
diff options
context:
space:
mode:
authorJose Ivan Vargas <jvargas@gitlab.com>2018-01-22 15:57:32 -0600
committerJose Ivan Vargas <jvargas@gitlab.com>2018-01-30 09:24:57 -0600
commitbfc2b8a3d2c06c80126365348ce75b3985185e83 (patch)
tree6c68670ea0a9da973589d722be8b26862e5bed16 /app/assets/javascripts/projects/tree
parent6042454600d79f1d6fb8e216c78b3e8b619a7a3e (diff)
downloadgitlab-ce-bfc2b8a3d2c06c80126365348ce75b3985185e83.tar.gz
Added realtime prop and corrected specs
Diffstat (limited to 'app/assets/javascripts/projects/tree')
-rw-r--r--app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue106
-rw-r--r--app/assets/javascripts/projects/tree/services/commit_pipeline_service.js11
2 files changed, 117 insertions, 0 deletions
diff --git a/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue b/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue
new file mode 100644
index 00000000000..e13acf8555a
--- /dev/null
+++ b/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue
@@ -0,0 +1,106 @@
+<script>
+ import Visibility from 'visibilityjs';
+ import ciIcon from '~/vue_shared/components/ci_icon.vue';
+ import Poll from '~/lib/utils/poll';
+ import Flash from '~/flash';
+ import tooltip from '~/vue_shared/directives/tooltip';
+ import CommitPipelineService from '../services/commit_pipeline_service';
+
+ export default {
+ directives: {
+ tooltip,
+ },
+ components: {
+ ciIcon,
+ },
+ props: {
+ endpoint: {
+ type: String,
+ required: true,
+ },
+ realtime: {
+ type: Boolean,
+ required: false,
+ default: true,
+ },
+ },
+ data() {
+ return {
+ ciStatus: {},
+ isLoading: true,
+ service: {},
+ stageTitle: '',
+ };
+ },
+ mounted() {
+ this.service = new CommitPipelineService(this.endpoint);
+ if (this.realtime) {
+ this.initPolling();
+ } else {
+ this.fetchPipelineCommitData();
+ }
+ },
+ methods: {
+ successCallback(res) {
+ if (res.data.pipelines.length > 0) {
+ this.ciStatus = res.data.pipelines[0].details.stages[0].status;
+ this.stageTitle = res.data.pipelines[0].details.stages[0].title;
+ this.isLoading = false;
+ } else {
+ this.isLoading = true;
+ }
+ },
+ errorCallback(err) {
+ Flash(err);
+ },
+ initPolling() {
+ this.poll = new Poll({
+ resource: this.service,
+ method: 'fetchData',
+ successCallback: response => this.successCallback(response),
+ errorCallback: this.errorCallback,
+ });
+
+ if (!Visibility.hidden()) {
+ this.isLoading = true;
+ this.poll.makeRequest();
+ } else {
+ this.fetchPipelineCommitData();
+ }
+
+ Visibility.change(() => {
+ if (!Visibility.hidden()) {
+ this.poll.restart();
+ } else {
+ this.poll.stop();
+ }
+ });
+ },
+ fetchPipelineCommitData() {
+ this.service.fetchData()
+ .then(this.successCallback)
+ .catch(this.errorCallback);
+ },
+ },
+ destroy() {
+ this.poll.stop();
+ },
+ };
+</script>
+<template>
+ <div
+ v-if="isLoading">
+ </div>
+ <a
+ v-else
+ :href="ciStatus.details_path"
+ >
+ <ci-icon
+ v-tooltip
+ :title="stageTitle"
+ :aria-label="stageTitle"
+ data-container="body"
+ :status="ciStatus"
+ />
+ </a>
+</template>
diff --git a/app/assets/javascripts/projects/tree/services/commit_pipeline_service.js b/app/assets/javascripts/projects/tree/services/commit_pipeline_service.js
new file mode 100644
index 00000000000..4b4189bc2de
--- /dev/null
+++ b/app/assets/javascripts/projects/tree/services/commit_pipeline_service.js
@@ -0,0 +1,11 @@
+import axios from '~/lib/utils/axios_utils';
+
+export default class CommitPipelineService {
+ constructor(endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ fetchData() {
+ return axios.get(this.endpoint);
+ }
+}