spina-admin-journal 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6bcd6816e32f3ea9345061c96fb045e2ad56b4e0784dc52fa553aa57a17fac5
4
- data.tar.gz: 83dc5d60bb02ecd87b9559db4923f81b97848842bb66c04f734cbb708c3159d6
3
+ metadata.gz: 699af672ff6d7d01b9d16ac482555eaf067ad7368d2a9149cd5e530da9f484aa
4
+ data.tar.gz: a4fbf7727835537e5f71df2c35b01d3b848764e6a75e2ffeac993e0852bf214d
5
5
  SHA512:
6
- metadata.gz: 94b6fa30869ad9a702b057d7dce487b8a522f9798d5d5d2897f554e19a75a9136760201b1a13d652a9e51f15aefbdf6b2cdd7bf0df3d73ae884f024cc193a37c
7
- data.tar.gz: f4acc58dcebdb7c13864cc99086376e516095658de37dcbb720127d2d65bdedb37b5dc658116b99f2a5d1f9152b17d0369ce52d3d5e6e674cf12ec5a7d0936b1
6
+ metadata.gz: 2a580ab0bf04617189936fc7ea06b9c08e4941a685474fdfd5a896589de7a797f0db602de90d85d95f0f06849b21da71414fdb4d8952abed3d6cda320bc8b6dc
7
+ data.tar.gz: 78454dba6fb8c595ee4d31e894dbc17f2217adad8960de4009fd7c373f30502ea8133e32bb985c17fc7dde9b5fea5cef6ecadd620254519f74b9be604ef2169a
@@ -46,6 +46,20 @@ module Spina
46
46
  end
47
47
  end
48
48
 
49
+ def sort
50
+ ActiveRecord::Base.transaction do
51
+ sort_params.each do |id, new_pos|
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
57
+ end
58
+ render json: { success: true, message: t('.sort_success') }
59
+ rescue ActiveRecord::RecordInvalid
60
+ render json: { success: false, message: t('.sort_error') }
61
+ end
62
+
49
63
  private
50
64
 
51
65
  def author_params
@@ -65,6 +79,10 @@ module Spina
65
79
  new_params
66
80
  end
67
81
 
82
+ def sort_params
83
+ params.require(:admin_journal_authorships).require(:list).permit!
84
+ end
85
+
68
86
  def set_breadcrumb
69
87
  add_breadcrumb Author.model_name.human(count: :many), admin_journal_authors_path
70
88
  end
@@ -77,6 +95,12 @@ module Spina
77
95
  @author = Author.find(params[:id])
78
96
  add_breadcrumb @author.primary_affiliation.name
79
97
  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
80
104
  end
81
105
  end
82
106
  end
@@ -13,6 +13,12 @@ module Spina
13
13
  # @!attribute [rw] author_name
14
14
  # @return [ActiveRecord::Relation] the associated affiliation of an author of the article
15
15
  belongs_to :affiliation
16
+ # @!attribute [rw] position
17
+ # @return [Integer] used to order the affiliations for each article
18
+
19
+ validates :position, presence: true, uniqueness: { scope: :article_id }
20
+
21
+ scope :sorted_within_article, -> { order(position: :asc) }
16
22
  end
17
23
  end
18
24
  end
@@ -1,4 +1,4 @@
1
- %tr
1
+ %tr{ data: { id: affiliation.id } }
2
2
  %td= affiliation.name
3
3
  %td= affiliation.institution.name
4
4
  %td= affiliation.articles.count
@@ -1,10 +1,15 @@
1
+ .sort-message
1
2
  .table-container
2
3
  %table.table
3
4
  %thead
4
5
  %tr
6
+ %th= ::Spina::Admin::Journal::Affiliation.human_attribute_name :position
5
7
  %th= ::Spina::Admin::Journal::Affiliation.human_attribute_name :name
6
8
  %th= ::Spina::Admin::Journal::Affiliation.human_attribute_name :institution
7
9
  %th= t '.number_of_articles'
8
10
  %th
