From 72a325eae2692c2d0d1ae5d0c463f60bce36c8a7 Mon Sep 17 00:00:00 2001
From: Anusha Ranganathan <anusha@cottagelabs.com>
Date: Thu, 30 Jan 2025 18:04:22 +0100
Subject: [PATCH] Display buttons to easily access groups

---
 .../controllers/hyrax/dashboard_controller.rb | 40 ++++++++++++++
 hyrax/app/helpers/hyrax_helper.rb             | 13 +++++
 .../views/hyrax/dashboard/show_admin.html.erb | 53 +++++++++++++++++++
 .../views/hyrax/dashboard/show_user.html.erb  | 45 ++++++++++++++++
 .../shared/_collections_to_display.html.erb   | 16 ++++++
 hyrax/config/collections_to_display.yml       |  2 +
 hyrax/config/locales/hyrax.en.yml             |  1 +
 7 files changed, 170 insertions(+)
 create mode 100644 hyrax/app/controllers/hyrax/dashboard_controller.rb
 create mode 100644 hyrax/app/views/hyrax/dashboard/show_admin.html.erb
 create mode 100644 hyrax/app/views/hyrax/dashboard/show_user.html.erb
 create mode 100644 hyrax/app/views/shared/_collections_to_display.html.erb
 create mode 100644 hyrax/config/collections_to_display.yml

diff --git a/hyrax/app/controllers/hyrax/dashboard_controller.rb b/hyrax/app/controllers/hyrax/dashboard_controller.rb
new file mode 100644
index 00000000..6927391f
--- /dev/null
+++ b/hyrax/app/controllers/hyrax/dashboard_controller.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+module Hyrax
+  class DashboardController < ApplicationController
+    include Blacklight::Base
+    include Hyrax::Breadcrumbs
+    include HyraxHelper
+    with_themed_layout 'dashboard'
+    before_action :authenticate_user!
+    before_action :build_breadcrumbs, only: [:show]
+    before_action :set_date_range
+
+    ##
+    # @!attribute [rw] sidebar_partials
+    #   @return [Hash]
+    #
+    # @example Add a custom partial to the tasks sidebar block
+    #   Hyrax::DashboardController.sidebar_partials[:tasks] << "hyrax/dashboard/sidebar/custom_task"
+    class_attribute :sidebar_partials
+    self.sidebar_partials = { activity: [], configuration: [], repository_content: [], tasks: [] }
+
+    def show
+      @collections_to_display = list_collections_to_display
+      if can? :read, :admin_dashboard
+        @presenter = Hyrax::Admin::DashboardPresenter.new
+        @admin_set_rows = Hyrax::AdminSetService.new(self).search_results_with_work_count(:read)
+        render 'show_admin'
+      else
+        @presenter = Dashboard::UserPresenter.new(current_user, view_context, params[:since])
+        render 'show_user'
+      end
+    end
+
+    private
+
+    def set_date_range
+      @start_date = params[:start_date] || Time.zone.today - 1.month
+      @end_date = params[:end_date] || Time.zone.today + 1.day
+    end
+  end
+end
\ No newline at end of file
diff --git a/hyrax/app/helpers/hyrax_helper.rb b/hyrax/app/helpers/hyrax_helper.rb
index 90ffd215..06a26fcb 100644
--- a/hyrax/app/helpers/hyrax_helper.rb
+++ b/hyrax/app/helpers/hyrax_helper.rb
@@ -212,4 +212,17 @@ module HyraxHelper
   
     [status.titleize, parsed_datetime, newest_file]
   end
+
+  def list_collections_to_display
+    collections_to_display = []
+    file_contents = File.new(Rails.root.join('config', 'collections_to_display.yml')).read
+    template = ERB.new file_contents
+    parsed_file = YAML.load(template.result(binding))
+    parsed_file['collections_to_display'].each do |collection_name|
+      c = Collection.where(title: collection_name).first
+      collections_to_display.append({id: c.id, title: c.title&.first, url: "/dashboard/collections/#{c.id}"})
+      # collections_to_display.append({id: c.id, title: c.title&.first, url: dashboard_collection_path(c.id)})
+    end
+    collections_to_display
+  end
 end
