FEATURE: adds a /admin/reports route to list all reports

This commit is contained in:
Joffrey JAFFEUX 2018-06-18 12:31:56 +02:00 committed by GitHub
parent 4b604b1e68
commit f2dbe66367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 129 additions and 8 deletions

View File

@ -4,7 +4,6 @@ import Report from "admin/models/report";
import computed from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend({
classNames: ["admin-reports"],
queryParams: ["mode", "start_date", "end_date", "category_id", "group_id"],
viewMode: "graph",
viewingTable: Em.computed.equal("viewMode", "table"),

View File

@ -0,0 +1,13 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
model() {
return ajax("/admin/reports").then(json => {
return json;
});
},
setupController(controller, model) {
controller.setProperties({ model: model.reports });
}
});

View File

@ -19,7 +19,7 @@ export default Discourse.Route.extend({
);
},
setupController: function(controller, model) {
setupController(controller, model) {
controller.setProperties({
model: model,
categoryId: model.get("category_id") || "all",

View File

@ -95,10 +95,13 @@ export default function() {
}
);
this.route("adminReports", {
path: "/reports/:type",
resetNamespace: true
});
this.route(
"adminReports",
{ path: "/reports", resetNamespace: true },
function() {
this.route("show", { path: ":type" });
}
);
this.route(
"adminFlags",

View File

@ -79,6 +79,10 @@
</div>
{{/conditional-loading-section}}
</div>
{{#link-to "adminReports"}}
{{i18n "admin.dashboard.all_reports"}}
{{/link-to}}
<div class="user-metrics">
{{dashboard-inline-table dataSourceNames="users_by_type" lastRefreshedAt=lastRefreshedAt}}

View File

@ -0,0 +1,17 @@
<h3>{{i18n "admin.reports.title"}}</h3>
<ul class="reports-list">
{{#each model as |report|}}
<li class="report">
{{#link-to 'adminReports.show' report.type}}
<h4 class="report-title">{{report.title}}</h4>
{{/link-to}}
{{#if report.description}}
<p class="report-description">
{{report.description}}
</p>
{{/if}}
</li>
{{/each}}
</ul>

View File

@ -1,4 +1,12 @@
<h3>{{model.title}}</h3>
<h3>
{{#link-to "adminReports"}}
{{i18n "admin.dashboard.all_reports"}}
{{/link-to}}
|
{{model.title}}
</h3>
{{#if model.description}}
<p>{{model.description}}</p>

View File

@ -5,6 +5,20 @@
padding-bottom: 0.5em;
}
.reports-list {
list-style: none;
margin: 0;
.report {
padding-bottom: 0.5em;
margin-bottom: 0.5em;
.report-description {
margin: 0;
}
}
}
.report-container {
display: flex;

View File

@ -1,6 +1,22 @@
require_dependency 'report'
class Admin::ReportsController < Admin::AdminController
def index
reports_methods = Report.singleton_methods.grep(/^report_(?!about)/)
reports = reports_methods.map do |name|
type = name.to_s.gsub('report_', '')
description = I18n.t("reports.#{type}.description", default: '')
{
type: type,
title: I18n.t("reports.#{type}.title"),
description: description.presence ? description : nil,
}
end
render_json_dump(reports: reports.sort_by { |report| report[:title] })
end
def show
report_type = params[:type]

View File

@ -2711,6 +2711,9 @@ en:
title: 'Discourse Admin'
moderator: 'Moderator'
reports:
title: "List of available reports"
dashboard:
title: "Dashboard"
last_updated: "Dashboard last updated:"
@ -2749,6 +2752,7 @@ en:
community_health: Community health
whats_new_in_discourse: Whats new in Discourse?
activity_metrics: Activity Metrics
all_reports: "All reports"
reports:
trend_title: "%{percent} change. Currently %{current}, was %{prev} in previous period."

View File

@ -1012,7 +1012,7 @@ en:
xaxis: "Day"
yaxis: "Total"
mobile_visits:
title: "User Visits"
title: "User Visits (mobile)"
xaxis: "Day"
yaxis: "Number of visits"
web_crawlers:

View File

@ -74,6 +74,7 @@ Discourse::Application.routes.draw do
end
end
get "reports" => "reports#index"
get "reports/:type" => "reports#show"
resources :groups, constraints: AdminConstraint.new do

View File

@ -0,0 +1,31 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Reports", {
loggedIn: true
});
QUnit.test("Visit reports page", assert => {
visit("/admin/reports");
andThen(() => {
assert.equal($(".reports-list .report").length, 1);
const $report = $(".reports-list .report:first-child");
assert.equal(
$report
.find(".report-title")
.html()
.trim(),
"My report"
);
assert.equal(
$report
.find(".report-description")
.html()
.trim(),
"List of my activities"
);
});
});

View File

@ -0,0 +1,11 @@
export default {
"/admin/reports": {
reports: [
{
title: "My report",
description: "List of my activities",
type: "my_report"
}
]
}
};