Skip to content

Commit

Permalink
Dashboard now displays a randomization overview, addresses #19.
Browse files Browse the repository at this point in the history
  • Loading branch information
remomueller committed Oct 27, 2019
1 parent 1a16119 commit 4576d37
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
36 changes: 22 additions & 14 deletions app/views/internal/dashboard.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/views/randomizations/_this_month.html.haml
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 32 additions & 0 deletions app/views/randomizations/_top_sites.html.haml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/views/randomizations/_total.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.mb-3
%strong
Total randomizations
%div{ style: "font-size: 2rem;font-weight: 300;" }= report.total_count
8 changes: 8 additions & 0 deletions app/views/reports/_page_link.html.haml
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 4576d37

Please sign in to comment.