Skip to content

Commit eb2a7e9

Browse files
committed
notify node owner for new answer, add all content to dashboard
Notify owner of any type of content for new answers (in existing thread or new thread). Add a dashboard showing latest 10 contents published of any type, so the author can follow easily new threads and comments on his/her content. For small screends, the dashboards are scrollable to avoid them to break the application layout. Dashboard titles are aligned with content (aligned on right for numbers and left for the rest).
1 parent 1d72a29 commit eb2a7e9

12 files changed

Lines changed: 147 additions & 86 deletions

File tree

app/assets/stylesheets/parts/tables.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ body#registrations-edit table {
2727
td,
2828
th {
2929
padding: 0.25rem;
30+
&.left {
31+
text-align: left;
32+
}
3033
&.date {
3134
white-space: nowrap;
3235
}
@@ -52,3 +55,15 @@ body#registrations-edit td {
5255
}
5356
}
5457
}
58+
59+
// To build scrollable table, we need to wrap them into a container
60+
.table_container {
61+
max-width: 100%;
62+
overflow-x: auto;
63+
td,
64+
th {
65+
&.number {
66+
white-space: nowrap;
67+
}
68+
}
69+
}

app/controllers/dashboard_controller.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ class DashboardController < ApplicationController
55

66
def index
77
@self_answer = params[:self] == "1"
8+
# News
9+
@candidates = News.where(author_email: current_account.email).candidate
10+
@drafts = News.where(author_email: current_account.email).draft
11+
# Comment threads
812
@comments = current_user.comments.on_dashboard.limit(30)
913
@comments = @comments.where(answered_to_self: false) unless @self_answer
10-
@posts = Node.where(user_id: current_user.id).on_dashboard(Post).limit(10)
14+
# Other nodes
15+
@nodes = Node.where(user_id: current_user.id).on_dashboard([News, Diary, Bookmark, Post, WikiPage]).limit(10)
16+
# Trackers can get very old, so keep them in their own dashboard
1117
@trackers = Node.where(user_id: current_user.id).on_dashboard(Tracker).limit(10)
12-
@news = News.where(author_email: current_account.email).candidate
13-
@drafts = News.where(author_email: current_account.email).draft
1418
end
1519

1620
def answers