diff --git a/hyrax/app/views/hyrax/dashboard/show_admin.html.erb b/hyrax/app/views/hyrax/dashboard/show_admin.html.erb
new file mode 100644
index 00000000..067b42ef
--- /dev/null
+++ b/hyrax/app/views/hyrax/dashboard/show_admin.html.erb
@@ -0,0 +1,53 @@
+<% provide :page_header do %>
+  <h1><%= t("hyrax.dashboard.title") %></h1>
+<% end %>
+
+<%= render 'shared/collections_to_display' %>
+
+<% if Hyrax.config.analytics? %>
+  <div class="row">
+    <div class="col-md-12">
+      <div class="panel panel-default">
+        <div class="panel-heading">
+          <h2 class="panel-title"><%= t(".graph_reports") %>:</h2>
+          <%= params[:start_date].present? ? params[:start_date].to_date : 1.month.ago.beginning_of_day.to_date %> -
+          <%= params[:end_date].present? ? params[:end_date].to_date : Time.zone.now.end_of_day.to_date %>
+        </div>
+        <div class="panel-body">
+          <%= render "hyrax/admin/analytics/date_range_form", redirect_path: hyrax.dashboard_path %>
+        </div>
+      </div>
+    </div>
+  </div>
+
+  <div class="row">
+    <div class="col-md-12">
+      <div class="panel panel-default">
+        <%= render 'user_activity' %>
+      </div>
+    </div>
+  </div>
+<% end %>
+
+<div class="row">
+  <div class="col-md-12">
+    <div class="panel panel-default">
+      <%= render 'repository_growth' %>
+    </div>
+  </div>
+</div>
+
+<div class="row">
+  <div class="col-md-4">
+    <%= render 'visibility_graph' %>
+  </div>
+  <div class="col-md-4">
+    <%= render 'work_type_graph' %>
+  </div>
+  <div class="col-md-4">
+    <%= render "resource_type_graph" %>
+  </div>
+</div>
+<br>
+<br>
+<%= render 'tabs' %>
\ No newline at end of file
diff --git a/hyrax/app/views/hyrax/dashboard/show_user.html.erb b/hyrax/app/views/hyrax/dashboard/show_user.html.erb
new file mode 100644
index 00000000..90cc21a9
--- /dev/null
+++ b/hyrax/app/views/hyrax/dashboard/show_user.html.erb
@@ -0,0 +1,45 @@
+<% provide :page_header do %>
+  <h1><%= t("hyrax.dashboard.title") %></h1>
+<% end %>
+
+<%= render 'shared/collections_to_display' %>
+
+<div class="panel panel-default user-activity">
+  <div class="panel-heading">
+    <h2 class="panel-title "><%= t("hyrax.dashboard.user_activity.title") %></h2>
+  </div>
+  <div class="panel-body">
+    <%= @presenter.render_recent_activity %>
+  </div>
+</div>
+
+<div class="panel panel-default" id="notifications">
+  <div class="panel-heading">
+    <h2 class="panel-title "><%= t("hyrax.dashboard.user_notifications") %></h2>
+  </div>
+  <div class="panel-body">
+    <%= @presenter.render_recent_notifications %>
+    <%= @presenter.link_to_additional_notifications %>
+  </div>
+</div>
+
+<% if Flipflop.proxy_deposit? %>
+  <div class="panel panel-default" id="proxy_management">
+    <div class="panel-heading">
+      <h2 class="panel-title "><%= t("hyrax.dashboard.current_proxies") %></h2>
+    </div>
+    <div class="panel-body">
+      <%= render 'hyrax/dashboard/_index_partials/current_proxy_rights', user: current_user %>
+      <%= @presenter.link_to_manage_proxies %>
+    </div>
+  </div>
+<% end %>
+
+<div class="panel panel-default transfers">
+  <div class="panel-heading">
+    <h2 class="panel-title "><%= t("hyrax.dashboard.transfer_of_ownership") %></h2>
+  </div>
+  <div class="panel-body">
+    <%= render 'hyrax/dashboard/_index_partials/transfers', presenter: @presenter.transfers %>
+  </div>
+</div>
\ No newline at end of file
diff --git a/hyrax/app/views/shared/_collections_to_display.html.erb b/hyrax/app/views/shared/_collections_to_display.html.erb
new file mode 100644
index 00000000..752614e9
--- /dev/null
+++ b/hyrax/app/views/shared/_collections_to_display.html.erb
@@ -0,0 +1,16 @@
+<% if @collections_to_display.present? %>
+  <div class="row">
+    <div class="col-md-12">
+      <div class="panel panel-default" id="user_groups">
+        <div class="panel-heading">
+          <h2 class="panel-title "><%= t("hyrax.dashboard.my_groups") %></h2>
+        </div>
+        <div class="panel-body">
+          <% @collections_to_display.each do |col| %>
+            <a href="<%= col[:url] %>" class="btn btn-info btn-inline" role="button"><%= col[:title] %></a>
+          <% end %>
+        </div>
+      </div>
+    </div>
+  </div>
+<% end %>
diff --git a/hyrax/config/collections_to_display.yml b/hyrax/config/collections_to_display.yml
new file mode 100644
index 00000000..7b598563
--- /dev/null
+++ b/hyrax/config/collections_to_display.yml
@@ -0,0 +1,2 @@
+collections_to_display:
+  - <%= ENV['CRC_1280_COLLECTION'] || 'CRC 1280' %>
\ No newline at end of file
diff --git a/hyrax/config/locales/hyrax.en.yml b/hyrax/config/locales/hyrax.en.yml
index 58aa4d17..2662897f 100644
--- a/hyrax/config/locales/hyrax.en.yml
+++ b/hyrax/config/locales/hyrax.en.yml
@@ -412,6 +412,7 @@ en:
         shared: Works (datasets) Shared with Me
         works: Works (datasets)
         your_works: Your Works (datasets)
+      my_groups: My groups
       no_transfer_requests: You haven't received any work (dataset) transfer requests
       no_transfers: You haven't transferred any work (dataset)
       proxy_help: Select a user who can deposit works (datasets) on your behalf. Both you and your proxy will be able to make changes to these works (datasets). You can revoke a proxy by clicking the Delete Proxy button. To revoke their ability to edit a work they previously submitted, remove them from the Sharing tab on each work (dataset).
-- 
GitLab