Skip to content

Commit

Permalink
Major refactoring, set min date to July 2015
Browse files Browse the repository at this point in the history
Move lang selector to footer
  • Loading branch information
MusikAnimal committed May 11, 2016
1 parent f15f15c commit c3d0d65
Show file tree
Hide file tree
Showing 61 changed files with 2,045 additions and 1,945 deletions.
4 changes: 2 additions & 2 deletions javascripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const pv = require('./shared/pv');
* @type {Object}
*/
const config = {
articleSelector: '.aqs-article-selector',
chart: '.aqs-chart',
chartConfig: {
Line: {
Expand Down Expand Up @@ -126,10 +125,11 @@ const config = {
tooltipTemplate: '<%if (label){%><%=label%>: <%}%><%= formatNumber(value) %>'
},
linearCharts: ['Line', 'Bar', 'Radar'],
minDate: moment('2015-08-01').startOf('day'),
minDate: moment('2015-07-01').startOf('day'),
maxDate: moment().subtract(1, 'days').startOf('day'),
platformSelector: '#platform-select',
projectInput: '.aqs-project-input',
select2Input: '.aqs-article-selector',
specialRanges: {
'last-week': [moment().subtract(1, 'week').startOf('week'), moment().subtract(1, 'week').endOf('week')],
'this-month': [moment().startOf('month'), moment().subtract(1, 'days').startOf('day')],
Expand Down
3 changes: 2 additions & 1 deletion javascripts/langviews/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const config = {
}
},
cookieExpiry: 30, // num days
dateLimit: 31, // num days
dateRangeSelector: '#range_input',
defaults: {
dateFormat: 'YYYY-MM-DD',
Expand All @@ -46,7 +47,7 @@ const config = {
}
}
},
minDate: moment('2015-08-01'),
minDate: moment('2015-07-01'),
maxDate: moment().subtract(1, 'days'),
platformSelector: '#platform_select',
projectInput: '#project_input',
Expand Down
88 changes: 4 additions & 84 deletions javascripts/langviews/langviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,6 @@ class LangViews extends Pv {
return params;
}

/**
* Simple metric to see how many use it (pageviews of the pageview, a meta-pageview, if you will :)
* @return {null} nothing
*/
patchUsage() {
if (location.host !== 'localhost') {
$.ajax({
url: `//tools.wmflabs.org/musikanimal/api/lv_uses/${this.project}`,
method: 'PATCH'
});
}
}

/**
* Parses the URL query string and sets all the inputs accordingly
* Should only be called on initial page load, until we decide to support pop states (probably never)
Expand All @@ -489,8 +476,8 @@ class LangViews extends Pv {
} else if (params.start) {
startDate = moment(params.start || moment().subtract(config.defaults.daysAgo, 'days'));
endDate = moment(params.end || Date.now());
if (startDate < moment('2015-08-01') || endDate < moment('2015-08-01')) {
this.addSiteNotice('danger', $.i18n('param-error-1'), $.i18n('invalid-params'), true);
if (startDate < config.minDate || endDate < config.minDate) {
this.addSiteNotice('danger', $.i18n('param-error-1', `${$.i18n('july')} 2015`), $.i18n('invalid-params'), true);
return;
} else if (startDate > endDate) {
this.addSiteNotice('warning', $.i18n('param-error-2'), $.i18n('invalid-params'), true);
Expand Down Expand Up @@ -558,76 +545,9 @@ class LangViews extends Pv {
* @returns {null} - nothing
*/
setupDateRangeSelector() {
const dateRangeSelector = $(config.dateRangeSelector);

/** transform config.specialRanges to have i18n as keys */
let ranges = {};
Object.keys(config.specialRanges).forEach(key => {
ranges[$.i18n(key)] = config.specialRanges[key];
});

dateRangeSelector.daterangepicker({
locale: {
format: this.dateFormat,
applyLabel: $.i18n('apply'),
cancelLabel: $.i18n('cancel'),
customRangeLabel: $.i18n('custom-range'),
dateLimit: { days: 31 },
daysOfWeek: [
$.i18n('su'),
$.i18n('mo'),
$.i18n('tu'),
$.i18n('we'),
$.i18n('th'),
$.i18n('fr'),
$.i18n('sa')
],
monthNames: [
$.i18n('january'),
$.i18n('february'),
$.i18n('march'),
$.i18n('april'),
$.i18n('may'),
$.i18n('june'),
$.i18n('july'),
$.i18n('august'),
$.i18n('september'),
$.i18n('october'),
$.i18n('november'),
$.i18n('december')
]
},
startDate: moment().subtract(config.defaults.daysAgo, 'days'),
minDate: config.minDate,
maxDate: config.maxDate,
ranges: ranges
});

/** so people know why they can't query data older than August 2015 */
$('.daterangepicker').append(
$('<div>')
.addClass('daterange-notice')
.html($.i18n('date-notice', document.title, "<a href='http://stats.grok.se' target='_blank'>stats.grok.se</a>"))
);

/**
* The special date range options (buttons the right side of the daterange picker)
*
* WARNING: we're unable to add class names or data attrs to the range options,
* so checking which was clicked is hardcoded based on the index of the LI,
* as defined in config.specialRanges
*/
$('.daterangepicker .ranges li').on('click', e => {
const index = $('.daterangepicker .ranges li').index(e.target),
container = this.daterangepicker.container,
inputs = container.find('.daterangepicker_input input');
this.specialRange = {
range: Object.keys(config.specialRanges)[index],
value: `${inputs[0].value} - ${inputs[1].value}`
};
});
super.setupDateRangeSelector();

dateRangeSelector.on('apply.daterangepicker', (e, action) => {
$(config.dateRangeSelector).on('apply.daterangepicker', (e, action) => {
if (action.chosenLabel === $.i18n('custom-range')) {
this.specialRange = null;

Expand Down
Loading

0 comments on commit c3d0d65

Please sign in to comment.