app/models/comment.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Comment < ActiveRecord::Base
3131
scope :under, ->(path) { where("materialized_path LIKE ?", "#{path}_%") }
3232
scope :published, -> { where(state: 'published') }
3333
scope :on_dashboard, -> { published.order(created_at: :desc) }
34+
scope :latest_published, -> {
35+
published.
36+
order(created_at: :desc).
37+
limit(1)
38+
}
3439
scope :footer, -> {
3540
# MariaDB tries to scan nodes first, which is a very slow, so we add an index hint
3641
from("comments USE INDEX (index_comments_on_state_and_created_at)").published.
@@ -139,6 +144,14 @@ def notify_parents
139144
end
140145
end
141146

147+
after_create :notify_node_owner
148+
def notify_node_owner
149+
if user_id != node.user_id
150+
node_owner = node.user.try(:account)
151+
node_owner.notify_answer_on node_id if node_owner
152+
end
153+
end
154+
142155
### Calculations ###
143156

144157
before_validation :default_score, on: :create
@@ -155,7 +168,7 @@ def nb_answers
155168
self.class.published.under(materialized_path).count
156169
end
157170

158-
def last_answer
171+
def latest_answer
159172
self.class.published.under(materialized_path).last
160173
end
161174

app/models/node.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Node < ActiveRecord::Base
3232
scope :visible, -> { where(public: true) }
3333
scope :by_date, -> { order(created_at: :desc) }
3434
scope :published_on, ->(d) { where(created_at: (d...d+1.day)) }
35-
scope :on_dashboard, ->(type) { public_listing(type, "created_at") }
35+
scope :on_dashboard, ->(types) { public_listing(types, "created_at") }
3636
scope :sitemap, ->(types) { public_listing(types, "id").where("score > 0") }
3737
scope :public_listing, ->(types, order) {
3838
types.map!(&:to_s) if types.is_a? Array
@@ -106,6 +106,10 @@ def threads
106106
@threads ||= Threads.all(self.id)
107107
end
108108

109+
def latest_answer
110+
comments.latest_published.first
111+
end
112+
109113
### Readings ###
110114

111115
def self.readings_keys_of(account_id)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%h2
2+
Vos dépêches en attente de modération
3+
- if @candidates.empty?
4+
Vous n’avez aucune dépêche en cours de modération
5+
- else
6+
.table_container
7+
%table#my_candidates
8+
%tr
9+
%th.left Section
10+
%th.left Sujet
11+
%th.left Date de soumission
12+
- @candidates.each do |news|
13+
%tr
14+
%td= news.section.title
15+
- if current_account.amr?
16+
%td= link_to news.title, [:moderation, news]
17+
- else
18+
%td= news.title
19+
%td= l news.node.created_at

app/views/dashboard/_comments.html.haml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@
99
-else
1010
= link_to "Inclure les réponses à mes commentaires", self: "1"
1111
%br
12-
%table#my_comments
13-
%tr
14-
%th Fil initiateur
15-
%th Sujet du commentaire
16-
%th Date
17-
%th Note
18-
%th <abbr title="Nombre de réponses">Rép.</abbr>
19-
%th Dernière réponse
20-
- @comments.each do |comment|
21-
- next if comment.node.nil?
22-
- answer = comment.last_answer
12+
.table_container
13+
%table#my_comments
2314
%tr
24-
%td #{translate_content_type comment.content_type} : #{link_to_content comment.content}
25-
%td= link_to comment.title, path_for_content(comment.node.content) + "#comment-#{comment.id}"
26-
%td.date= comment.created_at.to_s(:posted)
27-
%td.number= comment.bound_score
28-
%td.number
29-
- if answer && !answer.read_by?(current_account)
30-
= image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
31-
= comment.nb_answers
32-
%td.date= answer ? answer.created_at.to_s(:posted) : " "
15+
%th.left Fil initiateur
16+
%th.left Sujet du commentaire
17+
%th.left Date
18+
%th.number Note
19+
%th.number <abbr title="Nombre de réponses">Rép.</abbr>
20+
%th.left Dernière réponse
21+
- @comments.each do |comment|
22+
- next if comment.node.nil?
23+
- answer = comment.latest_answer
24+
%tr
25+
%td #{translate_content_type comment.content_type} : #{link_to_content comment.content}
26+
%td= link_to comment.title, path_for_content(comment.node.content) + "#comment-#{comment.id}"
27+
%td.date= comment.created_at.to_s(:posted)
28+
%td.number= comment.bound_score
29+
%td.number
30+
- if answer && !answer.read_by?(current_account)
31+
= image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
32+
= comment.nb_answers
33+
%td.date= answer ? answer.created_at.to_s(:posted) : " "

app/views/dashboard/_drafts.html.haml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
- else
66
%table#my_drafts
77
%tr
8-
%th Section
9-
%th Sujet
10-
%th Date de création
8+
%th.left Section
9+
%th.left Sujet
10+
%th.left Date de création
1111
- @drafts.each do |news|
1212
%tr
1313
%td= news.section.title

app/views/dashboard/_news.html.haml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
%h2
2+
Vos derniers contenus publiés
3+
- if contents.empty?
4+
%p
5+
Vous n’avez aucun contenu publié
6+
- else
7+
%p
8+
Ce tableau de bord vous montre vos 10 contenus les plus récemment publiés.
9+
%br
10+
Pour retrouver tous vos contenus, visitez votre profile&nbsp;: #{link_to(current_account.login, current_account.user)}.
11+
.table_container
12+
%table#my_published
13+
%tr
14+
%th.left Type
15+
%th.left Section / Forum
16+
%th.left Sujet
17+
%th.left Date
18+
%th.number Note
19+
%th.number <abbr title="Nombre de commentaires">Comm.</abbr>
20+
%th.left Dernier commentaire
21+
- contents.each do |node|
22+
%tr
23+
%td= translate_content_type node.content_type
24+
%td
25+
- if node.content.is_a? News
26+
= node.content.section.title
27+
- if node.content.is_a? Post
28+
= node.content.forum.title
29+
%td
30+
= link_to_content node.content
31+
%td.date= node.created_at.to_s(:posted)
32+
%td.number= node.score
33+
%td.number
34+
- if node.read_status(current_account).is_a? Integer
35+
= image_tag "/images/icones/comment.png", alt: "Nouveaux commentaires !", class: "thread-new-comments"
36+
= node.comments_count
37+
%td.date= node.latest_answer ? node.latest_answer.created_at.to_s(:posted) : " "

app/views/dashboard/_posts.html.haml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)