spina-admin-journal 0.5.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/spina_admin_journal_manifest.js +5 -2
- data/app/assets/javascripts/spina/admin/journal/application.js +0 -0
- data/app/components/spina/admin/journal/affiliations_list_component.rb +32 -0
- data/app/components/spina/admin/journal/application_component.rb +11 -0
- data/app/components/spina/admin/journal/articles_list_component.rb +54 -0
- data/app/components/spina/admin/journal/authors_list_component.rb +37 -0
- data/app/components/spina/admin/journal/authorships_list_component.rb +45 -0
- data/app/components/spina/admin/journal/empty_list_component.html.haml +1 -0
- data/app/components/spina/admin/journal/empty_list_component.rb +14 -0
- data/app/components/spina/admin/journal/institutions_list_component.rb +32 -0
- data/app/components/spina/admin/journal/issues_list_component.rb +47 -0
- data/app/components/spina/admin/journal/licences_list_component.rb +32 -0
- data/app/components/spina/admin/journal/list_component.html.haml +10 -0
- data/app/components/spina/admin/journal/list_component.rb +22 -0
- data/app/components/spina/admin/journal/list_item_component.html.haml +17 -0
- data/app/components/spina/admin/journal/list_item_component.rb +23 -0
- data/app/components/spina/admin/journal/volumes_list_component.rb +34 -0
- data/app/controllers/spina/admin/journal/application_controller.rb +3 -1
- data/app/controllers/spina/admin/journal/articles_controller.rb +14 -25
- data/app/controllers/spina/admin/journal/authors_controller.rb +15 -28
- data/app/controllers/spina/admin/journal/institutions_controller.rb +7 -5
- data/app/controllers/spina/admin/journal/issues_controller.rb +17 -24
- data/app/controllers/spina/admin/journal/journals_controller.rb +4 -3
- data/app/controllers/spina/admin/journal/licences_controller.rb +7 -5
- data/app/controllers/spina/admin/journal/volumes_controller.rb +9 -20
- data/app/models/spina/parts/admin/journal/page_range.rb +31 -0
- data/app/views/spina/admin/hooks/journal/_primary_navigation.html.haml +35 -26
- data/app/views/spina/admin/journal/articles/_form.html.haml +23 -24
- data/app/views/spina/admin/journal/articles/_form_authors.html.haml +1 -15
- data/app/views/spina/admin/journal/articles/_form_details.html.haml +27 -56
- data/app/views/spina/admin/journal/articles/index.html.haml +7 -17
- data/app/views/spina/admin/journal/authors/_form.html.haml +24 -24
- data/app/views/spina/admin/journal/authors/_form_affiliation.html.haml +8 -20
- data/app/views/spina/admin/journal/authors/_form_articles.html.haml +1 -18
- data/app/views/spina/admin/journal/authors/_form_details.html.haml +2 -6
- data/app/views/spina/admin/journal/authors/index.html.haml +7 -15
- data/app/views/spina/admin/journal/institutions/_form.html.haml +24 -24
- data/app/views/spina/admin/journal/institutions/_form_details.html.haml +2 -8
- data/app/views/spina/admin/journal/institutions/_form_view_affiliations.html.haml +1 -10
- data/app/views/spina/admin/journal/institutions/index.html.haml +7 -15
- data/app/views/spina/admin/journal/issues/_form.html.haml +23 -23
- data/app/views/spina/admin/journal/issues/_form_articles.html.haml +1 -14
- data/app/views/spina/admin/journal/issues/_form_details.html.haml +13 -28
- data/app/views/spina/admin/journal/issues/index.html.haml +7 -16
- data/app/views/spina/admin/journal/journals/_form.html.haml +22 -32
- data/app/views/spina/admin/journal/licences/_form.html.haml +19 -34
- data/app/views/spina/admin/journal/licences/index.html.haml +7 -16
- data/app/views/spina/admin/journal/volumes/_form.html.haml +25 -12
- data/app/views/spina/admin/journal/volumes/_form_details.html.haml +4 -10
- data/app/views/spina/admin/journal/volumes/_form_issues.html.haml +1 -13
- data/app/views/spina/admin/journal/volumes/index.html.haml +7 -16
- data/app/views/spina/admin/parts/admin/journal/page_ranges/_form.html.haml +6 -0
- data/config/locales/en.yml +25 -3
- data/config/routes.rb +5 -5
- data/db/migrate/20210626153728_create_spina_parts_admin_journal_page_ranges.rb +7 -0
- data/lib/spina/admin/journal/engine.rb +18 -0
- data/lib/spina/admin/journal/version.rb +1 -1
- data/lib/spina/admin/journal.rb +1 -0
- metadata +50 -65
- data/app/assets/javascripts/spina/admin/journal/application.es6 +0 -72
- data/app/views/layouts/spina/admin/journal/articles.html.haml +0 -10
- data/app/views/layouts/spina/admin/journal/authors.html.haml +0 -10
- data/app/views/layouts/spina/admin/journal/institutions.html.haml +0 -10
- data/app/views/layouts/spina/admin/journal/issues.html.haml +0 -10
- data/app/views/layouts/spina/admin/journal/journals.html.haml +0 -10
- data/app/views/layouts/spina/admin/journal/licences.html.haml +0 -10
- data/app/views/layouts/spina/admin/journal/volumes.html.haml +0 -10
- data/app/views/spina/admin/journal/affiliations/_affiliation.html.haml +0 -8
- data/app/views/spina/admin/journal/application/_empty_list.html.haml +0 -3
- data/app/views/spina/admin/journal/articles/_article.html.haml +0 -10
- data/app/views/spina/admin/journal/authors/_author.html.haml +0 -8
- data/app/views/spina/admin/journal/authorships/_authorship.html.haml +0 -9
- data/app/views/spina/admin/journal/institutions/_institution.html.haml +0 -9
- data/app/views/spina/admin/journal/issues/_issue.html.haml +0 -9
- data/app/views/spina/admin/journal/journals/index.html.haml +0 -27
- data/app/views/spina/admin/journal/licences/_licence.html.haml +0 -11
- data/app/views/spina/admin/journal/volumes/_volume.html.haml +0 -7
- data/vendor/assets/javascripts/spina/admin/journal/html5sortable.js +0 -1295
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e696fd8633a8dc7ab2b57166808c7e989792307f0d3481a0eb5e73b0d05d175
|
4
|
+
data.tar.gz: bb15a7e5c115a2302e95f3224d85840dcfc6f46d8ec88b1c18bd67b4d0ba02b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e1f1e24116d3955595ef1fc705f4e93a25028daeaac15b42a147d4cadeec0b2bb5c6176d4d9c98dbb104f66dd325a006a156eea6d8afab270cb096cb386772f
|
7
|
+
data.tar.gz: d6541162de0b4e925c3c6dda25ac08d4e5292c6f3b2c8ac4306f933000aee56dfbc8cbcd2ee0704a0499a5a512e1179d429b47cbe8a17ea205a47324eaf2c382
|
@@ -1,3 +1,6 @@
|
|
1
|
-
//= link spina/admin/journal/application.js
|
2
1
|
//= link spina/admin/journal/application.css
|
3
|
-
|
2
|
+
|
3
|
+
//= link_directory ../javascripts/spina/admin/journal/controllers
|
4
|
+
//= link_directory ../javascripts/spina/admin/journal/libraries
|
5
|
+
|
6
|
+
//= link spina/admin/journal/application.js
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of licences. Not sortable.
|
7
|
+
class AffiliationsListComponent < ListComponent
|
8
|
+
def initialize(affiliations:)
|
9
|
+
@affiliations = affiliations
|
10
|
+
end
|
11
|
+
|
12
|
+
def before_render
|
13
|
+
@list_items = generate_list_items(@affiliations)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
render ListComponent.new(list_items: @list_items, sortable: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_list_items(affiliations)
|
23
|
+
affiliations.map do |affiliation|
|
24
|
+
{ id: affiliation.id,
|
25
|
+
label: affiliation.reversed_name,
|
26
|
+
path: helpers.spina.edit_admin_journal_author_path(affiliation.author) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of articles. Articles should only be sortable if presented within the contex of an
|
7
|
+
# issue.
|
8
|
+
class ArticlesListComponent < ListComponent
|
9
|
+
attr_reader :sortable
|
10
|
+
|
11
|
+
def initialize(articles:, sortable: false)
|
12
|
+
@articles = articles
|
13
|
+
@sortable = sortable
|
14
|
+
end
|
15
|
+
|
16
|
+
def before_render
|
17
|
+
@list_items = generate_list_items(@articles)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
render ListComponent.new(list_items: @list_items,
|
22
|
+
sortable: sortable?,
|
23
|
+
sort_path: generate_sort_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sortable?
|
27
|
+
sortable
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_list_items(articles)
|
33
|
+
articles.map do |article|
|
34
|
+
{ id: article.id,
|
35
|
+
label: generate_label(article),
|
36
|
+
path: helpers.spina.edit_admin_journal_article_path(article.id) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_label(article) # rubocop:disable Metrics/AbcSize
|
41
|
+
t('spina.admin.journal.articles.article_number', volume_number: article.issue.volume.number, # rubocop:disable Style/StringConcatenation
|
42
|
+
issue_number: article.issue.number,
|
43
|
+
article_number: article.number
|
44
|
+
) + ' | ' + t('spina.admin.journal.articles.title_author', title: article.title, # rubocop:disable Layout/MultilineMethodCallBraceLayout Layout/SpaceInsideParens
|
45
|
+
author: article.authorships.sorted_within_article.map { |authorship| authorship.affiliation.surname }.join(', ')) # rubocop:disable Layout/LineLength
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_sort_path
|
49
|
+
@articles.any? ? helpers.spina.sort_admin_journal_issues_path(@articles.first.issue.id) : ''
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of authors. Not sortable.
|
7
|
+
class AuthorsListComponent < ListComponent
|
8
|
+
def initialize(authors:)
|
9
|
+
@authors = authors
|
10
|
+
end
|
11
|
+
|
12
|
+
def before_render
|
13
|
+
@list_items = generate_list_items(@authors)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
render ListComponent.new(list_items: @list_items, sortable: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_list_items(authors)
|
23
|
+
authors.map do |author|
|
24
|
+
{ id: author.id,
|
25
|
+
label: generate_label(author),
|
26
|
+
path: helpers.spina.edit_admin_journal_author_path(author) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_label(author)
|
31
|
+
t 'spina.admin.journal.authors.name_institution', name: author.primary_affiliation.name,
|
32
|
+
institution: author.primary_affiliation.institution.name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of authorships. Sortable when displayed in their corresponding article.
|
7
|
+
class AuthorshipsListComponent < ListComponent
|
8
|
+
attr_reader :sortable
|
9
|
+
|
10
|
+
def initialize(authorships:, sortable: false)
|
11
|
+
@authorships = authorships
|
12
|
+
@sortable = sortable
|
13
|
+
end
|
14
|
+
|
15
|
+
def before_render
|
16
|
+
@list_items = generate_list_items(@authorships)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
render ListComponent.new(list_items: @list_items,
|
21
|
+
sortable: sortable?,
|
22
|
+
sort_path: generate_sort_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def sortable?
|
26
|
+
sortable
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generate_list_items(authorships)
|
32
|
+
authorships.map do |authorship|
|
33
|
+
{ id: authorship.id,
|
34
|
+
label: authorship.affiliation.reversed_name,
|
35
|
+
path: helpers.spina.edit_admin_journal_author_path(authorship.affiliation.author) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_sort_path
|
40
|
+
@authorships.any? ? helpers.spina.sort_admin_journal_authors_path(@authorships.first.article.id) : ''
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
= @message
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# Displays a message indicating that a {ListComponent} has no items.
|
7
|
+
class EmptyListComponent < ApplicationComponent
|
8
|
+
def initialize(message: t('spina.admin.journal.empty_list'))
|
9
|
+
@message = message
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of institutions. Not sortable.
|
7
|
+
class InstitutionsListComponent < ListComponent
|
8
|
+
def initialize(institutions:)
|
9
|
+
@institutions = institutions
|
10
|
+
end
|
11
|
+
|
12
|
+
def before_render
|
13
|
+
@list_items = generate_list_items(@institutions)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
render ListComponent.new(list_items: @list_items, sortable: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_list_items(institutions)
|
23
|
+
institutions.map do |institution|
|
24
|
+
{ id: institution.id,
|
25
|
+
label: institution.name,
|
26
|
+
path: helpers.spina.edit_admin_journal_institution_path(institution.id) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of issues. Issues should only be sortable if presented within the contex of a
|
7
|
+
# volume.
|
8
|
+
class IssuesListComponent < ListComponent
|
9
|
+
attr_reader :sortable
|
10
|
+
|
11
|
+
def initialize(issues:, sortable: false)
|
12
|
+
@issues = issues
|
13
|
+
@sortable = sortable
|
14
|
+
end
|
15
|
+
|
16
|
+
def before_render
|
17
|
+
@list_items = generate_list_items(@issues)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
render ListComponent.new(list_items: @list_items,
|
22
|
+
sortable: sortable?,
|
23
|
+
sort_path: generate_sort_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sortable?
|
27
|
+
sortable
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_list_items(issues)
|
33
|
+
issues.map do |issue|
|
34
|
+
{ id: issue.id,
|
35
|
+
label: t('spina.admin.journal.issues.volume_issue', volume_number: issue.volume.number,
|
36
|
+
issue_number: issue.number),
|
37
|
+
path: helpers.spina.edit_admin_journal_issue_path(issue.id) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_sort_path
|
42
|
+
@issues.any? ? helpers.spina.sort_admin_journal_issues_path(@issues.first.volume.id) : ''
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A list of licences. Not sortable.
|
7
|
+
class LicencesListComponent < ListComponent
|
8
|
+
def initialize(licences:)
|
9
|
+
@licences = licences
|
10
|
+
end
|
11
|
+
|
12
|
+
def before_render
|
13
|
+
@list_items = generate_list_items(@licences)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
render ListComponent.new(list_items: @list_items, sortable: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_list_items(licences)
|
23
|
+
licences.map do |licence|
|
24
|
+
{ id: licence.id,
|
25
|
+
label: licence.name,
|
26
|
+
path: helpers.spina.edit_admin_journal_licence_path(licence) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- if sortable?
|
2
|
+
.ml-8.mt-8.text-gray-600.text-sm= t 'spina.admin.journal.sort_info'
|
3
|
+
.my-6.md:m-8.bg-white.md:rounded-lg.border-l-0.border-r-0.border.md:border-r.md:border-l.border-gray-200.border-b-0.shadow-sm{ data: { controller: 'sortable' } }
|
4
|
+
= form_with(url: @sort_path, data: { sortable_target: 'form' }) { |f| }
|
5
|
+
%ul{ data: { sortable_target: 'list' } }
|
6
|
+
- if @list_items.any?
|
7
|
+
- @list_items.each do |item|
|
8
|
+
= render Spina::Admin::Journal::ListItemComponent.new(id: item[:id], label: item[:label], path: item[:path], sortable: sortable?)
|
9
|
+
- else
|
10
|
+
= render Spina::Admin::Journal::EmptyListComponent.new
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A generic implementation of a list, resembling Spina's page list.
|
7
|
+
class ListComponent < ApplicationComponent
|
8
|
+
attr_reader :sortable
|
9
|
+
|
10
|
+
def initialize(list_items:, sortable: false, sort_path: '')
|
11
|
+
@sortable = sortable
|
12
|
+
@list_items = list_items
|
13
|
+
@sort_path = sort_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def sortable?
|
17
|
+
sortable
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
%li{data: { id: @id }}
|
2
|
+
.flex.items-center.border-gray-200.border-b.bg-opacity-50.w-full
|
3
|
+
- if sortable?
|
4
|
+
.p-4.text-gray-300.hover:text-gray-600.cursor-move{ data: { 'sortable-handle': true } }
|
5
|
+
= helpers.heroicon('menu-alt-4', style: :solid, class: 'w-4 h-4 -mr-4')
|
6
|
+
|
7
|
+
.flex-auto
|
8
|
+
.block.text-spina.font-medium.text-sm.p-4{class: 'hover:text-spina-dark' }
|
9
|
+
= link_to @path do
|
10
|
+
= @label
|
11
|
+
|
12
|
+
.flex-1
|
13
|
+
|
14
|
+
= link_to @path, class: 'btn btn-link mr-4' do
|
15
|
+
.flex.flex-nowrap.items-center.px-8.py-1
|
16
|
+
= helpers.heroicon 'pencil-alt', style: :outline, class: 'w-4 h-4'
|
17
|
+
.ml-2= t 'spina.admin.journal.edit'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A generic list item that is only intended to be called by {ListItemComponent}.
|
7
|
+
class ListItemComponent < ApplicationComponent
|
8
|
+
attr_reader :sortable
|
9
|
+
|
10
|
+
def initialize(id:, label:, path:, sortable: false)
|
11
|
+
@label = label
|
12
|
+
@id = id
|
13
|
+
@path = path
|
14
|
+
@sortable = sortable
|
15
|
+
end
|
16
|
+
|
17
|
+
def sortable?
|
18
|
+
sortable
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spina
|
4
|
+
module Admin
|
5
|
+
module Journal
|
6
|
+
# A sortable list of volumes.
|
7
|
+
class VolumesListComponent < ListComponent
|
8
|
+
def initialize(volumes:)
|
9
|
+
@volumes = volumes
|
10
|
+
end
|
11
|
+
|
12
|
+
def before_render
|
13
|
+
@list_items = generate_list_items(@volumes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
render ListComponent.new(list_items: @list_items,
|
18
|
+
sortable: true,
|
19
|
+
sort_path: helpers.spina.sort_admin_journal_volumes_path(Journal.instance.id))
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def generate_list_items(volumes)
|
25
|
+
volumes.map do |volume|
|
26
|
+
{ id: volume.id,
|
27
|
+
label: t('spina.admin.journal.volumes.volume_number', number: volume.number),
|
28
|
+
path: helpers.spina.edit_admin_journal_volume_path(volume.id) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -5,9 +5,11 @@ module Spina
|
|
5
5
|
module Journal
|
6
6
|
# Custom controller for journal plugin. Sets the layout and adds a flash type.
|
7
7
|
class ApplicationController < AdminController
|
8
|
+
helper ::Spina::Engine.routes.url_helpers
|
9
|
+
|
8
10
|
add_flash_types :success
|
9
11
|
|
10
|
-
layout :admin_layout
|
12
|
+
layout :admin_layout
|
11
13
|
|
12
14
|
before_action :set_locale
|
13
15
|
|
@@ -7,6 +7,7 @@ module Spina
|
|
7
7
|
class ArticlesController < ApplicationController
|
8
8
|
PARTS_PARAMS = [
|
9
9
|
:name, :title, :type, :content, :filename, :signed_blob_id, :alt, :attachment_id, :image_id,
|
10
|
+
:first_page, :last_page,
|
10
11
|
{ images_attributes: %i[filename signed_blob_id image_id alt],
|
11
12
|
content_attributes: [
|
12
13
|
:name, :title,
|
@@ -20,7 +21,7 @@ module Spina
|
|
20
21
|
params.merge("#{locale}_content_attributes": [*PARTS_PARAMS])
|
21
22
|
end
|
22
23
|
PARAMS = [:issue_id, :licence_id, :title, :url, :doi, :status, { affiliation_ids: [], **CONTENT_PARAMS }].freeze
|
23
|
-
PARTS = %w[abstract attachment].freeze
|
24
|
+
PARTS = %w[abstract attachment page_range].freeze
|
24
25
|
|
25
26
|
before_action :set_breadcrumb
|
26
27
|
before_action :set_tabs, except: %i[index destroy sort]
|
@@ -40,23 +41,25 @@ module Spina
|
|
40
41
|
|
41
42
|
def edit; end
|
42
43
|
|
43
|
-
def create
|
44
|
+
def create # rubocop:disable Metrics/AbcSize
|
44
45
|
@article = Article.new(article_params)
|
45
46
|
sister_articles = Article.where(issue: @article.issue_id)
|
46
47
|
@article.number = sister_articles.any? ? sister_articles.sorted_desc.first.number + 1 : 1
|
47
48
|
|
48
49
|
if @article.save
|
49
|
-
redirect_to
|
50
|
+
redirect_to edit_admin_journal_article_path(@article), success: t('.saved')
|
50
51
|
else
|
51
|
-
|
52
|
+
flash.now[:alert] = t('.failed')
|
53
|
+
render :new, status: :unprocessable_entity
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
57
|
def update
|
56
58
|
if @article.update(article_params)
|
57
|
-
redirect_to
|
59
|
+
redirect_to edit_admin_journal_article_path(@article), success: t('.saved')
|
58
60
|
else
|
59
|
-
|
61
|
+
flash.now[:alert] = t('.failed')
|
62
|
+
render :edit, status: :unprocessable_entity
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
@@ -70,31 +73,17 @@ module Spina
|
|
70
73
|
end
|
71
74
|
|
72
75
|
def sort
|
73
|
-
|
74
|
-
|
75
|
-
Article.find(id.to_i).update_attribute(:number, new_pos.to_i) # rubocop:disable Rails/SkipsModelValidations
|
76
|
-
end
|
77
|
-
validate_sort_order
|
76
|
+
params[:ids].each.with_index do |id, index|
|
77
|
+
Article.where(id: id).update_all(number: index + 1) # rubocop:disable Rails/SkipsModelValidations
|
78
78
|
end
|
79
|
-
|
80
|
-
|
81
|
-
render json: { success: false, message: t('.sort_error') }
|
79
|
+
flash.now[:info] = t('spina.pages.sorting_saved')
|
80
|
+
render_flash
|
82
81
|
end
|
83
82
|
|
84
83
|
private
|
85
84
|
|
86
85
|
def article_params
|
87
|
-
params.require(:
|
88
|
-
end
|
89
|
-
|
90
|
-
def sort_params
|
91
|
-
params.require(:admin_journal_articles).require(:list).permit!
|
92
|
-
end
|
93
|
-
|
94
|
-
def validate_sort_order
|
95
|
-
Article.where(issue_id: params[:issue_id]).each do |article|
|
96
|
-
raise ActiveRecord::RecordInvalid if article.invalid?
|
97
|
-
end
|
86
|
+
params.require(:article).permit(PARAMS)
|
98
87
|
end
|
99
88
|
|
100
89
|
def set_breadcrumb
|
@@ -16,6 +16,7 @@ module Spina
|
|
16
16
|
def new
|
17
17
|
@author = Author.new
|
18
18
|
@author.affiliations << Affiliation.new(status: :primary)
|
19
|
+
add_breadcrumb t('.new')
|
19
20
|
end
|
20
21
|
|
21
22
|
def edit; end
|
@@ -23,17 +24,19 @@ module Spina
|
|
23
24
|
def create
|
24
25
|
@author = Author.new(modified_params)
|
25
26
|
if @author.save
|
26
|
-
redirect_to
|
27
|
+
redirect_to edit_admin_journal_author_path(@author), success: t('.saved')
|
27
28
|
else
|
28
|
-
|
29
|
+
flash.now[:alert] = t('.failed')
|
30
|
+
render :new, status: :unprocessable_entity
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
def update
|
33
35
|
if @author.update(modified_params)
|
34
|
-
redirect_to
|
36
|
+
redirect_to edit_admin_journal_author_path(@author), success: t('.saved')
|
35
37
|
else
|
36
|
-
|
38
|
+
flash.now[:alert] = t('.failed')
|
39
|
+
render :edit, status: :unprocessable_entity
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -47,29 +50,23 @@ module Spina
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def sort
|
50
|
-
|
51
|
-
|
52
|
-
# ignore uniqueness validation for now
|
53
|
-
Authorship.find(id.to_i).update_attribute(:position, new_pos.to_i) # rubocop:disable Rails/SkipsModelValidations
|
54
|
-
end
|
55
|
-
# do validations after reordering is complete
|
56
|
-
validate_sort_order
|
53
|
+
params[:ids].each.with_index do |id, index|
|
54
|
+
Authorship.where(id: id).update_all(position: index + 1) # rubocop:disable Rails/SkipsModelValidations
|
57
55
|
end
|
58
|
-
|
59
|
-
|
60
|
-
render json: { success: false, message: t('.sort_error') }
|
56
|
+
flash.now[:info] = t('spina.pages.sorting_saved')
|
57
|
+
render_flash
|
61
58
|
end
|
62
59
|
|
63
60
|
private
|
64
61
|
|
65
62
|
def author_params
|
66
|
-
params.require(:
|
67
|
-
|
68
|
-
|
63
|
+
params.require(:author).permit(:primary_affiliation_index,
|
64
|
+
affiliations_attributes: %i[id institution_id first_name
|
65
|
+
surname])
|
69
66
|
end
|
70
67
|
|
71
68
|
def modified_params
|
72
|
-
primary_affiliation_index = params[:
|
69
|
+
primary_affiliation_index = params[:author][:primary_affiliation_index]
|
73
70
|
new_params = author_params.except :primary_affiliation_index
|
74
71
|
unless new_params[:affiliations_attributes].nil? || primary_affiliation_index.nil?
|
75
72
|
new_params[:affiliations_attributes].each_key do |index|
|
@@ -79,10 +76,6 @@ module Spina
|
|
79
76
|
new_params
|
80
77
|
end
|
81
78
|
|
82
|
-
def sort_params
|
83
|
-
params.require(:admin_journal_authorships).require(:list).permit!
|
84
|
-
end
|
85
|
-
|
86
79
|
def set_breadcrumb
|
87
80
|
add_breadcrumb Author.model_name.human(count: :many), admin_journal_authors_path
|
88
81
|
end
|
@@ -95,12 +88,6 @@ module Spina
|
|
95
88
|
@author = Author.find(params[:id])
|
96
89
|
add_breadcrumb @author.primary_affiliation.name
|
97
90
|
end
|
98
|
-
|
99
|
-
def validate_sort_order
|
100
|
-
Authorship.where(article_id: params[:article_id]).each do |authorship|
|
101
|
-
raise ActiveRecord::RecordInvalid if authorship.invalid?
|
102
|
-
end
|
103
|
-
end
|
104
91
|
end
|
105
92
|
end
|
106
93
|
end
|