Skip to content

Commit

Permalink
Adds Explore Collection Dashboard into Admin options. (#747)
Browse files Browse the repository at this point in the history
* Adds Explore Collection Dashboard into Admin options.

* Removes the unneeded yml.

* Cleans up schema automated changes and rubocop requests.

* Adds link to root admin.
  • Loading branch information
bwatson78 authored Mar 10, 2023
1 parent aee90f1 commit 4605476
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ lib/tasks/ci.rake
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/master.key
config/emory/groups/*

# Only include if you have production secrets in this file, which is no longer a Rails default
# config/secrets.yml
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.8.1)
minitest (5.18.0)
momentjs-rails (2.29.4.1)
railties (>= 3.1)
multipart-post (2.1.1)
mysql2 (0.5.2)
namae (1.0.1)
Expand Down
47 changes: 47 additions & 0 deletions app/controllers/admin/explore_collections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true
module Admin
class ExploreCollectionsController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.
#
# def update
# super
# send_foo_updated_email(requested_resource)
# end

# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`
# actions.
#
# def find_resource(param)
# Foo.find_by!(slug: param)
# end

# The result of this lookup will be available as `requested_resource`

# Override this if you have certain roles that require a subset
# this will be used to set the records shown on the `index` action.
#
# def scoped_resource
# if current_user.super_admin?
# resource_class
# else
# resource_class.with_less_stuff
# end
# end

# Override `resource_params` if you want to transform the submitted
# data before it's persisted. For example, the following would turn all
# empty values into nil values. It uses other APIs such as `resource_class`
# and `dashboard`:
#
# def resource_params
# params.require(resource_class.model_name.param_key).
# permit(dashboard.permitted_attributes).
# transform_values { |value| value == "" ? nil : value }
# end

# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
# for more information
end
end
77 changes: 77 additions & 0 deletions app/dashboards/explore_collection_dashboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true
require "administrate/base_dashboard"

class ExploreCollectionDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
title: Field::String,
banner_path: Field::String,
collection_path: Field::String,
description: Field::Text,
active: Field::Boolean,
created_at: Field::DateTime,
updated_at: Field::DateTime
}.freeze

# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
id
title
active
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
id
title
banner_path
collection_path
description
active
created_at
updated_at
].freeze

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[
title
banner_path
collection_path
description
active
].freeze

# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
# field of the dashboard.
#
# For example to add an option to search for open resources by typing "open:"
# in the search field:
#
# COLLECTION_FILTERS = {
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {
active: ->(resources) { resources.where(active: true) }
}.freeze

# Overwrite this method to customize how explore collections are displayed
# across all pages of the admin dashboard.
#
# def display_resource(explore_collection)
# "ExploreCollection ##{explore_collection.id}"
# end
end
7 changes: 7 additions & 0 deletions app/models/explore_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class ExploreCollection < ApplicationRecord
validates :title, presence: true
validates :banner_path, presence: true
validates :collection_path, presence: true
validates :description, presence: true
end
8 changes: 2 additions & 6 deletions app/presenters/explore_collections_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# frozen_string_literal: true

class ExploreCollectionsPresenter
attr_reader :config
attr_reader :collections

def initialize
@config = YAML.safe_load(File.open(Rails.root.join('config', 'explore_collections.yml')))
end

def collections
@collections = @config['collections']
@collections = ExploreCollection.all.select(&:active?).sample(3)
end
end
3 changes: 2 additions & 1 deletion app/views/admin/admin/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<h1 class="static-heading">Admin Dashboard</h1>
<p class="static-blurb-body contacts-blurb"><%= link_to 'Content Blocks Dashboard', '/admin/content_blocks', class: "static-blurb-link" %></p>
<p class="static-blurb-body contacts-blurb"><%= link_to 'Content Blocks Dashboard', '/admin/content_blocks', class: "static-blurb-link" %></p>
<p class="static-blurb-body contacts-blurb"><%= link_to 'Explore Collections Dashboard', '/admin/explore_collections', class: "static-blurb-link" %></p>
8 changes: 4 additions & 4 deletions app/views/catalog/_explore_collections.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<div class="col-12 col-sm-6 col-lg-4 mt-3">
<div class="tile-listing has-badge has-description has-action card">
<div class="tile-badge"> Featured Collection </div>
<div class="tile-listing-image"><%= image_tag c["image"], alt: c["title"] %></div>
<%= link_to c["title"], c["path"], class: "link tile-listing-title" %>
<p class="tile-listing-description mt-2"><%= c["description"] %></p>
<%= link_to "View Collection", c["path"], class: "link tile-listing-action mt-auto" %>
<div class="tile-listing-image"><%= image_tag c.banner_path, alt: c.title %></div>
<%= link_to c.title, c.collection_path, class: "link tile-listing-title" %>
<p class="tile-listing-description mt-2"><%= c.description %></p>
<%= link_to "View Collection", c.collection_path, class: "link tile-listing-action mt-auto" %>
</div>
</div>
<% end %>
Expand Down
13 changes: 0 additions & 13 deletions config/explore_collections.yml

This file was deleted.

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Rails.application.routes.draw do
namespace :admin do
resources :content_blocks
resources :explore_collections

root to: "admin#index"
end
Expand Down
29 changes: 29 additions & 0 deletions db/concerns/default_explore_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module DefaultExploreCollections
def stub_default_explore_collections
ExploreCollection.find_or_create_by(
title: 'Health Sciences Center Library Artifact Collection',
banner_path: 'https://curate.library.emory.edu//branding/5053ffbg7n-cor/banner/HS-S023_B067_P004.jpg',
collection_path: 'https://digital.library.emory.edu/catalog/5053ffbg7n-cor',
description: "Contains a wide selection of medical instruments including surgical instruments, physician's medicine bags, scales, tourniquets, scarifier sets, and other instruments dating from 1832 to 2000.",
active: true
)

ExploreCollection.find_or_create_by(
title: 'Robert Langmuir African American Photograph Collection',
banner_path: 'https://curate.library.emory.edu//branding/914nk98sfv-cor/banner/40644j0ztx-cor.jpg',
collection_path: 'https://digital.library.emory.edu/catalog/914nk98sfv-cor',
description: 'Collection of photographs depicting African American life and culture collected by Robert Langmuir.',
active: true
)

ExploreCollection.find_or_create_by(
title: 'Oxford College Collection of Asian Artifacts',
banner_path: 'https://curate.library.emory.edu//branding/320sqv9s4v-cor/banner/OXKOBE_045_P0001.jpg',
collection_path: 'https://digital.library.emory.edu/catalog/320sqv9s4v-cor',
description: 'Contains a variety of Japanese, Korean, and Chinese artifacts, most of them purchased in Kobe, Japan by William Patillo Turner while he was a member of the Japan Mission of the United Methodist Church, South.',
active: true
)
end
end
17 changes: 17 additions & 0 deletions db/migrate/20230309172105_create_explore_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateExploreCollections < ActiveRecord::Migration[5.2]
def up
create_table :explore_collections, if_not_exists: true do |t|
t.string :title
t.string :banner_path
t.string :collection_path
t.text :description
t.boolean :active, default: true

t.timestamps
end
end

def down
drop_table :explore_collections, if_exists: true
end
end
9 changes: 9 additions & 0 deletions db/migrate/20230309212040_stub_default_explore_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require_relative '../concerns/default_explore_collections'

class StubDefaultExploreCollections < ActiveRecord::Migration[5.2]
include ::DefaultExploreCollections

def change
stub_default_explore_collections
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_02_28_165358) do
ActiveRecord::Schema.define(version: 2023_03_09_212040) do

create_table "bookmarks", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
t.integer "user_id", null: false
Expand All @@ -31,6 +31,16 @@
t.datetime "updated_at", null: false
end

create_table "explore_collections", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
t.string "title"
t.string "banner_path"
t.string "collection_path"
t.text "description"
t.boolean "active", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "searches", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
t.binary "query_params"
t.integer "user_id"
Expand Down
Loading

0 comments on commit 4605476

Please sign in to comment.