From 5e5adcca37b9ea471def176b8dc728250b947421 Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Tue, 23 Nov 2021 14:25:18 +0100 Subject: [PATCH] cleanup research --- app/models/research/journal.rb | 2 +- app/models/research/journal/article.rb | 28 ++++++------------- app/models/research/journal/volume.rb | 18 ++++-------- app/models/research/researcher.rb | 2 +- .../admin/education/schools/show.html.erb | 4 +-- .../admin/research/journals/show.html.erb | 8 ++++-- .../research/researchers/jekyll.html.erb | 8 +++--- ...32213_remove_unused_infos_from_research.rb | 7 +++++ db/schema.rb | 5 +--- lib/tasks/app.rake | 2 +- 10 files changed, 34 insertions(+), 50 deletions(-) create mode 100644 db/migrate/20211123132213_remove_unused_infos_from_research.rb diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 5a5989671..cc10ff138 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -22,7 +22,7 @@ # class Research::Journal < ApplicationRecord belongs_to :university - has_one :website, class_name: 'Communication::Website', as: :about + has_many :websites, class_name: 'Communication::Website', as: :about has_many :volumes, foreign_key: :research_journal_id has_many :articles, foreign_key: :research_journal_id diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index 32157535e..94eb530bc 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -4,7 +4,6 @@ # # id :uuid not null, primary key # abstract :text -# github_path :text # keywords :text # old_text :text # published_at :date @@ -32,53 +31,42 @@ # fk_rails_... (updated_by_id => users.id) # class Research::Journal::Article < ApplicationRecord - include WithGithub + include WithJekyll + include WithPublicationToWebsites has_rich_text :text + has_one_attached :pdf belongs_to :university belongs_to :journal, foreign_key: :research_journal_id belongs_to :volume, foreign_key: :research_journal_volume_id, optional: true belongs_to :updated_by, class_name: 'User' has_and_belongs_to_many :researchers, class_name: 'Research::Researcher' + has_many :websites, -> { distinct }, through: :journal validates :title, :published_at, presence: true after_commit :update_researchers - has_one_attached :pdf - scope :ordered, -> { order(:published_at, :created_at) } def pdf_path "/assets/articles/#{id}/#{pdf.filename}" end - def website - journal.website - end - def to_s "#{ title }" end - protected - - def github_path_generated + def github_path "_articles/#{id}.html" end - def to_jekyll - ApplicationController.render( - template: 'admin/research/journal/articles/jekyll', - layout: false, - assigns: { article: self } - ) - end + private def update_researchers - return unless website + return unless websites.any? researchers.each do |researcher| - researcher.publish_to_website(website) + websites.each { |website| website.publish_object(researcher) } end end end diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index fdb2521db..03f059d2b 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -4,7 +4,6 @@ # # id :uuid not null, primary key # description :text -# github_path :text # keywords :text # number :integer # published_at :date @@ -25,13 +24,15 @@ # fk_rails_... (university_id => universities.id) # class Research::Journal::Volume < ApplicationRecord - has_one_attached_deletable :cover + include WithJekyll + include WithPublicationToWebsites - include WithGithub + has_one_attached_deletable :cover belongs_to :university belongs_to :journal, foreign_key: :research_journal_id has_many :articles, foreign_key: :research_journal_volume_id + has_many :websites, -> { distinct }, through: :journal scope :ordered, -> { order(number: :desc, published_at: :desc) } @@ -47,17 +48,8 @@ class Research::Journal::Volume < ApplicationRecord "##{ number } #{ title }" end - protected - - def github_path_generated + def github_path "_volumes/#{id}.html" end - def to_jekyll - ApplicationController.render( - template: 'admin/research/journal/volumes/jekyll', - layout: false, - assigns: { volume: self } - ) - end end diff --git a/app/models/research/researcher.rb b/app/models/research/researcher.rb index a5ae0ab54..fb22dd765 100644 --- a/app/models/research/researcher.rb +++ b/app/models/research/researcher.rb @@ -5,7 +5,6 @@ # id :uuid not null, primary key # first_name :string # last_name :string -# old_biography :text # created_at :datetime not null # updated_at :datetime not null # university_id :uuid @@ -22,6 +21,7 @@ # fk_rails_... (user_id => users.id) # class Research::Researcher < ApplicationRecord + include WithJekyll include WithPublicationToWebsites has_rich_text :biography diff --git a/app/views/admin/education/schools/show.html.erb b/app/views/admin/education/schools/show.html.erb index 03a8d1628..d434ebc26 100644 --- a/app/views/admin/education/schools/show.html.erb +++ b/app/views/admin/education/schools/show.html.erb @@ -44,7 +44,7 @@ <div class="card-body"> <ul class="list-unstyled"> <% @school.websites.each do |website| %> - <%= link_to website, [:admin, website] %><br> + <li><%= link_to website, [:admin, website] %></li> <% end %> </ul> </div> @@ -54,8 +54,6 @@ </div> - - <% content_for :action_bar_right do %> <%= edit_link @school %> <% end %> diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb index 674a37a04..cd6ffa3f7 100644 --- a/app/views/admin/research/journals/show.html.erb +++ b/app/views/admin/research/journals/show.html.erb @@ -1,10 +1,12 @@ <% content_for :title, @journal %> <% content_for :title_right do %> - <% if @journal.website %> - <%= Communication::Website.model_name.human %> + <% if @journal.websites.any? %> + <%= Communication::Website.model_name.human(count: 2) %> <i class="fas fa-arrow-right small"></i> - <%= link_to @journal.website, [:admin, @journal.website] %><br> + <% @journal.websites.each do |website| %> + <%= link_to website, [:admin, website] %><br> + <% end %> <% end %> <% if @journal.issn %><%= Research::Journal.human_attribute_name('issn') %> <%= @journal.issn %><% end %> <% end %> diff --git a/app/views/admin/research/researchers/jekyll.html.erb b/app/views/admin/research/researchers/jekyll.html.erb index 446221fd2..698fec862 100644 --- a/app/views/admin/research/researchers/jekyll.html.erb +++ b/app/views/admin/research/researchers/jekyll.html.erb @@ -1,7 +1,7 @@ --- -title: "<%= "#{ @object }"%>" -first_name: "<%= @object.first_name %>" -last_name: "<%= @object.last_name %>" +title: "<%= "#{ @researcher }"%>" +first_name: "<%= @researcher.first_name %>" +last_name: "<%= @researcher.last_name %>" biography: > - <%= prepare_for_github @object.biography, @object.university %> + <%= prepare_for_github @researcher.biography, @researcher.university %> --- diff --git a/db/migrate/20211123132213_remove_unused_infos_from_research.rb b/db/migrate/20211123132213_remove_unused_infos_from_research.rb new file mode 100644 index 000000000..5fb6f2792 --- /dev/null +++ b/db/migrate/20211123132213_remove_unused_infos_from_research.rb @@ -0,0 +1,7 @@ +class RemoveUnusedInfosFromResearch < ActiveRecord::Migration[6.1] + def change + remove_column :research_researchers, :old_biography + remove_column :research_journal_articles, :github_path + remove_column :research_journal_volumes, :github_path + end +end diff --git a/db/schema.rb b/db/schema.rb index 32e1f8878..fb9b916fe 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.define(version: 2021_11_22_142007) do +ActiveRecord::Schema.define(version: 2021_11_23_132213) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -417,7 +417,6 @@ ActiveRecord::Schema.define(version: 2021_11_22_142007) do t.text "abstract" t.text "references" t.text "keywords" - t.text "github_path" t.index ["research_journal_id"], name: "index_research_journal_articles_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_articles_on_research_journal_volume_id" t.index ["university_id"], name: "index_research_journal_articles_on_university_id" @@ -441,7 +440,6 @@ ActiveRecord::Schema.define(version: 2021_11_22_142007) do t.datetime "updated_at", precision: 6, null: false t.text "description" t.text "keywords" - t.text "github_path" t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id" t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end @@ -461,7 +459,6 @@ ActiveRecord::Schema.define(version: 2021_11_22_142007) do create_table "research_researchers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "first_name" t.string "last_name" - t.text "old_biography" t.uuid "user_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index e00449085..92f5579ce 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -10,7 +10,7 @@ namespace :app do task fix: :environment do # Communication::Website::Post.find_each { |post| post.update(text: post.old_text) } # Communication::Website::Page.find_each { |page| page.update(text: page.old_text) } - Research::Researcher.find_each { |researcher| researcher.update(biography: researcher.old_biography) if researcher.biography.blank? } + # Research::Researcher.find_each { |researcher| researcher.update(biography: researcher.old_biography) if researcher.biography.blank? } Research::Journal::Article.find_each { |article| article.update(text: article.old_text) if article.text.blank? } Communication::Website.find_each { |website| website.build_home(university_id: website.university_id).save if website.home.nil? } end -- GitLab