diff --git a/app/controllers/admin/research/journals/papers/kinds_controller.rb b/app/controllers/admin/research/journals/papers/kinds_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..6fd93dd007614fb2624848fde5443639cdf5a38a --- /dev/null +++ b/app/controllers/admin/research/journals/papers/kinds_controller.rb @@ -0,0 +1,70 @@ +class Admin::Research::Journals::Papers::KindsController < Admin::Research::Journals::ApplicationController + load_and_authorize_resource class: Research::Journal::Paper::Kind, through: :journal + + def index + breadcrumb + end + + def show + @papers = @kind.papers.page params[:page] + breadcrumb + add_breadcrumb @kind + end + + def static + @about = @kind + render layout: false + end + + def new + breadcrumb + add_breadcrumb t('create') + end + + def edit + breadcrumb + add_breadcrumb @kind, admin_research_journal_kind_path(@kind) + add_breadcrumb t('edit') + end + + def create + @kind.assign_attributes( + journal: @journal, + university: current_university + ) + if @kind.save_and_sync + redirect_to admin_research_journal_kind_path(@kind), notice: t('admin.successfully_created_html', model: @paper_kind.to_s) + else + breadcrumb + add_breadcrumb t('create') + render :new, status: :unprocessable_entity + end + end + + def update + if @kind.update_and_sync(kind_params) + redirect_to admin_research_journal_kind_path(@kind), notice: t('admin.successfully_updated_html', model: @paper_kind.to_s) + else + breadcrumb + add_breadcrumb @kind, admin_research_journal_kind_path(@kind) + add_breadcrumb t('edit') + render :edit, status: :unprocessable_entity + end + end + + def destroy + @kind.destroy_and_sync + redirect_to admin_research_journal_path(@journal), notice: t('admin.successfully_destroyed_html', model: @paper_kind.to_s) + end + + private + + def breadcrumb + super + add_breadcrumb Research::Journal::Paper::Kind.model_name.human(count: 2), admin_research_journal_kinds_path + end + + def kind_params + params.require(:research_journal_paper_kind).permit(:title, :slug) + end +end diff --git a/app/controllers/admin/research/journals/papers_controller.rb b/app/controllers/admin/research/journals/papers_controller.rb index fc8dc28e94debde1f36dc3691c1093a9c61b7b43..31d4852fd9b32aacbab7ba57e679b657ccdeca56 100644 --- a/app/controllers/admin/research/journals/papers_controller.rb +++ b/app/controllers/admin/research/journals/papers_controller.rb @@ -11,6 +11,11 @@ class Admin::Research::Journals::PapersController < Admin::Research::Journals::A breadcrumb end + def static + @about = @paper + render layout: false + end + def new breadcrumb end @@ -42,7 +47,7 @@ class Admin::Research::Journals::PapersController < Admin::Research::Journals::A breadcrumb add_breadcrumb t('edit') render :edit, status: :unprocessable_entity - end + end end def destroy @@ -60,7 +65,9 @@ class Admin::Research::Journals::PapersController < Admin::Research::Journals::A def paper_params params.require(:research_journal_paper) - .permit(:title, :slug, :text, :published, :published_at, :summary, :abstract, :meta_description, :pdf, :references, :keywords, :research_journal_volume_id, person_ids: []) + .permit( + :title, :slug, :text, :published, :published_at, :summary, :abstract, :meta_description, + :pdf, :references, :keywords, :research_journal_volume_id, :kind_id, person_ids: []) .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/research/journals/volumes_controller.rb b/app/controllers/admin/research/journals/volumes_controller.rb index f8395fa9e4b26030e03aada3affe0c50cb8f0b69..a56c41a1fefd784cf5903016baaf55b555b38eb8 100644 --- a/app/controllers/admin/research/journals/volumes_controller.rb +++ b/app/controllers/admin/research/journals/volumes_controller.rb @@ -11,6 +11,11 @@ class Admin::Research::Journals::VolumesController < Admin::Research::Journals:: breadcrumb end + def static + @about = @volume + render layout: false + end + def new breadcrumb end diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb index 6ccc4ead71e421ea263a734aa51386caeadff3fd..1dd99dea3435a14964106026aff16fa4e0359f16 100644 --- a/app/controllers/admin/research/journals_controller.rb +++ b/app/controllers/admin/research/journals_controller.rb @@ -13,6 +13,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll def show @papers = @journal.papers.ordered.limit(10) + @kinds = @journal.kinds.ordered breadcrumb end diff --git a/app/models/ability.rb b/app/models/ability.rb index 1823110847763618c8c981661ee11182a5c73fa1..78c91ac1be684c53d5a3dbf26a38b60044cfdb61 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -92,6 +92,7 @@ class Ability can :manage, :all_programs # needed to prevent program_manager to access specific global screens can :manage, Research::Journal, university_id: @user.university_id can :manage, Research::Journal::Paper, university_id: @user.university_id + can :manage, Research::Journal::Paper::Kind, university_id: @user.university_id can :manage, Research::Journal::Volume, university_id: @user.university_id can :manage, Research::Laboratory, university_id: @user.university_id can :manage, Research::Laboratory::Axis, university_id: @user.university_id diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 2cf68b7922040236d1c417deb01a3ed36976d67d..21149af299ea637529ad441c4c9af6eb6960c15a 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -31,6 +31,7 @@ class Research::Journal < ApplicationRecord has_many :published_papers, -> { published }, class_name: 'Research::Journal::Paper', foreign_key: :research_journal_id, dependent: :destroy has_many :people, -> { distinct }, through: :papers has_many :people_through_published_papers, -> { distinct }, through: :published_papers, source: :people + has_many :kinds, class_name: 'Research::Journal::Paper::Kind' scope :ordered, -> { order(:title) } scope :for_search_term, -> (term) { diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index baf4e402acbc66eba5f5233a53e234fc1aac8b05..9761f41a4f58d7687e46b175220e8e91740904fc 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -16,6 +16,7 @@ # title :string # created_at :datetime not null # updated_at :datetime not null +# paper_kind_id :uuid indexed # research_journal_id :uuid not null, indexed # research_journal_volume_id :uuid indexed # university_id :uuid not null, indexed @@ -23,6 +24,7 @@ # # Indexes # +# index_research_journal_papers_on_paper_kind_id (paper_kind_id) # index_research_journal_papers_on_research_journal_id (research_journal_id) # index_research_journal_papers_on_research_journal_volume_id (research_journal_volume_id) # index_research_journal_papers_on_university_id (university_id) @@ -34,6 +36,7 @@ # fk_rails_22f161a6a7 (research_journal_volume_id => research_journal_volumes.id) # fk_rails_2713063b85 (updated_by_id => users.id) # fk_rails_935541e014 (university_id => universities.id) +# fk_rails_db4e38788c (paper_kind_id => research_journal_paper_kinds.id) # class Research::Journal::Paper < ApplicationRecord include Sanitizable @@ -48,6 +51,7 @@ class Research::Journal::Paper < ApplicationRecord belongs_to :journal, foreign_key: :research_journal_id belongs_to :volume, foreign_key: :research_journal_volume_id, optional: true + belongs_to :kind, class_name: 'Research::Journal::Paper::Kind', optional: true belongs_to :updated_by, class_name: 'User' has_and_belongs_to_many :people, class_name: 'University::Person', diff --git a/app/models/research/journal/paper/kind.rb b/app/models/research/journal/paper/kind.rb new file mode 100644 index 0000000000000000000000000000000000000000..da961c04fcc36061726831a3d8b4d67e2e6324d2 --- /dev/null +++ b/app/models/research/journal/paper/kind.rb @@ -0,0 +1,36 @@ +# == Schema Information +# +# Table name: research_journal_paper_kinds +# +# id :uuid not null, primary key +# slug :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# journal_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_research_journal_paper_kinds_on_journal_id (journal_id) +# index_research_journal_paper_kinds_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_57217513c3 (journal_id => research_journals.id) +# fk_rails_8e6f992b9d (university_id => universities.id) +# +class Research::Journal::Paper::Kind < ApplicationRecord + include WithUniversity + include WithGit + include WithSlug + + belongs_to :journal, class_name: 'Research::Journal' + has_many :papers + + scope :ordered, -> { order(:title) } + + def to_s + "#{title}" + end +end diff --git a/app/views/admin/research/journals/papers/_form.html.erb b/app/views/admin/research/journals/papers/_form.html.erb index e733d046260ff095c6d6c84b583ea7bbfd570496..8b85cdff12da0de64468cc0c48bd24cecfef542f 100644 --- a/app/views/admin/research/journals/papers/_form.html.erb +++ b/app/views/admin/research/journals/papers/_form.html.erb @@ -35,6 +35,7 @@ <%= f.input :published_at, html5: true %> <%= f.input :keywords, as: :text, input_html: { rows: 2 } %> <%= f.association :people, collection: current_university.people.researchers.ordered, as: :check_boxes %> + <%= f.association :kind, collection: @journal.kinds.ordered if @journal.kinds.any? %> </div> </div> <%= render 'admin/application/meta_description/form', f: f, about: paper %> diff --git a/app/views/admin/research/journals/papers/_list.html.erb b/app/views/admin/research/journals/papers/_list.html.erb index 92e82aa45cec31a969562e9b313a131a46019e02..aae767ac2b8b319769010821e6873a2f74786c99 100644 --- a/app/views/admin/research/journals/papers/_list.html.erb +++ b/app/views/admin/research/journals/papers/_list.html.erb @@ -2,7 +2,8 @@ <table class="<%= table_classes %>"> <thead> <tr> - <th><%= Research::Journal::Paper.model_name.human %></th> + <th><%= Research::Journal::Paper.human_attribute_name('title') %></th> + <th><%= Research::Journal::Paper.human_attribute_name('volume') %></th> <th><%= Research::Journal::Paper.human_attribute_name('published_at') %></th> <th></th> </tr> @@ -15,6 +16,7 @@ admin_research_journal_paper_path(journal_id: paper.journal, id: paper), class: "#{'draft' unless paper.published?}" %> </td> + <td><%= link_to paper.volume, admin_research_journal_volume_path(paper.volume) if paper.volume %></td> <td><%= l(paper.published_at.to_time, format: :date_with_explicit_month) if paper.published_at.present? %></td> <td class="text-end"> <div class="btn-group" role="group"> diff --git a/app/views/admin/research/journals/papers/kinds/_form.html.erb b/app/views/admin/research/journals/papers/kinds/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..853d1f38afa3b8fe779dbf9e9dafa55c65004936 --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/_form.html.erb @@ -0,0 +1,38 @@ +<% +url = kind.new_record? ? admin_research_journal_kinds_path + : admin_research_journal_kind_path(kind) +%> +<%= simple_form_for kind, url: url do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + <div class="row"> + <div class="col-md-8"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('content') %></h5> + </div> + <div class="card-body"> + <%= f.input :title %> + </div> + </div> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('metadata') %></h5> + </div> + <div class="card-body"> + <%= f.input :slug, + as: :string, + input_html: kind.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#research_journal_paper_kind_title' } + } %> + </div> + </div> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/research/journals/papers/kinds/_list.html.erb b/app/views/admin/research/journals/papers/kinds/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..df45956d7bb811bdb61ff7064da9ae014afbbadc --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/_list.html.erb @@ -0,0 +1,34 @@ +<div class="table-responsive"> + <table class="<%= table_classes %>"> + <thead> + <tr> + <th><%= Research::Journal::Paper::Kind.human_attribute_name('title') %></th> + <th><%= Research::Journal::Paper.model_name.human(count: 2) %></th> + <th></th> + </tr> + </thead> + <tbody> + <% kinds.each do |kind| %> + <tr> + <td> + <%= link_to kind, + admin_research_journal_kind_path(journal_id: kind.journal, id: kind) %> + </td> + <td><%= kind.papers.count %></td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= link_to t('edit'), + edit_admin_research_journal_kind_path(journal_id: kind.journal, id: kind), + class: button_classes %> + <%= link_to t('delete'), + admin_research_journal_kind_path(journal_id: kind.journal, id: kind), + method: :delete, + data: { confirm: t('please_confirm') }, + class: button_classes_danger %> + </div> + </td> + </tr> + <% end %> + </tbody> + </table> +</div> diff --git a/app/views/admin/research/journals/papers/kinds/edit.html.erb b/app/views/admin/research/journals/papers/kinds/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..23e01d488bce530df4610865b6df39909a126891 --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/edit.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, @kind %> + +<%= render 'form', kind: @kind %> diff --git a/app/views/admin/research/journals/papers/kinds/index.html.erb b/app/views/admin/research/journals/papers/kinds/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..81ac607bbd41bec6874545502e3632dd592109b0 --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/index.html.erb @@ -0,0 +1,7 @@ +<% content_for :title, Research::Journal::Paper::Kind.model_name.human(count: 2) %> + +<%= render 'admin/research/journals/papers/kinds/list', kinds: @kinds %> + +<% content_for :action_bar_right do %> + <%= link_to t('create'), new_admin_research_journal_kind_path, class: button_classes %> +<% end %> diff --git a/app/views/admin/research/journals/papers/kinds/new.html.erb b/app/views/admin/research/journals/papers/kinds/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..1dbb60dda17bc324b93976c3b70971f4fc747264 --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, Research::Journal::Paper::Kind.model_name.human %> + +<%= render 'form', kind: @kind %> diff --git a/app/views/admin/research/journals/papers/kinds/show.html.erb b/app/views/admin/research/journals/papers/kinds/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..b4f8798a4b8572bef813e791ceb9cc65c051d3c0 --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/show.html.erb @@ -0,0 +1,19 @@ +<% content_for :title, @kind %> + +<%= render 'admin/research/journals/papers/list', papers: @papers %> + +<% content_for :action_bar_left do %> + <%= link_to t('destroy'), + admin_research_journal_kind_path(@kind), + data: { confirm: t('please_confirm') }, + class: button_classes_danger %> + <%= link_to t('static'), + static_admin_research_journal_kind_path(@kind), + class: button_classes('btn-light') if current_user.server_admin? %> +<% end %> + +<% content_for :action_bar_right do %> + <%= link_to t('edit'), + edit_admin_research_journal_kind_path(@kind), + class: button_classes %> +<% end %> diff --git a/app/views/admin/research/journals/papers/kinds/static.html.erb b/app/views/admin/research/journals/papers/kinds/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..2e4291d1fa4fa8b077ea425bee0ea0340edca156 --- /dev/null +++ b/app/views/admin/research/journals/papers/kinds/static.html.erb @@ -0,0 +1,5 @@ +--- +title: >- + <%= prepare_text_for_static @about.title %> +slug: "<%= @about.slug %>" +--- diff --git a/app/views/admin/research/journals/papers/show.html.erb b/app/views/admin/research/journals/papers/show.html.erb index f3bf6ca7c1dfc7c1eb0527c5ba3a449ebf8a44df..a4ab2037d7da3cb5eb430fa5c27ea0650ef90e41 100644 --- a/app/views/admin/research/journals/papers/show.html.erb +++ b/app/views/admin/research/journals/papers/show.html.erb @@ -47,6 +47,12 @@ </h3> <p><%= @paper.keywords %></p> <% end %> + <% if @paper.kind %> + <h3 class="h5"> + <%= Research::Journal::Paper.human_attribute_name('kind') %> + </h3> + <p><%= link_to @paper.kind, admin_research_journal_kind_path(@paper.kind) %></p> + <% end %> <% if @paper.people.any? %> <h3 class="h5"> <%= Research::Journal::Paper.human_attribute_name('people') %> @@ -65,6 +71,9 @@ <% content_for :action_bar_left do %> <%= destroy_link @paper %> + <%= link_to t('static'), + static_admin_research_journal_paper_path(@paper), + class: button_classes('btn-light') if current_user.server_admin? %> <% end %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/research/journals/papers/static.html.erb b/app/views/admin/research/journals/papers/static.html.erb index 3e38a4349020456c7c991042ffeb36951b823b27..77156fbc1409f5e6b567441b6dc3eef40ca3e017 100644 --- a/app/views/admin/research/journals/papers/static.html.erb +++ b/app/views/admin/research/journals/papers/static.html.erb @@ -1,6 +1,13 @@ --- -title: "<%= @about.title %>" +title: >- + <%= prepare_text_for_static @about.title %> slug: "<%= @about.slug %>" +<% if @about.kind %> +paper_kind: >- + <%= prepare_text_for_static @about.kind %> +paper_kinds: + - "<%= @about.kind.slug %>" +<% end %> <% if @about.volume && @about.volume.path %> volumes: - "<%= @about.volume.path %>" diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb index 4cf2893c0aabc906c5052480805a21efce60aa54..d3a88ddf1c0a69badfb2954a989878f82fde4351 100644 --- a/app/views/admin/research/journals/show.html.erb +++ b/app/views/admin/research/journals/show.html.erb @@ -11,52 +11,72 @@ <% if @journal.issn %><%= Research::Journal.human_attribute_name('issn') %> <%= @journal.issn %><% end %> <% end %> -<%= render 'admin/application/summary/show', about: @journal %> -<div class="card mt-5"> - <div class="card-header"> - <div class="float-end"> - <%= link_to t('create'), - new_admin_research_journal_volume_path(journal_id: @journal), - class: button_classes %> - </div> - <h2 class="card-title"> - <%= link_to Research::Journal::Volume.model_name.human(count: 2), - admin_research_journal_volumes_path(journal_id: @journal) %></h2> +<div class="row"> + <div class="col-md-8"> + <%= render 'admin/application/summary/show', about: @journal %> + </div> + <div class="col-md-4"> + <%= render 'admin/application/meta_description/show', about: @journal %> </div> - <div class="card-body"> - <div class="row"> - <% @journal.volumes.ordered.limit(4).each do |volume| %> - <div class="col-md-3 mt-4"> - <div class="card"> - <%= image_tag volume.featured_image, class: 'img-fluid' if volume.featured_image.attached? %> - <div class="card-body"> - <%= link_to volume, - admin_research_journal_volume_path(journal_id: @journal, id: volume), - class: "stretched-link #{'draft' unless volume.published?}" %> - </div> - </div> +</div> + +<div class="float-end"> + <%= link_to t('create'), + new_admin_research_journal_volume_path(journal_id: @journal), + class: button_classes %> +</div> +<h2 class="h4"> + <%= link_to Research::Journal::Volume.model_name.human(count: 2), + admin_research_journal_volumes_path(journal_id: @journal) %> +</h2> +<div class="row"> + <% @journal.volumes.ordered.limit(4).each do |volume| %> + <div class="col-md-3 mt-4 p-0"> + <div class="card"> + <%= kamifusen_tag volume.featured_image, width: 600, class: 'img-fluid' if volume.featured_image.attached? %> + <div class="card-body"> + <%= link_to volume, + admin_research_journal_volume_path(journal_id: @journal, id: volume), + class: "stretched-link #{'draft' unless volume.published?}" %> </div> - <% end %> + </div> </div> - </div> + <% end %> </div> -<div class="card mt-5"> - <div class="card-header"> - <div class="float-end"> - <%= link_to t('create'), - new_admin_research_journal_paper_path(journal_id: @journal), - class: button_classes %> +<div class="row"> + <div class="col-md-8"> + <div class="card mt-5"> + <div class="card-header"> + <div class="float-end"> + <%= link_to t('create'), + new_admin_research_journal_paper_path(journal_id: @journal), + class: button_classes %> + </div> + <h2 class="card-title"> + <%= link_to Research::Journal::Paper.model_name.human(count: 2), + admin_research_journal_papers_path(journal_id: @journal) %></h2> + </div> + <%= render 'admin/research/journals/papers/list', papers: @papers %> + </div> + </div> + <div class="col-md-4"> + <div class="card mt-5"> + <div class="card-header"> + <div class="float-end"> + <%= link_to t('create'), + new_admin_research_journal_kind_path(journal_id: @journal), + class: button_classes %> + </div> + <h2 class="card-title"> + <%= link_to Research::Journal::Paper::Kind.model_name.human(count: 2), + admin_research_journal_kind_path(journal_id: @journal) %></h2> + </div> + <%= render 'admin/research/journals/papers/kinds/list', kinds: @kinds %> </div> - <h2 class="card-title"> - <%= link_to Research::Journal::Paper.model_name.human(count: 2), - admin_research_journal_papers_path(journal_id: @journal) %></h2> </div> - <%= render 'admin/research/journals/papers/list', papers: @papers %> </div> -<%= render 'admin/application/meta_description/show', about: @journal %> - <% content_for :action_bar_left do %> <%= destroy_link @journal %> <% end %> diff --git a/app/views/admin/research/journals/volumes/show.html.erb b/app/views/admin/research/journals/volumes/show.html.erb index 3294c87dc9f948c429d38adb63cf23e119dff031..1872da74cef693b7fde577f38866b0bd6b54e390 100644 --- a/app/views/admin/research/journals/volumes/show.html.erb +++ b/app/views/admin/research/journals/volumes/show.html.erb @@ -3,57 +3,50 @@ <div class="row"> <div class="col-md-9"> <%= render 'admin/application/summary/show', about: @volume %> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h2 class="card-title mb-0 h5"><%= t('content') %></h2> - </div> - <div class="card-body"> - <% if @papers.any? %> - <h3 class="h5 mt-4"><%= Research::Journal::Volume.human_attribute_name('papers') %></h3> - <div class="table-responsive"> - <table class="<%= table_classes %>"> - <thead> - <tr> - <% if can? :reorder, Research::Journal::Paper %> - <th width="20" class="ps-0"> </th> - <% end %> - <th class="ps-0"><%= Research::Journal::Paper.model_name.human %></th> - <th><%= Research::Journal::Paper.human_attribute_name('published_at') %></th> - <th></th> - </tr> - </thead> - <tbody data-sortable data-sort-url="<%= reorder_admin_research_journal_papers_path(journal_id: @journal.id) %>"> - <% @papers.each do |paper| %> - <tr data-id="<%= paper.id %>"> - <% if can? :reorder, Research::Journal::Paper %> - <td><i class="fa fa-bars handle"></i></td> - <% end %> - <td> - <%= link_to paper, - admin_research_journal_paper_path(journal_id: paper.journal, id: paper), - class: "#{'draft' unless paper.published?}" %> - </td> - <td><%= l(paper.published_at.to_time, format: :date_with_explicit_month) if paper.published_at.present? %></td> - <td class="text-end"> - <div class="btn-group" role="group"> - <%= link_to t('edit'), - edit_admin_research_journal_paper_path(journal_id: paper.journal, id: paper), - class: button_classes %> - <%= link_to t('delete'), - admin_research_journal_paper_path(journal_id: paper.journal, id: paper), - method: :delete, - data: { confirm: t('please_confirm') }, - class: button_classes_danger %> - </div> - </td> - </tr> + <% if @papers.any? %> + <h3 class="h5 mt-5"><%= Research::Journal::Paper.model_name.human(count: 2) %></h3> + <div class="table-responsive"> + <table class="<%= table_classes %>"> + <thead> + <tr> + <% if can? :reorder, Research::Journal::Paper %> + <th width="20" class="ps-0"> </th> + <% end %> + <th class="ps-0"><%= Research::Journal::Paper.human_attribute_name('title') %></th> + <th><%= Research::Journal::Paper.human_attribute_name('published_at') %></th> + <th></th> + </tr> + </thead> + <tbody data-sortable data-sort-url="<%= reorder_admin_research_journal_papers_path(journal_id: @journal.id) %>"> + <% @papers.each do |paper| %> + <tr data-id="<%= paper.id %>"> + <% if can? :reorder, Research::Journal::Paper %> + <td><i class="fa fa-bars handle"></i></td> <% end %> - </tbody> - </table> - </div> - <% end %> + <td> + <%= link_to paper, + admin_research_journal_paper_path(journal_id: paper.journal, id: paper), + class: "#{'draft' unless paper.published?}" %> + </td> + <td><%= l(paper.published_at.to_time, format: :date_with_explicit_month) if paper.published_at.present? %></td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= link_to t('edit'), + edit_admin_research_journal_paper_path(journal_id: paper.journal, id: paper), + class: button_classes %> + <%= link_to t('delete'), + admin_research_journal_paper_path(journal_id: paper.journal, id: paper), + method: :delete, + data: { confirm: t('please_confirm') }, + class: button_classes_danger %> + </div> + </td> + </tr> + <% end %> + </tbody> + </table> </div> - </div> + <% end %> </div> <div class="col-md-3"> <div class="card flex-fill w-100"> @@ -74,6 +67,9 @@ <% content_for :action_bar_left do %> <%= destroy_link @volume %> + <%= link_to t('static'), + static_admin_research_journal_volume_path(@volume), + class: button_classes('btn-light') if current_user.server_admin? %> <% end %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/research/journals/volumes/static.html.erb b/app/views/admin/research/journals/volumes/static.html.erb index 284cefba7cc7a2268aa2ad1271fa97c9d65798f9..4400d5ea285b5d047cc01f0edca64378b778040a 100644 --- a/app/views/admin/research/journals/volumes/static.html.erb +++ b/app/views/admin/research/journals/volumes/static.html.erb @@ -1,5 +1,6 @@ --- -title: "<%= @about.title %>" +title: >- + <%= prepare_text_for_static @about.title %> slug: "<%= @about.slug %>" number: <%= @about.number %> issn: "<%= @about.journal.issn %>" diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml index 7e0270965abc5b8d78550366fbf035c41ff09f3c..4ac3f87f6e41abfd7ed54e47c57380af2400dcfe 100644 --- a/config/locales/research/en.yml +++ b/config/locales/research/en.yml @@ -10,6 +10,9 @@ en: research/journal/paper: one: Paper other: Papers + research/journal/paper/kind: + one: Kind of paper + other: Kinds of paper research/journal/volume: one: Volume other: Volumes @@ -33,9 +36,12 @@ en: published: Published? published_at: Published at references: References + kind: Kind of paper people: Authors text: Text title: Title + research/journal/paper/kind: + title: Title research/journal/volume: featured_image: Cover featured_image_alt: Alt text diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml index 2b5e8e04aa3bca8f8bf0d8be788c77d68dcb0c91..baa9d39da0b2063d69f970cb75eb4c8ce6818ece 100644 --- a/config/locales/research/fr.yml +++ b/config/locales/research/fr.yml @@ -10,6 +10,9 @@ fr: research/journal/paper: one: Papier other: Papiers + research/journal/paper/kind: + one: Type de papier + other: Types de papier research/journal/volume: one: Volumes other: Volumes @@ -33,9 +36,12 @@ fr: published: Publié ? published_at: Publié le references: Références + kind: Type de papier people: Auteu·rs·rices text: Texte title: Titre + research/journal/paper/kind: + title: Titre research/journal/volume: featured_image: Couverture featured_image_alt: Texte alternatif diff --git a/config/routes/admin/research.rb b/config/routes/admin/research.rb index 7a1189c6039be5fd66838d756ef9429487bcda61..024239d0f6c7c1eca66573baa71689122ef27de3 100644 --- a/config/routes/admin/research.rb +++ b/config/routes/admin/research.rb @@ -1,11 +1,23 @@ namespace :research do resources :researchers, only: [:index, :show] resources :journals do - resources :volumes, controller: 'journals/volumes' + resources :volumes, controller: 'journals/volumes' do + member do + get :static + end + end resources :papers, controller: 'journals/papers' do collection do + resources :kinds, controller: 'journals/papers/kinds' do + member do + get :static + end + end post :reorder end + member do + get :static + end end end resources :laboratories do diff --git a/db/migrate/20230118175136_create_research_journal_paper_kinds.rb b/db/migrate/20230118175136_create_research_journal_paper_kinds.rb new file mode 100644 index 0000000000000000000000000000000000000000..a9d214686c5c812a1cc06d26e67c62e8468d84ed --- /dev/null +++ b/db/migrate/20230118175136_create_research_journal_paper_kinds.rb @@ -0,0 +1,12 @@ +class CreateResearchJournalPaperKinds < ActiveRecord::Migration[7.0] + def change + create_table :research_journal_paper_kinds, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :journal, null: false, foreign_key: {to_table: :research_journals}, type: :uuid + t.string :title + t.string :slug + + t.timestamps + end + end +end diff --git a/db/migrate/20230118201432_add_paper_kind_to_research_journal_paper.rb b/db/migrate/20230118201432_add_paper_kind_to_research_journal_paper.rb new file mode 100644 index 0000000000000000000000000000000000000000..f0f82bd2f4494902db9d4313e423acb8dbf71ebb --- /dev/null +++ b/db/migrate/20230118201432_add_paper_kind_to_research_journal_paper.rb @@ -0,0 +1,5 @@ +class AddPaperKindToResearchJournalPaper < ActiveRecord::Migration[7.0] + def change + add_reference :research_journal_papers, :paper_kind, foreign_key: {to_table: :research_journal_paper_kinds}, type: :uuid + end +end diff --git a/db/migrate/20230119164205_rename_paper_kind_id_to_kind_id.rb b/db/migrate/20230119164205_rename_paper_kind_id_to_kind_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..4fca97166c078845a6e628cd4074309d24bf12fc --- /dev/null +++ b/db/migrate/20230119164205_rename_paper_kind_id_to_kind_id.rb @@ -0,0 +1,5 @@ +class RenamePaperKindIdToKindId < ActiveRecord::Migration[7.0] + def change + rename_column :research_journal_papers, :paper_kind_id, :kind_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 317c9d831a3e1be7975386c68e4ad29d4038bd0d..788fd636df29d9867cd853ac0ad24dcbd8fa106b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_18_155630) do +ActiveRecord::Schema[7.0].define(version: 2023_01_19_164205) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -565,6 +565,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_155630) do t.string "summernote_locale" end + create_table "research_journal_paper_kinds", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "journal_id", null: false + t.string "title" + t.string "slug" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["journal_id"], name: "index_research_journal_paper_kinds_on_journal_id" + t.index ["university_id"], name: "index_research_journal_paper_kinds_on_university_id" + end + create_table "research_journal_papers", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "title" t.datetime "published_at", precision: nil @@ -583,6 +594,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_155630) do t.text "text" t.text "meta_description" t.text "summary" + t.uuid "kind_id" + t.index ["kind_id"], name: "index_research_journal_papers_on_kind_id" t.index ["research_journal_id"], name: "index_research_journal_papers_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_papers_on_research_journal_volume_id" t.index ["university_id"], name: "index_research_journal_papers_on_university_id" @@ -933,6 +946,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_155630) do add_foreign_key "education_schools", "universities" add_foreign_key "imports", "universities" add_foreign_key "imports", "users" + add_foreign_key "research_journal_paper_kinds", "research_journals", column: "journal_id" + add_foreign_key "research_journal_paper_kinds", "universities" + add_foreign_key "research_journal_papers", "research_journal_paper_kinds", column: "kind_id" add_foreign_key "research_journal_papers", "research_journal_volumes" add_foreign_key "research_journal_papers", "research_journals" add_foreign_key "research_journal_papers", "universities" diff --git a/test/fixtures/research/journal/paper/kinds.yml b/test/fixtures/research/journal/paper/kinds.yml new file mode 100644 index 0000000000000000000000000000000000000000..70e0e791df4d71edfc2999ee0e6125994c469f0b --- /dev/null +++ b/test/fixtures/research/journal/paper/kinds.yml @@ -0,0 +1,34 @@ +# == Schema Information +# +# Table name: research_journal_paper_kinds +# +# id :uuid not null, primary key +# slug :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# journal_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_research_journal_paper_kinds_on_journal_id (journal_id) +# index_research_journal_paper_kinds_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_57217513c3 (journal_id => research_journals.id) +# fk_rails_8e6f992b9d (university_id => universities.id) +# + +one: + university: default_university + journal: default_journal + title: Articles + slug: articles + +two: + university: default_university + journal: default_journal + title: Recensions + slug: recensions diff --git a/test/fixtures/research/journals.yml b/test/fixtures/research/journals.yml new file mode 100644 index 0000000000000000000000000000000000000000..763bdc8429fcf189c286f3c58a343d993804e388 --- /dev/null +++ b/test/fixtures/research/journals.yml @@ -0,0 +1,3 @@ +default_journal: + university: default_university + title: Journal diff --git a/test/models/research/journal/paper/kind_test.rb b/test/models/research/journal/paper/kind_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..3eed2b6d5f60b69c6b9c22bbb82f9babf565049d --- /dev/null +++ b/test/models/research/journal/paper/kind_test.rb @@ -0,0 +1,29 @@ +# == Schema Information +# +# Table name: research_journal_paper_kinds +# +# id :uuid not null, primary key +# slug :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# journal_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_research_journal_paper_kinds_on_journal_id (journal_id) +# index_research_journal_paper_kinds_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_57217513c3 (journal_id => research_journals.id) +# fk_rails_8e6f992b9d (university_id => universities.id) +# +require "test_helper" + +class Research::Journal::Paper::KindTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/research/journal/paper/kinds_test.rb b/test/system/research/journal/paper/kinds_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..2eb2ed93afebc9e1563501f00f548bbfbb27c50a --- /dev/null +++ b/test/system/research/journal/paper/kinds_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class Research::Journal::Paper::KindsTest < ApplicationSystemTestCase + setup do + @research_journal_paper_kind = research_journal_paper_kinds(:one) + end + + test "visiting the index" do + visit research_journal_paper_kinds_url + assert_selector "h1", text: "Kinds" + end + + test "should create kind" do + visit research_journal_paper_kinds_url + click_on "New kind" + + fill_in "Slug", with: @research_journal_paper_kind.slug + fill_in "Title", with: @research_journal_paper_kind.title + click_on "Create Kind" + + assert_text "Kind was successfully created" + click_on "Back" + end + + test "should update Kind" do + visit research_journal_paper_kind_url(@research_journal_paper_kind) + click_on "Edit this kind", match: :first + + fill_in "Slug", with: @research_journal_paper_kind.slug + fill_in "Title", with: @research_journal_paper_kind.title + click_on "Update Kind" + + assert_text "Kind was successfully updated" + click_on "Back" + end + + test "should destroy Kind" do + visit research_journal_paper_kind_url(@research_journal_paper_kind) + click_on "Destroy this kind", match: :first + + assert_text "Kind was successfully destroyed" + end +end