gitlab-org--gitlab-foss/app/assets/javascripts/vue_pipelines_index/pipelines.js.es6

136 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-10-26 14:43:58 -04:00
/* global Vue, gl */
/* eslint-disable no-param-reassign, no-bitwise*/
2016-10-26 14:43:58 -04:00
((gl) => {
2016-11-18 17:26:49 -05:00
const SPREAD = '...';
const PREV = 'Prev';
const NEXT = 'Next';
const FIRST = '<< First';
const LAST = 'Last >>';
gl.VuePipelines = Vue.extend({
components: {
2016-11-11 00:21:09 -05:00
runningPipeline: gl.VueRunningPipeline,
pipelineActions: gl.VuePipelineActions,
stages: gl.VueStages,
2016-11-22 14:36:45 -05:00
commit: gl.CommitComponent,
2016-11-11 00:21:09 -05:00
pipelineUrl: gl.VuePipelineUrl,
pipelineHead: gl.VuePipelineHead,
glPagination: gl.VueGlPagination,
statusScope: gl.VueStatusScope,
timeAgo: gl.VueTimeAgo,
},
2016-10-29 15:50:08 -04:00
data() {
return {
pipelines: [],
timeLoopInterval: '',
intervalId: '',
2016-11-10 15:17:33 -05:00
updatedAt: '',
pagenum: 1,
count: {
all: 0,
running_or_pending: 0,
},
2016-11-11 00:21:09 -05:00
pageRequest: false,
2016-10-29 15:50:08 -04:00
};
},
props: [
'scope',
'store',
],
created() {
const url = window.location.toString();
if (~url.indexOf('?') && !~url.indexOf('scope=pipelines')) {
this.pagenum = url.split('?')[1].split('=')[1];
}
2016-11-10 12:16:27 -05:00
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope);
},
methods: {
changepage(e, last) {
const text = e.target.innerText;
2016-11-18 17:26:49 -05:00
if (text === SPREAD) return;
2016-11-08 15:04:30 -05:00
if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text;
2016-11-18 17:26:49 -05:00
if (text === LAST) this.pagenum = last;
if (text === NEXT) this.pagenum = +this.pagenum + 1;
if (text === PREV) this.pagenum = +this.pagenum - 1;
if (text === FIRST) this.pagenum = 1;
window.history.pushState({}, null, `?p=${this.pagenum}`);
clearInterval(this.timeLoopInterval);
2016-11-11 00:21:09 -05:00
this.pageRequest = true;
2016-11-10 12:16:27 -05:00
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope);
},
2016-11-22 14:36:45 -05:00
author(pipeline) {
const { commit } = pipeline;
const author = commit.author;
2016-11-22 14:36:45 -05:00
if (author) return author;
const nonUser = {
avatar_url: commit.author_gravatar_url,
web_url: `mailto:${commit.author_email}`,
username: commit.author_name,
};
return nonUser;
2016-11-22 14:36:45 -05:00
},
ref(pipeline) {
const { ref } = pipeline;
const commitRef = {
name: ref.name,
tag: ref['tag?'],
ref_url: ref.url,
};
return commitRef;
},
2016-12-02 12:18:23 -05:00
addTimeInterval(id, start) {
this.allTimeIntervals.push({ id, start });
},
},
template: `
<div>
2016-12-01 17:02:26 -05:00
<div class="pipelines realtime-loading" v-if='pipelines.length < 1'>
2016-11-11 00:21:09 -05:00
<i class="fa fa-spinner fa-spin"></i>
</div>
<div class="table-holder" v-if='pipelines.length > 0'>
<table class="table ci-table">
<pipeline-head></pipeline-head>
<tbody>
<tr class="commit" v-for='pipeline in pipelines'>
<status-scope :pipeline='pipeline'></status-scope>
<pipeline-url :pipeline='pipeline'></pipeline-url>
<td>
<commit
:author='author(pipeline)'
:tag="pipeline.ref['tag?']"
:title='pipeline.commit.title'
:commit_ref='ref(pipeline)'
:short_sha='pipeline.commit.short_id'
:commit_url='pipeline.commit.commit_url'
>
</commit>
</td>
<stages :pipeline='pipeline'></stages>
<time-ago
:pipeline='pipeline'
>
</time-ago>
<pipeline-actions :pipeline='pipeline'></pipeline-actions>
</tr>
</tbody>
</table>
</div>
2016-12-01 17:02:26 -05:00
<div class="pipelines realtime-loading" v-if='pageRequest'>
2016-11-11 00:21:09 -05:00
<i class="fa fa-spinner fa-spin"></i>
</div>
<gl-pagination
v-if='count.all > 30'
:pagenum='pagenum'
:changepage='changepage'
:count='count.all'
>
</gl-pagination>
2016-11-01 20:16:51 -04:00
</div>
`,
2016-10-26 14:43:58 -04:00
});
})(window.gl || (window.gl = {}));