Skip to content
Open
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
15 changes: 15 additions & 0 deletions app/assets/stylesheets/parts/tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ body#registrations-edit table {
td,
th {
padding: 0.25rem;
&.left {
text-align: left;
}
&.date {
white-space: nowrap;
}
Expand All @@ -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;
}
}
}
10 changes: 7 additions & 3 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions app/views/dashboard/_candidates.html.haml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 21 additions & 20 deletions app/views/dashboard/_comments.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <abbr title="Nombre de réponses">Rép.</abbr>
%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 <abbr title="Nombre de réponses">Rép.</abbr>
%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) : " "
6 changes: 3 additions & 3 deletions app/views/dashboard/_drafts.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions app/views/dashboard/_news.html.haml

This file was deleted.

37 changes: 37 additions & 0 deletions app/views/dashboard/_nodes.html.haml
Original file line number Diff line number Diff line change
@@ -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&nbsp;: #{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 <abbr title="Nombre de commentaires">Comm.</abbr>
%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) : " "
21 changes: 0 additions & 21 deletions app/views/dashboard/_posts.html.haml

This file was deleted.

41 changes: 24 additions & 17 deletions app/views/dashboard/_trackers.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <abbr title="Nombre de commentaires">Comm.</abbr>
%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) : " "
4 changes: 2 additions & 2 deletions app/views/dashboard/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'