diff --git a/CHANGELOG.md b/CHANGELOG.md index 501d431..eed4499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 12.0.0 ### Enhancements +- **Dashboard Changes** + - Dashboard now displays a randomization overview - **Folder Changes** - Folders are now sorted alphabetically in each category - All files in a folder can be downloaded as a single zip file diff --git a/app/models/report.rb b/app/models/report.rb index ada1a63..a8af55b 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -47,6 +47,8 @@ def self.searchable_attributes def reverse_report_rows report_rows.reorder(Arel.sql("report_rows.position desc nulls first")) end + has_many :page_reports, -> { order(Arel.sql("position nulls last")) } + has_many :pages, through: :page_reports # Methods def refresh! diff --git a/app/views/internal/dashboard.html.haml b/app/views/internal/dashboard.html.haml index 5473832..0c3de35 100644 --- a/app/views/internal/dashboard.html.haml +++ b/app/views/internal/dashboard.html.haml @@ -11,21 +11,29 @@ %strong Complete your profile = render "directory/profile_form", user: current_user +- @report = Report.where(archived: false).find_by(report_type: "randomizations_by_site_by_month") + .d-flex.flex-column.flex-sm-row.justify-content-between - .dashboard-container.flex-fill - .mb-3 - %strong - Welcome to the - = ENV["website_name"] - website! - %p - Quickly find - = icon("fas", "file-alt", class: "text-primary") - = link_to "documents", folders_path - and - = succeed "." do - = icon("fas", "user-circle", class: "text-primary") - = link_to "contact info", directory_path + .dashboard-container + - if @report + = render "randomizations/total", report: @report + = render "randomizations/this_month", report: @report + = render "randomizations/top_sites", report: @report + = render "reports/page_link", report: @report + - else + .mb-3 + %strong + Welcome to the + = ENV["website_name"] + website! + %p + Quickly find + = icon("fas", "file-alt", class: "text-primary") + = link_to "documents", folders_path + and + = succeed "." do + = icon("fas", "user-circle", class: "text-primary") + = link_to "contact info", directory_path - if @featured_documents.present? || @top_documents.present? .dashboard-container.ml-0.ml-sm-3.flex-fill diff --git a/app/views/randomizations/_this_month.html.haml b/app/views/randomizations/_this_month.html.haml new file mode 100644 index 0000000..598d553 --- /dev/null +++ b/app/views/randomizations/_this_month.html.haml @@ -0,0 +1,8 @@ +- first_row = report.report_rows.first +- if first_row + .mb-3 + %strong + This month + %p + = pluralize(first_row.result.count, "subject") + randomized this month. diff --git a/app/views/randomizations/_top_sites.html.haml b/app/views/randomizations/_top_sites.html.haml new file mode 100644 index 0000000..3be2c1b --- /dev/null +++ b/app/views/randomizations/_top_sites.html.haml @@ -0,0 +1,32 @@ +- if report.header + - site_map = {} + - report.header.select{ |h| h.key?("id") }.each do |hash| + - site_map[hash["id"].to_s] = hash["label"] + - counts = {} + - report.report_rows.each do |report_row| + - result = report_row.result || {} + - (result["sites"] || []).each_with_index do |hash, index| + - if hash["site_id"] + - counts[site_map[hash["site_id"].to_s]] ||= 0 + - counts[site_map[hash["site_id"].to_s]] += hash["count"].to_i + + - max_count = counts.values.max + - sites = counts.select { |_, v| v == max_count }.collect { |k, _| k } + +- if sites.present? + .mb-3 + %strong + Top + = "site".pluralize(sites.count) + + %p + = sites.collect{ |site| content_tag(:span, site, class: "nowrap text-primary") }.to_sentence.html_safe + - if sites.size > 1 + lead + - else + leads + with + = succeed "." do + %strong= pluralize(max_count, "total randomization") + - if sites.size > 1 + each diff --git a/app/views/randomizations/_total.html.haml b/app/views/randomizations/_total.html.haml new file mode 100644 index 0000000..ecb309c --- /dev/null +++ b/app/views/randomizations/_total.html.haml @@ -0,0 +1,5 @@ +.mb-3 + %strong + Total randomizations + %div{ style: "font-size: 2rem;font-weight: 300;" }= report.total_count + diff --git a/app/views/reports/_page_link.html.haml b/app/views/reports/_page_link.html.haml new file mode 100644 index 0000000..f33b4c1 --- /dev/null +++ b/app/views/reports/_page_link.html.haml @@ -0,0 +1,8 @@ +- page = report.pages.where(archived: false).first +- if page + .mb-3 + = icon("fas", "chart-area") + View + = link_to report_page_path(page) do + = page.name + = icon("fas", "caret-right")