mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Fix date range sometimes leaving out today
This commit is contained in:
24
extensions/statistics/js/admin/dist/extension.js
vendored
24
extensions/statistics/js/admin/dist/extension.js
vendored
@@ -36,13 +36,14 @@ System.register('flarum/statistics/components/StatisticsWidget', ['flarum/compon
|
|||||||
value: function init() {
|
value: function init() {
|
||||||
babelHelpers.get(StatisticsWidget.prototype.__proto__ || Object.getPrototypeOf(StatisticsWidget.prototype), 'init', this).call(this);
|
babelHelpers.get(StatisticsWidget.prototype.__proto__ || Object.getPrototypeOf(StatisticsWidget.prototype), 'init', this).call(this);
|
||||||
|
|
||||||
var now = new Date();
|
var today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
this.entities = ['users', 'discussions', 'posts'];
|
this.entities = ['users', 'discussions', 'posts'];
|
||||||
this.periods = {
|
this.periods = {
|
||||||
last_7_days: { start: now - 86400000 * 7, end: now, step: 86400000 },
|
last_7_days: { start: today - 86400000 * 6, end: today, step: 86400000 },
|
||||||
last_28_days: { start: now - 86400000 * 28, end: now, step: 86400000 },
|
last_28_days: { start: today - 86400000 * 27, end: today, step: 86400000 },
|
||||||
last_12_months: { start: now - 86400000 * 365, end: now, step: 86400000 * 7 }
|
last_12_months: { start: today - 86400000 * 364, end: today, step: 86400000 * 7 }
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectedEntity = 'users';
|
this.selectedEntity = 'users';
|
||||||
@@ -129,16 +130,15 @@ System.register('flarum/statistics/components/StatisticsWidget', ['flarum/compon
|
|||||||
value: function drawChart(elm, isInitialized, context) {
|
value: function drawChart(elm, isInitialized, context) {
|
||||||
var entity = this.selectedEntity;
|
var entity = this.selectedEntity;
|
||||||
var period = this.periods[this.selectedPeriod];
|
var period = this.periods[this.selectedPeriod];
|
||||||
var daily = app.data.statistics[this.selectedEntity].daily;
|
|
||||||
var labels = [];
|
var labels = [];
|
||||||
var thisPeriod = [];
|
var thisPeriod = [];
|
||||||
var lastPeriod = [];
|
var lastPeriod = [];
|
||||||
|
|
||||||
for (var i = period.start; i < period.end; i += period.step) {
|
for (var i = period.start; i <= period.end; i += period.step) {
|
||||||
var date = new Date(i);
|
labels.push(moment(i).format('D MMM'));
|
||||||
date.setHours(0, 0, 0, 0);
|
|
||||||
labels.push(moment(date).format('D MMM'));
|
|
||||||
thisPeriod.push(this.getPeriodCount(entity, { start: i, end: i + period.step }));
|
thisPeriod.push(this.getPeriodCount(entity, { start: i, end: i + period.step }));
|
||||||
|
|
||||||
var periodLength = period.end - period.start;
|
var periodLength = period.end - period.start;
|
||||||
lastPeriod.push(this.getPeriodCount(entity, { start: i - periodLength, end: i - periodLength + period.step }));
|
lastPeriod.push(this.getPeriodCount(entity, { start: i - periodLength, end: i - periodLength + period.step }));
|
||||||
}
|
}
|
||||||
@@ -151,11 +151,11 @@ System.register('flarum/statistics/components/StatisticsWidget', ['flarum/compon
|
|||||||
data: { labels: labels, datasets: datasets },
|
data: { labels: labels, datasets: datasets },
|
||||||
type: 'line',
|
type: 'line',
|
||||||
height: 200,
|
height: 200,
|
||||||
x_axis_mode: 'tick', // for short label ticks
|
x_axis_mode: 'tick',
|
||||||
y_axis_mode: 'span', // for long horizontal lines, or 'tick'
|
y_axis_mode: 'span',
|
||||||
is_series: 1,
|
is_series: 1,
|
||||||
show_dots: 0,
|
show_dots: 0,
|
||||||
colors: ['rgba(0,0,0,0.2)', app.forum.attribute('themePrimaryColor')],
|
colors: ['rgba(0,0,0,0.1)', app.forum.attribute('themePrimaryColor')],
|
||||||
format_tooltip_x: function format_tooltip_x(d) {
|
format_tooltip_x: function format_tooltip_x(d) {
|
||||||
return d;
|
return d;
|
||||||
},
|
},
|
||||||
|
@@ -19,13 +19,14 @@ export default class StatisticsWidget extends DashboardWidget {
|
|||||||
init() {
|
init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
const now = new Date();
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
this.entities = ['users', 'discussions', 'posts'];
|
this.entities = ['users', 'discussions', 'posts'];
|
||||||
this.periods = {
|
this.periods = {
|
||||||
last_7_days: {start: now - 86400000 * 7, end: now, step: 86400000},
|
last_7_days: {start: today - 86400000 * 6, end: today, step: 86400000},
|
||||||
last_28_days: {start: now - 86400000 * 28, end: now, step: 86400000},
|
last_28_days: {start: today - 86400000 * 27, end: today, step: 86400000},
|
||||||
last_12_months: {start: now - 86400000 * 365, end: now, step: 86400000 * 7}
|
last_12_months: {start: today - 86400000 * 364, end: today, step: 86400000 * 7}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectedEntity = 'users';
|
this.selectedEntity = 'users';
|
||||||
@@ -85,16 +86,15 @@ export default class StatisticsWidget extends DashboardWidget {
|
|||||||
drawChart(elm, isInitialized, context) {
|
drawChart(elm, isInitialized, context) {
|
||||||
const entity = this.selectedEntity;
|
const entity = this.selectedEntity;
|
||||||
const period = this.periods[this.selectedPeriod];
|
const period = this.periods[this.selectedPeriod];
|
||||||
const daily = app.data.statistics[this.selectedEntity].daily;
|
|
||||||
const labels = [];
|
const labels = [];
|
||||||
const thisPeriod = [];
|
const thisPeriod = [];
|
||||||
const lastPeriod = [];
|
const lastPeriod = [];
|
||||||
|
|
||||||
for (let i = period.start; i < period.end; i += period.step) {
|
for (let i = period.start; i <= period.end; i += period.step) {
|
||||||
const date = new Date(i);
|
labels.push(moment(i).format('D MMM'));
|
||||||
date.setHours(0, 0, 0, 0);
|
|
||||||
labels.push(moment(date).format('D MMM'));
|
|
||||||
thisPeriod.push(this.getPeriodCount(entity, {start: i, end: i + period.step}));
|
thisPeriod.push(this.getPeriodCount(entity, {start: i, end: i + period.step}));
|
||||||
|
|
||||||
const periodLength = period.end - period.start;
|
const periodLength = period.end - period.start;
|
||||||
lastPeriod.push(this.getPeriodCount(entity, {start: i - periodLength, end: i - periodLength + period.step}));
|
lastPeriod.push(this.getPeriodCount(entity, {start: i - periodLength, end: i - periodLength + period.step}));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user