Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Sorting UI for Scanned Resources
Browse files Browse the repository at this point in the history
This allows scanned resources' FileSets to be re-ordered via JQuery-UI
Sortable.
  • Loading branch information
Trey Terrell committed Nov 3, 2015
1 parent a3e4067 commit 6f332d4
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 66 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem 'coffee-rails', '~> 4.1.0'

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down Expand Up @@ -53,6 +54,7 @@ gem 'hydra-works', github: 'projecthydra-labs/hydra-works', branch: 'master'
gem 'hydra-pcdm', github: 'projecthydra-labs/hydra-pcdm', branch: 'master'
gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation', branch: 'master'
gem 'hydra-derivatives', github: 'projecthydra/hydra-derivatives', branch: 'master'
gem 'active-fedora', github: 'projecthydra/active_fedora', branch: 'master'

gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
Expand Down
137 changes: 73 additions & 64 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GIT
remote: git://github.com/projecthydra-labs/activefedora-aggregation.git
revision: fc28a063e9aa475cfaf78f891e0233afb9d8153c
revision: 00d46792af0fa887da59dd9581f3ecf6b5b822e6
branch: master
specs:
activefedora-aggregation (0.5.0)
activefedora-aggregation (0.6.0)
active-fedora (~> 9.5)
activesupport
rdf (~> 1.1.16.0)
rdf (~> 1.1, >= 1.1.17.1)
rdf-vocab (~> 0.8.1)

GIT
Expand Down Expand Up @@ -52,6 +52,22 @@ GIT
hydra-file_characterization (~> 0.3, >= 0.3.3)
hydra-pcdm (~> 0.3)

GIT
remote: git://github.com/projecthydra/active_fedora.git
revision: 608140a8ee2bf9a74fb89446558fbeb765f0dfca
branch: master
specs:
active-fedora (9.6.1)
active-triples (~> 0.7.1)
activesupport (>= 4.1.0)
deprecation
ldp (~> 0.4.0)
linkeddata
nom-xml (>= 0.5.1)
om (~> 3.1)
rdf-rdfxml (~> 1.1)
rsolr (~> 1.0.10)

