Add Posts Read + Visits to User Directory

This commit is contained in:
Robin Ward 2015-03-24 15:31:07 -04:00
parent 66bda5267c
commit 1e3e4135a3
5 changed files with 31 additions and 4 deletions

View File

@ -4,8 +4,14 @@ import { iconHTML } from 'discourse/helpers/fa-icon';
export default Ember.Component.extend(StringBuffer, {
tagName: 'th',
classNames: ['sortable'],
attributeBindings: ['title'],
rerenderTriggers: ['order', 'asc'],
title: function() {
const labelKey = 'directory.' + this.get('field');
return I18n.t(labelKey + '_long', { defaultValue: I18n.t(labelKey) });
}.property('field'),
renderString(buffer) {
const icon = this.get('icon');

View File

@ -18,6 +18,8 @@
{{directory-toggle field="topic_count" order=order asc=asc}}
{{directory-toggle field="post_count" order=order asc=asc}}
{{directory-toggle field="topics_entered" order=order asc=asc}}
{{directory-toggle field="posts_read" order=order asc=asc}}
{{directory-toggle field="days_visited" order=order asc=asc}}
{{#if showTimeRead}}
<th>{{i18n "directory.time_read"}}</th>
{{/if}}
@ -31,6 +33,8 @@
<td>{{number item.model.topic_count}}</td>
<td>{{number item.model.post_count}}</td>
<td>{{number item.model.topics_entered}}</td>
<td>{{number item.model.posts_read}}</td>
<td>{{number item.model.days_visited}}</td>
{{#if showTimeRead}}
<td><span class='time-read'>{{unbound item.model.time_read}}</span></td>
{{/if}}

View File

@ -7,7 +7,9 @@ class DirectoryItem < ActiveRecord::Base
:likes_given,
:topics_entered,
:topic_count,
:post_count]
:post_count,
:posts_read,
:days_visited]
end
def self.period_types
@ -31,13 +33,15 @@ class DirectoryItem < ActiveRecord::Base
end
exec_sql "INSERT INTO directory_items
(period_type, user_id, likes_received, likes_given, topics_entered, topic_count, post_count)
(period_type, user_id, likes_received, likes_given, topics_entered, days_visited, posts_read, topic_count, post_count)
SELECT
:period_type,
u.id,
SUM(CASE WHEN ua.action_type = :was_liked_type THEN 1 ELSE 0 END),
SUM(CASE WHEN ua.action_type = :like_type THEN 1 ELSE 0 END),
(SELECT COUNT(topic_id) FROM topic_views AS v WHERE v.user_id = u.id AND v.viewed_at > :since),
COALESCE((SELECT COUNT(topic_id) FROM topic_views AS v WHERE v.user_id = u.id AND v.viewed_at >= :since), 0),
COALESCE((SELECT COUNT(id) FROM user_visits AS uv WHERE uv.user_id = u.id AND uv.visited_at >= :since), 0),
COALESCE((SELECT SUM(posts_read) FROM user_visits AS uv2 WHERE uv2.user_id = u.id AND uv2.visited_at >= :since), 0),
SUM(CASE WHEN ua.action_type = :new_topic_type THEN 1 ELSE 0 END),
SUM(CASE WHEN ua.action_type = :reply_type THEN 1 ELSE 0 END)
FROM users AS u

View File

@ -242,11 +242,18 @@ en:
title: "Users"
likes_given: "Given"
likes_received: "Received"
topics_entered: "Topics Entered"
topics_entered: "Entered"
topics_entered_long: "Topics Entered"
time_read: "Time Read"
topic_count: "Topics"
topic_count_long: "Topics Created"
post_count: "Replies"
post_count_long: "Replies Posted"
no_results: "No results were found."
days_visited: "Visits"
days_visited_long: "Days Visited"
posts_read: "Read"
posts_read_long: "Posts Read"
total_rows:
one: "1 user"
other: "%{count} users"

View File

@ -0,0 +1,6 @@
class AddMoreToDirectoryItems < ActiveRecord::Migration
def change
add_column :directory_items, :days_visited, :integer, null: false, default: 0
add_column :directory_items, :posts_read, :integer, null: false, default: 0
end
end