Skip to content

Commit

Permalink
Merge pull request #1260 from samvera/collection_thumbnails
Browse files Browse the repository at this point in the history
Add thumbnails to collections
  • Loading branch information
mjgiarlo authored Jun 23, 2017
2 parents e71ecb0 + bcdd6df commit 379bd9e
Show file tree
Hide file tree
Showing 34 changed files with 359 additions and 148 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: ruby
sudo: false
dist: trusty
# Use old image to fix redis: https://github.com/travis-ci/travis-ci/issues/7941#issuecomment-310252839
group: deprecated-2017Q2

cache:
bundler: true
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/hyrax.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
//= require hyrax/admin/admin_set/registered_users
//= require hyrax/admin/admin_set/participants
//= require hyrax/admin/admin_set/visibility
//= require hyrax/collections/editor
//= require hyrax/editor
//= require hyrax/editor/admin_set_widget
//= require hyrax/editor/controlled_vocabulary
Expand All @@ -91,6 +92,8 @@
//= require hyrax/workflow_actions_affix
//= require hyrax/authority_select
//= require hyrax/per_page
//= require hyrax/thumbnail_select


// this needs to be after batch_select so that the form ids get setup correctly
//= require hyrax/batch_edit
44 changes: 15 additions & 29 deletions app/assets/javascripts/hyrax/admin/admin_set_controls.es6
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
export default class {
constructor(elem) {
this.loadThumbnailOptions(elem)
// The editor for the AdminSets
// Add search for user/group to the edit an admin set's participants page
// Add search for thumbnail to the edit descriptions
import Visibility from 'hyrax/admin/admin_set/visibility'
import Participants from 'hyrax/admin/admin_set/participants'
import ThumbnailSelect from 'hyrax/thumbnail_select'

let Participants = require('hyrax/admin/admin_set/participants');
let participants = new Participants(elem.find('#participants'))
participants.setup();
export default class {
constructor(elem) {
let url = window.location.pathname.replace('edit', 'files')
this.thumbnailSelect = new ThumbnailSelect(url, elem.find('#admin_set_thumbnail_id'))

let Visibility = require('hyrax/admin/admin_set/visibility');
let visibilityTab = new Visibility(elem.find('#visibility'));
visibilityTab.setup();
}
let participants = new Participants(elem.find('#participants'))
participants.setup();

// Dynamically load the file options into the "Thumbnail" select field.
loadThumbnailOptions(elem) {
let url = window.location.pathname.replace('edit', 'files')
elem.find('#admin_set_thumbnail_id').select2({
ajax: { // Use the jQuery.ajax wrapper provided by Select2
url: url,
dataType: "json",
results: function(data, page) {
return { results: data }
}
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected repository's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the repository name is shown preselected
callback({ text: $(element).data('text') })
}
})
}
let visibilityTab = new Visibility(elem.find('#visibility'));
visibilityTab.setup();
}
}
26 changes: 17 additions & 9 deletions app/assets/javascripts/hyrax/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Hyrax = {
this.permissions();
this.notifications();
this.transfers();
this.editor();
this.workEditor();
this.fileManager();
this.selectWorkType();
this.datatable();
this.admin();
this.adminSetEditor();
this.collectionEditor();
this.adminStatisticsGraphs();
this.tinyMCE();
this.perPage();
Expand All @@ -26,12 +27,19 @@ Hyrax = {
});
},