GIT
remote: git://github.com/projecthydra/hydra-collections.git
revision: c8abfb472265e45f852b358b769f3d8cb7af9979
Expand Down Expand Up @@ -108,16 +124,6 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
active-fedora (9.5.0)
active-triples (~> 0.7.1)
activesupport (>= 4.1.0)
deprecation
ldp (~> 0.4.0)
linkeddata
nom-xml (>= 0.5.1)
om (~> 3.1)
rdf-rdfxml (~> 1.1.0)
rsolr (~> 1.0.10)
active-triples (0.7.2)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -257,7 +263,7 @@ GEM
docile (1.1.5)
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
ebnf (0.3.9)
ebnf (1.0.0)
rdf (~> 1.1)
sxp (~> 0.1, >= 0.1.3)
equivalent-xml (0.6.0)
Expand Down Expand Up @@ -331,9 +337,9 @@ GEM
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.3)
json-ld (1.1.11)
json-ld (1.99.0)
multi_json (~> 1.11)
rdf (~> 1.1, >= 1.1.7)
rdf (~> 1.99)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
Expand All @@ -345,27 +351,27 @@ GEM
linkeddata (>= 1.1)
slop
link_header (0.0.8)
linkeddata (1.1.11)
equivalent-xml (~> 0.5)
json-ld (~> 1.1, >= 1.1.8)
linkeddata (1.99.0)
equivalent-xml (~> 0.6)
json-ld (~> 1.99)
nokogiri (~> 1.6)
rdf (~> 1.1, >= 1.1.11)
rdf-aggregate-repo (~> 1.1)
rdf-isomorphic (~> 1.1)
rdf (~> 1.99)
rdf-aggregate-repo (~> 1.99)
rdf-isomorphic (~> 1.99)
rdf-json (~> 1.1, >= 1.1.2)
rdf-microdata (~> 2.0, >= 2.0.1)
rdf-n3 (~> 1.1, >= 1.1.3)
rdf-rdfa (~> 1.1, >= 1.1.6)
rdf-rdfxml (~> 1.1, >= 1.1.4)
rdf-reasoner (~> 0.2, >= 0.2.1)
rdf-tabular (~> 0.1, >= 0.1.2)
rdf-trig (~> 1.1, >= 1.1.4)
rdf-trix (~> 1.1)
rdf-turtle (~> 1.1, >= 1.1.6)
rdf-vocab (~> 0.8)
rdf-xsd (~> 1.1, >= 1.1.3)
sparql (~> 1.1, >= 1.1.5)
sparql-client (~> 1.1, >= 1.1.3)
rdf-microdata (~> 2.0, >= 2.0.2)
rdf-n3 (~> 1.99)
rdf-rdfa (~> 1.99)
rdf-rdfxml (~> 1.1, >= 1.1.5)
rdf-reasoner (~> 0.3)
rdf-tabular (~> 0.3)
rdf-trig (~> 1.99, >= 1.99.0.1)
rdf-trix (~> 1.99)
rdf-turtle (~> 1.99)
rdf-vocab (~> 0.8, >= 0.8.6)
rdf-xsd (~> 1.1, >= 1.1.5)
sparql (~> 1.99)
sparql-client (~> 1.99)
logger (1.2.8)
loofah (2.0.3)
nokogiri (>= 1.5.9)
Expand All @@ -378,7 +384,7 @@ GEM
mime-types (2.6.2)
mini_magick (4.3.6)
mini_portile (0.6.2)
minitest (5.8.1)
minitest (5.8.2)
modernizr-rails (2.7.1)
mono_logger (1.1.0)
multi_json (1.11.2)
Expand Down Expand Up @@ -465,55 +471,56 @@ GEM
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.4.2)
rdf (1.1.16.1)
rdf (1.99.0)
link_header (~> 0.0, >= 0.0.8)
rdf-aggregate-repo (1.1.0)
rdf (>= 1.1)
rdf-isomorphic (1.1.0.1)
rdf (~> 1.1, >= 1.1.16.1)
rdf-aggregate-repo (1.99.0)
rdf (~> 1.99)
rdf-isomorphic (1.99.0)
rdf (~> 1.99)
rdf-json (1.1.2)
rdf (~> 1.1)
rdf-microdata (2.0.1)
rdf-microdata (2.0.2)
htmlentities (~> 4.3)
nokogiri (~> 1.6)
rdf (~> 1.1)
rdf-xsd (~> 1.1)
rdf-n3 (1.1.3)
rdf (~> 1.1, >= 1.1.5)
rdf-rdfa (1.1.6)
rdf-n3 (1.99.0)
rdf (~> 1.99)
rdf-rdfa (1.99.0)
haml (~> 4.0)
htmlentities (~> 4.3)
rdf (~> 1.1, >= 1.1.6)
rdf (~> 1.99)
rdf-aggregate-repo (~> 1.1)
rdf-xsd (~> 1.1)
rdf-rdfxml (1.1.4)
rdf-rdfxml (1.1.5)
htmlentities (~> 4.3)
rdf (~> 1.1, >= 1.1.6)
rdf-rdfa (~> 1.1, >= 1.1.4.1)
rdf-xsd (~> 1.1)
rdf-reasoner (0.2.2)
rdf-reasoner (0.3.0)
rdf (~> 1.1, >= 1.1.4.2)
rdf-turtle (~> 1.1)
rdf-vocab (~> 0.8)
rdf-xsd (~> 1.1)
rdf-tabular (0.2.1)
rdf-tabular (0.3.0)
addressable (~> 2.3)
bcp47 (~> 0.3, >= 0.3.3)
json-ld (~> 1.1)
rdf (~> 1.1, >= 1.1.7)
rdf-vocab (~> 0.8)
rdf-xsd (~> 1.1)
rdf-trig (1.1.5)
ebnf (~> 0.3, >= 0.3.7)
rdf (~> 1.1, >= 1.1.11)
rdf-turtle (~> 1.1, >= 1.1.7)
rdf-trix (1.1.0)
rdf (>= 1.1)
rdf-turtle (1.1.8)
ebnf (~> 0.3, >= 0.3.6)
rdf (~> 1.1, >= 1.1.10)
rdf-trig (1.99.0.1)
ebnf (~> 1.0)
rdf (~> 1.99)
rdf-turtle (~> 1.99)
rdf-trix (1.99.0)
rdf (~> 1.1)
rdf-turtle (1.99.0)
ebnf (~> 1.0)
rdf (~> 1.99)
rdf-vocab (0.8.6)
rdf (~> 1.1, >= 1.1.10)
rdf-xsd (1.1.4)
rdf-xsd (1.1.5)
rdf (~> 1.1, >= 1.1.9)
rdoc (4.2.0)
redis (3.2.1)
Expand Down Expand Up @@ -601,15 +608,15 @@ GEM
nokogiri
stomp
xml-simple
sparql (1.1.9)
sparql (1.99.0)
builder (~> 3.2)
ebnf (~> 0.3, >= 0.3.9)
rdf (~> 1.1, >= 1.1.13)
rdf-aggregate-repo (~> 1.1, >= 1.1.0)
ebnf (~> 1.0)
rdf (~> 1.99)
rdf-aggregate-repo (~> 1.99)
rdf-xsd (~> 1.1)
sparql-client (~> 1.1)
sxp (~> 0.1)
sparql-client (1.1.6)
sparql-client (1.99.0)
net-http-persistent (~> 2.9)
rdf (~> 1.1)
spring (1.4.0)
Expand Down Expand Up @@ -667,6 +674,7 @@ PLATFORMS
ruby

DEPENDENCIES
active-fedora!
activefedora-aggregation!
capistrano-passenger
capistrano-rails
Expand All @@ -688,6 +696,7 @@ DEPENDENCIES
jbuilder (~> 2.0)
jettywrapper
jquery-rails
jquery-ui-rails
launchy
modernizr-rails
omniauth-cas
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui/sortable
//= require turbolinks//
// Required by Blacklight
//= require blacklight/blacklight
Expand Down
71 changes: 71 additions & 0 deletions app/assets/javascripts/sortable.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
jQuery ->
window.sort_manager = new SortManager
class Flash
constructor: ->
@element = $("*[data-reorder-action='flash']")
@element.children(".close").click =>
@element.hide()
reset_type: ->
@element.removeClass("alert-success")
@element.removeClass("alert-danger")
set: (type, message) ->
this.reset_type()
@element.addClass("alert-#{type}")
@element.children(".text").text(message)
@element.show()
@element.removeClass("hidden")
class SortManager
constructor: ->
@element = $("#sortable")
@sorting_info = {}
@sorting_actions = []
this.initialize_sort()
this.initialize_persist_button()
this.initialize_flash()
initialize_sort: ->
@element.sortable()
@element.disableSelection()
@element.on("sortstop", this.stopped_sorting)
@element.on("sortstart", this.started_sorting)
initialize_persist_button: ->
@persist_button = $("*[data-reorder-action='persist']")
@persist_button.click(this.persist_ordering)
initialize_flash: ->
@flash = new Flash
started_sorting: (event, ui) =>
@sorting_element = $(ui.item)
@sorting_info.start = this.get_sort_position(ui.item)
window.sorting_element = $(ui.item)
stopped_sorting: (event, ui) =>
@sorting_info.end = this.get_sort_position($(ui.item))
return if @sorting_info.end == @sorting_info.start
@persist_button.removeClass("disabled")
get_sort_position: (item) ->
@element.children().index(item)
get_order: ->
$("*[data-reorder-id]").map(->
$(this).data("reorder-id")
).toArray()
persist_ordering: (event) =>
event.preventDefault()
return if @persisting == true
@persisting = true
console.log("Persisting Reordering")
@persist_button.addClass("disabled")
@persist_button.data("old-text", @persist_button.text())
@persist_button.text("Saving...")
order = this.get_order()
$.post("/concern/scanned_resources/#{@element.data("id")}/reorder.json", {order: order}).done( (data) =>
@sorting_actions = []
if data.message?
@flash.set('success', data.message)
).always( =>
@persist_button.text(@persist_button.data("old-text"))
@persisting = false
).fail( (data, message) =>
if data?.message?
@flash.set('danger', data.message)
else
@flash.set('danger', "Unable to save new order.")
@persist_button.removeClass("disabled")
)
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
@import 'components/positioning';

@import "components/viewer";
@import "jquery-ui/sortable"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class CurationConcerns::ScannedResourcesController < CurationConcerns::CurationConcernsController
include CurationConcerns::ParentContainer
set_curation_concern_type ScannedResource
skip_load_and_authorize_resource only: [:show, :manifest]
skip_load_and_authorize_resource only: [:show, :manifest, :reorder]

def create
super
Expand All @@ -24,4 +24,29 @@ def pdf
actor.generate_pdf
redirect_to main_app.download_path(curation_concern, file: 'pdf')
end

def reorder
@members = presenter.file_presenters
end

def save_order
lock_manager.lock(curation_concern.id) do
form = ReorderForm.new(curation_concern)
form.order = params[:order]
if form.save
render json: { message: "Succesfully updated order." }
else
render json: { message: form.errors.full_messages.to_sentence }, status: :bad_request
end
end
end

private

def lock_manager
@lock_manager ||= CurationConcerns::LockManager.new(
CurationConcerns.config.lock_time_to_live,
CurationConcerns.config.lock_retry_count,
CurationConcerns.config.lock_retry_delay)
end
end
Loading

0 comments on commit 6f332d4

Please sign in to comment.