spina-admin-journal 0.1.0 → 0.4.2

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: 75a11c42a861742be9bee3d10d3a84f745f2d489b8a1ad61bf8e699f4f7fdc04
4
- data.tar.gz: 343abc141c3af6b35492ec12a4c99325b116a3f63c5058fe7c61359cdfcd0da2
3
+ metadata.gz: cf3f41e632c032cf855ea7be3d2d6297e0f3d0eba015906afcb2c7497b8a0e16
4
+ data.tar.gz: 59e90ab32fa02f5400870002cffa3a0b7f7fe1f590ca03f8f2b22f008a72b074
5
5
  SHA512:
6
- metadata.gz: 8209f366bfdd31dee8b559a9ca0c3966f3383687560b87a20cda19fbb198eb8faa5929d07e1b97b773464ab950fb5d2c298b4e168a22afacec726c7bb7fee2a4
7
- data.tar.gz: 7182be875c118c6c59322b6e5a3fd51d81d5d51700be8db549ae48438df05bbb2fd9c290219cdbcae3d28b5530e172e5891ceb1636954c7aa36410406f96573b
6
+ metadata.gz: d8aebef70619bebbab5d5832639aa4dff527f909e4828a62aea7210eb69c0c2f0cddf2eb68871890457f751b3af00df686dbca919fedffb13276d89894b3b9ea
7
+ data.tar.gz: 1f1de9525d2e5ae4c57bdd9eeb55bfb106e3bcc3b9d32fcb1f8591820a89865a57311b65c7f57f48ca2a4ee95dcc219f4199ccd2354fdb11339accf1bf0dcc75
@@ -19,7 +19,7 @@ module Spina
19
19
  CONTENT_PARAMS = Spina.config.locales.inject({}) do |params, locale|
20
20
  params.merge("#{locale}_content_attributes": [*PARTS_PARAMS])
21
21
  end
22
- PARAMS = [:issue_id, :title, :url, :doi, { affiliation_ids: [], **CONTENT_PARAMS }].freeze
22
+ PARAMS = [:issue_id, :title, :url, :doi, :status, { affiliation_ids: [], **CONTENT_PARAMS }].freeze
23
23
  PARTS = %w[abstract attachment].freeze
24
24
 
25
25
  before_action :set_breadcrumb
@@ -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
@@ -20,7 +20,7 @@ module Spina
20
20
  params.merge("#{locale}_content_attributes": [*PARTS_PARAMS])
21
21
  end
22
22
  PARAMS = [:volume_id, :title, :date, { **CONTENT_PARAMS }].freeze
23
- PARTS = %w[cover_img description].freeze
23
+ PARTS = %w[cover_img description attachment].freeze
24
24
 
25
25
  before_action :set_breadcrumb
26
26
  before_action :set_tabs, except: %i[index destroy sort]
@@ -7,12 +7,13 @@ module Spina
7
7
  #
8
8
  # === Validators
9
9
  # Presence:: {#number}, {#title}
10
- # Uniqueness:: {#number} (scope: issue)
10
+ # Uniqueness:: {#number} (scope: issue) {status}
11
11
  # URI:: {#url}
12
12
  #
13
13
  # === Scopes
14
14
  # sorted_asc:: sorted in order of increasing number
15
15
  # sorted_desc:: sorted highest number first
16
+ # visible:: articles that should be visible to the public
16
17
  #
17
18
  # @see Issue
18
19
  # @see Author
@@ -33,9 +34,6 @@ module Spina
33
34
  # @!attribute [rw] issue
34
35
  # @return [Issue] The issue that contains this article.
35
36
  belongs_to :issue
36
- # @!attribute [rw] file
37
- # @return [Spina::Attachment] The attached file
38
- belongs_to :file, class_name: 'Spina::Attachment', optional: true
39
37
 
40
38
  # @!attribute [rw] authorships
41
39
  has_many :authorships, dependent: :destroy
@@ -43,12 +41,23 @@ module Spina
43
41
  # @return [ActiveRecord::Relation] The authors of the article.
44
42
  has_many :affiliations, through: :authorships
45
43
 
44
+ # @!attribute [rw] status
45
+ # @return [Integer] the current status of the article
46
+ enum status: { published: 0, draft: 1, meta: 2 }
47
+
46
48
  validates :number, presence: true, uniqueness: { scope: :issue_id }
47
49
  validates :title, presence: true
48
50
  validates :url, 'spina/admin/journal/uri': true
51
+ validates :status, presence: true
49
52
 
