2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
2017-03-11 01:45:34 -05:00
|
|
|
import Cookies from 'js-cookie';
|
2017-10-02 08:32:53 -04:00
|
|
|
import Flash from '../flash';
|
2017-04-18 09:55:09 -04:00
|
|
|
import Translate from '../vue_shared/translate';
|
2017-10-09 03:45:51 -04:00
|
|
|
import banner from './components/banner.vue';
|
2017-09-26 06:47:19 -04:00
|
|
|
import stageCodeComponent from './components/stage_code_component.vue';
|
|
|
|
import stagePlanComponent from './components/stage_plan_component.vue';
|
|
|
|
import stageComponent from './components/stage_component.vue';
|
|
|
|
import stageReviewComponent from './components/stage_review_component.vue';
|
|
|
|
import stageStagingComponent from './components/stage_staging_component.vue';
|
|
|
|
import stageTestComponent from './components/stage_test_component.vue';
|
2017-09-25 07:23:29 -04:00
|
|
|
import CycleAnalyticsService from './cycle_analytics_service';
|
|
|
|
import CycleAnalyticsStore from './cycle_analytics_store';
|
2016-10-20 00:34:16 -04:00
|
|
|
|
2017-04-18 09:55:09 -04:00
|
|
|
Vue.use(Translate);
|
|
|
|
|
2018-02-28 12:13:46 -05:00
|
|
|
export default () => {
|
2016-11-21 15:04:16 -05:00
|
|
|
const OVERVIEW_DIALOG_COOKIE = 'cycle_analytics_help_dismissed';
|
2016-10-20 00:34:16 -04:00
|
|
|
|
2018-10-10 02:09:55 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2016-10-20 00:34:16 -04:00
|
|
|
el: '#cycle-analytics',
|
|
|
|
name: 'CycleAnalytics',
|
2018-01-03 18:14:55 -05:00
|
|
|
components: {
|
|
|
|
banner,
|
|
|
|
'stage-issue-component': stageComponent,
|
|
|
|
'stage-plan-component': stagePlanComponent,
|
|
|
|
'stage-code-component': stageCodeComponent,
|
|
|
|
'stage-test-component': stageTestComponent,
|
|
|
|
'stage-review-component': stageReviewComponent,
|
|
|
|
'stage-staging-component': stageStagingComponent,
|
|
|
|
'stage-production-component': stageComponent,
|
|
|
|
},
|
2017-09-25 07:23:29 -04:00
|
|
|
data() {
|
|
|
|
const cycleAnalyticsEl = document.querySelector('#cycle-analytics');
|
|
|
|
const cycleAnalyticsService = new CycleAnalyticsService({
|
|
|
|
requestPath: cycleAnalyticsEl.dataset.requestPath,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
store: CycleAnalyticsStore,
|
|
|
|
state: CycleAnalyticsStore.state,
|
|
|
|
isLoading: false,
|
|
|
|
isLoadingStage: false,
|
|
|
|
isEmptyStage: false,
|
|
|
|
hasError: false,
|
|
|
|
startDate: 30,
|
|
|
|
isOverviewDialogDismissed: Cookies.get(OVERVIEW_DIALOG_COOKIE),
|
|
|
|
service: cycleAnalyticsService,
|
|
|
|
};
|
2016-10-20 19:24:36 -04:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
currentStage() {
|
2017-09-25 07:23:29 -04:00
|
|
|
return this.store.currentActiveStage();
|
2016-10-20 19:24:36 -04:00
|
|
|
},
|
|
|
|
},
|
2016-10-20 00:34:16 -04:00
|
|
|
created() {
|
|
|
|
this.fetchCycleAnalyticsData();
|
|
|
|
},
|
|
|
|
methods: {
|
2016-10-20 19:24:36 -04:00
|
|
|
handleError() {
|
2017-09-25 07:23:29 -04:00
|
|
|
this.store.setErrorState(true);
|
2016-10-20 19:24:36 -04:00
|
|
|
return new Flash('There was an error while fetching cycle analytics data.');
|
2016-10-20 00:34:16 -04:00
|
|
|
},
|
|
|
|
initDropdown() {
|
|
|
|
const $dropdown = $('.js-ca-dropdown');
|
|
|
|
const $label = $dropdown.find('.dropdown-label');
|
|
|
|
|
2018-10-10 02:09:55 -04:00
|
|
|
$dropdown
|
|
|
|
.find('li a')
|
|
|
|
.off('click')
|
|
|
|
.on('click', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
const $target = $(e.currentTarget);
|
|
|
|
this.startDate = $target.data('value');
|
2016-10-20 00:34:16 -04:00
|
|
|
|
2018-10-10 02:09:55 -04:00
|
|
|
$label.text($target.text().trim());
|
|
|
|
this.fetchCycleAnalyticsData({ startDate: this.startDate });
|
|
|
|
});
|
2016-10-20 00:34:16 -04:00
|
|
|
},
|
|
|
|
fetchCycleAnalyticsData(options) {
|
2016-10-20 19:24:36 -04:00
|
|
|
const fetchOptions = options || { startDate: this.startDate };
|
2016-10-20 00:34:16 -04:00
|
|
|
|
2016-10-20 19:24:36 -04:00
|
|
|
this.isLoading = true;
|
2016-10-20 00:34:16 -04:00
|
|
|
|
2017-09-25 07:23:29 -04:00
|
|
|
this.service
|
2016-10-20 19:24:36 -04:00
|
|
|
.fetchCycleAnalyticsData(fetchOptions)
|
2018-10-10 02:09:55 -04:00
|
|
|
.then(response => {
|
2017-09-25 07:23:29 -04:00
|
|
|
this.store.setCycleAnalyticsData(response);
|
2016-10-20 19:24:36 -04:00
|
|
|
this.selectDefaultStage();
|
2016-10-20 00:34:16 -04:00
|
|
|
this.initDropdown();
|
2017-09-25 07:23:29 -04:00
|
|
|
this.isLoading = false;
|
2016-10-20 00:34:16 -04:00
|
|
|
})
|
2017-09-25 07:23:29 -04:00
|
|
|
.catch(() => {
|
2016-10-20 19:24:36 -04:00
|
|
|
this.handleError();
|
|
|
|
this.isLoading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
selectDefaultStage() {
|
2017-08-04 04:07:05 -04:00
|
|
|
const stage = this.state.stages[0];
|
2016-11-19 02:38:07 -05:00
|
|
|
this.selectStage(stage);
|
2016-10-20 19:24:36 -04:00
|
|
|
},
|
|
|
|
selectStage(stage) {
|
|
|
|
if (this.isLoadingStage) return;
|
|
|
|
if (this.currentStage === stage) return;
|
|
|
|
|
2016-11-19 02:38:07 -05:00
|
|
|
if (!stage.isUserAllowed) {
|
2017-09-25 07:23:29 -04:00
|
|
|
this.store.setActiveStage(stage);
|
2016-11-19 02:38:07 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-20 19:24:36 -04:00
|
|
|
this.isLoadingStage = true;
|
2017-09-25 07:23:29 -04:00
|
|
|
this.store.setStageEvents([], stage);
|
|
|
|
this.store.setActiveStage(stage);
|
2016-10-20 19:24:36 -04:00
|
|
|
|
2017-09-25 07:23:29 -04:00
|
|
|
this.service
|
2016-10-20 19:24:36 -04:00
|
|
|
.fetchStageData({
|
|
|
|
stage,
|
|
|
|
startDate: this.startDate,
|
|
|
|
})
|
2018-10-10 02:09:55 -04:00
|
|
|
.then(response => {
|
2016-11-16 16:11:27 -05:00
|
|
|
this.isEmptyStage = !response.events.length;
|
2017-09-25 07:23:29 -04:00
|
|
|
this.store.setStageEvents(response.events, stage);
|
|
|
|
this.isLoadingStage = false;
|
2016-10-20 19:24:36 -04:00
|
|
|
})
|
2017-09-25 07:23:29 -04:00
|
|
|
.catch(() => {
|
2016-10-20 19:24:36 -04:00
|
|
|
this.isEmptyStage = true;
|
|
|
|
this.isLoadingStage = false;
|
2016-10-20 00:34:16 -04:00
|
|
|
});
|
2016-10-20 19:24:36 -04:00
|
|
|
},
|
|
|
|
dismissOverviewDialog() {
|
|
|
|
this.isOverviewDialogDismissed = true;
|
2017-04-08 04:44:03 -04:00
|
|
|
Cookies.set(OVERVIEW_DIALOG_COOKIE, '1', { expires: 365 });
|
2016-10-20 19:24:36 -04:00
|
|
|
},
|
|
|
|
},
|
2016-10-20 00:34:16 -04:00
|
|
|
});
|
2018-02-28 12:13:46 -05:00
|
|
|
};
|