mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 07:41:43 +08:00
dashboard next: minor quality improvements
* locale for title * minimum chart/table while loading * sort users by type * more spacing in the UI * minor refactoring
This commit is contained in:
@ -5,7 +5,7 @@ import loadScript from 'discourse/lib/load-script';
|
|||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: ["dashboard-mini-chart"],
|
classNames: ["dashboard-mini-chart"],
|
||||||
|
|
||||||
classNameBindings: ["trend", "oneDataPoint"],
|
classNameBindings: ["trend", "oneDataPoint", "isLoading"],
|
||||||
|
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
total: null,
|
total: null,
|
||||||
@ -13,11 +13,9 @@ export default Ember.Component.extend({
|
|||||||
title: null,
|
title: null,
|
||||||
chartData: null,
|
chartData: null,
|
||||||
oneDataPoint: false,
|
oneDataPoint: false,
|
||||||
|
|
||||||
backgroundColor: "rgba(200,220,240,0.3)",
|
backgroundColor: "rgba(200,220,240,0.3)",
|
||||||
borderColor: "#08C",
|
borderColor: "#08C",
|
||||||
|
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
@ -46,17 +44,9 @@ export default Ember.Component.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeTrend(total, prevTotal) {
|
|
||||||
const percentChange = ((total - prevTotal) / prevTotal) * 100;
|
|
||||||
|
|
||||||
if (percentChange > 50) return "double-up";
|
|
||||||
if (percentChange > 0) return "up";
|
|
||||||
if (percentChange === 0) return "stable";
|
|
||||||
if (percentChange < 50) return "double-down";
|
|
||||||
if (percentChange < 0) return "down";
|
|
||||||
},
|
|
||||||
|
|
||||||
fetchReport() {
|
fetchReport() {
|
||||||
|
this.set("isLoading", true);
|
||||||
|
|
||||||
let payload = {data: {}};
|
let payload = {data: {}};
|
||||||
|
|
||||||
if (this.get("startDate")) {
|
if (this.get("startDate")) {
|
||||||
@ -67,8 +57,6 @@ export default Ember.Component.extend({
|
|||||||
payload.data.end_date = this.get("endDate").toISOString();
|
payload.data.end_date = this.get("endDate").toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("isLoading", true);
|
|
||||||
|
|
||||||
ajax(this.get("dataSource"), payload)
|
ajax(this.get("dataSource"), payload)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const report = response.report;
|
const report = response.report;
|
||||||
@ -94,9 +82,9 @@ export default Ember.Component.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
drawChart() {
|
drawChart() {
|
||||||
const ctx = this.$(".chart-canvas")[0].getContext("2d");
|
const context = this.$(".chart-canvas")[0].getContext("2d");
|
||||||
|
|
||||||
let data = {
|
const data = {
|
||||||
labels: this.get("chartData").map(r => r.x),
|
labels: this.get("chartData").map(r => r.x),
|
||||||
datasets: [{
|
datasets: [{
|
||||||
data: this.get("chartData").map(r => r.y),
|
data: this.get("chartData").map(r => r.y),
|
||||||
@ -105,25 +93,32 @@ export default Ember.Component.extend({
|
|||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = {
|
this._chart = new window.Chart(context, this._buildChartConfig(data));
|
||||||
|
},
|
||||||
|
|
||||||
|
_buildChartConfig(data) {
|
||||||
|
return {
|
||||||
type: "line",
|
type: "line",
|
||||||
data: data,
|
data,
|
||||||
options: {
|
options: {
|
||||||
legend: { display: false },
|
legend: { display: false },
|
||||||
responsive: true,
|
responsive: true,
|
||||||
layout: {
|
layout: { padding: { left: 0, top: 0, right: 0, bottom: 0 } },
|
||||||
padding: { left: 0, top: 0, right: 0, bottom: 0 }
|
|
||||||
},
|
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{ display: true, ticks: { suggestedMin: 0 } }],
|
||||||
display: true,
|
|
||||||
ticks: { suggestedMin: 0 }
|
|
||||||
}],
|
|
||||||
xAxes: [{ display: true }],
|
xAxes: [{ display: true }],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
this._chart = new window.Chart(ctx, config);
|
_computeTrend(total, prevTotal) {
|
||||||
}
|
const percentChange = ((total - prevTotal) / prevTotal) * 100;
|
||||||
|
|
||||||
|
if (percentChange > 50) return "double-up";
|
||||||
|
if (percentChange > 0) return "up";
|
||||||
|
if (percentChange === 0) return "stable";
|
||||||
|
if (percentChange < 50) return "double-down";
|
||||||
|
if (percentChange < 0) return "down";
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,8 @@ import computed from 'ember-addons/ember-computed-decorators';
|
|||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: ["dashboard-mini-table"],
|
classNames: ["dashboard-mini-table"],
|
||||||
|
|
||||||
|
classNameBindings: ["isLoading"],
|
||||||
|
|
||||||
total: null,
|
total: null,
|
||||||
labels: null,
|
labels: null,
|
||||||
title: null,
|
title: null,
|
||||||
@ -26,18 +28,20 @@ export default Ember.Component.extend({
|
|||||||
fetchReport() {
|
fetchReport() {
|
||||||
this.set("isLoading", true);
|
this.set("isLoading", true);
|
||||||
|
|
||||||
ajax(this.get("dataSource")).then((response) => {
|
ajax(this.get("dataSource"))
|
||||||
const report = response.report;
|
.then((response) => {
|
||||||
|
const report = response.report;
|
||||||
|
const data = report.data.sort((a, b) => a.x >= b.x);
|
||||||
|
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
labels: report.data.map(r => r.x),
|
labels: data.map(r => r.x),
|
||||||
dataset: report.data.map(r => r.y),
|
dataset: data.map(r => r.y),
|
||||||
total: report.total,
|
total: report.total,
|
||||||
title: report.title,
|
title: report.title,
|
||||||
chartData: report.data
|
chartData: data
|
||||||
|
});
|
||||||
|
}).finally(() => {
|
||||||
|
this.set("isLoading", false);
|
||||||
});
|
});
|
||||||
}).finally(() => {
|
|
||||||
this.set("isLoading", false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,8 +8,6 @@ export default Ember.Controller.extend({
|
|||||||
|
|
||||||
@computed("period")
|
@computed("period")
|
||||||
startDate(period) {
|
startDate(period) {
|
||||||
if (period === "all") return null;
|
|
||||||
|
|
||||||
switch (period) {
|
switch (period) {
|
||||||
case "yearly":
|
case "yearly":
|
||||||
return moment().subtract(1, "year").startOf("day");
|
return moment().subtract(1, "year").startOf("day");
|
||||||
@ -26,14 +24,14 @@ export default Ember.Controller.extend({
|
|||||||
case "daily":
|
case "daily":
|
||||||
return moment().startOf("day");
|
return moment().startOf("day");
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("period")
|
@computed("period")
|
||||||
endDate(period) {
|
endDate(period) {
|
||||||
if (period === "all") return null;
|
return period === "all" ? null : moment().endOf("day");
|
||||||
|
|
||||||
return moment().endOf("day");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{{#conditional-loading-spinner condition=loading}}
|
{{#conditional-loading-spinner condition=loading}}
|
||||||
<div class="community-health section">
|
<div class="community-health section">
|
||||||
<div class="section-title">
|
<div class="section-title">
|
||||||
<h2>Community health</h2>
|
<h2>{{i18n "admin.dashboard.community_health"}}</h2>
|
||||||
{{period-chooser period=period action="changePeriod"}}
|
{{period-chooser period=period action="changePeriod"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -33,6 +33,4 @@
|
|||||||
<div class="section-column">
|
<div class="section-column">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{{/conditional-loading-spinner}}
|
{{/conditional-loading-spinner}}
|
||||||
|
@ -36,14 +36,17 @@
|
|||||||
.dashboard-mini-table {
|
.dashboard-mini-table {
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
|
|
||||||
|
&.is-loading {
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
.table-title {
|
.table-title {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: .5em;
|
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
margin: 0 .5em 0 0;
|
margin: .5em 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +85,10 @@
|
|||||||
width: calc(100% * (1/3) - 1px);
|
width: calc(100% * (1/3) - 1px);
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
|
|
||||||
|
&.is-loading {
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
.d-icon-question-circle {
|
.d-icon-question-circle {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@ -89,10 +96,9 @@
|
|||||||
.chart-title {
|
.chart-title {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: .5em;
|
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
margin: 0 .5em 0 0;
|
margin: .5em 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2733,6 +2733,7 @@ en:
|
|||||||
page_views: "Pageviews"
|
page_views: "Pageviews"
|
||||||
page_views_short: "Pageviews"
|
page_views_short: "Pageviews"
|
||||||
show_traffic_report: "Show Detailed Traffic Report"
|
show_traffic_report: "Show Detailed Traffic Report"
|
||||||
|
community_health: Community health
|
||||||
|
|
||||||
charts:
|
charts:
|
||||||
signups:
|
signups:
|
||||||
|
Reference in New Issue
Block a user