53
+ scope :visible, -> { where(status: %i[published meta]) }
50
54
  scope :sorted_asc, -> { includes(:issue).order('spina_admin_journal_issues.number ASC', number: :asc) }
51
55
  scope :sorted_desc, -> { includes(:issue).order('spina_admin_journal_issues.number DESC', number: :desc) }
56
+
57
+ # Returns true if the article should be visible to end users (i.e. is not a draft).
58
+ def visible?
59
+ published? || meta?
60
+ end
52
61
  end
53
62
  end
54
63
  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
@@ -30,9 +30,6 @@ module Spina
30
30
  # @!attribute [rw] volume
31
31
  # @return [ActiveRecord::Relation] the volume that contains this issue
32
32
  belongs_to :volume
33
- # @!attribute [rw] cover_img
34
- # @return [Spina::Image, nil] the issue's cover image
35
- belongs_to :cover_img, class_name: 'Spina::Image', optional: true
36
33
 
37
34
  # @!attribute [rw] issue
38
35
  # @return [ActiveRecord::Relation] the articles within this issue
@@ -20,9 +20,6 @@ module Spina
20
20
  # @return [String] The name of the journal.
21
21
  # @!attribute [rw] singleton_guard
22
22
  # @return [Integer] Used to guarantee that a record is unique.
23
- # @!attribute [rw] logo
24
- # @return [Spina::Image, nil] The Spina::Image representing the logo of the journal.
25
- belongs_to :logo, class_name: 'Spina::Image', optional: true
26
23
 
27
24
  # @!attribute [rw] volumes
28
25
  # @return [ActiveRecord::Relation] directly associated volumes
@@ -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')
@@ -15,6 +15,11 @@
15
15
  = ::Spina::Admin::Journal::Article.human_attribute_name :title
16
16
  .page-form-content
17
17
  = f.text_field :title
18
+ .page-form-group
19
+ .page-form-label
20
+ = Spina::Admin::Journal::Article.human_attribute_name :status
21
+ .page-form-content
22
+ = f.select :status, Spina::Admin::Journal::Article.statuses.keys.map { |key| [key.humanize, key] }
18
23
  .page-form-group
19
24
  .page-form-label
20
25
  = ::Spina::Admin::Journal::Author.model_name.human count: :many
@@ -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
@@ -4,7 +4,6 @@ class CreateSpinaAdminJournalJournals < ActiveRecord::Migration[6.0] # :nodoc:
4
4
  def change
5
5
  create_table :spina_admin_journal_journals do |t|
6
6
  t.string :name, null: false, default: 'Unnamed Journal'
7
- t.references :logo, null: true, foreign_key: { to_table: :spina_images }
8
7
  t.integer :singleton_guard, null: false, index: { unique: true }
9
8
 
10
9
  t.timestamps
@@ -7,7 +7,6 @@ class CreateSpinaAdminJournalIssues < ActiveRecord::Migration[6.0] # :nodoc:
7
7
  t.string :title, null: false, default: ''
8
8
  t.date :date, null: false
9
9
  t.references :volume, null: false, foreign_key: { to_table: :spina_admin_journal_volumes }
10
- t.references :cover_img, null: true, foreign_key: { to_table: :spina_images }
11
10
 
12
11
  t.timestamps
13
12
  end
@@ -8,7 +8,6 @@ class CreateSpinaAdminJournalArticles < ActiveRecord::Migration[6.0] # :nodoc:
8
8
  t.string :url, null: false, default: ''
9
9
  t.string :doi, null: false, default: ''
10
10
  t.references :issue, null: false, foreign_key: { to_table: :spina_admin_journal_issues }
11
- t.references :file, null: true, foreign_key: { to_table: :spina_attachments, on_delete: :nullify }
12
11
 
13
12
  t.timestamps
14
13
  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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddStatusToSpinaAdminJournalArticles < ActiveRecord::Migration[6.1] # :nodoc:
4
+ def change
5
+ add_column :spina_admin_journal_articles, :status, :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.1.0'
6
+ VERSION = '0.4.2'
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.1.0
4
+ version: 0.4.2
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-24 00:00:00.000000000 Z
11
+ date: 2021-05-24 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,8 @@ 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
362
+ - db/migrate/20210521121318_add_status_to_spina_admin_journal_articles.rb
360
363
  - lib/spina/admin/journal.rb
361
364
  - lib/spina/admin/journal/engine.rb
362
365
  - lib/spina/admin/journal/version.rb