2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import Cookies from 'js-cookie';
|
2018-03-17 18:26:18 +05:30
|
|
|
import Flash from '../flash';
|
2017-08-17 22:00:37 +05:30
|
|
|
import Translate from '../vue_shared/translate';
|
2018-03-17 18:26:18 +05:30
|
|
|
import banner from './components/banner.vue';
|
|
|
|
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';
|
|
|
|
import CycleAnalyticsService from './cycle_analytics_service';
|
|
|
|
import CycleAnalyticsStore from './cycle_analytics_store';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
export default () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const OVERVIEW_DIALOG_COOKIE = 'cycle_analytics_help_dismissed';
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
new Vue({ // eslint-disable-line no-new
|
2017-08-17 22:00:37 +05:30
|
|
|
el: '#cycle-analytics',
|
|
|
|
name: 'CycleAnalytics',
|
2018-03-17 18:26:18 +05:30
|
|
|
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,
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
currentStage() {
|
2018-03-17 18:26:18 +05:30
|
|
|
return this.store.currentActiveStage();
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.fetchCycleAnalyticsData();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleError() {
|
2018-03-17 18:26:18 +05:30
|
|
|
this.store.setErrorState(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
return new Flash('There was an error while fetching cycle analytics data.');
|
|
|
|
},
|
|
|
|
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');
|
|
|
|
|
|
|
|
$label.text($target.text().trim());
|
|
|
|
this.fetchCycleAnalyticsData({ startDate: this.startDate });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchCycleAnalyticsData(options) {
|
|
|
|
const fetchOptions = options || { startDate: this.startDate };
|
|
|
|
|
|
|
|
this.isLoading = true;
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
this.service
|
2017-08-17 22:00:37 +05:30
|
|
|
.fetchCycleAnalyticsData(fetchOptions)
|
2018-03-17 18:26:18 +05:30
|
|
|
.then(resp => resp.json())
|
|
|
|
.then((response) => {
|
|
|
|
this.store.setCycleAnalyticsData(response);
|
2017-08-17 22:00:37 +05:30
|
|
|
this.selectDefaultStage();
|
|
|
|
this.initDropdown();
|
2018-03-17 18:26:18 +05:30
|
|
|
this.isLoading = false;
|
2017-08-17 22:00:37 +05:30
|
|
|
})
|
2018-03-17 18:26:18 +05:30
|
|
|
.catch(() => {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.handleError();
|
|
|
|
this.isLoading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
selectDefaultStage() {
|
2017-09-10 17:25:29 +05:30
|
|
|
const stage = this.state.stages[0];
|
2017-08-17 22:00:37 +05:30
|
|
|
this.selectStage(stage);
|
|
|
|
},
|
|
|
|
selectStage(stage) {
|
|
|
|
if (this.isLoadingStage) return;
|
|
|
|
if (this.currentStage === stage) return;
|
|
|
|
|
|
|
|
if (!stage.isUserAllowed) {
|
2018-03-17 18:26:18 +05:30
|
|
|
this.store.setActiveStage(stage);
|
2017-08-17 22:00:37 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isLoadingStage = true;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.store.setStageEvents([], stage);
|
|
|
|
this.store.setActiveStage(stage);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
this.service
|
2017-08-17 22:00:37 +05:30
|
|
|
.fetchStageData({
|
|
|
|
stage,
|
|
|
|
startDate: this.startDate,
|
|
|
|
})
|
2018-03-17 18:26:18 +05:30
|
|
|
.then(resp => resp.json())
|
|
|
|
.then((response) => {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.isEmptyStage = !response.events.length;
|
2018-03-17 18:26:18 +05:30
|
|
|
this.store.setStageEvents(response.events, stage);
|
|
|
|
this.isLoadingStage = false;
|
2017-08-17 22:00:37 +05:30
|
|
|
})
|
2018-03-17 18:26:18 +05:30
|
|
|
.catch(() => {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.isEmptyStage = true;
|
|
|
|
this.isLoadingStage = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
dismissOverviewDialog() {
|
|
|
|
this.isOverviewDialogDismissed = true;
|
|
|
|
Cookies.set(OVERVIEW_DIALOG_COOKIE, '1', { expires: 365 });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|