// Add search for user/group to the edit an admin set's participants page
admin: function() {
// The AdminSet edit page
adminSetEditor: function() {
var AdminSetControls = require('hyrax/admin/admin_set_controls');
var controls = new AdminSetControls($('#admin-set-controls'));
},

// The Collection edit page
collectionEditor: function() {
var CollectionControls = require('hyrax/collections/editor');
var controls = new CollectionControls($('#collection-controls'));
},


// Pretty graphs on the dashboard page
adminStatisticsGraphs: function() {
var AdminGraphs = require('hyrax/admin/graphs');
Expand All @@ -47,8 +55,8 @@ Hyrax = {
}
},

// Functionality for the work edit page
editor: function () {
// The work edit page
workEditor: function () {
var element = $("[data-behavior='work-form']")
if (element.length > 0) {
var Editor = require('hyrax/editor');
Expand All @@ -65,7 +73,7 @@ Hyrax = {
},

// Add access grants for a user/group to a work/fileset/collection
// TODO: This could get moved to editor() or similar
// TODO: This could get moved to workEditor() or similar
permissions: function () {
var PermissionsControl = require('hyrax/permissions/control');
// On the edit work page
Expand Down Expand Up @@ -113,14 +121,14 @@ Hyrax = {
var FileManager = require('hyrax/file_manager');
new FileManager();
},

// Per Page select will submit its form to change records shown
perPage: function () {
var PerPage = require('hyrax/per_page');
$('#per_page').each(function () {
new PerPage($(this));
});
},
},

// Saved so that inline javascript can put data somewhere.
statistics: {},
Expand Down
11 changes: 11 additions & 0 deletions app/assets/javascripts/hyrax/collections/editor.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ThumbnailSelect from 'hyrax/thumbnail_select'

// Controls the behavior of the Collections edit form
// Add search for thumbnail to the edit descriptions
export default class {
constructor(elem) {
let url = window.location.pathname.replace('edit', 'files')
let field = elem.find('#collection_thumbnail_id')
this.thumbnailSelect = new ThumbnailSelect(url, field);
}
}
29 changes: 29 additions & 0 deletions app/assets/javascripts/hyrax/thumbnail_select.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Dynamically load the file options into the "Thumbnail" select field.
export default class {
/*
* @param {String} url the search endpoint
* @param {jQuery} the field to add the select to
*/
constructor(url, field) {
this.loadThumbnailOptions(url, field)
}

// Dynamically load the file options into the "Thumbnail" select field.
loadThumbnailOptions(url, field) {
field.select2({
ajax: { // Use the jQuery.ajax wrapper provided by Select2
url: url,
dataType: "json",
results: function(data, page) {
return { results: data }
}
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected repository's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the repository name is shown preselected
callback({ text: $(element).data('text') })
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module CollectionsControllerBehavior

# actions: index, create, new, edit, show, update, destroy, permissions, citation
before_action :authenticate_user!, except: [:show, :index]
load_and_authorize_resource except: [:index, :show, :create], instance_name: :collection

class_attribute :presenter_class,
:form_class,
Expand Down Expand Up @@ -215,10 +214,6 @@ def collection_params
form_class.model_attributes(params[:collection])
end

def form
@form ||= form_class.new(@collection)
end

# Queries Solr for members of the collection.
# Populates @response and @member_docs similar to Blacklight Catalog#index populating @response and @documents
def query_collection_members
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/hyrax/admin/admin_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def edit
end

# Renders a JSON response with a list of files in this admin set.
# This is used by the edit form
# This is used by the edit form to populate the thumbnail_id dropdown
def files
form = form_class.new(@admin_set)
result = form.select_files.map do |label, id|
{ id: id, text: label }
end
Expand Down Expand Up @@ -107,7 +106,12 @@ def setup_form
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.admin_sets'), hyrax.admin_admin_sets_path
add_breadcrumb action_breadcrumb, request.path
@form = form_class.new(@admin_set)
form
end

# initialize the form object
def form
@form ||= form_class.new(@admin_set, current_ability, repository)
end

# Overrides the parent implementation so that the returned search builder
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/hyrax/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,31 @@ module Hyrax
class CollectionsController < ApplicationController
include CollectionsControllerBehavior
include BreadcrumbsForCollections
layout :decide_layout
load_and_authorize_resource except: [:index, :show, :create], instance_name: :collection

# Renders a JSON response with a list of files in this collection
# This is used by the edit form to populate the thumbnail_id dropdown
def files
result = form.select_files.map do |label, id|
{ id: id, text: label }
end
render json: result
end

private

def form
@form ||= form_class.new(@collection, current_ability, repository)
end

def decide_layout
case action_name
when 'show'
theme
else
'dashboard'
end
end
end
end
11 changes: 6 additions & 5 deletions app/forms/hyrax/forms/admin_set_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ class AdminSetForm < Hyrax::Forms::CollectionForm
self.model_class = AdminSet
self.terms = [:title, :description, :thumbnail_id]

# @param [AdminSet] model
def initialize(model)
super(model)
end

# Cast any array values on the model to scalars.
def [](key)
return super if key == :thumbnail_id
Expand Down Expand Up @@ -42,6 +37,12 @@ def sanitize_params(form_params)
end
end
end

private

def member_work_ids
model.member_ids
end
end
end
end
44 changes: 39 additions & 5 deletions app/forms/hyrax/forms/collection_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ module Forms
class CollectionForm
include HydraEditor::Form
include HydraEditor::Form::Permissions
# Used by the search builder
attr_accessor :current_ability, :repository

delegate :id, :depositor, :permissions, to: :model

# Required for search builder (FIXME)
alias collection model

self.model_class = ::Collection
class_attribute :member_search_builder_class
self.member_search_builder_class = Hyrax::CollectionMemberSearchBuilder

delegate :human_readable_type, :member_ids, to: :model
delegate :blacklight_config, to: Hyrax::CollectionsController

self.terms = [:resource_type, :title, :creator, :contributor, :description,
:keyword, :license, :publisher, :date_created, :subject, :language,
Expand All @@ -17,15 +25,26 @@ class CollectionForm

self.required_fields = [:title]

# @param model [Collection] the collection model that backs this form
# @param current_ability [Ability] the capabilities of the current user
# @param repository [Blacklight::Solr::Repository] the solr repository
def initialize(model, current_ability, repository)
super(model)
@current_ability = current_ability
@repository = repository
end

# @return [Hash] All FileSets in the collection, file.to_s is the key, file.id is the value
def select_files
Hash[all_files]
Hash[all_files_with_access]
end

# Terms that appear above the accordion
def primary_terms
[:title]
end

# Terms that appear within the accordion
def secondary_terms
[:creator,
:contributor,
Expand All @@ -48,14 +67,29 @@ def display_additional_fields?
secondary_terms.any?
end

def thumbnail_title
return unless model.thumbnail
model.thumbnail.title.first
end

private

def all_files
member_presenters.flat_map(&:file_set_presenters).map { |x| [x.to_s, x.id] }
def all_files_with_access
member_presenters(member_work_ids).flat_map(&:file_set_presenters).map { |x| [x.to_s, x.id] }
end

# Override this method if you have a different way of getting the member's ids
def member_work_ids
response = repository.search(member_search_builder.merge(fl: 'id').query).response
response.fetch('docs').map { |doc| doc['id'] }
end

def member_search_builder
@member_search_builder ||= member_search_builder_class.new(self)
end

def member_presenters
PresenterFactory.build_for(ids: model.member_ids,
def member_presenters(member_ids)
PresenterFactory.build_for(ids: member_ids,
presenter_class: WorkShowPresenter,
presenter_args: [nil])
end
Expand Down
1 change: 0 additions & 1 deletion app/indexers/hyrax/admin_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def generate_solr_document
super.tap do |solr_doc|
# Makes Admin Sets show under the "Admin Sets" tab
Solrizer.set_field(solr_doc, 'generic_type', 'Admin Set', :facetable)
solr_doc['thumbnail_path_ss'] = thumbnail_path
end
end
end
Expand Down
1 change: 0 additions & 1 deletion app/indexers/hyrax/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def generate_solr_document
Solrizer.set_field(solr_doc, 'generic_type', 'Collection', :facetable)
# Index the size of the collection in bytes
solr_doc[Solrizer.solr_name(:bytes, STORED_LONG)] = object.bytes
solr_doc['thumbnail_path_ss'] = thumbnail_path
solr_doc['visibility_ssi'] = object.visibility

object.in_collections.each do |col|
Expand Down
1 change: 0 additions & 1 deletion app/indexers/hyrax/file_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def generate_solr_document
solr_doc['width_is'] = Integer(object.width.first) if object.width.present?
solr_doc['visibility_ssi'] = object.visibility
solr_doc['mime_type_ssi'] = object.mime_type
solr_doc['thumbnail_path_ss'] = thumbnail_path
# Index the Fedora-generated SHA1 digest to create a linkage between
# files on disk (in fcrepo.binary-store-path) and objects in the repository.
solr_doc['digest_ssim'] = digest_from_content
Expand Down
Loading

0 comments on commit 379bd9e

Please sign in to comment.