diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 709ad62..c75340c 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,3 +1,8 @@ en: site_settings: allow_solved_on_all_topics: "Allow users to select solutions on all topics (by default you control this by editing categories)" + reports: + accepted_solutions: + title: "Accepted solutions" + xaxis: "Day" + yaxis: "Total" diff --git a/plugin.rb b/plugin.rb index 58ca34c..3577b2c 100644 --- a/plugin.rb +++ b/plugin.rb @@ -90,6 +90,28 @@ after_initialize do ["is_accepted_answer"] end + if Report.respond_to?(:add_report) + AdminDashboardData::GLOBAL_REPORTS << "accepted_solutions" + + Report.add_report("accepted_solutions") do |report| + report.data = [] + accepted_solutions = TopicCustomField.where(name: "accepted_answer_post_id") + accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id = ?", report.category_id) if report.category_id + accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date) + .where("topic_custom_fields.created_at <= ?", report.end_date) + .group("DATE(topic_custom_fields.created_at)") + .order("DATE(topic_custom_fields.created_at)") + .count + .each do |date, count| + report.data << { x: date, y: count } + end + report.total = accepted_solutions.count + report.prev30Days = accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date - 30.days) + .where("topic_custom_fields.created_at <= ?", report.start_date) + .count + end + end + require_dependency 'topic_view_serializer' class ::TopicViewSerializer attributes :accepted_answer