2016-10-26 04:02:58 -04:00
|
|
|
/* eslint-disable */
|
2016-10-18 14:40:16 -04:00
|
|
|
//= require vue
|
|
|
|
|
2016-09-14 17:03:42 -04:00
|
|
|
((global) => {
|
|
|
|
|
2016-09-19 16:41:36 -04:00
|
|
|
const COOKIE_NAME = 'cycle_analytics_help_dismissed';
|
2016-09-23 05:46:06 -04:00
|
|
|
const store = gl.cycleAnalyticsStore = {
|
|
|
|
isLoading: true,
|
|
|
|
hasError: false,
|
2016-10-24 17:26:41 -04:00
|
|
|
isHelpDismissed: Cookies.get(COOKIE_NAME),
|
2016-09-23 05:46:06 -04:00
|
|
|
analytics: {}
|
|
|
|
};
|
2016-09-19 16:41:36 -04:00
|
|
|
|
2016-09-14 17:03:42 -04:00
|
|
|
gl.CycleAnalytics = class CycleAnalytics {
|
|
|
|
constructor() {
|
2016-09-19 16:41:36 -04:00
|
|
|
const that = this;
|
|
|
|
|
2016-09-14 17:03:42 -04:00
|
|
|
this.vue = new Vue({
|
|
|
|
el: '#cycle-analytics',
|
|
|
|
name: 'CycleAnalytics',
|
|
|
|
created: this.fetchData(),
|
2016-09-23 05:46:06 -04:00
|
|
|
data: store,
|
2016-09-19 16:41:36 -04:00
|
|
|
methods: {
|
|
|
|
dismissLanding() {
|
|
|
|
that.dismissLanding();
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 17:03:42 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-19 16:41:36 -04:00
|
|
|
fetchData(options) {
|
2016-09-23 05:46:06 -04:00
|
|
|
store.isLoading = true;
|
2016-09-19 16:41:36 -04:00
|
|
|
options = options || { startDate: 30 };
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: $('#cycle-analytics').data('request-path'),
|
|
|
|
method: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
contentType: 'application/json',
|
2016-10-14 17:29:54 -04:00
|
|
|
data: {
|
|
|
|
cycle_analytics: {
|
|
|
|
start_date: options.startDate
|
|
|
|
}
|
|
|
|
}
|
2016-09-19 16:41:36 -04:00
|
|
|
}).done((data) => {
|
2016-09-23 05:46:06 -04:00
|
|
|
this.decorateData(data);
|
2016-09-19 16:41:36 -04:00
|
|
|
this.initDropdown();
|
|
|
|
})
|
|
|
|
.error((data) => {
|
|
|
|
this.handleError(data);
|
|
|
|
})
|
|
|
|
.always(() => {
|
2016-09-23 05:46:06 -04:00
|
|
|
store.isLoading = false;
|
2016-09-19 16:41:36 -04:00
|
|
|
})
|
2016-09-14 17:03:42 -04:00
|
|
|
}
|
|
|
|
|
2016-09-19 16:41:36 -04:00
|
|
|
decorateData(data) {
|
|
|
|
data.summary = data.summary || [];
|
|
|
|
data.stats = data.stats || [];
|
|
|
|
|
|
|
|
data.summary.forEach((item) => {
|
|
|
|
item.value = item.value || '-';
|
|
|
|
});
|
|
|
|
|
|
|
|
data.stats.forEach((item) => {
|
2016-09-20 16:25:50 -04:00
|
|
|
item.value = item.value || '- - -';
|
2016-09-23 05:46:06 -04:00
|
|
|
});
|
2016-09-19 16:41:36 -04:00
|
|
|
|
2016-09-23 05:46:06 -04:00
|
|
|
store.analytics = data;
|
2016-09-14 17:03:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
handleError(data) {
|
2016-09-23 05:46:06 -04:00
|
|
|
store.hasError = true;
|
2016-09-19 16:41:36 -04:00
|
|
|
new Flash('There was an error while fetching cycle analytics data.', 'alert');
|
|
|
|
}
|
|
|
|
|
|
|
|
dismissLanding() {
|
2016-09-23 05:46:06 -04:00
|
|
|
store.isHelpDismissed = true;
|
2016-10-24 17:54:38 -04:00
|
|
|
Cookies.set(COOKIE_NAME, true);
|
2016-09-14 17:03:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
initDropdown() {
|
|
|
|
const $dropdown = $('.js-ca-dropdown');
|
|
|
|
const $label = $dropdown.find('.dropdown-label');
|
|
|
|
|
2016-09-19 16:41:36 -04:00
|
|
|
$dropdown.find('li a').off('click').on('click', (e) => {
|
2016-09-14 17:03:42 -04:00
|
|
|
e.preventDefault();
|
|
|
|
const $target = $(e.currentTarget);
|
2016-09-14 17:03:42 -04:00
|
|
|
const value = $target.data('value');
|
2016-09-14 17:03:42 -04:00
|
|
|
|
2016-09-14 17:03:42 -04:00
|
|
|
$label.text($target.text().trim());
|
2016-09-19 16:41:36 -04:00
|
|
|
this.fetchData({ startDate: value });
|
2016-09-14 17:03:42 -04:00
|
|
|
})
|
|
|
|
}
|
2016-09-19 16:41:36 -04:00
|
|
|
|
2016-09-14 17:03:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
})(window.gl || (window.gl = {}));
|