diff --git a/app/controllers/admin/research/publications_controller.rb b/app/controllers/admin/research/publications_controller.rb index 26ab47d50efa5f8172bc5b3aeeb2c84dee4e2f6f..9c9a4d052097f50d4000e48251fa12a55a21969d 100644 --- a/app/controllers/admin/research/publications_controller.rb +++ b/app/controllers/admin/research/publications_controller.rb @@ -10,6 +10,11 @@ class Admin::Research::PublicationsController < Admin::Research::ApplicationCont breadcrumb end + def static + @about = Research::Publication.find params[:id] + render layout: false + end + def update @publication = Research::Publication.find params[:id] # TODO update from api diff --git a/app/models/research/publication.rb b/app/models/research/publication.rb index b9d50e48acf93940dd9c84691cbfac7455f25a76..9432ec9e0a389e82eb535927ba18e8c48184efba 100644 --- a/app/models/research/publication.rb +++ b/app/models/research/publication.rb @@ -9,17 +9,22 @@ # hal_url :string # publication_date :date # ref :string +# slug :string # title :string # url :string # created_at :datetime not null # updated_at :datetime not null # class Research::Publication < ApplicationRecord + include WithGit + include WithSlug + has_and_belongs_to_many :research_people, class_name: 'University::Person', foreign_key: 'university_person_id', association_foreign_key: 'research_publication_id' alias :researchers :research_people + before_destroy { research_people.clear } validates_presence_of :docid @@ -39,6 +44,10 @@ class Research::Publication < ApplicationRecord publication end + def template_static + "admin/research/publications/static" + end + def doi_url return unless doi.present? "http://dx.doi.org/#{doi}" @@ -47,4 +56,13 @@ class Research::Publication < ApplicationRecord def to_s "#{title}" end + + protected + + def slug_unavailable?(slug) + self.class.unscoped + .where(slug: slug) + .where.not(id: self.id) + .exists? + end end diff --git a/app/views/admin/research/publications/_list.html.erb b/app/views/admin/research/publications/_list.html.erb index 4ebbe4c55909110ee464f2ecd291ab6159a89014..b03ba32612477a128d8eacbfb6c8c99eecb23cb4 100644 --- a/app/views/admin/research/publications/_list.html.erb +++ b/app/views/admin/research/publications/_list.html.erb @@ -12,7 +12,9 @@ <td><%= link_to publication, admin_research_publication_path(publication) %></td> <td> <% publication.researchers.each do |researcher| %> - <%= link_to researcher, admin_research_researcher_path(researcher) %> + <%= link_to_if researcher.university == current_university, + researcher, + admin_research_researcher_path(researcher) %> <% end %> </td> </tr> diff --git a/app/views/admin/research/publications/show.html.erb b/app/views/admin/research/publications/show.html.erb index 060d9294aa933ada72b2622498fd5a74406eb72e..9ca0010a81330855f533496fc4bb6cdb512a2724 100644 --- a/app/views/admin/research/publications/show.html.erb +++ b/app/views/admin/research/publications/show.html.erb @@ -12,3 +12,8 @@ <%= link_to 'HAL', @publication.hal_url, target: :_blank if @publication.hal_url %> <%= link_to 'DOI', @publication.doi_url, target: :_blank if @publication.doi_url %> +<% content_for :action_bar_left do %> + <%= link_to t('static'), + static_admin_research_publication_path(@publication), + class: button_classes('btn-light') if current_user.server_admin? %> +<% end %> diff --git a/app/views/admin/research/publications/static.html.erb b/app/views/admin/research/publications/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..5910efe141522de01b82ee8447c1558390ce224e --- /dev/null +++ b/app/views/admin/research/publications/static.html.erb @@ -0,0 +1,16 @@ +--- +title: "<%= @about.title %>" +date: "<%= @about.publication_date&.iso8601 %>" +slug: "<%= @about.slug %>" +docid: "<%= @about.docid %>" +ref: > + <%= sanitize @about.ref %> +url: + hal: "<%= @about.hal_url %>" + doi: "<%= @about.doi_url %>" + raw: "<%= @about.url %>" +researchers: +<% @about.researchers.each do |researcher| %> + - <%= researcher.slug %> +<% end %> +--- diff --git a/config/routes/admin/research.rb b/config/routes/admin/research.rb index 507867bf425dee5814bbdbe712ecdefbbbecc6c9..07af5308b7efb6eea6de132a1db7fed73fa820d6 100644 --- a/config/routes/admin/research.rb +++ b/config/routes/admin/research.rb @@ -1,6 +1,10 @@ namespace :research do resources :researchers, only: [:index, :show, :update] - resources :publications, only: [:index, :show, :update] + resources :publications, only: [:index, :show, :update] do + member do + get :static + end + end resources :journals do resources :volumes, controller: 'journals/volumes' resources :papers, controller: 'journals/papers' do diff --git a/db/migrate/20230115162644_add_slug_to_research_publications.rb b/db/migrate/20230115162644_add_slug_to_research_publications.rb new file mode 100644 index 0000000000000000000000000000000000000000..c9c4db47e9c5a4511fc631156c1231c6afc7a844 --- /dev/null +++ b/db/migrate/20230115162644_add_slug_to_research_publications.rb @@ -0,0 +1,5 @@ +class AddSlugToResearchPublications < ActiveRecord::Migration[7.0] + def change + add_column :research_publications, :slug, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3a0b5aadd7d52259a7075666d9d6145cfc189d92..fac3dcdacb10d31cbc597271b5a0645b0f33271c 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_15_092626) do +ActiveRecord::Schema[7.0].define(version: 2023_01_15_162644) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -671,6 +671,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_15_092626) do t.string "hal_url" t.date "publication_date" t.string "doi" + t.string "slug" end create_table "research_publications_university_people", id: false, force: :cascade do |t|