diff --git a/app/assets/stylesheets/parts/tables.scss b/app/assets/stylesheets/parts/tables.scss
index a8bfbd1e3..eb6671a7d 100644
--- a/app/assets/stylesheets/parts/tables.scss
+++ b/app/assets/stylesheets/parts/tables.scss
@@ -27,6 +27,9 @@ body#registrations-edit table {
td,
th {
padding: 0.25rem;
+ &.left {
+ text-align: left;
+ }
&.date {
white-space: nowrap;
}
@@ -52,3 +55,15 @@ body#registrations-edit td {
}
}
}
+
+// To build scrollable table, we need to wrap them into a container
+.table_container {
+ max-width: 100%;
+ overflow-x: auto;
+ td,
+ th {
+ &.number {
+ white-space: nowrap;
+ }
+ }
+}
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index bc14cda41..ae93d7678 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -5,12 +5,16 @@ class DashboardController < ApplicationController
def index
@self_answer = params[:self] == "1"
+ # News
+ @candidates = News.where(author_email: current_account.email).candidate
+ @drafts = News.where(author_email: current_account.email).draft
+ # Comment threads
@comments = current_user.comments.on_dashboard.limit(30)
@comments = @comments.where(answered_to_self: false) unless @self_answer
- @posts = Node.where(user_id: current_user.id).on_dashboard(Post).limit(10)
+ # Other nodes
+ @nodes = Node.where(user_id: current_user.id).on_dashboard([News, Diary, Bookmark, Post, WikiPage]).limit(10)
+ # Trackers can get very old, so keep them in their own dashboard
@trackers = Node.where(user_id: current_user.id).on_dashboard(Tracker).limit(10)
- @news = News.where(author_email: current_account.email).candidate
- @drafts = News.where(author_email: current_account.email).draft
end
def answers
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 32ba6b0d2..bcd0d8e16 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -31,6 +31,11 @@ class Comment < ActiveRecord::Base
scope :under, ->(path) { where("materialized_path LIKE ?", "#{path}_%") }
scope :published, -> { where(state: 'published') }
scope :on_dashboard, -> { published.order(created_at: :desc) }
+ scope :latest_published, -> {
+ published.
+ order(created_at: :desc).
+ limit(1)
+ }
scope :footer, -> {
# MariaDB tries to scan nodes first, which is a very slow, so we add an index hint
from("comments USE INDEX (index_comments_on_state_and_created_at)").published.
@@ -139,6 +144,14 @@ def notify_parents
end
end
+ after_create :notify_node_owner
+ def notify_node_owner
+ if user_id != node.user_id
+ node_owner = node.user.try(:account)
+ node_owner.notify_answer_on node_id if node_owner
+ end
+ end
+
### Calculations ###
before_validation :default_score, on: :create
@@ -155,7 +168,7 @@ def nb_answers
self.class.published.under(materialized_path).count
end
- def last_answer
+ def latest_answer
self.class.published.under(materialized_path).last
end
diff --git a/app/models/node.rb b/app/models/node.rb
index 5b4460f06..5080234e6 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -32,7 +32,7 @@ class Node < ActiveRecord::Base
scope :visible, -> { where(public: true) }
scope :by_date, -> { order(created_at: :desc) }
scope :published_on, ->(d) { where(created_at: (d...d+1.day)) }
- scope :on_dashboard, ->(type) { public_listing(type, "created_at") }
+ scope :on_dashboard, ->(types) { public_listing(types, "created_at") }
scope :sitemap, ->(types) { public_listing(types, "id").where("score > 0") }
scope :public_listing, ->(types, order) {
types.map!(&:to_s) if types.is_a? Array
@@ -106,6 +106,10 @@ def threads
@threads ||= Threads.all(self.id)
end
+ def latest_answer
+ comments.latest_published.first
+ end
+
### Readings ###
def self.readings_keys_of(account_id)
diff --git a/app/views/dashboard/_candidates.html.haml b/app/views/dashboard/_candidates.html.haml
new file mode 100644
index 000000000..f188cff67
--- /dev/null
+++ b/app/views/dashboard/_candidates.html.haml
@@ -0,0 +1,19 @@
+%h2
+ Vos dépêches en attente de modération
+- if @candidates.empty?
+ Vous n’avez aucune dépêche en cours de modération
+- else
+ .table_container
+ %table#my_candidates
+ %tr
+ %th.left Section
+ %th.left Sujet
+ %th.left Date de soumission
+ - @candidates.each do |news|
+ %tr
+ %td= news.section.title
+ - if current_account.amr?
+ %td= link_to news.title, [:moderation, news]
+ - else
+ %td= news.title
+ %td= l news.node.created_at
diff --git a/app/views/dashboard/_comments.html.haml b/app/views/dashboard/_comments.html.haml
index 3efcaf0ae..cf4c47d83 100644
--- a/app/views/dashboard/_comments.html.haml
+++ b/app/views/dashboard/_comments.html.haml
@@ -9,24 +9,25 @@
-else
= link_to "Inclure les réponses à mes commentaires", self: "1"
%br
- %table#my_comments
- %tr
- %th Fil initiateur
- %th Sujet du commentaire
- %th Date
- %th Note
- %th Rép.
- %th Dernière réponse
- - @comments.each do |comment|
- - next if comment.node.nil?
- - answer = comment.last_answer
+ .table_container
+ %table#my_comments
%tr
- %td #{translate_content_type comment.content_type} : #{link_to_content comment.content}
- %td= link_to comment.title, path_for_content(comment.node.content) + "#comment-#{comment.id}"
- %td.date= comment.created_at.to_s(:posted)
- %td.number= comment.bound_score
- %td.number
- - if answer && !answer.read_by?(current_account)
- = image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
- = comment.nb_answers
- %td.date= answer ? answer.created_at.to_s(:posted) : " "
+ %th.left Fil initiateur
+ %th.left Sujet du commentaire
+ %th.left Date
+ %th.number Note
+ %th.number Rép.
+ %th.left Dernière réponse
+ - @comments.each do |comment|
+ - next if comment.node.nil?
+ - answer = comment.latest_answer
+ %tr
+ %td #{translate_content_type comment.content_type} : #{link_to_content comment.content}
+ %td= link_to comment.title, path_for_content(comment.node.content) + "#comment-#{comment.id}"
+ %td.date= comment.created_at.to_s(:posted)
+ %td.number= comment.bound_score
+ %td.number
+ - if answer && !answer.read_by?(current_account)
+ = image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
+ = comment.nb_answers
+ %td.date= answer ? answer.created_at.to_s(:posted) : " "
diff --git a/app/views/dashboard/_drafts.html.haml b/app/views/dashboard/_drafts.html.haml
index 4e178bbd3..df84e0f9a 100644
--- a/app/views/dashboard/_drafts.html.haml
+++ b/app/views/dashboard/_drafts.html.haml
@@ -5,9 +5,9 @@
- else
%table#my_drafts
%tr
- %th Section
- %th Sujet
- %th Date de création
+ %th.left Section
+ %th.left Sujet
+ %th.left Date de création
- @drafts.each do |news|
%tr
%td= news.section.title
diff --git a/app/views/dashboard/_news.html.haml b/app/views/dashboard/_news.html.haml
deleted file mode 100644
index 28ca168a4..000000000
--- a/app/views/dashboard/_news.html.haml
+++ /dev/null
@@ -1,18 +0,0 @@
-%h2
- Vos dépêches en attente de modération
-- if @news.empty?
- Vous n’avez aucune dépêche en cours de modération
-- else
- %table#my_news
- %tr
- %th Section
- %th Sujet
- %th Date de soumission
- - @news.each do |news|
- %tr
- %td= news.section.title
- - if current_account.amr?
- %td= link_to news.title, [:moderation, news]
- - else
- %td= news.title
- %td= l news.node.created_at
diff --git a/app/views/dashboard/_nodes.html.haml b/app/views/dashboard/_nodes.html.haml
new file mode 100644
index 000000000..de608dc20
--- /dev/null
+++ b/app/views/dashboard/_nodes.html.haml
@@ -0,0 +1,37 @@
+%h2
+ Vos derniers contenus publiés
+- if contents.empty?
+ %p
+ Vous n’avez aucun contenu publié
+- else
+ %p
+ Ce tableau de bord vous montre vos 10 contenus les plus récemment publiés.
+ %br
+ Pour retrouver tous vos contenus, visitez votre profile : #{link_to(current_account.login, current_account.user)}.
+ .table_container
+ %table#my_published
+ %tr
+ %th.left Type
+ %th.left Section / Forum
+ %th.left Sujet
+ %th.left Date
+ %th.number Note
+ %th.number Comm.
+ %th.left Dernier commentaire
+ - contents.each do |node|
+ %tr
+ %td= translate_content_type node.content_type
+ %td
+ - if node.content.is_a? News
+ = node.content.section.title
+ - if node.content.is_a? Post
+ = node.content.forum.title
+ %td
+ = link_to_content node.content
+ %td.date= node.created_at.to_s(:posted)
+ %td.number= node.score
+ %td.number
+ - if node.read_status(current_account).is_a? Integer
+ = image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
+ = node.comments_count
+ %td.date= node.latest_answer ? node.latest_answer.created_at.to_s(:posted) : " "
diff --git a/app/views/dashboard/_posts.html.haml b/app/views/dashboard/_posts.html.haml
deleted file mode 100644
index 9b1b9bcdf..000000000
--- a/app/views/dashboard/_posts.html.haml
+++ /dev/null
@@ -1,21 +0,0 @@
-%h2
- Vos derniers messages dans les forums
-- if @posts.empty?
- %p
- Vous n’avez posté aucun message dans les forums
-- else
- %table#my_posts
- %tr
- %th Forum
- %th Sujet
- %th Note
- %th Nombre de commentaires
- %th Date du message
- - @posts.each do |node|
- - post = node.content
- %tr
- %td= post.forum.title
- %td= link_to post.title, [post.forum, post]
- %td.number= node.score
- %td.number= node.comments.count
- %td.date= post.created_at.to_s(:posted)
diff --git a/app/views/dashboard/_trackers.html.haml b/app/views/dashboard/_trackers.html.haml
index e99eb872b..6ba1a8442 100644
--- a/app/views/dashboard/_trackers.html.haml
+++ b/app/views/dashboard/_trackers.html.haml
@@ -4,20 +4,27 @@
%p
Vous n’avez posté aucune entrée dans le suivi
- else
- %table#my_trackers
- %tr
- %th Catégorie
- %th Sujet
- %th État
- %th Note
- %th Nombre de commentaires
- %th Date du message
- - @trackers.each do |node|
- - tracker = node.content
- %tr{class: tracker.state}
- %td= tracker.category.title
- %td= link_to tracker.title, tracker
- %td= tracker.state_name
- %td.number= node.score
- %td.number= node.comments.count
- %td.date= tracker.created_at.to_s(:posted)
+ .table_container
+ %table#my_trackers
+ %tr
+ %th.left Catégorie
+ %th.left Sujet
+ %th.left Date
+ %th.left État
+ %th.number Note
+ %th.number Comm.
+ %th.left Dernier commentaire
+ - @trackers.each do |node|
+ - tracker = node.content
+ - answer = node.latest_answer
+ %tr{class: tracker.state}
+ %td= tracker.category.title
+ %td= link_to tracker.title, tracker
+ %td.date= tracker.created_at.to_s(:posted)
+ %td= tracker.state_name
+ %td.number= node.score
+ %td.number
+ - if answer && !answer.read_by?(current_account)
+ = image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
+ = node.comments.count
+ %td.date= answer ? answer.created_at.to_s(:posted) : " "
diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml
index 04ddc6a25..f7d64e032 100644
--- a/app/views/dashboard/index.html.haml
+++ b/app/views/dashboard/index.html.haml
@@ -5,7 +5,7 @@
=h1 "Votre tableau de bord"
= render 'drafts'
- = render 'news'
+ = render 'candidates'
+ = render 'nodes', contents: @nodes
= render 'comments'
- = render 'posts'
= render 'trackers'