works_cited 0.1.14 → 0.1.15
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 +4 -4
- data/README.md +27 -2
- data/VERSION +1 -1
- data/app/assets/javascripts/works_cited/addFields.js +44 -0
- data/app/assets/javascripts/works_cited/application.js +6 -1
- data/app/assets/javascripts/works_cited/loadPreview.js +45 -0
- data/app/assets/javascripts/works_cited/removeFields.js +37 -0
- data/app/assets/javascripts/works_cited/shared.js +59 -0
- data/app/assets/javascripts/works_cited/showFields.js +9 -0
- data/app/assets/javascripts/works_cited/submitForm.js +33 -0
- data/app/controllers/concerns/works_cited/params.rb +24 -0
- data/app/controllers/works_cited/citations_controller.rb +26 -13
- data/app/helpers/works_cited/application_helper.rb +46 -1
- data/app/models/works_cited/citation.rb +30 -34
- data/app/models/works_cited/contributor.rb +11 -28
- data/app/views/works_cited/citation_types/fields/_book.html.haml +1 -1
- data/app/views/works_cited/citation_types/fields/_electronic.html.haml +1 -1
- data/app/views/works_cited/citation_types/fields/_email.html.haml +1 -1
- data/app/views/works_cited/citation_types/fields/_interview.html.haml +1 -1
- data/app/views/works_cited/citation_types/fields/_periodical.html.haml +1 -1
- data/app/views/works_cited/citation_types/fields/_tweet.html.haml +1 -1
- data/app/views/works_cited/citations/_citation_fields.html.haml +28 -0
- data/app/views/works_cited/citations/_fields.html.haml +14 -0
- data/app/views/works_cited/citations/_form.html.haml +16 -53
- data/app/views/works_cited/citations/preview.html.haml +1 -1
- data/app/views/works_cited/contributors/_contributor_fields.html.haml +11 -0
- data/config/routes.rb +8 -2
- data/db/migrate/20210915160902_add_index_to_works_cited_contributors.rb +5 -1
- data/lib/works_cited/mixins/has_works_cited.rb +14 -1
- data/spec/dummy/app/controllers/doodads_controller.rb +2 -1
- data/spec/dummy/app/controllers/things_controller.rb +1 -1
- data/spec/dummy/app/views/doodads/_form.html.haml +2 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20210915161011_create_works_cited_citations.works_cited.rb +1 -0
- data/spec/dummy/db/migrate/20210915161012_create_works_cited_contributors.works_cited.rb +1 -0
- data/spec/dummy/db/migrate/20210915161013_add_index_to_works_cited_contributors.works_cited.rb +4 -1
- data/spec/dummy/db/schema.rb +60 -59
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +26893 -15
- data/spec/dummy/log/test.log +24838 -0
- data/spec/factories/things.rb +8 -0
- data/spec/models/doodad_spec.rb +13 -1
- data/spec/models/thing_spec.rb +13 -1
- data/spec/models/works_cited/citation_spec.rb +12 -0
- data/spec/requests/works_cited/citations_spec.rb +10 -8
- data/spec/routing/works_cited/citations_routing_spec.rb +5 -1
- data/works_cited.gemspec +14 -4
- metadata +13 -3
- data/app/views/works_cited/contributors/_fields.html.haml +0 -9
@@ -0,0 +1,28 @@
|
|
1
|
+
:ruby
|
2
|
+
preview_path = f.object.new_record? ? works_cited.preview_citation_url : works_cited.preview_citation_url(f.object.id)
|
3
|
+
%fieldset.nested-fields{id: "citation-#{f.index}"}
|
4
|
+
%legend
|
5
|
+
%h4 Citation
|
6
|
+
= f.hidden_field :_destroy
|
7
|
+
= f.hidden_field :record, value: "#{f.object.record_type}:#{f.object.record_id}"
|
8
|
+
= f.input :citation_type, as: :select, collection: WorksCited.configuration.valid_citation_types, :input_html => {:onchange => "showFields('#{citation_id}', this.options[this.selectedIndex].value);"}
|
9
|
+
- WorksCited.configuration.valid_citation_types.each do |citation_type|
|
10
|
+
.fields{ class: "fields-#{citation_type}", style: 'display: none;' }
|
11
|
+
= works_cited_type_fields f, citation_type
|
12
|
+
%fieldset.works_cited_contributors
|
13
|
+
%legend
|
14
|
+
%h3 Contributors
|
15
|
+
%div#works_cited_contributors
|
16
|
+
= f.simple_fields_for :works_cited_contributors do |g|
|
17
|
+
= render 'works_cited/contributors/contributor_fields', f: g
|
18
|
+
= works_cited_link_to_add_fields 'Add Contributor', f, :works_cited_contributors, 'works_cited/contributors/contributor_fields'
|
19
|
+
%fieldset#preview{ style: 'display: none;' }
|
20
|
+
%legend
|
21
|
+
%h2
|
22
|
+
Preview
|
23
|
+
%small (Real-time)
|
24
|
+
.preview-html#preview-html
|
25
|
+
= link_to "Remove", '#', class: 'remove_fields button button-danger'
|
26
|
+
:javascript
|
27
|
+
showFields('#{f.index}', '#{f.object.citation_type || 'book'}')
|
28
|
+
startPreview('#{preview_path}', 'citation-#{f.index}', '#{record.class.table_name.singularize}[works_cited_citations_attributes][#{f.index}]')
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- if cannot?(:manage, WorksCited::Citation)
|
2
|
+
Not authorized for citations.
|
3
|
+
- else
|
4
|
+
= stylesheet_link_tag 'works_cited/application'
|
5
|
+
= javascript_include_tag 'works_cited/application'
|
6
|
+
%fieldset.citations
|
7
|
+
%legend
|
8
|
+
%h3 Works Cited
|
9
|
+
%div#citations
|
10
|
+
= form.simple_fields_for :works_cited_citations do |g|
|
11
|
+
= render 'works_cited/citations/citation_fields', f: g, record: form.object
|
12
|
+
= works_cited_link_to_add_fields "Add Citation", form, :works_cited_citations, 'works_cited/citations/citation_fields'
|
13
|
+
:javascript
|
14
|
+
addFilterToSubmit()
|
@@ -1,6 +1,9 @@
|
|
1
|
+
:ruby
|
2
|
+
preview_path = @citation.new_record? ? works_cited.preview_citations_url : works_cited.preview_citation_url(@citation.id)
|
3
|
+
citation_id = @citation.new_record? ? 'new' : @citation.id
|
1
4
|
= stylesheet_link_tag 'works_cited/application'
|
2
5
|
= javascript_include_tag 'works_cited/application'
|
3
|
-
= simple_form_for @citation, html: { id:
|
6
|
+
= simple_form_for @citation, html: { id: "citation-#{citation_id}"} do |f|
|
4
7
|
- if @citation.errors.any?
|
5
8
|
#error_explanation
|
6
9
|
%h2= "#{pluralize(@citation.errors.count, "error")} prohibited this citation from being saved:"
|
@@ -10,17 +13,17 @@
|
|
10
13
|
.shared-field
|
11
14
|
= f.hidden_field :id
|
12
15
|
= f.input :record, collection: @records, as: :grouped_select, group_method: :records, group_label_method: :record_type, label_method: :name, value_method: :id, selected: "#{@citation.record_type}:#{@citation.record_id}", include_blank: 'Select a Record'
|
13
|
-
= f.input :citation_type, as: :select, collection: WorksCited.configuration.valid_citation_types, :input_html => {:onchange => "showFields(this.options[this.selectedIndex].value);"}
|
16
|
+
= f.input :citation_type, as: :select, collection: WorksCited.configuration.valid_citation_types, :input_html => {:onchange => "showFields('#{citation_id}', this.options[this.selectedIndex].value);"}
|
14
17
|
- WorksCited.configuration.valid_citation_types.each do |citation_type|
|
15
|
-
.fields{
|
16
|
-
=
|
17
|
-
%fieldset
|
18
|
+
.fields{ class: "fields-#{citation_type}", style: 'display: none;' }
|
19
|
+
= works_cited_type_fields f, citation_type
|
20
|
+
%fieldset.works_cited_contributors
|
18
21
|
%legend
|
19
|
-
%
|
20
|
-
|
21
|
-
=
|
22
|
-
|
23
|
-
|
22
|
+
%h3 Contributors
|
23
|
+
%div#works_cited_contributors
|
24
|
+
= f.simple_fields_for :works_cited_contributors do |g|
|
25
|
+
= render 'works_cited/contributors/contributor_fields', f: g
|
26
|
+
= works_cited_link_to_add_fields 'Add Contributor', f, :works_cited_contributors, 'works_cited/contributors/contributor_fields'
|
24
27
|
%fieldset#preview{ style: 'display: none;' }
|
25
28
|
%legend
|
26
29
|
%h2
|
@@ -30,46 +33,6 @@
|
|
30
33
|
.actions
|
31
34
|
.button-wrapper= f.submit 'Save', class: 'button-large button-action'
|
32
35
|
:javascript
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
for (index = 0; index < fields.length; ++index) {
|
37
|
-
var textField = fields[index];
|
38
|
-
textField.addEventListener('change', loadPreview)
|
39
|
-
}
|
40
|
-
|
41
|
-
function loadPreview() {
|
42
|
-
// Build formData object.
|
43
|
-
var formData = new FormData(document.querySelector('form'))
|
44
|
-
var authenticity_token = document.head.querySelector('meta[name="csrf-token"]').content
|
45
|
-
var preview = document.getElementById('preview')
|
46
|
-
var container = document.getElementById('preview-html')
|
47
|
-
|
48
|
-
fetch('#{preview_citation_url}',
|
49
|
-
{
|
50
|
-
method: 'post',
|
51
|
-
headers: {
|
52
|
-
'X-Requested-With': 'XMLHttpRequest',
|
53
|
-
'X-CSRF-Token': authenticity_token
|
54
|
-
},
|
55
|
-
body: formData,
|
56
|
-
credentials: 'same-origin'
|
57
|
-
})
|
58
|
-
.then(function(response) {
|
59
|
-
// When the page is loaded convert it to text
|
60
|
-
return response.text()
|
61
|
-
})
|
62
|
-
.then((html) => {
|
63
|
-
preview.style.display = 'block'
|
64
|
-
container.innerHTML = html
|
65
|
-
})
|
66
|
-
}
|
67
|
-
function showFields(citation_type) {
|
68
|
-
for (let element of document.getElementsByClassName('fields')){
|
69
|
-
element.style.display='none'
|
70
|
-
}
|
71
|
-
document.getElementById(`fields-${citation_type}`).style.display = 'block'
|
72
|
-
}
|
73
|
-
|
74
|
-
showFields('#{@citation.citation_type || 'book'}')
|
75
|
-
loadPreview()
|
36
|
+
showFields('#{citation_id}', '#{@citation.citation_type || 'book'}')
|
37
|
+
startPreview('#{preview_path}', 'citation-#{citation_id}', 'citation')
|
38
|
+
addFilterToSubmit()
|
@@ -1 +1 @@
|
|
1
|
-
= works_cited_preview
|
1
|
+
= works_cited_preview citation, contributors
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%fieldset.nested-fields
|
2
|
+
%legend
|
3
|
+
%h4 Contributor
|
4
|
+
= f.hidden_field :_destroy
|
5
|
+
= f.input :contributor_role, collection: WorksCited.configuration.valid_contributor_roles.map { |x| [x, x] }
|
6
|
+
= f.input :first
|
7
|
+
= f.input :middle, hint: 'Only the initial is used'
|
8
|
+
= f.input :last
|
9
|
+
= f.input :suffix
|
10
|
+
= f.input :handle
|
11
|
+
= link_to "Remove", '#', class: 'remove_fields button button-danger'
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
WorksCited::Engine.routes.draw do
|
4
|
-
|
5
|
-
|
4
|
+
resources :citations do
|
5
|
+
member do
|
6
|
+
post 'preview', defaults: { format: :json }
|
7
|
+
end
|
8
|
+
collection do
|
9
|
+
post 'preview', defaults: { format: :json }
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Contributors need to be indexed on their name
|
1
4
|
class AddIndexToWorksCitedContributors < ActiveRecord::Migration[6.1]
|
2
5
|
def change
|
3
|
-
add_index :works_cited_contributors, [
|
6
|
+
add_index :works_cited_contributors, %i[last first middle suffix handle], name: :index_citation_name,
|
7
|
+
length: 100
|
4
8
|
end
|
5
9
|
end
|
@@ -12,7 +12,7 @@ module WorksCited
|
|
12
12
|
include InstanceMethods
|
13
13
|
|
14
14
|
has_many :works_cited_citations, as: :record, class_name: 'WorksCited::Citation'
|
15
|
-
accepts_nested_attributes_for :works_cited_citations, allow_destroy: true
|
15
|
+
accepts_nested_attributes_for :works_cited_citations, reject_if: :all_blank, allow_destroy: true
|
16
16
|
end
|
17
17
|
# rubocop:enable Naming/PredicateName
|
18
18
|
|
@@ -22,6 +22,19 @@ module WorksCited
|
|
22
22
|
|
23
23
|
# Included by has_works_cited mixin
|
24
24
|
module InstanceMethods
|
25
|
+
def works_cited_citations_attributes=(raw_citations)
|
26
|
+
array = []
|
27
|
+
raw_citations&.each do |_index, citation|
|
28
|
+
destroy = citation.delete(:_destroy)
|
29
|
+
if destroy == '1'
|
30
|
+
Citation.find(citation[:id]).destroy if citation[:id]
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
34
|
+
array << citation
|
35
|
+
end
|
36
|
+
super array
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# :nocov:
|
4
4
|
# Super basic controller for Doodads
|
5
5
|
class DoodadsController < ApplicationController
|
6
|
+
include WorksCited::Params
|
6
7
|
before_action :set_doodad, only: %i[show edit update destroy]
|
7
8
|
|
8
9
|
# GET /doodads
|
@@ -56,7 +57,7 @@ class DoodadsController < ApplicationController
|
|
56
57
|
|
57
58
|
# Only allow a list of trusted parameters through.
|
58
59
|
def doodad_params
|
59
|
-
params.require(:doodad).permit(:name, :description)
|
60
|
+
params.require(:doodad).permit(:name, :description, works_cited_params)
|
60
61
|
end
|
61
62
|
end
|
62
63
|
# :nocov:
|
@@ -56,7 +56,7 @@ class ThingsController < ApplicationController
|
|
56
56
|
|
57
57
|
# Only allow a list of trusted parameters through.
|
58
58
|
def thing_params
|
59
|
-
params.require(:thing).permit(:name, :description)
|
59
|
+
params.require(:thing).permit(:name, :description, works_cited_params)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
# :nocov:
|
Binary file
|
data/spec/dummy/db/migrate/20210915161013_add_index_to_works_cited_contributors.works_cited.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This migration comes from works_cited (originally 20210915160902)
|
2
4
|
class AddIndexToWorksCitedContributors < ActiveRecord::Migration[6.1]
|
3
5
|
def change
|
4
|
-
add_index :works_cited_contributors, [
|
6
|
+
add_index :works_cited_contributors, %i[last first middle suffix handle], name: :index_citation_name,
|
7
|
+
length: 100
|
5
8
|
end
|
6
9
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is auto-generated from the current state of the database. Instead
|
2
4
|
# of editing this file, please use the migrations feature of Active Record to
|
3
5
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -10,73 +12,72 @@
|
|
10
12
|
#
|
11
13
|
# It's strongly recommended that you check this file into your version control system.
|
12
14
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
14
|
-
|
15
|
-
|
16
|
-
t.
|
17
|
-
t.
|
18
|
-
t.datetime
|
19
|
-
t.datetime "updated_at", precision: 6, null: false
|
15
|
+
ActiveRecord::Schema.define(version: 20_210_915_161_013) do
|
16
|
+
create_table 'doodads', force: :cascade do |t|
|
17
|
+
t.string 'name'
|
18
|
+
t.text 'description'
|
19
|
+
t.datetime 'created_at', precision: 6, null: false
|
20
|
+
t.datetime 'updated_at', precision: 6, null: false
|
20
21
|
end
|
21
22
|
|
22
|
-
create_table
|
23
|
-
t.string
|
24
|
-
t.text
|
25
|
-
t.datetime
|
26
|
-
t.datetime
|
23
|
+
create_table 'things', force: :cascade do |t|
|
24
|
+
t.string 'name'
|
25
|
+
t.text 'description'
|
26
|
+
t.datetime 'created_at', precision: 6, null: false
|
27
|
+
t.datetime 'updated_at', precision: 6, null: false
|
27
28
|
end
|
28
29
|
|
29
|
-
create_table
|
30
|
-
t.boolean
|
31
|
-
t.string
|
32
|
-
t.string
|
33
|
-
t.string
|
34
|
-
t.datetime
|
35
|
-
t.datetime
|
36
|
-
t.datetime
|
37
|
-
t.datetime
|
38
|
-
t.index [
|
39
|
-
t.index [
|
30
|
+
create_table 'users', force: :cascade do |t|
|
31
|
+
t.boolean 'admin', default: false
|
32
|
+
t.string 'email', default: '', null: false
|
33
|
+
t.string 'encrypted_password', default: '', null: false
|
34
|
+
t.string 'reset_password_token'
|
35
|
+
t.datetime 'reset_password_sent_at'
|
36
|
+
t.datetime 'remember_created_at'
|
37
|
+
t.datetime 'created_at', precision: 6, null: false
|
38
|
+
t.datetime 'updated_at', precision: 6, null: false
|
39
|
+
t.index ['email'], name: 'index_users_on_email', unique: true
|
40
|
+
t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
|
40
41
|
end
|
41
42
|
|
42
|
-
create_table
|
43
|
-
t.string
|
44
|
-
t.string
|
45
|
-
t.string
|
46
|
-
t.string
|
47
|
-
t.string
|
48
|
-
t.string
|
49
|
-
t.string
|
50
|
-
t.string
|
51
|
-
t.string
|
52
|
-
t.string
|
53
|
-
t.string
|
54
|
-
t.string
|
55
|
-
t.string
|
56
|
-
t.string
|
57
|
-
t.string
|
58
|
-
t.datetime
|
59
|
-
t.datetime
|
60
|
-
t.string
|
61
|
-
t.integer
|
62
|
-
t.datetime
|
63
|
-
t.datetime
|
64
|
-
t.index [
|
43
|
+
create_table 'works_cited_citations', force: :cascade do |t|
|
44
|
+
t.string 'citation_type'
|
45
|
+
t.string 'media'
|
46
|
+
t.string 'title'
|
47
|
+
t.string 'container_title'
|
48
|
+
t.string 'publisher'
|
49
|
+
t.string 'city'
|
50
|
+
t.string 'edition'
|
51
|
+
t.string 'volume'
|
52
|
+
t.string 'number'
|
53
|
+
t.string 'series'
|
54
|
+
t.string 'year'
|
55
|
+
t.string 'pages'
|
56
|
+
t.string 'url'
|
57
|
+
t.string 'online_database'
|
58
|
+
t.string 'doi'
|
59
|
+
t.datetime 'published_at'
|
60
|
+
t.datetime 'accessed_at'
|
61
|
+
t.string 'record_type', null: false
|
62
|
+
t.integer 'record_id', null: false
|
63
|
+
t.datetime 'created_at', precision: 6, null: false
|
64
|
+
t.datetime 'updated_at', precision: 6, null: false
|
65
|
+
t.index %w[record_type record_id], name: 'index_works_cited_citations_on_record'
|
65
66
|
end
|
66
67
|
|
67
|
-
create_table
|
68
|
-
t.integer
|
69
|
-
t.string
|
70
|
-
t.string
|
71
|
-
t.string
|
72
|
-
t.string
|
73
|
-
t.string
|
74
|
-
t.string
|
75
|
-
t.datetime
|
76
|
-
t.datetime
|
77
|
-
t.index [
|
78
|
-
t.index [
|
68
|
+
create_table 'works_cited_contributors', force: :cascade do |t|
|
69
|
+
t.integer 'works_cited_citation_id', null: false
|
70
|
+
t.string 'contributor_role'
|
71
|
+
t.string 'first'
|
72
|
+
t.string 'middle'
|
73
|
+
t.string 'last'
|
74
|
+
t.string 'suffix'
|
75
|
+
t.string 'handle'
|
76
|
+
t.datetime 'created_at', precision: 6, null: false
|
77
|
+
t.datetime 'updated_at', precision: 6, null: false
|
78
|
+
t.index %w[last first middle suffix handle], name: 'index_citation_name'
|
79
|
+
t.index ['works_cited_citation_id'], name: 'index_works_cited_contributors_on_works_cited_citation_id'
|
79
80
|
end
|
80
81
|
|
81
|
-
add_foreign_key
|
82
|
+
add_foreign_key 'works_cited_contributors', 'works_cited_citations'
|
82
83
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|