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

almost there (except the attachments)

parent a2fc170d
No related branches found
No related tags found
No related merge requests found
......@@ -23,24 +23,14 @@
#
class Communication::Extranet::File < ApplicationRecord
include Sanitizable
include WithPublication
include WithUniversity
belongs_to :extranet, class_name: 'Communication::Extranet'
validates :name, presence: true
before_validation :set_published_at
scope :published, -> { where(published: true) }
scope :ordered, -> { order(published_at: :desc) }
def to_s
"#{name}"
end
protected
def set_published_at
self.published_at = Time.zone.now if published && published_at.nil?
end
end
......@@ -33,6 +33,7 @@ class Communication::Extranet::Post < ApplicationRecord
include WithUniversity
include WithFeaturedImage
include WithBlocks
include WithPublication
include WithPermalink
include WithSlug
......@@ -41,11 +42,6 @@ class Communication::Extranet::Post < ApplicationRecord
validates :title, presence: true
before_validation :set_published_at
scope :published, -> { where(published: true) }
scope :ordered, -> { order(published_at: :desc) }
def to_s
"#{title}"
end
......@@ -58,8 +54,4 @@ class Communication::Extranet::Post < ApplicationRecord
.where.not(id: self.id)
.exists?
end
def set_published_at
self.published_at = Time.zone.now if published && published_at.nil?
end
end
module WithPublication
extend ActiveSupport::Concern
included do
scope :published, -> { where(published: true) }
scope :draft, -> { where(published: false) }
scope :ordered, -> { order(published_at: :desc) }
before_validation :set_published_at
end
def draft?
!published || published_in_the_future?
end
def published_in_the_future?
published && published_at > Time.now
end
protected
def set_published_at
self.published_at = Time.zone.now if published && published_at.nil?
end
end
......@@ -3,19 +3,21 @@
<thead>
<tr>
<th class="ps-0" width="60%"><%= Communication::Extranet::File.human_attribute_name('name') %></th>
<th class="ps-3"><%= Communication::Extranet::File.human_attribute_name('published') %></th>
<th colspan="2" class="ps-3"><%= Communication::Extranet::File.human_attribute_name('meta') %></th>
</tr>
</thead>
<tbody>
<% files.each do |file| %>
<tr <% unless file.published? %>class="draft"<% end %>>
<tr <% if file.draft? %>class="draft"<% end %>>
<td class="ps-0">
<%= link_to file,
admin_communication_extranet_file_path(extranet_id: file.extranet.id, id: file.id),
class: "#{'draft' unless file.published?}" %>
</td>
<td class="ps-3 small">
<%= l file.published_at, format: :date_with_explicit_month if file.published_at %><br>
<%= t file.published %>,
<%= l file.published_at, format: :date_with_explicit_month if file.published_at %>
</td>
<td>
<div class="btn-group" role="group">
......
......@@ -4,6 +4,7 @@
<tr>
<th class="ps-0" width="60%"><%= Communication::Extranet::Post.human_attribute_name('title') %></th>
<th><%= Communication::Extranet::Post.human_attribute_name('featured_image') %></th>
<th class="ps-3"><%= Communication::Extranet::Post.human_attribute_name('published') %></th>
<th colspan="2" class="ps-3"><%= Communication::Extranet::Post.human_attribute_name('meta') %></th>
</tr>
</thead>
......@@ -16,6 +17,7 @@
<td><%= image_tag post.featured_image.representation(resize: '200x'),
width: 100 if post.featured_image.attached? && post.featured_image.representable? %></td>
<td class="ps-3 small">
<%= t post.published %>,
<%= l post.published_at, format: :date_with_explicit_month if post.published_at %><br>
<%= post.author %>
</td>
......
<% content_for :title, Communication::Extranet::File.model_name.human(count: 2) %>
<% content_for :title, Communication::Extranet.human_attribute_name(:feature_files) %>
<%= render 'extranet/files/files/list', files: @files %>
\ No newline at end of file
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