Skip to content
Snippets Groups Projects
Commit a218c5c8 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

authors

parent 75a8d31f
No related branches found
No related tags found
No related merge requests found
Showing
with 65 additions and 8 deletions
......@@ -56,6 +56,6 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A
end
def article_params
params.require(:research_journal_article).permit(:title, :text, :published_at, :research_journal_volume_id)
params.require(:research_journal_article).permit(:title, :text, :published_at, :research_journal_volume_id, researcher_ids: [])
end
end
......@@ -32,6 +32,7 @@ class Research::Journal::Article < ApplicationRecord
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'
after_save :publish_to_github
......@@ -54,5 +55,17 @@ class Research::Journal::Article < ApplicationRecord
data: data,
remote_file: "_articles/#{id}.md",
commit_message: "Save volume #{ title }"
researchers.each do |researcher|
github.publish local_directory: "tmp/researchers",
local_file: "#{researcher.id}.md",
data: ApplicationController.render(
template: 'admin/research/researchers/jekyll',
layout: false,
assigns: { researcher: researcher }
),
remote_file: "_researchers/#{ researcher.id }.md",
commit_message: "Save researcher #{ researcher }"
end
end
end
......@@ -20,6 +20,7 @@
#
class Research::Researcher < ApplicationRecord
belongs_to :user, optional: true
has_and_belongs_to_many :articles, class_name: 'Research::Journal::Article'
def to_s
"#{ first_name } #{ last_name }"
......
......@@ -4,6 +4,7 @@
<%= f.input :title %>
<%= f.association :volume, collection: @journal.volumes %>
<%= f.input :published_at, html5: true %>
<%= f.association :researchers %>
</div>
<div class="col-md-8">
<%= f.input :text, input_html: { rows: 30 } %>
......
......@@ -4,7 +4,7 @@
<thead>
<tr>
<th><%= Research::Journal::Article.model_name.human %></th>
<th>Published at</th>
<th><%= Research::Journal::Article.human_attribute_name('published_at') %></th>
<th></th>
</tr>
</thead>
......
<% content_for :title, @article %>
<p>
<strong>Published at:</strong>
<strong><%= Research::Journal::Article.human_attribute_name('published_at') %></strong>
<%= @article.published_at&.to_date %>
</p>
<p>
<strong><%= Research::Journal::Article.human_attribute_name('researchers') %></strong>
<ul>
<% @article.researchers.each do |researcher| %>
<li><%= link_to researcher, [:admin, researcher] %></li>
<% end %>
</ul>
</p>
<%= @article.text %>
<% content_for :buttons do %>
......
---
first_name: "<%= @researcher.first_name %>"
last_name: <%= @researcher.last_name %>
biography: "<%= @researcher.biography %>"
---
......@@ -16,11 +16,20 @@
</p>
<% if @researcher.user %>
<p>
<strong><%= Research::Researcher.human_attribute_name('user') %></strong>
<%= link_to @researcher.user, [:admin, @researcher.user] %>
</p>
<% end %>
<p>
<strong><%= Research::Researcher.human_attribute_name('user') %></strong>
<%= link_to @researcher.user, [:admin, @researcher.user] %>
<strong><%= Research::Researcher.human_attribute_name('articles') %></strong>
<ul>
<% @researcher.articles.each do |article| %>
<li><%= link_to article, admin_research_journal_article_path(journal_id: article.journal.id, id: article) %></li>
<% end %>
</ul>
</p>
<% end %>
<% content_for :buttons do %>
<%= edit_link @researcher %>
......
......@@ -19,6 +19,9 @@ fr:
attributes:
research/journal:
title: Titre
research/journal/article:
title: Titre
researchers: Auteu·rs·rices
research/researcher:
first_name: Prénom
last_name: Nom
......
class CreateJoinTableResearchResearcherJournalArticle < ActiveRecord::Migration[6.1]
def change
create_table :research_journal_articles_researchers do |t|
t.references :researcher, null: false, foreign_key: {to_table: :research_researchers}, type: :uuid
t.references :article, null: false, foreign_key: {to_table: :research_journal_articles}, type: :uuid
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_09_07_152734) do
ActiveRecord::Schema.define(version: 2021_09_07_155328) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
......@@ -109,6 +109,13 @@ ActiveRecord::Schema.define(version: 2021_09_07_152734) do
t.index ["updated_by_id"], name: "index_research_journal_articles_on_updated_by_id"
end
create_table "research_journal_articles_researchers", force: :cascade do |t|
t.uuid "researcher_id", null: false
t.uuid "article_id", null: false
t.index ["article_id"], name: "index_research_journal_articles_researchers_on_article_id"
t.index ["researcher_id"], name: "index_research_journal_articles_researchers_on_researcher_id"
end
create_table "research_journal_volumes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "research_journal_id", null: false
......@@ -196,6 +203,8 @@ ActiveRecord::Schema.define(version: 2021_09_07_152734) do
add_foreign_key "research_journal_articles", "research_journals"
add_foreign_key "research_journal_articles", "universities"
add_foreign_key "research_journal_articles", "users", column: "updated_by_id"
add_foreign_key "research_journal_articles_researchers", "research_journal_articles", column: "article_id"
add_foreign_key "research_journal_articles_researchers", "research_researchers", column: "researcher_id"
add_foreign_key "research_journal_volumes", "research_journals"
add_foreign_key "research_journal_volumes", "universities"
add_foreign_key "research_journals", "universities"
......
......@@ -18,7 +18,6 @@
#
# fk_rails_... (user_id => users.id)
#
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
first_name: MyString
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment