From 8b32408a3b03eb97a0194f6c41416259d46812f8 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 19 Jul 2018 21:51:11 -0400 Subject: [PATCH] FEATURE: improves staff notes report to support dates --- .../recent-staff-notes-report-table.hbs | 2 +- assets/stylesheets/staff_notes.scss | 16 ++++++++++- config/locales/server.en.yml | 4 +-- plugin.rb | 27 +++++++++---------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs b/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs index 8d2a379..7e30fb3 100644 --- a/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs +++ b/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs @@ -1,4 +1,4 @@ {{admin-report - dataSourceName="recent_staff_notes" + dataSourceName="staff_notes" startDate=lastWeek endDate=endDate}} diff --git a/assets/stylesheets/staff_notes.scss b/assets/stylesheets/staff_notes.scss index dceb9eb..bb19acb 100644 --- a/assets/stylesheets/staff_notes.scss +++ b/assets/stylesheets/staff_notes.scss @@ -46,6 +46,20 @@ cursor: pointer; } -.admin-report.recent-staff-notes { +.admin-report.staff-notes { grid-column: span 12; + + .admin-report-table { + table-layout: auto; + + tbody tr td, + thead tr th { + text-align: left; + } + + thead tr th.note, + tbody tr td.note { + width: 60%; + } + } } diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index c2da8b5..07e6907 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -9,8 +9,8 @@ en: user_silenced: "@%{username} silenced this account until %{silenced_till}. Reason: %{reason}" reports: - recent_staff_notes: - title: "Recent staff notes" + staff_notes: + title: "Staff notes" labels: user: User note: Note diff --git a/plugin.rb b/plugin.rb index 1096718..3d9d5d1 100644 --- a/plugin.rb +++ b/plugin.rb @@ -264,27 +264,26 @@ after_initialize do end if respond_to? :add_report - add_report('recent_staff_notes') do |report| + add_report('staff_notes') do |report| report.modes = [:table] report.data = [] - # TODO - # plugin store row doesn’t have created_at - # this could be improved by querying on the text field - report.dates_filtering = false - report.labels = [ - { type: :link, properties: ["username", "user_url"], title: I18n.t("reports.recent_staff_notes.labels.user") }, - { type: :text, properties: ["note"], title: I18n.t("reports.recent_staff_notes.labels.note") }, - { type: :link, properties: ["moderator_username", "moderator_url"], title: I18n.t("reports.recent_staff_notes.labels.moderator") } + { type: :link, properties: ["username", "user_url"], title: I18n.t("reports.staff_notes.labels.user") }, + { type: :link, properties: ["moderator_username", "moderator_url"], title: I18n.t("reports.staff_notes.labels.moderator") }, + { type: :text, properties: ["note"], title: I18n.t("reports.staff_notes.labels.note") } ] - values = PluginStoreRow - .where(plugin_name: 'staff_notes') - .order(id: :desc) - .limit(report.limit || 10) - .pluck(:value) + values = [] + report.timeout = wrap_slow_query do + values = PluginStoreRow + .where(plugin_name: 'staff_notes') + .where("value::json->0->>'created_at'>?", report.start_date) + .where("value::json->0->>'created_at'