From d71ea21401839a477334d401f8e85badc712f8b9 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 19 Jan 2023 21:33:52 +0100 Subject: [PATCH] fix papers and volumes --- .../journals/papers/kinds_controller.rb | 7 +- .../research/journals/papers_controller.rb | 7 +- .../research/journals/volumes_controller.rb | 7 +- app/models/communication/website/permalink.rb | 2 + .../communication/website/permalink/paper.rb | 50 +++++++++++++ .../communication/website/permalink/volume.rb | 48 +++++++++++++ app/models/research/journal/paper.rb | 25 ++++--- app/models/research/journal/volume.rb | 9 ++- .../research/journals/papers/static.html.erb | 4 +- .../research/journals/volumes/static.html.erb | 2 +- test/fixtures/education/programs.yml | 4 +- test/fixtures/research/journals.yml | 21 ++++++ test/fixtures/university/people.yml | 70 ++++++++++--------- 13 files changed, 205 insertions(+), 51 deletions(-) create mode 100644 app/models/communication/website/permalink/paper.rb create mode 100644 app/models/communication/website/permalink/volume.rb diff --git a/app/controllers/admin/research/journals/papers/kinds_controller.rb b/app/controllers/admin/research/journals/papers/kinds_controller.rb index 6fd93dd00..3740b69ca 100644 --- a/app/controllers/admin/research/journals/papers/kinds_controller.rb +++ b/app/controllers/admin/research/journals/papers/kinds_controller.rb @@ -13,7 +13,12 @@ class Admin::Research::Journals::Papers::KindsController < Admin::Research::Jour def static @about = @kind - render layout: false + @website = @journal.websites.first + if @website.nil? + render plain: "Pas de site Web liƩ au journal" + else + render layout: false + end end def new diff --git a/app/controllers/admin/research/journals/papers_controller.rb b/app/controllers/admin/research/journals/papers_controller.rb index 31d4852fd..10c257c71 100644 --- a/app/controllers/admin/research/journals/papers_controller.rb +++ b/app/controllers/admin/research/journals/papers_controller.rb @@ -13,7 +13,12 @@ class Admin::Research::Journals::PapersController < Admin::Research::Journals::A def static @about = @paper - render layout: false + @website = @journal.websites.first + if @website.nil? + render plain: "Pas de site Web liƩ au journal" + else + render layout: false + end end def new diff --git a/app/controllers/admin/research/journals/volumes_controller.rb b/app/controllers/admin/research/journals/volumes_controller.rb index a56c41a1f..34af4361e 100644 --- a/app/controllers/admin/research/journals/volumes_controller.rb +++ b/app/controllers/admin/research/journals/volumes_controller.rb @@ -13,7 +13,12 @@ class Admin::Research::Journals::VolumesController < Admin::Research::Journals:: def static @about = @volume - render layout: false + @website = @journal.websites.first + if @website.nil? + render plain: "Pas de site Web liƩ au journal" + else + render layout: false + end end def new diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb index 993dc56ff..276d8df83 100644 --- a/app/models/communication/website/permalink.rb +++ b/app/models/communication/website/permalink.rb @@ -30,6 +30,8 @@ class Communication::Website::Permalink < ApplicationRecord "Communication::Website::Post" => Communication::Website::Permalink::Post, "Education::Diploma" => Communication::Website::Permalink::Diploma, "Education::Program" => Communication::Website::Permalink::Program, + "Research::Journal::Paper" => Communication::Website::Permalink::Paper, + "Research::Journal::Volume" => Communication::Website::Permalink::Volume, "University::Organization" => Communication::Website::Permalink::Organization, "University::Person" => Communication::Website::Permalink::Person, "University::Person::Administrator" => Communication::Website::Permalink::Administrator, diff --git a/app/models/communication/website/permalink/paper.rb b/app/models/communication/website/permalink/paper.rb new file mode 100644 index 000000000..b81a0fddd --- /dev/null +++ b/app/models/communication/website/permalink/paper.rb @@ -0,0 +1,50 @@ +# == Schema Information +# +# Table name: communication_website_permalinks +# +# id :uuid not null, primary key +# about_type :string not null, indexed => [about_id] +# is_current :boolean default(TRUE) +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid not null, indexed => [about_type] +# university_id :uuid not null, indexed +# website_id :uuid not null, indexed +# +# Indexes +# +# index_communication_website_permalinks_on_about (about_type,about_id) +# index_communication_website_permalinks_on_university_id (university_id) +# index_communication_website_permalinks_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_e9646cce64 (university_id => universities.id) +# fk_rails_f389ba7d45 (website_id => communication_websites.id) +# +class Communication::Website::Permalink::Paper < Communication::Website::Permalink + def self.required_in_config?(website) + website.about == about.journal + end + + def self.static_config_key + :papers + end + + # /papiers/:slug/ + def self.pattern_in_website(website) + "/#{website.special_page(Communication::Website::Page::ResearchPaper).slug_with_ancestors}/:year-:month-:day-:slug/" + end + + protected + + def substitutions + { + year: about.published_at.strftime("%Y"), + month: about.published_at.strftime("%m"), + day: about.published_at.strftime("%d"), + slug: about.slug + } + end +end diff --git a/app/models/communication/website/permalink/volume.rb b/app/models/communication/website/permalink/volume.rb new file mode 100644 index 000000000..2f7a36572 --- /dev/null +++ b/app/models/communication/website/permalink/volume.rb @@ -0,0 +1,48 @@ +# == Schema Information +# +# Table name: communication_website_permalinks +# +# id :uuid not null, primary key +# about_type :string not null, indexed => [about_id] +# is_current :boolean default(TRUE) +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid not null, indexed => [about_type] +# university_id :uuid not null, indexed +# website_id :uuid not null, indexed +# +# Indexes +# +# index_communication_website_permalinks_on_about (about_type,about_id) +# index_communication_website_permalinks_on_university_id (university_id) +# index_communication_website_permalinks_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_e9646cce64 (university_id => universities.id) +# fk_rails_f389ba7d45 (website_id => communication_websites.id) +# +class Communication::Website::Permalink::Volume < Communication::Website::Permalink + def self.required_in_config?(website) + website.about == about.journal + end + + def self.static_config_key + :volumes + end + + # /volumes/:slug/ + def self.pattern_in_website(website) + "/#{website.special_page(Communication::Website::Page::ResearchVolume).slug_with_ancestors}/:year-:slug/" + end + + protected + + def substitutions + { + year: about.published_at.strftime("%Y"), + slug: about.slug + } + end +end diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index bf7e587d7..1b0e1502f 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -16,7 +16,7 @@ # title :string # created_at :datetime not null # updated_at :datetime not null -# paper_kind_id :uuid indexed +# kind_id :uuid indexed # research_journal_id :uuid not null, indexed # research_journal_volume_id :uuid indexed # university_id :uuid not null, indexed @@ -24,7 +24,7 @@ # # Indexes # -# index_research_journal_papers_on_paper_kind_id (paper_kind_id) +# index_research_journal_papers_on_kind_id (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) @@ -36,13 +36,14 @@ # 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) +# fk_rails_db4e38788c (kind_id => research_journal_paper_kinds.id) # class Research::Journal::Paper < ApplicationRecord include Sanitizable include WithUniversity include WithGit include WithBlobs + include WithPermalink include WithPosition include WithSlug @@ -66,8 +67,20 @@ class Research::Journal::Paper < ApplicationRecord scope :published, -> { where(published: true) } scope :ordered, -> { order(published_at: :desc, created_at: :desc) } + def published? + published && published_at && published_at.to_date <= Date.today + end + + def for_website?(website) + journal == website.about + end + def git_path(website) - "#{git_path_content_prefix(website)}papers/#{published_at.year}#{path}.html" if published_at + "#{git_path_content_prefix(website)}papers/#{static_path}.html" if published? + end + + def static_path + "#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}" end def template_static @@ -88,10 +101,6 @@ class Research::Journal::Paper < ApplicationRecord "#{ title }" end - def path - "/#{published_at.strftime "%Y-%m-%d"}-#{slug}" if published_at - end - protected def other_papers_in_the_volume diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 2779adf14..99c8761a4 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -35,6 +35,7 @@ class Research::Journal::Volume < ApplicationRecord include WithGit include WithBlobs include WithFeaturedImage + include WithPermalink include WithSlug has_summernote :text @@ -49,8 +50,12 @@ class Research::Journal::Volume < ApplicationRecord scope :published, -> { where(published: true) } scope :ordered, -> { order(number: :desc, published_at: :desc) } - def website - journal.website + def published? + published && published_at && published_at.to_date <= Date.today + end + + def for_website?(website) + journal == website.about end def git_path(website) diff --git a/app/views/admin/research/journals/papers/static.html.erb b/app/views/admin/research/journals/papers/static.html.erb index 77156fbc1..b0fa46c06 100644 --- a/app/views/admin/research/journals/papers/static.html.erb +++ b/app/views/admin/research/journals/papers/static.html.erb @@ -1,7 +1,7 @@ --- title: >- <%= prepare_text_for_static @about.title %> -slug: "<%= @about.slug %>" +<%= render 'admin/application/static/permalink' %> <% if @about.kind %> paper_kind: >- <%= prepare_text_for_static @about.kind %> @@ -10,7 +10,7 @@ paper_kinds: <% end %> <% if @about.volume && @about.volume.path %> volumes: - - "<%= @about.volume.path %>" + - "<%= @about.volume.path.delete_prefix('/') %>" <% end %> weight: <%= @about.position %> date: "<%= @about.published_at.iso8601 %>" diff --git a/app/views/admin/research/journals/volumes/static.html.erb b/app/views/admin/research/journals/volumes/static.html.erb index 4400d5ea2..88870d954 100644 --- a/app/views/admin/research/journals/volumes/static.html.erb +++ b/app/views/admin/research/journals/volumes/static.html.erb @@ -1,7 +1,7 @@ --- title: >- <%= prepare_text_for_static @about.title %> -slug: "<%= @about.slug %>" +<%= render 'admin/application/static/permalink' %> number: <%= @about.number %> issn: "<%= @about.journal.issn %>" keywords: > diff --git a/test/fixtures/education/programs.yml b/test/fixtures/education/programs.yml index d44de7e29..d57e55b11 100644 --- a/test/fixtures/education/programs.yml +++ b/test/fixtures/education/programs.yml @@ -9,13 +9,12 @@ # contacts :text # content :text # continuing :boolean -# description :text -# description_short :text # duration :text # evaluation :text # featured_image_alt :string # featured_image_credit :text # initial :boolean +# meta_description :text # name :string # objectives :text # opportunities :text @@ -32,6 +31,7 @@ # results :text # short_name :string # slug :string +# summary :text # created_at :datetime not null # updated_at :datetime not null # diploma_id :uuid indexed diff --git a/test/fixtures/research/journals.yml b/test/fixtures/research/journals.yml index 763bdc842..4ee7c0c8f 100644 --- a/test/fixtures/research/journals.yml +++ b/test/fixtures/research/journals.yml @@ -1,3 +1,24 @@ +# == Schema Information +# +# Table name: research_journals +# +# id :uuid not null, primary key +# issn :string +# meta_description :text +# summary :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# +# Indexes +# +# index_research_journals_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_96097d5f10 (university_id => universities.id) +# default_journal: university: default_university title: Journal diff --git a/test/fixtures/university/people.yml b/test/fixtures/university/people.yml index 2281277b1..efbd6df9f 100644 --- a/test/fixtures/university/people.yml +++ b/test/fixtures/university/people.yml @@ -2,38 +2,42 @@ # # Table name: university_people # -# id :uuid not null, primary key -# address :string -# biography :text -# birthdate :date -# city :string -# country :string -# description :text -# description_short :text -# email :string -# first_name :string -# gender :integer -# habilitation :boolean default(FALSE) -# is_administration :boolean -# is_alumnus :boolean default(FALSE) -# is_author :boolean -# is_researcher :boolean -# is_teacher :boolean -# last_name :string -# linkedin :string -# name :string -# phone_mobile :string -# phone_personal :string -# phone_professional :string -# slug :string -# tenure :boolean default(FALSE) -# twitter :string -# url :string -# zipcode :string -# created_at :datetime not null -# updated_at :datetime not null -# university_id :uuid not null, indexed -# user_id :uuid indexed +# id :uuid not null, primary key +# address :string +# biography :text +# birthdate :date +# city :string +# country :string +# email :string +# first_name :string +# gender :integer +# habilitation :boolean default(FALSE) +# hal_doc_identifier :string +# hal_form_identifier :string +# hal_person_identifier :string +# is_administration :boolean +# is_alumnus :boolean default(FALSE) +# is_author :boolean +# is_researcher :boolean +# is_teacher :boolean +# last_name :string +# linkedin :string +# mastodon :string +# meta_description :text +# name :string +# phone_mobile :string +# phone_personal :string +# phone_professional :string +# slug :string +# summary :text +# tenure :boolean default(FALSE) +# twitter :string +# url :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# user_id :uuid indexed # # Indexes # @@ -55,4 +59,4 @@ alumnus: cohorts: - default_cohort university: default_university - user: alumnus \ No newline at end of file + user: alumnus -- GitLab