gitlab-org--gitlab-foss/app/assets/javascripts/cycle_analytics/cycle_analytics_bundle.js

137 lines
4.4 KiB
JavaScript
Raw Normal View History

/* global Flash */
2017-03-17 17:21:25 +00:00
import Vue from 'vue';
2017-03-11 06:45:34 +00:00
import Cookies from 'js-cookie';
import LimitWarningComponent from './components/limit_warning_component';
2017-03-17 17:21:25 +00:00
require('./components/stage_code_component');
require('./components/stage_issue_component');
require('./components/stage_plan_component');
require('./components/stage_production_component');
require('./components/stage_review_component');
require('./components/stage_staging_component');
require('./components/stage_test_component');
require('./components/total_time_component');
require('./cycle_analytics_service');
require('./cycle_analytics_store');
require('./default_event_objects');
2016-10-20 04:34:16 +00:00
$(() => {
const OVERVIEW_DIALOG_COOKIE = 'cycle_analytics_help_dismissed';
2016-10-20 04:34:16 +00:00
const cycleAnalyticsEl = document.querySelector('#cycle-analytics');
const cycleAnalyticsStore = gl.cycleAnalytics.CycleAnalyticsStore;
const cycleAnalyticsService = new gl.cycleAnalytics.CycleAnalyticsService({
requestPath: cycleAnalyticsEl.dataset.requestPath,
});
2016-10-20 04:34:16 +00:00
gl.cycleAnalyticsApp = new Vue({
el: '#cycle-analytics',
name: 'CycleAnalytics',
data: {
state: cycleAnalyticsStore.state,
isLoading: false,
isLoadingStage: false,
isEmptyStage: false,
hasError: false,
startDate: 30,
isOverviewDialogDismissed: Cookies.get(OVERVIEW_DIALOG_COOKIE),
},
computed: {
currentStage() {
return cycleAnalyticsStore.currentActiveStage();
},
},
components: {
'stage-issue-component': gl.cycleAnalytics.StageIssueComponent,
'stage-plan-component': gl.cycleAnalytics.StagePlanComponent,
2016-11-21 22:26:19 +00:00
'stage-code-component': gl.cycleAnalytics.StageCodeComponent,
'stage-test-component': gl.cycleAnalytics.StageTestComponent,
'stage-review-component': gl.cycleAnalytics.StageReviewComponent,
'stage-staging-component': gl.cycleAnalytics.StageStagingComponent,
'stage-production-component': gl.cycleAnalytics.StageProductionComponent,
},
2016-10-20 04:34:16 +00:00
created() {
this.fetchCycleAnalyticsData();
},
methods: {
handleError() {
2016-10-20 04:34:16 +00:00
cycleAnalyticsStore.setErrorState(true);
return new Flash('There was an error while fetching cycle analytics data.');
2016-10-20 04:34:16 +00:00
},
initDropdown() {
const $dropdown = $('.js-ca-dropdown');
const $label = $dropdown.find('.dropdown-label');
$dropdown.find('li a').off('click').on('click', (e) => {
e.preventDefault();
const $target = $(e.currentTarget);
this.startDate = $target.data('value');
2016-10-20 04:34:16 +00:00
$label.text($target.text().trim());
this.fetchCycleAnalyticsData({ startDate: this.startDate });
2016-10-20 04:34:16 +00:00
});
},
fetchCycleAnalyticsData(options) {
const fetchOptions = options || { startDate: this.startDate };
2016-10-20 04:34:16 +00:00
this.isLoading = true;
2016-10-20 04:34:16 +00:00
cycleAnalyticsService
.fetchCycleAnalyticsData(fetchOptions)
.done((response) => {
2016-10-20 04:34:16 +00:00
cycleAnalyticsStore.setCycleAnalyticsData(response);
this.selectDefaultStage();
2016-10-20 04:34:16 +00:00
this.initDropdown();
})
.error(() => {
this.handleError();
})
.always(() => {
this.isLoading = false;
});
},
selectDefaultStage() {
const stage = this.state.stages.first();
this.selectStage(stage);
},
selectStage(stage) {
if (this.isLoadingStage) return;
if (this.currentStage === stage) return;
if (!stage.isUserAllowed) {
cycleAnalyticsStore.setActiveStage(stage);
return;
}
this.isLoadingStage = true;
cycleAnalyticsStore.setStageEvents([], stage);
cycleAnalyticsStore.setActiveStage(stage);
cycleAnalyticsService
.fetchStageData({
stage,
startDate: this.startDate,
})
.done((response) => {
this.isEmptyStage = !response.events.length;
cycleAnalyticsStore.setStageEvents(response.events, stage);
})
.error(() => {
this.isEmptyStage = true;
2016-10-20 04:34:16 +00:00
})
.always(() => {
this.isLoadingStage = false;
2016-10-20 04:34:16 +00:00
});
},
dismissOverviewDialog() {
this.isOverviewDialogDismissed = true;
Cookies.set(OVERVIEW_DIALOG_COOKIE, '1');
},
},
2016-10-20 04:34:16 +00:00
});
// Register global components
Vue.component('limit-warning', LimitWarningComponent);
Vue.component('total-time', gl.cycleAnalytics.TotalTimeComponent);
2016-10-20 04:34:16 +00:00
});