From ba0cec209125eca9b6c193fea38aa65df96af636 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 14 May 2018 14:23:51 +0200 Subject: [PATCH] UX: minor fixes to new dashboard UI - adds a link to search log - display a text if log search queries is disabled - adds link to trust level and user types - adds a description for eeach report when browsing a report directly --- .../admin/components/dashboard-table.js.es6 | 5 ++ .../controllers/admin-dashboard-next.js.es6 | 43 +++++++------- .../admin/mixins/async-report.js.es6 | 2 + .../components/dashboard-inline-table.hbs | 10 +++- .../templates/components/dashboard-table.hbs | 58 ++++++++++--------- .../admin/templates/dashboard_next.hbs | 46 ++++++++++----- .../javascripts/admin/templates/reports.hbs | 4 ++ .../common/admin/dashboard_next.scss | 7 ++- app/models/report.rb | 10 ++-- config/locales/client.en.yml | 4 ++ config/site_settings.yml | 4 +- 11 files changed, 120 insertions(+), 73 deletions(-) diff --git a/app/assets/javascripts/admin/components/dashboard-table.js.es6 b/app/assets/javascripts/admin/components/dashboard-table.js.es6 index 8d6ba5eb141..6db70f9bb89 100644 --- a/app/assets/javascripts/admin/components/dashboard-table.js.es6 +++ b/app/assets/javascripts/admin/components/dashboard-table.js.es6 @@ -6,8 +6,11 @@ import { number } from 'discourse/lib/formatter'; export default Ember.Component.extend(AsyncReport, { classNames: ["dashboard-table"], + classNameBindings : ["isDisabled"], help: null, helpPage: null, + isDisabled: Ember.computed.not("siteSettings.log_search_queries"), + disabledLabel: "admin.dashboard.reports.disabled", @computed("report") values(report) { @@ -29,6 +32,8 @@ export default Ember.Component.extend(AsyncReport, { }, fetchReport() { + if (this.get("isDisabled")) return; + this.set("isLoading", true); let payload = { data: { async: true } }; diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 index 1dead81e483..ac359b8cd78 100644 --- a/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 @@ -1,9 +1,9 @@ -import { setting } from 'discourse/lib/computed'; +import { setting } from "discourse/lib/computed"; import DiscourseURL from "discourse/lib/url"; import computed from "ember-addons/ember-computed-decorators"; import AdminDashboardNext from "admin/models/admin-dashboard-next"; import Report from "admin/models/report"; -import VersionCheck from 'admin/models/version-check'; +import VersionCheck from "admin/models/version-check"; const PROBLEMS_CHECK_MINUTES = 1; @@ -13,26 +13,25 @@ export default Ember.Controller.extend({ isLoading: false, dashboardFetchedAt: null, exceptionController: Ember.inject.controller("exception"), - showVersionChecks: setting('version_checks'), + showVersionChecks: setting("version_checks"), diskSpace: Ember.computed.alias("model.attributes.disk_space"), - + logSearchQueriesEnabled: setting("log_search_queries"), availablePeriods: ["yearly", "quarterly", "monthly", "weekly"], - @computed('problems.length') + @computed("problems.length") foundProblems(problemsLength) { - return this.currentUser.get('admin') && (problemsLength || 0) > 0; + return this.currentUser.get("admin") && (problemsLength || 0) > 0; }, - - @computed('foundProblems') + @computed("foundProblems") thereWereProblems(foundProblems) { - if (!this.currentUser.get('admin')) { return false; } + if (!this.currentUser.get("admin")) { return false; } if (foundProblems) { - this.set('hadProblems', true); + this.set("hadProblems", true); return true; } else { - return this.get('hadProblems') || false; + return this.get("hadProblems") || false; } }, @@ -47,7 +46,7 @@ export default Ember.Controller.extend({ AdminDashboardNext.find().then(adminDashboardNextModel => { if (versionChecks) { - this.set('versionCheck', VersionCheck.create(adminDashboardNextModel.version_check)); + this.set("versionCheck", VersionCheck.create(adminDashboardNextModel.version_check)); } this.setProperties({ @@ -63,29 +62,29 @@ export default Ember.Controller.extend({ }); } - if (!this.get('problemsFetchedAt') || moment().subtract(PROBLEMS_CHECK_MINUTES, 'minutes').toDate() > this.get('problemsFetchedAt')) { + if (!this.get("problemsFetchedAt") || moment().subtract(PROBLEMS_CHECK_MINUTES, "minutes").toDate() > this.get("problemsFetchedAt")) { this.loadProblems(); } }, loadProblems() { - this.set('loadingProblems', true); - this.set('problemsFetchedAt', new Date()); + this.set("loadingProblems", true); + this.set("problemsFetchedAt", new Date()); AdminDashboardNext.fetchProblems().then(d => { - this.set('problems', d.problems); + this.set("problems", d.problems); }).finally(() => { - this.set('loadingProblems', false); + this.set("loadingProblems", false); }); }, - @computed('problemsFetchedAt') + @computed("problemsFetchedAt") problemsTimestamp(problemsFetchedAt) { - return moment(problemsFetchedAt).locale('en').format('LLL'); + return moment(problemsFetchedAt).locale("en").format("LLL"); }, @computed("period") startDate(period) { - let fullDay = moment().locale('en').utc().subtract(1, "day"); + let fullDay = moment().locale("en").utc().subtract(1, "day"); switch (period) { case "yearly": @@ -107,12 +106,12 @@ export default Ember.Controller.extend({ @computed() lastWeek() { - return moment().locale('en').utc().endOf("day").subtract(1, "week"); + return moment().locale("en").utc().endOf("day").subtract(1, "week"); }, @computed() endDate() { - return moment().locale('en').utc().subtract(1, "day").endOf("day"); + return moment().locale("en").utc().subtract(1, "day").endOf("day"); }, @computed("updated_at") diff --git a/app/assets/javascripts/admin/mixins/async-report.js.es6 b/app/assets/javascripts/admin/mixins/async-report.js.es6 index 96f541935ad..c06c01ef141 100644 --- a/app/assets/javascripts/admin/mixins/async-report.js.es6 +++ b/app/assets/javascripts/admin/mixins/async-report.js.es6 @@ -47,6 +47,8 @@ export default Ember.Mixin.create({ loadReport() {}, + fetchReport() {}, + @computed("dataSourceName") dataSource(dataSourceName) { return `/admin/reports/${dataSourceName}`; diff --git a/app/assets/javascripts/admin/templates/components/dashboard-inline-table.hbs b/app/assets/javascripts/admin/templates/components/dashboard-inline-table.hbs index a5c22f86c68..9e97de2f469 100644 --- a/app/assets/javascripts/admin/templates/components/dashboard-inline-table.hbs +++ b/app/assets/javascripts/admin/templates/components/dashboard-inline-table.hbs @@ -18,9 +18,13 @@ - {{#each values as |value|}} - {{number value}} - {{/each}} + {{#unless hasBlock}} + {{#each values as |value|}} + {{number value}} + {{/each}} + {{else}} + {{yield (hash report=report)}} + {{/unless}} diff --git a/app/assets/javascripts/admin/templates/components/dashboard-table.hbs b/app/assets/javascripts/admin/templates/components/dashboard-table.hbs index d658f4bb019..5055d04175d 100644 --- a/app/assets/javascripts/admin/templates/components/dashboard-table.hbs +++ b/app/assets/javascripts/admin/templates/components/dashboard-table.hbs @@ -1,31 +1,37 @@ -{{#conditional-loading-section isLoading=isLoading title=report.title}} -
-

{{report.title}}

+{{#if isDisabled}} + {{{i18n disabledLabel}}} +{{else}} + {{#conditional-loading-section isLoading=isLoading title=report.title}} +
+

{{report.title}}

- {{#if help}} - {{i18n help}} - {{/if}} -
+ {{#if help}} + {{i18n help}} + {{/if}} +
-
- - - - {{#each labels as |label|}} - - {{/each}} - - - - - {{#each values as |value|}} +
+
{{label}}
+ - {{#each value as |v|}} - + {{#each labels as |label|}} + {{/each}} - {{/each}} - -
{{v}}{{label}}
-
-{{/conditional-loading-section}} + + + + {{#each values as |value|}} + + {{#each value as |v|}} + {{v}} + {{/each}} + + {{/each}} + + + + {{yield}} + + {{/conditional-loading-section}} +{{/if}} diff --git a/app/assets/javascripts/admin/templates/dashboard_next.hbs b/app/assets/javascripts/admin/templates/dashboard_next.hbs index 3f7ad4f6d11..fb1951cd282 100644 --- a/app/assets/javascripts/admin/templates/dashboard_next.hbs +++ b/app/assets/javascripts/admin/templates/dashboard_next.hbs @@ -1,14 +1,14 @@ {{plugin-outlet name="admin-dashboard-top"}}
-{{#if showVersionChecks}} -
- {{partial 'admin/templates/version-checks'}} -
-
- {{partial 'admin/templates/dashboard-problems'}} -
-{{/if}} + {{#if showVersionChecks}} +
+ {{partial 'admin/templates/version-checks'}} +
+
+ {{partial 'admin/templates/dashboard-problems'}} +
+ {{/if}}
@@ -85,13 +85,25 @@ {{/conditional-loading-section}} - {{dashboard-inline-table - dataSourceName="users_by_type" - lastRefreshedAt=lastRefreshedAt}} + {{#dashboard-inline-table dataSourceName="users_by_type" lastRefreshedAt=lastRefreshedAt as |context|}} + {{#each context.report.data as |data|}} + + + {{number data.y}} + + + {{/each}} + {{/dashboard-inline-table}} - {{dashboard-inline-table - dataSourceName="users_by_trust_level" - lastRefreshedAt=lastRefreshedAt}} + {{#dashboard-inline-table dataSourceName="users_by_trust_level" lastRefreshedAt=lastRefreshedAt as |context|}} + {{#each context.report.data as |data|}} + + + {{number data.y}} + + + {{/each}} + {{/dashboard-inline-table}} {{#conditional-loading-section isLoading=isLoading title=(i18n "admin.dashboard.backups")}}
@@ -135,9 +147,13 @@
- {{dashboard-table-trending-search + {{#dashboard-table-trending-search dataSourceName="trending_search" + isEnabled=logSearchQueriesEnabled + disabledLabel="admin.dashboard.reports.trending_search.disabled" startDate=lastWeek endDate=endDate}} + {{{i18n "admin.dashboard.reports.trending_search.more"}}} + {{/dashboard-table-trending-search}}
diff --git a/app/assets/javascripts/admin/templates/reports.hbs b/app/assets/javascripts/admin/templates/reports.hbs index 1a6b4bf0477..eab27824252 100644 --- a/app/assets/javascripts/admin/templates/reports.hbs +++ b/app/assets/javascripts/admin/templates/reports.hbs @@ -1,5 +1,9 @@

{{model.title}}

+{{#if model.description}} +

{{model.description}}

+{{/if}} +
{{i18n 'admin.dashboard.reports.start_date'}} {{date-picker-past value=startDate defaultDate=startDate}} {{i18n 'admin.dashboard.reports.end_date'}} {{date-picker-past value=endDate defaultDate=endDate}} diff --git a/app/assets/stylesheets/common/admin/dashboard_next.scss b/app/assets/stylesheets/common/admin/dashboard_next.scss index 46fd65c00ad..afe91b2614f 100644 --- a/app/assets/stylesheets/common/admin/dashboard_next.scss +++ b/app/assets/stylesheets/common/admin/dashboard_next.scss @@ -65,6 +65,11 @@ .dashboard-table { margin-bottom: 1em; + &.is-disabled { + background: $primary-low; + padding: 1em; + } + @include small-width { table { tbody tr td { @@ -91,7 +96,7 @@ table-layout: fixed; thead { - border: 1px solid $primary-low; + border: 1px solid $primary-low; tr { background: $primary-low; th { diff --git a/app/models/report.rb b/app/models/report.rb index 0bc05d6cbda..a3af4387da3 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -324,7 +324,7 @@ class Report def self.report_users_by_trust_level(report) report.data = [] User.real.group('trust_level').count.sort.each do |level, count| - report.data << { x: level.to_i, y: count } + report.data << { key: TrustLevel.levels[level.to_i], x: level.to_i, y: count } end end @@ -401,16 +401,16 @@ class Report label = Proc.new { |key| I18n.t("reports.users_by_type.xaxis_labels.#{key}") } admins = User.real.admins.count - report.data << { x: label.call("admin"), y: admins } if admins > 0 + report.data << { key: "admin", x: label.call("admin"), y: admins } if admins > 0 moderators = User.real.moderators.count - report.data << { x: label.call("moderator"), y: moderators } if moderators > 0 + report.data << { key: "moderator", x: label.call("moderator"), y: moderators } if moderators > 0 suspended = User.real.suspended.count - report.data << { x: label.call("suspended"), y: suspended } if suspended > 0 + report.data << { key: "suspended", x: label.call("suspended"), y: suspended } if suspended > 0 silenced = User.real.silenced.count - report.data << { x: label.call("silenced"), y: silenced } if silenced > 0 + report.data << { key: "silenced", x: label.call("silenced"), y: silenced } if silenced > 0 end def self.report_trending_search(report) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 6e51ddda806..adc06eda489 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -2765,6 +2765,10 @@ en: start_date: "Start Date" end_date: "End Date" groups: "All groups" + disabled: "This report is disabled" + trending_search: + more: 'Search logs' + disabled: 'Trending search report is disabled. Enable log search queries to collect data.' commits: latest_changes: "Latest changes: please update often!" diff --git a/config/site_settings.yml b/config/site_settings.yml index b5901c8d92c..def3802eaf9 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1323,7 +1323,9 @@ search: search_recent_posts_size: default: 100000 max: 100000 - log_search_queries: true + log_search_queries: + client: true + default: true search_query_log_max_size: default: 1000000 max: 1000000