Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/assets/stylesheets/parts/content.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* contenu du site (hors commentaire) */
article,
ul.threads > li.comment,
ul.comments_list > li.comment,
.markdown_cheatsheet,
#contents > form,
form#new_post,
Expand Down Expand Up @@ -30,6 +31,10 @@ body#wiki_pages-changes #contents {
font-size: 1em;
}

#contents > ul.comments_list {
padding: 0;
}

article {
position: relative;
header {
Expand Down
16 changes: 13 additions & 3 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: UTF-8
class CommentsController < ApplicationController
before_action :authenticate_account!, except: [:index, :show]
before_action :find_node, except: [:templeet]
before_action :find_comment, except: [:index, :new, :answer, :create, :templeet]
before_action :authenticate_account!, except: [:index, :show, :latest]
before_action :find_node, except: [:templeet, :latest]
before_action :find_comment, except: [:index, :new, :answer, :create, :templeet, :latest]

def index
@comments = @node.comments.published.order('id DESC')
Expand All @@ -12,6 +12,16 @@ def index
end
end

def latest
@comments = Comment.latest.
page(params[:page]).
order(created_at: :desc)
respond_to do |wants|
wants.html
wants.atom
end
end

def show
enforce_view_permission(@comment)
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Comment < ActiveRecord::Base
limit(12).
select([:id, :node_id, :title])
}
scope :latest, -> {
where(["created_at >= ?", Date.current - 7.day])
}

paginates_per 50

validates :title, presence: { message: "Le titre est obligatoire" },
length: { maximum: 100, message: "Le titre est trop long" }
Expand Down
25 changes: 25 additions & 0 deletions app/views/comments/latest.atom.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
atom_feed(:root_url => comments_latest_url) do |feed|
feed.title("LinuxFr.org : les derniers commentaires")
feed.updated(@comments.first.try :created_at)
feed.icon("/favicon.png")

@comments.each do |comment|
feed.entry(comment, :url => "#{url_for_content comment.node.content}#comment-#{comment.id}") do |entry|
in_response_to = content_tag(:p,
content_tag(:em,
"En réponse #{translate_to_content_type comment.content_type} #{link_to comment.node.content.title, path_for_content(comment.node.content)}.".html_safe
)
)
if comment.deleted?
entry.title("Commentaire supprimé")
entry.content("#{content_tag(:p, "Commentaire supprimé")} #{in_response_to}", :type => 'html')
else
entry.title(comment.title)
entry.content("#{comment.body} #{in_response_to}", :type => 'html')
end
entry.author do |author|
author.name(comment.user_name)
end
end
end
end
15 changes: 15 additions & 0 deletions app/views/comments/latest.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
= h1 "Les derniers commentaires"
- feed "Flux Atom des derniers commentaires"
%nav.toolbox
.follow_feed
= link_to "Flux Atom des derniers commentaires", "latest.atom"
-# order is not managed, but order_navbar is required due to float property on follow_feed div
.order_navbar
&nbsp;
%main#contents(role="main")
%ul.comments_list
- @comments.each do |comment|
%li.comment(id="comment-#{comment.id}")
= render comment
%nav.toolbox
= paginate(@comments, inner_window:10)
3 changes: 3 additions & 0 deletions app/views/moderation/news/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
%h2
= link_to "Étiquettes publiques", moderation_tags_path

%h2
= link_to "Derniers commentaires", comments_latest_path

%h2
= link_to "Sondages", moderation_polls_path
- if @polls.empty?
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
# Nodes
get "/tableau-de-bord" => "dashboard#index", as: :dashboard
get "/tableau-de-bord/reponses" => "dashboard#answers"
get "/comments/latest" => "comments#latest"
get "/comments/:id(,:d)(.html)" => "comments#templeet"
resources :nodes, only: [] do
resources :comments do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexOnCreatedAtToComments < ActiveRecord::Migration[5.2]
def change
add_index :comments, [:created_at], order: {created_at: :desc}
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_01_31_231806) do
ActiveRecord::Schema.define(version: 2021_09_13_191843) do

create_table "accounts", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
t.integer "user_id"
Expand Down Expand Up @@ -93,6 +93,7 @@
t.text "wiki_body", limit: 16777215
t.datetime "created_at"
t.datetime "updated_at"
t.index ["created_at"], name: "index_comments_on_created_at"
t.index ["node_id"], name: "index_comments_on_node_id"
t.index ["state", "created_at"], name: "index_comments_on_state_and_created_at"
t.index ["state", "materialized_path"], name: "index_comments_on_state_and_materialized_path", length: { materialized_path: 120 }
Expand Down