Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-05-23 16:22:38 +0300
committerPhil Hughes <me@iamphill.com>2018-05-24 12:38:02 +0300
commit5e79276b53f61cbd727411ed33e71d5b6fa5ca54 (patch)
tree602b13c443389e18c8471fe2a6041b9a4c966260 /app/assets/javascripts
parentcfe4d2f29dcdcfad96ae7ba5a5eb822fbe46a9a7 (diff)
improve API calls by calling internal API to get data
render job items (needs improvements to components)
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/api.js6
-rw-r--r--app/assets/javascripts/ide/components/pipelines/jobs.vue50
-rw-r--r--app/assets/javascripts/ide/stores/modules/pipelines/actions.js46
-rw-r--r--app/assets/javascripts/ide/stores/modules/pipelines/getters.js6
-rw-r--r--app/assets/javascripts/ide/stores/modules/pipelines/mutation_types.js4
-rw-r--r--app/assets/javascripts/ide/stores/modules/pipelines/mutations.js67
-rw-r--r--app/assets/javascripts/vue_shared/components/tabs/tab.vue3
7 files changed, 127 insertions, 55 deletions
diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js
index eb919241318..06fdc8fe65b 100644
--- a/app/assets/javascripts/api.js
+++ b/app/assets/javascripts/api.js
@@ -24,7 +24,7 @@ const Api = {
branchSinglePath: '/api/:version/projects/:id/repository/branches/:branch',
createBranchPath: '/api/:version/projects/:id/repository/branches',
pipelinesPath: '/api/:version/projects/:id/pipelines',
- pipelineJobsPath: '/api/:version/projects/:id/pipelines/:pipeline_id/jobs',
+ pipelineJobsPath: '/:project_path/pipelines/:id/builds.json',
group(groupId, callback) {
const url = Api.buildUrl(Api.groupPath).replace(':id', groupId);
@@ -232,8 +232,8 @@ const Api = {
pipelineJobs(projectPath, pipelineId, params = {}) {
const url = Api.buildUrl(this.pipelineJobsPath)
- .replace(':id', encodeURIComponent(projectPath))
- .replace(':pipeline_id', pipelineId);
+ .replace(':project_path', projectPath)
+ .replace(':id', pipelineId);
return axios.get(url, { params });
},
diff --git a/app/assets/javascripts/ide/components/pipelines/jobs.vue b/app/assets/javascripts/ide/components/pipelines/jobs.vue
index d69945b617c..a3a99ad457c 100644
--- a/app/assets/javascripts/ide/components/pipelines/jobs.vue
+++ b/app/assets/javascripts/ide/components/pipelines/jobs.vue
@@ -1,5 +1,7 @@
<script>
-import { mapActions, mapGetters } from 'vuex';
+import { mapActions, mapGetters, mapState } from 'vuex';
+import Icon from '../../../vue_shared/components/icon.vue';
+import CiIcon from '../../../vue_shared/components/ci_icon.vue';
import Tabs from '../../../vue_shared/components/tabs/tabs';
import Tab from '../../../vue_shared/components/tabs/tab.vue';
@@ -7,15 +9,18 @@ export default {
components: {
Tabs,
Tab,
+ Icon,
+ CiIcon,
},
computed: {
- ...mapGetters('pipelines', ['jobsCount', 'failedJobs']),
+ ...mapGetters('pipelines', ['jobsCount', 'failedJobsCount']),
+ ...mapState('pipelines', ['stages']),
},
mounted() {
- this.fetchJobs();
+ this.fetchStages();
},
methods: {
- ...mapActions('pipelines', ['fetchJobs']),
+ ...mapActions('pipelines', ['fetchStages']),
},
};
</script>
@@ -27,11 +32,44 @@ export default {
<template slot="title">
Jobs <span class="badge">{{ jobsCount }}</span>
</template>
- List all jobs here
+ <div style="overflow: auto;">
+ <div
+ v-for="stage in stages"
+ :key="stage.id"
+ class="panel panel-default"
+ >
+ <div
+ class="panel-heading"
+ @click="() => stage.isCollapsed = !stage.isCollapsed"
+ >
+ <ci-icon :status="stage.status" />
+ {{ stage.title }}
+ <span class="badge">
+ {{ stage.jobs.length }}
+ </span>
+ <icon
+ :name="stage.isCollapsed ? 'angle-left' : 'angle-down'"
+ css-classes="pull-right"
+ />
+ </div>
+ <div
+ class="panel-body"
+ v-show="!stage.isCollapsed"
+ >
+ <div
+ v-for="job in stage.jobs"
+ :key="job.id"
+ >
+ <ci-icon :status="job.status" />
+ {{ job.name }} #{{ job.id }}
+ </div>
+ </div>
+ </div>
+ </div>
</tab>
<tab>
<template slot="title">
- Failed Jobs <span class="badge">{{ failedJobs.length }}</span>
+ Failed Jobs <span class="badge">{{ failedJobsCount }}</span>
</template>
List all failed jobs here
</tab>
diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/actions.js b/app/assets/javascripts/ide/stores/modules/pipelines/actions.js
index 07f7b201f2e..994edd74aef 100644
--- a/app/assets/javascripts/ide/stores/modules/pipelines/actions.js
+++ b/app/assets/javascripts/ide/stores/modules/pipelines/actions.js
@@ -1,3 +1,4 @@
+import axios from 'axios';
import { __ } from '../../../../locale';
import Api from '../../../../api';
import flash from '../../../../flash';
@@ -21,29 +22,40 @@ export const fetchLatestPipeline = ({ dispatch, rootState }, sha) => {
.catch(() => dispatch('receiveLatestPipelineError'));
};
-export const requestJobs = ({ commit }) => commit(types.REQUEST_JOBS);
-export const receiveJobsError = ({ commit }) => {
- flash(__('There was an error loading jobs'));
- commit(types.RECEIVE_JOBS_ERROR);
+export const requestStages = ({ commit }) => commit(types.REQUEST_STAGES);
+export const receiveStagesError = ({ commit }) => {
+ flash(__('There was an error loading job stages'));
+ commit(types.RECEIVE_STAGES_ERROR);
};
-export const receiveJobsSuccess = ({ commit }, data) => commit(types.RECEIVE_JOBS_SUCCESS, data);
+export const receiveStagesSuccess = ({ commit }, data) =>
+ commit(types.RECEIVE_STAGES_SUCCESS, data);
+
+export const fetchStages = ({ dispatch, state, rootState }) => {
+ dispatch('requestStages');
-export const fetchJobs = ({ dispatch, state, rootState }, page = '1') => {
- dispatch('requestJobs');
+ Api.pipelineJobs(rootState.currentProjectId, state.latestPipeline.id)
+ .then(({ data }) => dispatch('receiveStagesSuccess', data))
+ .then(() => state.stages.forEach(stage => dispatch('fetchJobs', stage)))
+ .catch(() => dispatch('receiveStagesError'));
+};
- Api.pipelineJobs(rootState.currentProjectId, state.latestPipeline.id, {
- page,
- })
- .then(({ data, headers }) => {
- const nextPage = headers && headers['x-next-page'];
+export const requestJobs = ({ commit }, id) => commit(types.REQUEST_JOBS, id);
+export const receiveJobsError = ({ commit }, id) => {
+ flash(__('There was an error loading jobs'));
+ commit(types.RECEIVE_JOBS_ERROR, id);
+};
+export const receiveJobsSuccess = ({ commit }, { id, data }) =>
+ commit(types.RECEIVE_JOBS_SUCCESS, { id, data });
- dispatch('receiveJobsSuccess', data);
+export const fetchJobs = ({ dispatch }, stage) => {
+ dispatch('requestJobs', stage.id);
- if (nextPage) {
- dispatch('fetchJobs', nextPage);
- }
+ axios
+ .get(stage.dropdown_path)
+ .then(({ data }) => {
+ dispatch('receiveJobsSuccess', { id: stage.id, data });
})
- .catch(() => dispatch('receiveJobsError'));
+ .catch(() => dispatch('receiveJobsError', stage.id));
};
export default () => {};
diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/getters.js b/app/assets/javascripts/ide/stores/modules/pipelines/getters.js
index e1f55bcd933..99b4554a96e 100644
--- a/app/assets/javascripts/ide/stores/modules/pipelines/getters.js
+++ b/app/assets/javascripts/ide/stores/modules/pipelines/getters.js
@@ -1,9 +1,9 @@
export const hasLatestPipeline = state => !state.isLoadingPipeline && !!state.latestPipeline;
-export const failedJobs = state =>
+export const failedJobsCount = state =>
state.stages.reduce(
- (acc, stage) => acc.concat(stage.jobs.filter(job => job.status === 'failed')),
- [],
+ (acc, stage) => acc + stage.jobs.filter(j => j.status.label === 'failed').length,
+ 0,
);
export const jobsCount = state => state.stages.reduce((acc, stage) => acc + stage.jobs.length, 0);
diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/mutation_types.js b/app/assets/javascripts/ide/stores/modules/pipelines/mutation_types.js
index 6b5701670a6..0911b8ee6fb 100644
--- a/app/assets/javascripts/ide/stores/modules/pipelines/mutation_types.js
+++ b/app/assets/javascripts/ide/stores/modules/pipelines/mutation_types.js
@@ -2,6 +2,10 @@ export const REQUEST_LATEST_PIPELINE = 'REQUEST_LATEST_PIPELINE';
export const RECEIVE_LASTEST_PIPELINE_ERROR = 'RECEIVE_LASTEST_PIPELINE_ERROR';
export const RECEIVE_LASTEST_PIPELINE_SUCCESS = 'RECEIVE_LASTEST_PIPELINE_SUCCESS';
+export const REQUEST_STAGES = 'REQUEST_STAGES';
+export const RECEIVE_STAGES_ERROR = 'RECEIVE_STAGES_ERROR';
+export const RECEIVE_STAGES_SUCCESS = 'RECEIVE_STAGES_SUCCESS';
+
export const REQUEST_JOBS = 'REQUEST_JOBS';
export const RECEIVE_JOBS_ERROR = 'RECEIVE_JOBS_ERROR';
export const RECEIVE_JOBS_SUCCESS = 'RECEIVE_JOBS_SUCCESS';
diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js b/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js
index d28d9ca776d..7115f5e5386 100644
--- a/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js
+++ b/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js
@@ -18,37 +18,52 @@ export default {
};
}
},
- [types.REQUEST_JOBS](state) {
+ [types.REQUEST_STAGES](state) {
state.isLoadingJobs = true;
},
- [types.RECEIVE_JOBS_ERROR](state) {
+ [types.RECEIVE_STAGES_ERROR](state) {
state.isLoadingJobs = false;
},
- [types.RECEIVE_JOBS_SUCCESS](state, jobs) {
+ [types.RECEIVE_STAGES_SUCCESS](state, stages) {
state.isLoadingJobs = false;
- state.stages = jobs.reduce((acc, job) => {
- let stage = acc.find(s => s.title === job.stage);
-
- if (!stage) {
- stage = {
- title: job.stage,
- isCollapsed: false,
- jobs: [],
- };
-
- acc.push(stage);
- }
-
- stage.jobs = stage.jobs.concat({
- id: job.id,
- name: job.name,
- status: job.status,
- stage: job.stage,
- duration: job.duration,
- });
-
- return acc;
- }, state.stages);
+ state.stages = stages.map((stage, i) => ({
+ ...stage,
+ id: i,
+ isCollapsed: false,
+ isLoading: false,
+ jobs: [],
+ }));
+ },
+ [types.REQUEST_JOBS](state, id) {
+ state.stages = state.stages.reduce(
+ (acc, stage) =>
+ acc.concat({
+ ...stage,
+ isLoading: id === stage.id ? true : stage.isLoading,
+ }),
+ [],
+ );
+ },
+ [types.RECEIVE_JOBS_ERROR](state, id) {
+ state.stages = state.stages.reduce(
+ (acc, stage) =>
+ acc.concat({
+ ...stage,
+ isLoading: id === stage.id ? false : stage.isLoading,
+ }),
+ [],
+ );
+ },
+ [types.RECEIVE_JOBS_SUCCESS](state, { id, data }) {
+ state.stages = state.stages.reduce(
+ (acc, stage) =>
+ acc.concat({
+ ...stage,
+ isLoading: id === stage.id ? false : stage.isLoading,
+ jobs: id === stage.id ? data.latest_statuses : stage.jobs,
+ }),
+ [],
+ );
},
};
diff --git a/app/assets/javascripts/vue_shared/components/tabs/tab.vue b/app/assets/javascripts/vue_shared/components/tabs/tab.vue
index 2a35d6bc151..0ec7a0199fe 100644
--- a/app/assets/javascripts/vue_shared/components/tabs/tab.vue
+++ b/app/assets/javascripts/vue_shared/components/tabs/tab.vue
@@ -26,6 +26,9 @@ export default {
created() {
this.isTab = true;
},
+ updated() {
+ this.$parent.$forceUpdate();
+ },
};
</script>