Skip to content
Snippets Groups Projects
Unverified Commit f71f7f20 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

published volume

parent 75bdc95e
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap
def volume_params
params.require(:research_journal_volume)
.permit(
:title, :slug, :number, :keywords, :published_at, :description,
:title, :slug, :number, :keywords, :published, :published_at, :description,
:featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt
)
.merge(university_id: current_university.id)
......
......@@ -57,7 +57,7 @@ class Research::Journal::Article < ApplicationRecord
scope :published, -> { where(published: true) }
def git_path(website)
"content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
"content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if (volume.nil? || volume.published_at) && published_at
end
def git_dependencies(website)
......
......@@ -7,6 +7,7 @@
# featured_image_alt :string
# keywords :text
# number :integer
# published :boolean default(FALSE)
# published_at :date
# slug :string
# title :string
......@@ -37,6 +38,9 @@ class Research::Journal::Volume < ApplicationRecord
has_many :websites, -> { distinct }, through: :journal
has_many :researchers, through: :articles
before_validation :set_published_at, if: :published_changed?
scope :published, -> { where(published: true) }
scope :ordered, -> { order(number: :desc, published_at: :desc) }
def website
......@@ -62,4 +66,10 @@ class Research::Journal::Volume < ApplicationRecord
def to_s
"##{ number } #{ title }"
end
protected
def set_published_at
self.published_at = published? ? Time.zone.now : nil
end
end
......@@ -28,7 +28,7 @@
<div class="card-body">
<% if @article.volume %>
<h3 class="h5"><%= Research::Journal::Article.human_attribute_name('volume') %></h3>
<p><%= link_to @article.volume, [:admin, @article.volume] %></p>
<p><%= link_to @article.volume, [:admin, @article.volume], class: "#{'opacity-50' unless @article.volume.published?}" %></p>
<% end %>
<h3 class="h5"><%= Research::Journal::Article.human_attribute_name('published') %></h3>
<p><%= t @article.published %></p>
......
......@@ -30,6 +30,7 @@
</div>
<div class="card-body">
<%= f.input :number %>
<%= f.input :published %>
<%= f.input :published_at, html5: true %>
<%= f.input :keywords %>
</div>
......
......@@ -12,7 +12,11 @@
<tbody>
<% @volumes.each do |volume| %>
<tr>
<td><%= link_to volume, admin_research_journal_volume_path(journal_id: @journal, id: volume) %></td>
<td>
<%= link_to volume,
admin_research_journal_volume_path(journal_id: @journal, id: volume),
class: "#{'opacity-50' unless volume.published?}" %>
</td>
<td><%= image_tag volume.featured_image.variant(resize: 'x200'),
height: 100 if volume.featured_image.attached? %></td>
<td><%= volume.published_at %></td>
......
......@@ -30,7 +30,9 @@
<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' %>
<%= link_to volume,
admin_research_journal_volume_path(journal_id: @journal, id: volume),
class: "stretched-link #{'opacity-50' unless volume.published?}" %>
</div>
</div>
</div>
......
......@@ -33,6 +33,7 @@ en:
description: Description
keywords: Keywords
number: Number
published: Published?
published_at: Published at
title: Title
research:
......
......@@ -33,6 +33,7 @@ fr:
description: Description
keywords: Mots clés
number: Numéro
published: Publié ?
published_at: Publié le
title: Titre
research:
......
class AddPublishedToResearchJournalVolumes < ActiveRecord::Migration[6.1]
def change
add_column :research_journal_volumes, :published, :boolean, default: false
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_01_11_092324) do
ActiveRecord::Schema.define(version: 2022_01_11_101410) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
......@@ -477,6 +477,7 @@ ActiveRecord::Schema.define(version: 2022_01_11_092324) do
t.text "keywords"
t.string "slug"
t.string "featured_image_alt"
t.boolean "published", default: false
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
......
......@@ -38,6 +38,9 @@ namespace :app do
})
end
end
Research::Journal::Volume.find_each do |volume|
volume.update_column :published, volume.published_at.present?
end
end
namespace :db do
......
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