ld4l_virtual_collection 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.travis.yml +14 -0
- data/CHANGES.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +14 -0
- data/README.md +128 -0
- data/Rakefile +34 -0
- data/app/assets/images/ld4l_virtual_collection/loading_spinner.gif +0 -0
- data/app/assets/javascripts/ld4l_virtual_collection/application.js +19 -0
- data/app/assets/javascripts/ld4l_virtual_collection/collections.js +2 -0
- data/app/assets/javascripts/ld4l_virtual_collection/items.js +2 -0
- data/app/assets/stylesheets/ld4l_virtual_collection/_bootstrap-custom.scss +50 -0
- data/app/assets/stylesheets/ld4l_virtual_collection/application.css.scss +22 -0
- data/app/assets/stylesheets/ld4l_virtual_collection/collections.css.scss +4 -0
- data/app/assets/stylesheets/ld4l_virtual_collection/items.css.scss +4 -0
- data/app/assets/stylesheets/ld4l_virtual_collection/my_virtual_collections.css.scss +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/ld4l_virtual_collection/application_controller.rb +9 -0
- data/app/controllers/ld4l_virtual_collection/collections_controller.rb +101 -0
- data/app/controllers/ld4l_virtual_collection/items_controller.rb +94 -0
- data/app/controllers/ld4l_virtual_collection/my_virtual_collections_controller.rb +189 -0
- data/app/controllers/ld4l_virtual_collection/notes_controller.rb +84 -0
- data/app/controllers/ld4l_virtual_collection/tags_controller.rb +105 -0
- data/app/helpers/ld4l_virtual_collection/application_helper.rb +4 -0
- data/app/helpers/ld4l_virtual_collection/collections_helper.rb +4 -0
- data/app/helpers/ld4l_virtual_collection/items_helper.rb +4 -0
- data/app/models/ld4l_virtual_collection/collection.rb +47 -0
- data/app/models/ld4l_virtual_collection/item.rb +50 -0
- data/app/models/ld4l_virtual_collection/note.rb +52 -0
- data/app/models/ld4l_virtual_collection/tag.rb +94 -0
- data/app/views/layouts/ld4l_virtual_collection/application.html.erb +14 -0
- data/app/views/ld4l_virtual_collection/collections/_form.html.erb +28 -0
- data/app/views/ld4l_virtual_collection/collections/edit.html.erb +13 -0
- data/app/views/ld4l_virtual_collection/collections/index.html.erb +30 -0
- data/app/views/ld4l_virtual_collection/collections/new.html.erb +12 -0
- data/app/views/ld4l_virtual_collection/collections/show.html.erb +43 -0
- data/app/views/ld4l_virtual_collection/items/_collection_info.html.erb +14 -0
- data/app/views/ld4l_virtual_collection/items/_form.html.erb +25 -0
- data/app/views/ld4l_virtual_collection/items/edit.html.erb +14 -0
- data/app/views/ld4l_virtual_collection/items/index.html.erb +24 -0
- data/app/views/ld4l_virtual_collection/items/new.html.erb +14 -0
- data/app/views/ld4l_virtual_collection/items/show.html.erb +23 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_collection_lists.html.erb +82 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_edit_collection_modal.html.erb +20 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_form_collection.html.erb +51 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_form_collection_item.html.erb +48 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_form_collection_items_query.html.erb +37 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_form_item_note.html.erb +31 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_form_item_tag.html.erb +30 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_modals.html.erb +8 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_new_collection_item_modal.html.erb +20 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_new_collection_items_by_query_modal.html.erb +20 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_new_collection_modal.html.erb +20 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_selected_collection_header.html.erb +17 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_selected_collection_items.html.erb +121 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/_selected_collection_range.html.erb +44 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/edit_collection_modal.js.erb +1 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/index.html.erb +4 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/new_collection_item_modal.js.erb +1 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/new_collection_items_by_query_modal.js.erb +1 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/new_collection_modal.js.erb +1 -0
- data/app/views/ld4l_virtual_collection/my_virtual_collections/show.html.erb +14 -0
- data/bin/rails +12 -0
- data/config/routes.rb +16 -0
- data/ld4l_virtual_collection.gemspec +50 -0
- data/lib/ld4l_virtual_collection.rb +34 -0
- data/lib/ld4l_virtual_collection/configuration.rb +86 -0
- data/lib/ld4l_virtual_collection/engine.rb +23 -0
- data/lib/ld4l_virtual_collection/version.rb +3 -0
- data/lib/tasks/ld4l_virtual_collection_tasks.rake +4 -0
- data/test/controllers/ld4l_virtual_collection/collections_controller_test.rb +51 -0
- data/test/controllers/ld4l_virtual_collection/items_controller_test.rb +51 -0
- data/test/controllers/ld4l_virtual_collection/my_virtual_collections_controller_test.rb +51 -0
- data/test/controllers/ld4l_virtual_collection/virtual_collections_controller_test.rb +51 -0
- data/test/dummy/Gemfile +20 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/rdf_repositories.rb +32 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/ld4l_virtual_collection/collections.yml +11 -0
- data/test/fixtures/ld4l_virtual_collection/items.yml +11 -0
- data/test/fixtures/ld4l_virtual_collection/my_virtual_collections.yml +11 -0
- data/test/fixtures/ld4l_virtual_collection/virtual_collections.yml +9 -0
- data/test/helpers/ld4l_virtual_collection/collections_helper_test.rb +6 -0
- data/test/helpers/ld4l_virtual_collection/items_helper_test.rb +6 -0
- data/test/helpers/ld4l_virtual_collection/my_virtual_collections_helper_test.rb +6 -0
- data/test/helpers/ld4l_virtual_collection/virtual_collections_helper_test.rb +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/ld4l_virtual_collection_test.rb +7 -0
- data/test/models/ld4l_virtual_collection/collection_test.rb +9 -0
- data/test/models/ld4l_virtual_collection/item_test.rb +9 -0
- data/test/models/ld4l_virtual_collection/my_virtual_collection_test.rb +9 -0
- data/test/models/ld4l_virtual_collection/virtual_collection_test.rb +9 -0
- data/test/test_helper.rb +17 -0
- metadata +544 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# # MODIFIED to have engine application controller extend main application's controller
|
|
2
|
+
class Ld4lVirtualCollection::ApplicationController < ApplicationController
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
# # GENERATED
|
|
6
|
+
# module Ld4lVirtualCollection
|
|
7
|
+
# class ApplicationController < ActionController::Base
|
|
8
|
+
# end
|
|
9
|
+
# end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require_dependency "ld4l_virtual_collection/application_controller"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# TODO This code implies that @collection is an instance of the Collection model, but it is actually an instance of
|
|
5
|
+
# LD4L::OreRDF::Aggregation. Should the Collection model be updated to hold the instance of LD4L::OreRDF::Aggregation
|
|
6
|
+
# and have the methods updated to redirect to the Aggregation model? OR should Collection inherit from
|
|
7
|
+
# LD4L::OreRDF::Aggregation and get the methods that way? That seems the cleaner way to go.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module Ld4lVirtualCollection
|
|
11
|
+
class CollectionsController < ApplicationController
|
|
12
|
+
before_action :set_collection, only: [:show, :edit, :update, :destroy]
|
|
13
|
+
|
|
14
|
+
# GET /collections
|
|
15
|
+
def index
|
|
16
|
+
@collections = Collection.all
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# GET /collections/1
|
|
20
|
+
def show
|
|
21
|
+
# puts("*** Entering CTRL: show collection")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# GET /collections/new
|
|
25
|
+
def new
|
|
26
|
+
# puts("*** Entering CTRL: new collection")
|
|
27
|
+
@collection = Collection.new
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# GET /collections/1/edit
|
|
31
|
+
def edit
|
|
32
|
+
# puts("*** Entering CTRL: edit")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# POST /collections
|
|
36
|
+
def create
|
|
37
|
+
# puts("*** Entering CTRL: create collection")
|
|
38
|
+
@collection = Collection.new(collection_params)
|
|
39
|
+
persisted = false
|
|
40
|
+
error_msg = ''
|
|
41
|
+
begin
|
|
42
|
+
persisted = LD4L::OreRDF::PersistAggregation.call(@collection)
|
|
43
|
+
rescue ArgumentError
|
|
44
|
+
# TODO should check that error message from ArgumentError is that Title is missing.
|
|
45
|
+
error_msg = "Title is required."
|
|
46
|
+
end
|
|
47
|
+
if persisted == true
|
|
48
|
+
flash[:notice] = 'Collection was successfully created.'
|
|
49
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s)
|
|
50
|
+
else
|
|
51
|
+
flash[:error] = "Collection not created. #{error_msg}"
|
|
52
|
+
redirect_to my_virtual_collections_path
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# PATCH/PUT /collections/1
|
|
57
|
+
def update
|
|
58
|
+
# puts("*** Entering CTRL: update collection")
|
|
59
|
+
@collection = Collection.update(collection_params)
|
|
60
|
+
persisted = false
|
|
61
|
+
error_msg = ''
|
|
62
|
+
begin
|
|
63
|
+
# TODO -- should update check that proxies persisted as well???
|
|
64
|
+
persisted = LD4L::OreRDF::PersistAggregation.call(@collection)
|
|
65
|
+
rescue ArgumentError
|
|
66
|
+
# TODO should check that error message from ArgumentError is that Title is missing.
|
|
67
|
+
error_msg = "Title is required."
|
|
68
|
+
end
|
|
69
|
+
if persisted == true
|
|
70
|
+
flash[:notice] = 'Collection was successfully updated.'
|
|
71
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s)
|
|
72
|
+
else
|
|
73
|
+
flash[:error] = "Collection not updated. #{error_msg}"
|
|
74
|
+
redirect_to my_virtual_collections_path
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# DELETE /collections/1
|
|
79
|
+
def destroy
|
|
80
|
+
# puts("*** Entering CTRL: destroy collection")
|
|
81
|
+
if LD4L::OreRDF::DestroyAggregation.call(@collection) == true
|
|
82
|
+
redirect_to my_virtual_collections_path, notice: 'Collection was successfully destroyed.'
|
|
83
|
+
else
|
|
84
|
+
# TODO Should it redirect to edit??? OR list??? OR where???
|
|
85
|
+
# TODO How to add error message about what failed to be destroyed???
|
|
86
|
+
render :edit
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
92
|
+
def set_collection
|
|
93
|
+
@collection = Collection.find(params[:id])
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Only allow a trusted parameter "white list" through.
|
|
97
|
+
def collection_params
|
|
98
|
+
params[:collection]
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require_dependency "ld4l_virtual_collection/application_controller"
|
|
2
|
+
|
|
3
|
+
module Ld4lVirtualCollection
|
|
4
|
+
class ItemsController < ApplicationController
|
|
5
|
+
before_action :set_collection
|
|
6
|
+
before_action :set_item, only: [:show, :edit, :update, :destroy, :metadata_from_uri]
|
|
7
|
+
|
|
8
|
+
# GET /collections/1/items
|
|
9
|
+
def index
|
|
10
|
+
@items = Item.all(@collection)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /collections/1/items/1
|
|
14
|
+
def show
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# GET /collections/1/items/new
|
|
18
|
+
def new
|
|
19
|
+
# puts("*** Entering CTRL: new item")
|
|
20
|
+
@item = Item.new(@collection)
|
|
21
|
+
@proxy_for = ""
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# GET /items/1/edit
|
|
25
|
+
def edit
|
|
26
|
+
# puts("*** Entering CTRL: edit item")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# POST /collections/1/items
|
|
30
|
+
def create
|
|
31
|
+
# puts("*** Entering CTRL: create item")
|
|
32
|
+
@item = Item.new(@collection, item_params)
|
|
33
|
+
|
|
34
|
+
# TODO How to save only affected items & collection instead of all items & collection???
|
|
35
|
+
if LD4L::OreRDF::PersistAggregation.call(@collection) == true
|
|
36
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s), notice: 'Item was successfully created.'
|
|
37
|
+
else
|
|
38
|
+
# TODO How to add error message about what failed to persist???
|
|
39
|
+
render :new
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# PATCH/PUT /collections/1/items/1
|
|
44
|
+
def update
|
|
45
|
+
# puts("*** Entering CTRL: update item")
|
|
46
|
+
@item = Item.update(@collection, @item, item_params)
|
|
47
|
+
# TODO How to save only affected items & collection instead of all items & collection???
|
|
48
|
+
if LD4L::OreRDF::PersistAggregation.call(@collection) == true
|
|
49
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s), notice: 'Item was successfully updated.'
|
|
50
|
+
else
|
|
51
|
+
render :edit
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# GET /collections/1/items/1
|
|
56
|
+
def metadata_from_uri
|
|
57
|
+
# puts("*** Entering CTRL: create_from_uri (item)")
|
|
58
|
+
LD4L::WorksRDF::GetMetadataFromURI(@proxy_for)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# DELETE /collections/1/items/1
|
|
62
|
+
def destroy
|
|
63
|
+
# puts("*** Entering CTRL: destroy item")
|
|
64
|
+
# TODO -- need to implement destroy in ORE Gem -- Destroying just the item leaves the aggregates triples
|
|
65
|
+
@item.destroy ## TODO REMOVE THIS LINE WHEN DestroyProxy IS IMPLEMENTED
|
|
66
|
+
# if LD4L::OreRDF::DestroyProxy.call(@collection,@item.rdf_subject) == true
|
|
67
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s), notice: 'Item was successfully removed.'
|
|
68
|
+
# else
|
|
69
|
+
# # TODO Should it redirect to edit??? OR list??? OR where???
|
|
70
|
+
# # TODO How to add error message about what failed to be destroyed???
|
|
71
|
+
# render :edit
|
|
72
|
+
# end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
77
|
+
def set_item
|
|
78
|
+
@item = Item.find(params[:id])
|
|
79
|
+
@proxy_for = @item.proxy_for_subject
|
|
80
|
+
@proxy_for |= ""
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Only allow a trusted parameter "white list" through.
|
|
84
|
+
def item_params
|
|
85
|
+
white_list_params = params.permit(:proxy_for) unless params.has_key?(:item)
|
|
86
|
+
white_list_params = params.require(:item).permit(:proxy_for) if params.has_key?(:item)
|
|
87
|
+
white_list_params
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def set_collection
|
|
91
|
+
@collection = Collection.find(params["collection_id"])
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
require_dependency "ld4l_virtual_collection/application_controller"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# TODO This code implies that @collection is an instance of the Collection model, but it is actually an instance of
|
|
5
|
+
# LD4L::OreRDF::Aggregation. Should the Collection model be updated to hold the instance of LD4L::OreRDF::Aggregation
|
|
6
|
+
# and have the methods updated to redirect to the Aggregation model? OR should Collection inherit from
|
|
7
|
+
# LD4L::OreRDF::Aggregation and get the methods that way? That seems the cleaner way to go.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module Ld4lVirtualCollection
|
|
11
|
+
class MyVirtualCollectionsController < ApplicationController
|
|
12
|
+
before_action :set_collections, :set_page_title
|
|
13
|
+
before_action :set_collection, only: [:edit, :update, :destroy, :edit_collection_modal, :new_collection_item_modal]
|
|
14
|
+
before_action :set_collection_and_items, only: [:show]
|
|
15
|
+
|
|
16
|
+
# GET /my_virtual_collections
|
|
17
|
+
def index
|
|
18
|
+
@collection = Collection.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# GET /my_virtual_collections/1
|
|
22
|
+
def show
|
|
23
|
+
# puts("*** Entering CTRL: show virtual collection")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# GET /my_virtual_collections/new_collection_modal
|
|
27
|
+
def new_collection_modal
|
|
28
|
+
# puts("*** Entering CTRL: new virtual collection")
|
|
29
|
+
@collection = Collection.new
|
|
30
|
+
respond_to do |format|
|
|
31
|
+
format.html
|
|
32
|
+
format.js
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# GET /my_virtual_collections/edit_collection_modal/1
|
|
37
|
+
def edit_collection_modal
|
|
38
|
+
# puts("*** Entering CTRL: edit virtual collection")
|
|
39
|
+
respond_to do |format|
|
|
40
|
+
format.html
|
|
41
|
+
format.js
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# GET /my_virtual_collections/new_collection_item_modal/1
|
|
47
|
+
def new_collection_item_modal
|
|
48
|
+
# puts("*** Entering CTRL: new virtual collection item")
|
|
49
|
+
@item = Item.new(@collection)
|
|
50
|
+
@proxy_for = ""
|
|
51
|
+
respond_to do |format|
|
|
52
|
+
format.html
|
|
53
|
+
format.js
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# # TODO XXX
|
|
59
|
+
# # GET /my_virtual_collections/new_collection_items_by_query_modal/1
|
|
60
|
+
# def new_collection_items_by_query_modal
|
|
61
|
+
# # puts("*** Entering CTRL: new virtual collection items by query")
|
|
62
|
+
# @item = Item.new(@collection)
|
|
63
|
+
# @proxy_for = ""
|
|
64
|
+
# respond_to do |format|
|
|
65
|
+
# format.html
|
|
66
|
+
# format.js
|
|
67
|
+
# end
|
|
68
|
+
# end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# # GET /my_virtual_collections/1/edit
|
|
72
|
+
# def edit
|
|
73
|
+
# # puts("*** Entering CTRL: edit")
|
|
74
|
+
# end
|
|
75
|
+
#
|
|
76
|
+
# # POST /my_virtual_collections
|
|
77
|
+
# def create
|
|
78
|
+
# puts("*** Entering CTRL: create collection")
|
|
79
|
+
# @collection = Collection.new(collection_params)
|
|
80
|
+
# if LD4L::OreRDF::PersistAggregation.call(@collection) == true
|
|
81
|
+
# redirect_to collection_path(@collection.id.to_s), notice: 'Collection was successfully created.'
|
|
82
|
+
# else
|
|
83
|
+
# # TODO How to add error message about what failed to persist???
|
|
84
|
+
# render :new
|
|
85
|
+
# end
|
|
86
|
+
# end
|
|
87
|
+
#
|
|
88
|
+
# # PATCH/PUT /my_virtual_collections/1
|
|
89
|
+
# def update
|
|
90
|
+
# puts("*** Entering CTRL: update collection")
|
|
91
|
+
# @collection = Collection.update(collection_params)
|
|
92
|
+
# # TODO -- should update check that proxies persisted as well???
|
|
93
|
+
# if LD4L::OreRDF::PersistAggregation.call(@collection) == true
|
|
94
|
+
# redirect_to collection_path(@collection.id.to_s), notice: 'Collection was successfully updated.'
|
|
95
|
+
# else
|
|
96
|
+
# # TODO How to add error message about what failed to persist???
|
|
97
|
+
# render :edit
|
|
98
|
+
# end
|
|
99
|
+
# end
|
|
100
|
+
#
|
|
101
|
+
# # DELETE /my_virtual_collections/1
|
|
102
|
+
# def destroy
|
|
103
|
+
# puts("*** Entering CTRL: destroy collection")
|
|
104
|
+
# if LD4L::OreRDF::DestroyAggregation.call(@collection) == true
|
|
105
|
+
# redirect_to collections_url, notice: 'Collection was successfully destroyed.'
|
|
106
|
+
# else
|
|
107
|
+
# # TODO Should it redirect to edit??? OR list??? OR where???
|
|
108
|
+
# # TODO How to add error message about what failed to be destroyed???
|
|
109
|
+
# render :edit
|
|
110
|
+
# end
|
|
111
|
+
# end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
115
|
+
def set_page_title
|
|
116
|
+
@heading = "Virtual Collections"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def set_collections
|
|
120
|
+
@collections = []
|
|
121
|
+
collections = Collection.all
|
|
122
|
+
Ld4lVirtualCollection::Engine.configuration.debug_logger.warn("*** Entering CTRL: set_collections -- @collections=#{@collections}")
|
|
123
|
+
collections.each do |uri, col|
|
|
124
|
+
parsed_col = {}
|
|
125
|
+
parsed_col[:title] = col[:title]
|
|
126
|
+
parsed_col[:description] = col[:description]
|
|
127
|
+
parsed_col[:uri] = uri
|
|
128
|
+
parsed_col[:id] = /https?:\/\/(\w*):?(\d{4})?([\/\w]*)\/(\w{10}-\w{4}-\w{4}-\w{4}-\w{12})/.match(uri).values_at(4)
|
|
129
|
+
@collections << parsed_col
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# TODO Sorting collections alphabetically...
|
|
133
|
+
# TODO * @collections is a hash, so it can't be sorted
|
|
134
|
+
# TODO * need to convert @collections from a hash to an array
|
|
135
|
+
|
|
136
|
+
# @watched = Watched.all
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def set_collection
|
|
140
|
+
@select_id = params[:id]
|
|
141
|
+
@collection = Collection.find(@select_id)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def set_collection_and_items
|
|
145
|
+
Ld4lVirtualCollection::Engine.configuration.debug_logger.warn("*** Entering CTRL: set_collection_and_items")
|
|
146
|
+
Ld4lVirtualCollection::Engine.configuration.debug_logger.warn("params=#{params}")
|
|
147
|
+
@select_id = params[:id]
|
|
148
|
+
@collection = Collection.find(@select_id)
|
|
149
|
+
@items = []
|
|
150
|
+
if @collection
|
|
151
|
+
Ld4lVirtualCollection::Engine.configuration.debug_logger.warn("****** Get metadata for virtual collection #{@collection.title}")
|
|
152
|
+
@collection.proxy_resources.each do |proxy|
|
|
153
|
+
next if proxy.nil?
|
|
154
|
+
uri = proxy.proxy_for_subject
|
|
155
|
+
next if uri.nil?
|
|
156
|
+
Ld4lVirtualCollection::Engine.configuration.debug_logger.warn(" begin processing URI: #{uri}")
|
|
157
|
+
parsable_uri = URI(uri) if uri
|
|
158
|
+
metadata_callback = Ld4lVirtualCollection::Engine.configuration.find_metadata_callback(parsable_uri.host) if parsable_uri
|
|
159
|
+
metadata_callback = Ld4lVirtualCollection::Engine.configuration.get_default_metadata_callback unless metadata_callback
|
|
160
|
+
items_metadata = metadata_callback.call( [ uri ] ) if metadata_callback
|
|
161
|
+
|
|
162
|
+
notes = Ld4lVirtualCollection::Note.all(@collection,proxy)
|
|
163
|
+
note = notes.first if notes && notes.size > 0
|
|
164
|
+
note = Ld4lVirtualCollection::Note.new(@collection,proxy) unless notes && notes.size > 0
|
|
165
|
+
|
|
166
|
+
tag_values = Ld4lVirtualCollection::Tag.all_values(proxy)
|
|
167
|
+
tag = Ld4lVirtualCollection::Tag.new(@collection,proxy)
|
|
168
|
+
|
|
169
|
+
@items << { :proxy => proxy, :metadata => items_metadata.first, :proxy_for => uri, :note => note, :tag => tag, :tags => tag_values } if items_metadata && items_metadata.size > 0
|
|
170
|
+
|
|
171
|
+
Ld4lVirtualCollection::Engine.configuration.debug_logger.warn(" processing complete - #{@items.size} items retrieved")
|
|
172
|
+
### TODO Look for all usage of proxy_for and make sure correct. Cause it isn't correct here.
|
|
173
|
+
|
|
174
|
+
# @proxy_for = uri ### TODO This isn't correct as the proxy gets reset with every loop. How is it being used? Should get proxy from @items.
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
# TODO: Following 3 values are kludged for first page. Need better method for calculating when multiple pages.
|
|
178
|
+
@first_idx = @items.size > 0 ? 1 : 0
|
|
179
|
+
@last_idx = @items.size <= 20 ? @items.size : 20
|
|
180
|
+
@num_items = @items.size
|
|
181
|
+
@note = nil
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# Only allow a trusted parameter "white list" through.
|
|
185
|
+
def my_virtual_collection_params
|
|
186
|
+
params[:collection]
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require_dependency "ld4l_virtual_collection/application_controller"
|
|
2
|
+
|
|
3
|
+
module Ld4lVirtualCollection
|
|
4
|
+
class NotesController < ApplicationController
|
|
5
|
+
before_action :set_collection_and_item, only: [:new, :create, :index]
|
|
6
|
+
before_action :set_note, only: [:show, :edit, :update, :destroy]
|
|
7
|
+
|
|
8
|
+
# GET /collections/1/items/1/notes
|
|
9
|
+
def index
|
|
10
|
+
@notes = Note.all(@collection,@item)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /notes/1
|
|
14
|
+
def show
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# GET /collections/1/items/1/notes/new
|
|
18
|
+
def new
|
|
19
|
+
# puts("*** Entering CTRL: new note")
|
|
20
|
+
@note = Note.new(@collection,@item)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# GET /notes/1/edit
|
|
24
|
+
def edit
|
|
25
|
+
# puts("*** Entering CTRL: edit note")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# POST /collections/1/items/1/notes
|
|
29
|
+
def create
|
|
30
|
+
# puts("*** Entering CTRL: create note")
|
|
31
|
+
@note = Note.new(@collection, @item, note_params)
|
|
32
|
+
|
|
33
|
+
if @note.persist! == true
|
|
34
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s), notice: 'Note was successfully created.'
|
|
35
|
+
else
|
|
36
|
+
# TODO How to add error message about what failed to persist???
|
|
37
|
+
render :new
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# PATCH/PUT /notes/1
|
|
42
|
+
def update
|
|
43
|
+
# puts("*** Entering CTRL: update note")
|
|
44
|
+
@note = Note.update(@note, note_params)
|
|
45
|
+
# TODO should check old and new values and only update if changed
|
|
46
|
+
# TODO How to save only affected items & collection instead of all items & collection???
|
|
47
|
+
if @note.persist! == true
|
|
48
|
+
redirect_to my_virtual_collection_path(note_params[:collection_id]), notice: 'Note was successfully updated.'
|
|
49
|
+
else
|
|
50
|
+
render :edit
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# DELETE /notes/1
|
|
55
|
+
def destroy
|
|
56
|
+
# puts("*** Entering CTRL: destroy note")
|
|
57
|
+
@note.destroy
|
|
58
|
+
# if LD4L::OreRDF::DestroyProxy.call(@collection,@item.rdf_subject) == true
|
|
59
|
+
redirect_to my_virtual_collection_path(@collection.id.to_s), notice: 'Note was successfully removed.'
|
|
60
|
+
# else
|
|
61
|
+
# # TODO Should it redirect to edit??? OR list??? OR where???
|
|
62
|
+
# # TODO How to add error message about what failed to be destroyed???
|
|
63
|
+
# render :edit
|
|
64
|
+
# end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
69
|
+
def set_note
|
|
70
|
+
@note = Note.find(params[:id])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Only allow a trusted parameter "white list" through.
|
|
74
|
+
def note_params
|
|
75
|
+
params[:note]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def set_collection_and_item
|
|
79
|
+
@collection = Collection.find(params["collection_id"])
|
|
80
|
+
@item = Item.find(params["item_id"])
|
|
81
|
+
@proxy_for = @item && @item.proxy_for && @item.proxy_for.first ? @item.proxy_for.first.rdf_subject : ""
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|