2016-10-19 08:17:33 +00:00
|
|
|
//= require vue
|
2016-11-21 20:56:18 +00:00
|
|
|
//= require_tree ./svg
|
2016-10-19 08:17:33 +00:00
|
|
|
//= require_tree .
|
2016-10-20 04:34:16 +00:00
|
|
|
|
|
|
|
$(() => {
|
2016-11-21 20:04: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({
|
2016-10-20 23:24:36 +00:00
|
|
|
requestPath: cycleAnalyticsEl.dataset.requestPath,
|
|
|
|
});
|
2016-10-20 04:34:16 +00:00
|
|
|
|
|
|
|
gl.cycleAnalyticsApp = new Vue({
|
|
|
|
el: '#cycle-analytics',
|
|
|
|
name: 'CycleAnalytics',
|
2016-10-20 23:24:36 +00:00
|
|
|
data: {
|
|
|
|
state: cycleAnalyticsStore.state,
|
|
|
|
isLoading: false,
|
|
|
|
isLoadingStage: false,
|
|
|
|
isEmptyStage: false,
|
2016-11-15 19:10:31 +00:00
|
|
|
hasError: false,
|
2016-10-20 23:24:36 +00:00
|
|
|
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,
|
2016-10-20 23:24:36 +00:00
|
|
|
'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: {
|
2016-10-20 23:24:36 +00:00
|
|
|
handleError() {
|
2016-10-20 04:34:16 +00:00
|
|
|
cycleAnalyticsStore.setErrorState(true);
|
2016-10-20 23:24:36 +00:00
|
|
|
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);
|
2016-10-20 23:24:36 +00:00
|
|
|
this.startDate = $target.data('value');
|
2016-10-20 04:34:16 +00:00
|
|
|
|
|
|
|
$label.text($target.text().trim());
|
2016-10-20 23:24:36 +00:00
|
|
|
this.fetchCycleAnalyticsData({ startDate: this.startDate });
|
2016-10-20 04:34:16 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchCycleAnalyticsData(options) {
|
2016-10-20 23:24:36 +00:00
|
|
|
const fetchOptions = options || { startDate: this.startDate };
|
2016-10-20 04:34:16 +00:00
|
|
|
|
2016-10-20 23:24:36 +00:00
|
|
|
this.isLoading = true;
|
2016-10-20 04:34:16 +00:00
|
|
|
|
|
|
|
cycleAnalyticsService
|
2016-10-20 23:24:36 +00:00
|
|
|
.fetchCycleAnalyticsData(fetchOptions)
|
|
|
|
.done((response) => {
|
2016-10-20 04:34:16 +00:00
|
|
|
cycleAnalyticsStore.setCycleAnalyticsData(response);
|
2016-10-20 23:24:36 +00:00
|
|
|
this.selectDefaultStage();
|
2016-10-20 04:34:16 +00:00
|
|
|
this.initDropdown();
|
|
|
|
})
|
2016-10-20 23:24:36 +00:00
|
|
|
.error(() => {
|
|
|
|
this.handleError();
|
|
|
|
})
|
|
|
|
.always(() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
selectDefaultStage() {
|
2016-11-19 07:38:07 +00:00
|
|
|
const stage = this.state.stages.first();
|
|
|
|
this.selectStage(stage);
|
2016-10-20 23:24:36 +00:00
|
|
|
},
|
|
|
|
selectStage(stage) {
|
|
|
|
if (this.isLoadingStage) return;
|
|
|
|
if (this.currentStage === stage) return;
|
|
|
|
|
2016-11-19 07:38:07 +00:00
|
|
|
if (!stage.isUserAllowed) {
|
|
|
|
cycleAnalyticsStore.setActiveStage(stage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-20 23:24:36 +00:00
|
|
|
this.isLoadingStage = true;
|
2016-11-16 21:11:27 +00:00
|
|
|
cycleAnalyticsStore.setStageEvents([]);
|
2016-10-20 23:24:36 +00:00
|
|
|
cycleAnalyticsStore.setActiveStage(stage);
|
|
|
|
|
|
|
|
cycleAnalyticsService
|
|
|
|
.fetchStageData({
|
|
|
|
stage,
|
|
|
|
startDate: this.startDate,
|
|
|
|
})
|
|
|
|
.done((response) => {
|
2016-11-16 21:11:27 +00:00
|
|
|
this.isEmptyStage = !response.events.length;
|
|
|
|
cycleAnalyticsStore.setStageEvents(response.events);
|
2016-10-20 23:24:36 +00:00
|
|
|
})
|
|
|
|
.error(() => {
|
|
|
|
this.isEmptyStage = true;
|
2016-10-20 04:34:16 +00:00
|
|
|
})
|
|
|
|
.always(() => {
|
2016-10-20 23:24:36 +00:00
|
|
|
this.isLoadingStage = false;
|
2016-10-20 04:34:16 +00:00
|
|
|
});
|
2016-10-20 23:24:36 +00:00
|
|
|
},
|
|
|
|
dismissOverviewDialog() {
|
|
|
|
this.isOverviewDialogDismissed = true;
|
|
|
|
Cookies.set(OVERVIEW_DIALOG_COOKIE, '1');
|
|
|
|
},
|
|
|
|
},
|
2016-10-20 04:34:16 +00:00
|
|
|
});
|
2016-11-16 21:07:47 +00:00
|
|
|
|
|
|
|
// Register global components
|
|
|
|
Vue.component('total-time', gl.cycleAnalytics.TotalTimeComponent);
|
2016-10-20 04:34:16 +00:00
|
|
|
});
|