9
- %tbody
10
- = render @article.affiliations.any? ? @article.affiliations : 'empty_list', message: t('.no_authors')
11
+ %tbody.html5sortable{ data: { id: @article.id, sorted_collection: 'admin_journal_authorships', sort_url: !@article.id.nil? && sort_admin_journal_authors_url(@article) } }
12
+ - if @article.authorships.any?
13
+ = render @article.authorships.sorted_within_article
14
+ - else
15
+ = render 'empty_list', message: t('.no_authors')
@@ -0,0 +1,9 @@
1
+ %tr{ data: { id: authorship.id } }
2
+ %td.position-display= authorship.position
3
+ %td= authorship.affiliation.name
4
+ %td= authorship.affiliation.institution.name
5
+ %td= authorship.affiliation.articles.count
6
+ %td.nowrap.align-right
7
+ = link_to edit_admin_journal_author_path(authorship.affiliation.author.id), class: 'button button-link' do
8
+ = icon 'pencil-outline'
9
+ = t '.view'
@@ -100,6 +100,9 @@ en:
100
100
  saved: Author saved.
101
101
  destroy:
102
102
  deleted: Author deleted.
103
+ sort:
104
+ sort_success: Sorted successfully!
105
+ sort_error: There was an error when sorting. Check the server logs for more information.
103
106
  form:
104
107
  save: Save author
105
108
  form_details:
@@ -145,12 +148,15 @@ en:
145
148
  spina/admin/journal/article:
146
149
  one: Article
147
150
  other: Articles
151
+ spina/admin/journal/authorship:
152
+ one: Authorship
153
+ other: Authorships
154
+ spina/admin/journal/affiliation:
155
+ one: Affiliation
156
+ other: Affiliations
148
157
  spina/admin/journal/author:
149
158
  one: Author
150
159
  other: Authors
151
- spina/admin/journal/author_name:
152
- one: Author name
153
- other: Author names
154
160
  spina/admin/journal/institution:
155
161
  one: Institution
156
162
  other: Institutions
@@ -169,8 +175,9 @@ en:
169
175
  title: Title
170
176
  url: URL
171
177
  doi: DOI
178
+ spina/admin/journal/authorship:
179
+ position: Position
172
180
  spina/admin/journal/author:
173
- spina/admin/journal/author_name:
174
181
  spina/admin/journal/institution:
175
182
  name: Institution Name
176
183
 
data/config/routes.rb CHANGED
@@ -13,9 +13,11 @@ Spina::Engine.routes.draw do
13
13
  resources :articles, except: %i[show] do
14
14
  patch 'sort/:issue_id' => 'articles#sort', as: :sort, on: :collection
15
15
  end
16
+ resources :authors, except: %i[show] do
17
+ patch 'sort/:article_id' => 'authors#sort', as: :sort, on: :collection
18
+ end
16
19
 
17
20
  resources :institutions, except: %i[show]
18
- resources :authors, except: %i[show]
19
21
  end
20
22
  end
21
23
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddPositionToSpinaAdminJournalAuthorships < ActiveRecord::Migration[6.1] # :nodoc:
4
+ def change
5
+ add_column :spina_admin_journal_authorships, :position, :integer, null: false, default: 0
6
+ end
7
+ end
@@ -3,7 +3,7 @@
3
3
  module Spina
4
4
  module Admin
5
5
  module Journal
6
- VERSION = '0.2.0'
6
+ VERSION = '0.3.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spina-admin-journal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Van Steene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-25 00:00:00.000000000 Z
11
+ date: 2021-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: babel-transpiler
@@ -318,6 +318,7 @@ files:
318
318
  - app/views/spina/admin/journal/authors/edit.html.haml
319
319
  - app/views/spina/admin/journal/authors/index.html.haml
320
320
  - app/views/spina/admin/journal/authors/new.html.haml
321
+ - app/views/spina/admin/journal/authorships/_authorship.html.haml
321
322
  - app/views/spina/admin/journal/institutions/_form.html.haml
322
323
  - app/views/spina/admin/journal/institutions/_form_details.html.haml
323
324
  - app/views/spina/admin/journal/institutions/_form_view_affiliations.html.haml
@@ -357,6 +358,7 @@ files:
357
358
  - db/migrate/20210424123450_add_json_attributes_to_spina_admin_journal_journals.rb
358
359
  - db/migrate/20210424123521_add_json_attributes_to_spina_admin_journal_issues.rb
359
360
  - db/migrate/20210424123555_add_json_attributes_to_spina_admin_journal_articles.rb
361
+ - db/migrate/20210512122931_add_position_to_spina_admin_journal_authorships.rb
360
362
  - lib/spina/admin/journal.rb
361
363
  - lib/spina/admin/journal/engine.rb
362
364
  - lib/spina/admin/journal/version.rb