FEATURE: add quarterly period to Top page

This commit is contained in:
Neil Lalonde 2015-07-28 12:31:31 -04:00
parent dc8a68fd29
commit 7518918b8f
6 changed files with 78 additions and 36 deletions

View File

@ -106,6 +106,7 @@ const controllerOpts = {
new: Discourse.computed.endWith('model.filter', 'new'),
top: Em.computed.notEmpty('period'),
yearly: Em.computed.equal('period', 'yearly'),
quarterly: Em.computed.equal('period', 'quarterly'),
monthly: Em.computed.equal('period', 'monthly'),
weekly: Em.computed.equal('period', 'weekly'),
daily: Em.computed.equal('period', 'daily'),

View File

@ -1,6 +1,7 @@
const TITLE_SUBS = {
all: 'all_time',
yearly: 'this_year',
quarterly: 'this_quarter',
monthly: 'this_month',
daily: 'today',
};
@ -13,6 +14,9 @@ export default Ember.Handlebars.makeBoundHelper(function (period, options) {
case 'yearly':
dateString = moment().subtract(1, 'year').format(I18n.t('dates.long_with_year_no_time')) + " - " + moment().format(I18n.t('dates.long_with_year_no_time'));
break;
case 'quarterly':
dateString = moment().subtract(3, 'month').format(I18n.t('dates.long_no_year_no_time')) + " - " + moment().format(I18n.t('dates.long_no_year_no_time'));
break;
case 'weekly':
dateString = moment().subtract(1, 'week').format(I18n.t('dates.long_no_year_no_time')) + " - " + moment().format(I18n.t('dates.long_no_year_no_time'));
break;

View File

@ -32,7 +32,7 @@ class TopTopic < ActiveRecord::Base
def self.periods
@@periods ||= [:all, :yearly, :monthly, :weekly, :daily].freeze
@@periods ||= [:all, :yearly, :quarterly, :monthly, :weekly, :daily].freeze
end
def self.sort_orders
@ -181,10 +181,11 @@ class TopTopic < ActiveRecord::Base
def self.start_of(period)
case period
when :yearly then 1.year.ago
when :monthly then 1.month.ago
when :weekly then 1.week.ago
when :daily then 1.day.ago
when :yearly then 1.year.ago
when :monthly then 1.month.ago
when :quarterly then 3.months.ago
when :weekly then 1.week.ago
when :daily then 1.day.ago
end
end
@ -207,38 +208,56 @@ end
#
# Table name: top_topics
#
# id :integer not null, primary key
# topic_id :integer
# yearly_posts_count :integer default(0), not null
# yearly_views_count :integer default(0), not null
# yearly_likes_count :integer default(0), not null
# monthly_posts_count :integer default(0), not null
# monthly_views_count :integer default(0), not null
# monthly_likes_count :integer default(0), not null
# weekly_posts_count :integer default(0), not null
# weekly_views_count :integer default(0), not null
# weekly_likes_count :integer default(0), not null
# daily_posts_count :integer default(0), not null
# daily_views_count :integer default(0), not null
# daily_likes_count :integer default(0), not null
# yearly_score :float default(0.0)
# monthly_score :float default(0.0)
# weekly_score :float default(0.0)
# daily_score :float default(0.0)
# id :integer not null, primary key
# topic_id :integer
# yearly_posts_count :integer default(0), not null
# yearly_views_count :integer default(0), not null
# yearly_likes_count :integer default(0), not null
# monthly_posts_count :integer default(0), not null
# monthly_views_count :integer default(0), not null
# monthly_likes_count :integer default(0), not null
# weekly_posts_count :integer default(0), not null
# weekly_views_count :integer default(0), not null
# weekly_likes_count :integer default(0), not null
# daily_posts_count :integer default(0), not null
# daily_views_count :integer default(0), not null
# daily_likes_count :integer default(0), not null
# daily_score :float default(0.0)
# weekly_score :float default(0.0)
# monthly_score :float default(0.0)
# yearly_score :float default(0.0)
# all_score :float default(0.0)
# daily_op_likes_count :integer default(0), not null
# weekly_op_likes_count :integer default(0), not null
# monthly_op_likes_count :integer default(0), not null
# yearly_op_likes_count :integer default(0), not null
# quarterly_posts_count :integer default(0), not null
# quarterly_views_count :integer default(0), not null
# quarterly_likes_count :integer default(0), not null
# quarterly_score :float default(0.0)
# quarterly_op_likes_count :integer default(0), not null
#
# Indexes
#
# index_top_topics_on_daily_likes_count (daily_likes_count)
# index_top_topics_on_daily_posts_count (daily_posts_count)
# index_top_topics_on_daily_views_count (daily_views_count)
# index_top_topics_on_monthly_likes_count (monthly_likes_count)
# index_top_topics_on_monthly_posts_count (monthly_posts_count)
# index_top_topics_on_monthly_views_count (monthly_views_count)
# index_top_topics_on_topic_id (topic_id) UNIQUE
# index_top_topics_on_weekly_likes_count (weekly_likes_count)
# index_top_topics_on_weekly_posts_count (weekly_posts_count)
# index_top_topics_on_weekly_views_count (weekly_views_count)
# index_top_topics_on_yearly_likes_count (yearly_likes_count)
# index_top_topics_on_yearly_posts_count (yearly_posts_count)
# index_top_topics_on_yearly_views_count (yearly_views_count)
# index_top_topics_on_daily_likes_count (daily_likes_count)
# index_top_topics_on_daily_op_likes_count (daily_op_likes_count)
# index_top_topics_on_daily_posts_count (daily_posts_count)
# index_top_topics_on_daily_views_count (daily_views_count)
# index_top_topics_on_monthly_likes_count (monthly_likes_count)
# index_top_topics_on_monthly_op_likes_count (monthly_op_likes_count)
# index_top_topics_on_monthly_posts_count (monthly_posts_count)
# index_top_topics_on_monthly_views_count (monthly_views_count)
# index_top_topics_on_quarterly_likes_count (quarterly_likes_count)
# index_top_topics_on_quarterly_op_likes_count (quarterly_op_likes_count)
# index_top_topics_on_quarterly_posts_count (quarterly_posts_count)
# index_top_topics_on_quarterly_views_count (quarterly_views_count)
# index_top_topics_on_topic_id (topic_id) UNIQUE
# index_top_topics_on_weekly_likes_count (weekly_likes_count)
# index_top_topics_on_weekly_op_likes_count (weekly_op_likes_count)
# index_top_topics_on_weekly_posts_count (weekly_posts_count)
# index_top_topics_on_weekly_views_count (weekly_views_count)
# index_top_topics_on_yearly_likes_count (yearly_likes_count)
# index_top_topics_on_yearly_op_likes_count (yearly_op_likes_count)
# index_top_topics_on_yearly_posts_count (yearly_posts_count)
# index_top_topics_on_yearly_views_count (yearly_views_count)
#

View File

@ -1669,6 +1669,8 @@ en:
title: "All Time"
yearly:
title: "Yearly"
quarterly:
title: "Quarterly"
monthly:
title: "Monthly"
weekly:
@ -1677,6 +1679,7 @@ en:
title: "Daily"
all_time: "All Time"
this_year: "Year"
this_quarter: "Quarter"
this_month: "Month"
this_week: "Week"
today: "Today"

View File

@ -0,0 +1,14 @@
class AddQuarterlyToTopTopics < ActiveRecord::Migration
def change
add_column :top_topics, :quarterly_posts_count, :integer, default: 0, null: false
add_column :top_topics, :quarterly_views_count, :integer, default: 0, null: false
add_column :top_topics, :quarterly_likes_count, :integer, default: 0, null: false
add_column :top_topics, :quarterly_score, :float, default: 0.0
add_column :top_topics, :quarterly_op_likes_count, :integer, default: 0, null: false
add_index :top_topics, [:quarterly_posts_count]
add_index :top_topics, [:quarterly_views_count]
add_index :top_topics, [:quarterly_likes_count]
add_index :top_topics, [:quarterly_op_likes_count]
end
end

View File

@ -49,6 +49,7 @@ export default {
],
"periods":[
"yearly",
"quarterly",
"monthly",
"weekly",
"daily"