blacklight_folders 1.0.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/LICENSE +15 -0
- data/README.rdoc +50 -0
- data/Rakefile +68 -0
- data/app/assets/javascripts/blacklight_folders/catalog/edit.js +28 -0
- data/app/assets/javascripts/blacklight_folders/catalog/index.js +65 -0
- data/app/assets/javascripts/blacklight_folders/catalog/show.js +27 -0
- data/app/assets/javascripts/blacklight_folders/catalog.js +1 -0
- data/app/assets/javascripts/blacklight_folders/folder_items.js +36 -0
- data/app/assets/javascripts/blacklight_folders/sort.js +10 -0
- data/app/assets/javascripts/blacklight_folders.js +8 -0
- data/app/assets/stylesheets/blacklight_folders/_blacklight_folders.css.scss +4 -0
- data/app/assets/stylesheets/blacklight_folders/_folders.css.scss +56 -0
- data/app/assets/stylesheets/blacklight_folders/_forms.css.scss +11 -0
- data/app/assets/stylesheets/blacklight_folders/_nestable.css.scss +129 -0
- data/app/controllers/blacklight/folders/application_controller.rb +11 -0
- data/app/controllers/blacklight/folders/folders_controller.rb +162 -0
- data/app/controllers/concerns/blacklight/folders/application_controller_behavior.rb +63 -0
- data/app/forms/blacklight/folders/folder_form.rb +74 -0
- data/app/helpers/blacklight/folders/application_helper.rb +29 -0
- data/app/helpers/blacklight/folders/crud_links_helper.rb +29 -0
- data/app/helpers/blacklight/folders/folders_helper.rb +14 -0
- data/app/helpers/blacklight/folders/main_app_helper.rb +30 -0
- data/app/models/ability.rb +4 -0
- data/app/models/blacklight/folders/folder.rb +120 -0
- data/app/models/blacklight/folders/folder_item.rb +21 -0
- data/app/models/blacklight/folders/solr_response.rb +20 -0
- data/app/models/concerns/blacklight/folders/ability.rb +39 -0
- data/app/models/concerns/blacklight/folders/solr_document.rb +3 -0
- data/app/models/concerns/blacklight/folders/user.rb +20 -0
- data/app/views/blacklight/folders/_add_to_folder.html.erb +10 -0
- data/app/views/blacklight/folders/_folder_control.html.erb +1 -0
- data/app/views/blacklight/folders/folders/_folder.html.erb +22 -0
- data/app/views/blacklight/folders/folders/_folder_item.html.erb +2 -0
- data/app/views/blacklight/folders/folders/_form.html.erb +78 -0
- data/app/views/blacklight/folders/folders/_index_header_default.html.erb +20 -0
- data/app/views/blacklight/folders/folders/_marc_tools.html.erb +10 -0
- data/app/views/blacklight/folders/folders/_tools.html.erb +11 -0
- data/app/views/blacklight/folders/folders/edit.html.erb +2 -0
- data/app/views/blacklight/folders/folders/index.html.erb +33 -0
- data/app/views/blacklight/folders/folders/new.html.erb +2 -0
- data/app/views/blacklight/folders/folders/show.endnote.erb +1 -0
- data/app/views/blacklight/folders/folders/show.html.erb +43 -0
- data/app/views/blacklight/folders/show/_add_to_folder.html.erb +18 -0
- data/app/views/blacklight/folders/show/_folder_controls.html.erb +15 -0
- data/app/views/blacklight/nav/_folders.html.erb +14 -0
- data/app/views/catalog/_show_sidebar.html.erb +11 -0
- data/config/jetty.yml +6 -0
- data/config/locales/blacklight_folders.en.yml +73 -0
- data/config/routes.rb +5 -0
- data/db/migrate/1416883534_create_blacklight_folders_folders.rb +12 -0
- data/db/migrate/1416883577_create_blacklight_folders_folder_items.rb +13 -0
- data/lib/blacklight_folders/engine.rb +11 -0
- data/lib/blacklight_folders/version.rb +5 -0
- data/lib/blacklight_folders.rb +4 -0
- data/lib/generators/blacklight_folders/install_generator.rb +53 -0
- data/lib/generators/blacklight_folders/templates/blacklight_folders.rb +12 -0
- data/lib/generators/blacklight_folders/templates/blacklight_folders_helper.rb +3 -0
- data/lib/migration/bookmark_migrator.rb +45 -0
- data/lib/tasks/blacklight_folders_tasks.rake +12 -0
- metadata +269 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
<%= form_for @folder, html: { role: 'form', class: 'form-horizontal folder-actions' } do |f| %>
|
2
|
+
<div class="row">
|
3
|
+
<div class="col-sm-6">
|
4
|
+
<% if @folder.errors.any? %>
|
5
|
+
<div id="error_explanation">
|
6
|
+
<h2><%= pluralize(@folder.errors.count, "error") %> prohibited this folder from being saved:</h2>
|
7
|
+
|
8
|
+
<ul>
|
9
|
+
<% @folder.errors.full_messages.each do |message| %>
|
10
|
+
<li><%= message %></li>
|
11
|
+
<% end %>
|
12
|
+
</ul>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<div class="form-group">
|
17
|
+
<%= f.label :name, class: 'col-sm-2 control-label' %>
|
18
|
+
<div class="col-sm-10">
|
19
|
+
<%= f.text_field :name, class: 'form-control' %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="form-group">
|
24
|
+
<%= label_tag nil, t("blacklight/folders/folder.visibility", scope: "helpers.label"), class: 'col-sm-2 control-label' %>
|
25
|
+
<div class="col-sm-10">
|
26
|
+
|
27
|
+
<label class="radio-inline">
|
28
|
+
<%= f.radio_button(:visibility, Blacklight::Folders::Folder::PUBLIC) %>
|
29
|
+
<%= human_friendly_visibility(Blacklight::Folders::Folder::PUBLIC) %>
|
30
|
+
</label>
|
31
|
+
|
32
|
+
<label class="radio-inline">
|
33
|
+
<%= f.radio_button(:visibility, Blacklight::Folders::Folder::PRIVATE) %>
|
34
|
+
<%= human_friendly_visibility(Blacklight::Folders::Folder::PRIVATE) %>
|
35
|
+
</label>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
<div class="col-sm-6 pull-right">
|
40
|
+
<div><%= f.submit class: 'btn btn-primary' %></div>
|
41
|
+
<% if @folder.persisted? && can?(:destroy, @folder) %>
|
42
|
+
<%= link_to action_label(@folder, :delete), folder_path(@folder), method: :delete, class: 'btn btn-danger', data: { confirm: "Are you sure you want to delete this folder and all its contents?" } %>
|
43
|
+
<% end %>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div class="dd" data-folder_id="<%= f.object.id %>">
|
48
|
+
<ol id="documents" class="dd-list">
|
49
|
+
<%= f.fields_for :items do |i| %>
|
50
|
+
|
51
|
+
<li class="row dd-item" data-id="<%= i.object.id %>">
|
52
|
+
|
53
|
+
<div class="col-sm-2">
|
54
|
+
<span class="pull-left hidden dd-handle glyphicon glyphicon-resize-vertical"></span>
|
55
|
+
<%= i.text_field :position, class: 'form-control position-input' %>
|
56
|
+
</div>
|
57
|
+
<div class="col-sm-6 title">
|
58
|
+
<% document = @folder.documents[i.options[:child_index]] %>
|
59
|
+
<%= link_to_document document, document_show_link_field(document) %>
|
60
|
+
</div>
|
61
|
+
<div class="col-sm-2 title">
|
62
|
+
<% options_for_select = options_for_folder_select(without: document) %>
|
63
|
+
<% unless options_for_select.empty? %>
|
64
|
+
<%= i.select :folder_id, options_for_select, { include_blank: "Move to..." }, class: "form-control" %>
|
65
|
+
<% end %>
|
66
|
+
</div>
|
67
|
+
<div class="col-sm-2 checkbox">
|
68
|
+
<label>
|
69
|
+
<%= i.check_box :_destroy %>
|
70
|
+
Delete
|
71
|
+
</label>
|
72
|
+
</div>
|
73
|
+
</li>
|
74
|
+
<% end %>
|
75
|
+
</ol>
|
76
|
+
</div>
|
77
|
+
|
78
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
<% # header bar for doc items in index view -%>
|
3
|
+
<div class="documentHeader row">
|
4
|
+
|
5
|
+
<%# main title container for doc partial view
|
6
|
+
How many bootstrap columns need to be reserved
|
7
|
+
for bookmarks control depends on size.
|
8
|
+
-%>
|
9
|
+
<h5 class="index_title col-sm-9 col-lg-10">
|
10
|
+
<% counter = document_counter + 1 %>
|
11
|
+
<span class="document-counter">
|
12
|
+
<%= t('blacklight.search.documents.counter', :counter => counter) if counter %>
|
13
|
+
</span>
|
14
|
+
<%= link_to presenter(document).render_document_index_label(document_show_link_field(document)), main_app.solr_document_path(document) %>
|
15
|
+
</h5>
|
16
|
+
|
17
|
+
<% # bookmark functions for items/docs -%>
|
18
|
+
<%= render_index_doc_actions document, :wrapping_class => "index-document-functions col-sm-3 col-lg-2" %>
|
19
|
+
</div>
|
20
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% if @folder.documents.any? {|d| d.exports_as? :endnote } %>
|
2
|
+
<li class="endnote">
|
3
|
+
<%= link_to t('blacklight.tools.endnote'), { format: :endnote }, class: "btn btn-default", id: "endnoteLink" %>
|
4
|
+
</li>
|
5
|
+
<% end %>
|
6
|
+
<% if @folder.documents.any? {|d| d.exports_as? :refworks_marc_txt } %>
|
7
|
+
<li class="refworks">
|
8
|
+
<%= link_to t('blacklight.tools.refworks'), refworks_export_url(url: folder_export_url(@folder, :refworks_marc_txt)), class: "btn btn-default", id: "refworksLink" %>
|
9
|
+
</li>
|
10
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<ul class="bookmarkTools nav nav-pills">
|
2
|
+
<li class="cite">
|
3
|
+
<%= link_to t('blacklight.tools.cite'), main_app.citation_catalog_path(:sort=>params[:sort], :per_page=>params[:per_page], :id => @folder.documents.map {|doc| doc.id}), {:id => 'citeLink', :name => 'citation', :class => 'btn btn-default', :data => {:ajax_modal => "trigger"}} %>
|
4
|
+
</li>
|
5
|
+
|
6
|
+
<li class="email">
|
7
|
+
<%= link_to t('blacklight.tools.email'), main_app.email_catalog_path(:sort=>params[:sort], :per_page=>params[:per_page], :id => @folder.documents.map {|doc| doc.id}), :class=>"btn btn-default", :id => "emailLink", :data => {:ajax_modal => "trigger"} %>
|
8
|
+
</li>
|
9
|
+
|
10
|
+
<%= render_marc_tools %>
|
11
|
+
</ul>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<div class="folder-index">
|
2
|
+
<div class="row">
|
3
|
+
<h1 class="col-lg-8">Folders <small>(<%= @folders.size %> total)</small></h1>
|
4
|
+
|
5
|
+
<%= form_tag blacklight_folders.folders_path, method: :get, class:"col-lg-4", id: "sort-tool" do %>
|
6
|
+
<%= select_tag 'order_by', options_for_select({ 'Name' => 'name', 'Size' => 'number_of_members', 'Created' => 'created_at', 'Updated' => 'updated_at' }, params[:order_by]), prompt: "Sort by..." %>
|
7
|
+
<% end %>
|
8
|
+
</div>
|
9
|
+
<table id="folders" class="table">
|
10
|
+
<thead>
|
11
|
+
<tr>
|
12
|
+
<th><%= t('.table.headers.name') %></th>
|
13
|
+
<th><%= t('.table.headers.size') %></th>
|
14
|
+
<th><%= t('.table.headers.visibility') %></th>
|
15
|
+
<th><%= t('.table.headers.created') %></th>
|
16
|
+
<th><%= t('.table.headers.updated') %></th>
|
17
|
+
<th><%= t('.table.headers.actions') %></th>
|
18
|
+
</tr>
|
19
|
+
</thead>
|
20
|
+
|
21
|
+
<tbody>
|
22
|
+
<%= render partial: 'folder', collection: @folders %>
|
23
|
+
</tbody>
|
24
|
+
</table>
|
25
|
+
|
26
|
+
<% if can? :create, Blacklight::Folders::Folder %>
|
27
|
+
<div class='actions'>
|
28
|
+
<div class='primary-actions'>
|
29
|
+
<%= link_to action_label(Blacklight::Folders::Folder.new), blacklight_folders.new_folder_path, class: 'btn btn-primary' %>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
33
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render_endnote_texts(@folder.documents) %>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<div class="folder-view">
|
2
|
+
<p id="notice"><%= notice %></p>
|
3
|
+
|
4
|
+
<% if can? :edit, @folder %>
|
5
|
+
<div class="primary-actions">
|
6
|
+
<%= link_to edit_folder_path(@folder), class: 'btn btn-default' do %>
|
7
|
+
<span class="glyphicon glyphicon-pencil"></span> <%= action_label(@folder, :edit_long) %>
|
8
|
+
<% end %>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
11
|
+
<h1><%= @folder.name %></h1>
|
12
|
+
<div>
|
13
|
+
<span class="owner-label"><%= t("blacklight/folders/folder.user", scope: "helpers.label") %>:</span> <span class="owner"><%= @folder.user.guest? ? 'Guest' : @folder.user %></span>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div>
|
17
|
+
<span class="visibility-label"><%= t("blacklight/folders/folder.visibility", scope: "helpers.label") %>:</span> <span class="visibility"><%= human_friendly_visibility(@folder.visibility) %></span>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div>
|
21
|
+
<span class="created-label">
|
22
|
+
<%= t("blacklight/folders/folder.created", scope: "helpers.label") %>:
|
23
|
+
</span>
|
24
|
+
<span class="created" title="<%= @folder.created_at %>">
|
25
|
+
<%= t('blacklight.folders.folders.folder.ago', time: time_ago_in_words(@folder.created_at)) %>
|
26
|
+
</span>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div>
|
30
|
+
<span class="updated-label">
|
31
|
+
<%= t("blacklight/folders/folder.updated", scope: "helpers.label") %>:
|
32
|
+
</span>
|
33
|
+
<span class="updated" title="<%= @folder.updated_at %>">
|
34
|
+
<%= t('blacklight.folders.folders.folder.ago', time: time_ago_in_words(@folder.updated_at)) %>
|
35
|
+
</span>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<%= render 'tools' %>
|
39
|
+
|
40
|
+
<div id="documents">
|
41
|
+
<%= render partial: 'folder_item', collection: @folder.items, locals: { docs: @folder.documents } %>
|
42
|
+
</div>
|
43
|
+
</div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% options_for_select = options_for_folder_select(without: @document) %>
|
2
|
+
|
3
|
+
<% unless options_for_select.empty? %>
|
4
|
+
<div>
|
5
|
+
<%= form_for :folder, url: blacklight_folders.add_bookmarks_to_folder_path, method: :patch do |f| %>
|
6
|
+
|
7
|
+
<%= hidden_field_tag(:document_ids, @document.id) %>
|
8
|
+
|
9
|
+
<div class="field">
|
10
|
+
<%= f.select :id, options_for_select, prompt: t(:'.select.prompt') %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="actions">
|
14
|
+
<%= f.submit 'Add to Folder', class: 'btn btn-primary btn-sm' %>
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% in_folders = Blacklight::Folders::Folder.for_user(current_or_guest_user).with_document(@document) %>
|
2
|
+
|
3
|
+
<% unless in_folders.empty? %>
|
4
|
+
<div class="panel panel-default folders">
|
5
|
+
<div class="panel-heading">Folders</div>
|
6
|
+
<div class="panel-body">
|
7
|
+
<%= t('.contained_in') %>
|
8
|
+
<ul>
|
9
|
+
<% in_folders.each do |folder| %>
|
10
|
+
<li> <%= link_to folder.name, blacklight_folders.folder_path(folder) %> </li>
|
11
|
+
<% end %>
|
12
|
+
</ul>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%= link_to "#{t(:'blacklight_folders.main_navigation.folders')} (#{current_or_guest_user.folders.size})", blacklight_folders.folders_path, id: 'folders-nav-dropdown', class: "dropdown-toggle", data: { toggle: "dropdown"}, role: "button", 'aria-expanded' => "false" %>
|
2
|
+
|
3
|
+
<ul class="dropdown-menu" role="menu" aria-labeledby="folders-nav-dropdown">
|
4
|
+
<% if can? :create, Blacklight::Folders::Folder %>
|
5
|
+
<li><%= link_to t(:'helpers.action.blacklight/folders/folder.create'), blacklight_folders.new_folder_path %></li>
|
6
|
+
<li role="presentation" class="divider"></li>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% current_or_guest_user.folders.most_recent.limit(Blacklight::Folders::Folder::MENU_LIMIT).each do |folder| %>
|
10
|
+
<li><%= link_to truncate(folder.name, length: 20), blacklight_folders.folder_path(folder) %></li>
|
11
|
+
<% end %>
|
12
|
+
<li role="presentation" class="divider"></li>
|
13
|
+
<li><%= link_to t(:'blacklight_folders.main_navigation.all_folders'), blacklight_folders.folders_path %></li>
|
14
|
+
</ul>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= render 'show_tools' %>
|
2
|
+
<%= render 'blacklight/folders/show/folder_controls' %>
|
3
|
+
|
4
|
+
<% unless @document.more_like_this.empty? %>
|
5
|
+
<div class="panel panel-default">
|
6
|
+
<div class="panel-heading">More Like This</div>
|
7
|
+
<div class="panel-body">
|
8
|
+
<%= render collection: @document.more_like_this, partial: 'show_more_like_this', as: :document %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
data/config/jetty.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
en:
|
2
|
+
helpers:
|
3
|
+
action:
|
4
|
+
edit_long: "Edit %{model}"
|
5
|
+
blacklight/folders/folder:
|
6
|
+
delete: "Delete Folder"
|
7
|
+
create: "Create a New Folder"
|
8
|
+
edit_long: "Edit Folder"
|
9
|
+
submit:
|
10
|
+
blacklight_folders_default: &blacklight_folders_default
|
11
|
+
create: "Save"
|
12
|
+
submit: "Save changes"
|
13
|
+
update: "Save changes"
|
14
|
+
created: "The %{model} was created."
|
15
|
+
updated: "The %{model} was successfully updated."
|
16
|
+
destroyed: "The %{model} was deleted."
|
17
|
+
folder:
|
18
|
+
submit: "Create Folder"
|
19
|
+
update: "Update Folder"
|
20
|
+
created: "The folder was created."
|
21
|
+
updated: "The folder was successfully updated."
|
22
|
+
added_one: "Added document to %{folder_name}"
|
23
|
+
added_many: "Added documents to %{folder_name}"
|
24
|
+
label:
|
25
|
+
blacklight/folders/folder:
|
26
|
+
user: "Owner"
|
27
|
+
visibility: "Visibility"
|
28
|
+
created: "Created"
|
29
|
+
updated: "Updated"
|
30
|
+
activerecord:
|
31
|
+
models:
|
32
|
+
blacklight/folders/folder_item: Item
|
33
|
+
blacklight/folders/folder: Folder
|
34
|
+
attributes:
|
35
|
+
blacklight/folders/folder:
|
36
|
+
visibility:
|
37
|
+
public: "Anyone"
|
38
|
+
private: "Only me"
|
39
|
+
blacklight_folders:
|
40
|
+
main_navigation:
|
41
|
+
folders: "Folders"
|
42
|
+
all_folders: "Show All"
|
43
|
+
blacklight:
|
44
|
+
folders:
|
45
|
+
add_to_folder:
|
46
|
+
select:
|
47
|
+
prompt: "Add to folder"
|
48
|
+
show:
|
49
|
+
add_to_folder:
|
50
|
+
select:
|
51
|
+
prompt: "Select a Folder"
|
52
|
+
folder_controls:
|
53
|
+
contained_in: 'This item is contained in:'
|
54
|
+
folders:
|
55
|
+
edit:
|
56
|
+
header: "Manage Folder"
|
57
|
+
index:
|
58
|
+
table:
|
59
|
+
headers:
|
60
|
+
name: "Name"
|
61
|
+
size: "Size"
|
62
|
+
visibility: "Visibility"
|
63
|
+
created: "Created"
|
64
|
+
updated: "Updated"
|
65
|
+
actions: "Actions"
|
66
|
+
folder:
|
67
|
+
ago: "%{time} ago"
|
68
|
+
|
69
|
+
default_folder_name: "Default folder"
|
70
|
+
catalog:
|
71
|
+
search:
|
72
|
+
folder:
|
73
|
+
label: "Move checked %{doctype} to %{model}"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateBlacklightFoldersFolders < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :blacklight_folders_folders do |t|
|
4
|
+
t.string :name
|
5
|
+
t.references :user, null: false, polymorphic: true, index: true
|
6
|
+
t.string :visibility
|
7
|
+
t.integer :number_of_members, default: 0, null: false
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateBlacklightFoldersFolderItems < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
create_table :blacklight_folders_folder_items do |t|
|
5
|
+
t.references :folder, null: false, index: true
|
6
|
+
t.references :bookmark, null: false, index: true
|
7
|
+
t.integer :position
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Load blacklight so that we can override blacklight views
|
2
|
+
require 'blacklight'
|
3
|
+
require 'acts_as_list'
|
4
|
+
require 'cancan'
|
5
|
+
require 'select2-rails'
|
6
|
+
|
7
|
+
module Blacklight::Folders
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
isolate_namespace Blacklight::Folders
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module BlacklightFolders
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
desc "It will set up your rails app to use the blacklight_folders engine.\n\n"
|
6
|
+
|
7
|
+
def copy_initializer
|
8
|
+
template "blacklight_folders.rb", "config/initializers/blacklight_folders.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_routes
|
12
|
+
route 'mount Blacklight::Folders::Engine, at: "blacklight"'
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_migrations
|
16
|
+
rake "blacklight_folders:install:migrations"
|
17
|
+
rake "db:migrate"
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_model_mixins
|
21
|
+
inject_into_class 'app/models/user.rb', User, ' include Blacklight::Folders::User'
|
22
|
+
inject_into_class 'app/models/solr_document.rb', SolrDocument, ' include Blacklight::Folders::SolrDocument'
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_controller_mixins
|
26
|
+
inject_into_file 'app/controllers/application_controller.rb', :after => /Blacklight::Controller\s*\n/ do
|
27
|
+
" include Blacklight::Folders::ApplicationControllerBehavior\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_helper
|
32
|
+
copy_file "blacklight_folders_helper.rb", "app/helpers/blacklight_folders_helper.rb"
|
33
|
+
inject_into_class 'app/helpers/application_helper.rb', ApplicationHelper, " include BlacklightFoldersHelper"
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_style
|
37
|
+
inject_into_file 'app/assets/stylesheets/blacklight.css.scss', "@import 'blacklight_folders/blacklight_folders';", after: /@import 'blacklight\/blacklight';\s*\n/
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_javascript
|
41
|
+
unless IO.read("app/assets/javascripts/application.js").include?('blacklight_folders')
|
42
|
+
marker = IO.read("app/assets/javascripts/application.js").include?('blacklight/blacklight') ?
|
43
|
+
'//= require blacklight/blacklight' : "//= require jquery_ujs"
|
44
|
+
insert_into_file "app/assets/javascripts/application.js", after: marker do
|
45
|
+
%q{
|
46
|
+
//
|
47
|
+
//= require blacklight_folders}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Remove bookmark from the navbar
|
2
|
+
CatalogController.blacklight_config.navbar.partials.delete(:bookmark)
|
3
|
+
# Remove bookmark from catalog#index
|
4
|
+
CatalogController.blacklight_config.index.document_actions.delete(:bookmark)
|
5
|
+
# Remove bookmark from catalog#show
|
6
|
+
CatalogController.blacklight_config.show.document_actions.delete(:bookmark)
|
7
|
+
|
8
|
+
|
9
|
+
CatalogController.add_results_document_tool(:folder, partial: 'blacklight/folders/folder_control')
|
10
|
+
CatalogController.add_results_collection_tool(:folder, partial: 'blacklight/folders/add_to_folder')
|
11
|
+
CatalogController.add_show_tools_partial(:folder, partial: 'blacklight/folders/show/add_to_folder')
|
12
|
+
CatalogController.add_nav_action(:folder, partial: 'blacklight/nav/folders', if: Proc.new { |ctx| ctx.current_ability.can?(:index, Blacklight::Folders::Folder) } )
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class BookmarkMigrator
|
2
|
+
|
3
|
+
attr_reader :errors
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@verbose = options[:verbose]
|
7
|
+
@logging = options[:logging]
|
8
|
+
@errors = []
|
9
|
+
@default_folder_name = I18n.translate(:'blacklight.folders.default_folder_name')
|
10
|
+
end
|
11
|
+
|
12
|
+
def migrate
|
13
|
+
raise 'Default folder name is not defined' if @default_folder_name.match(/translation missing/)
|
14
|
+
@errors = []
|
15
|
+
log_message 'Begin migration of existing bookmarks.'
|
16
|
+
|
17
|
+
User.where(guest: false).find_each do |user|
|
18
|
+
folder = default_folder(user)
|
19
|
+
bookmarks_to_add = user.bookmarks - folder.bookmarks
|
20
|
+
bookmarks_to_add.map do |b|
|
21
|
+
folder.items.build(bookmark: b)
|
22
|
+
end
|
23
|
+
|
24
|
+
unless folder.save
|
25
|
+
msg = "Unable to save bookmarks to folder: #{folder.id}"
|
26
|
+
log_message "ERROR: #{msg}"
|
27
|
+
@errors << msg
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
log_message "Migration complete with #{@errors.count} errors."
|
32
|
+
@errors.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_folder(user)
|
36
|
+
folder = user.folders.where(name: @default_folder_name).first
|
37
|
+
folder ||= user.create_default_folder
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_message(message)
|
41
|
+
puts message if @verbose
|
42
|
+
Rails.logger.info "#{self.class}: #{message}" if @logging
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :blacklight_folders do
|
2
|
+
namespace :db do
|
3
|
+
|
4
|
+
desc "Convert existing bookmarks to a folder with bookmarks"
|
5
|
+
task :migrate_data => :environment do
|
6
|
+
require 'migration/bookmark_migrator'
|
7
|
+
migrator = BookmarkMigrator.new(verbose: true, logging: true)
|
8
|
+
migrator.migrate
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|