Add relative_date_duration site setting

This commit is contained in:
Neil Lalonde 2013-07-10 12:38:43 -04:00
parent cc47616cdb
commit 0e3e5bf533
5 changed files with 34 additions and 3 deletions

View File

@ -105,13 +105,16 @@ Discourse.Formatter = (function(){
case(distanceInMinutes >= 90 && distanceInMinutes <= 1439):
formatted = t("about_x_hours", {count: Math.round(distanceInMinutes / 60.0)});
break;
case(Discourse.SiteSettings.relative_date_duration === 0 && distanceInMinutes <= 525599):
formatted = shortDateNoYear(date);
break;
case(distanceInMinutes >= 1440 && distanceInMinutes <= 2519):
formatted = t("x_days", {count: 1});
break;
case(distanceInMinutes >= 2520 && distanceInMinutes <= 20160):
case(distanceInMinutes >= 2520 && distanceInMinutes <= ((Discourse.SiteSettings.relative_date_duration||14) * 1440)):
formatted = t("x_days", {count: Math.round(distanceInMinutes / 1440.0)});
break;
case(distanceInMinutes >= 20160 && distanceInMinutes <= 525599):
case(distanceInMinutes >= ((Discourse.SiteSettings.relative_date_duration||14) * 1440) && distanceInMinutes <= 525599):
formatted = shortDateNoYear(date);
break;
default:

View File

@ -230,6 +230,8 @@ class SiteSetting < ActiveRecord::Base
setting(:minimum_topics_similar, 50)
client_setting(:relative_date_duration, 14)
def self.generate_api_key!
self.api_key = SecureRandom.hex(32)
end

View File

@ -648,6 +648,8 @@ en:
minimum_topics_similar: "How many topics need to exist in the database before similar topics are presented."
relative_date_duration: "Number of days after posting where post dates will be shown as relative instead of absolute. Examples: relative date: 7d, absolute date: 20 Feb"
notification_types:
mentioned: "%{display_username} mentioned you in %{link}"

View File

@ -81,6 +81,30 @@ test("formating tiny dates", function() {
equal(formatDays(365), "> 1y");
equal(formatDays(500), "> 1y");
equal(formatDays(365*2), "> 2y");
var originalValue = Discourse.SiteSettings.relative_date_duration;
Discourse.SiteSettings.relative_date_duration = 7;
equal(formatDays(7), "7d");
equal(formatDays(8), shortDate(8));
Discourse.SiteSettings.relative_date_duration = 1;
equal(formatDays(1), "1d");
equal(formatDays(2), shortDate(2));
Discourse.SiteSettings.relative_date_duration = 0;
equal(formatMins(0), "< 1m");
equal(formatMins(2), "2m");
equal(formatMins(60), "1h");
equal(formatDays(1), shortDate(1));
equal(formatDays(2), shortDate(2));
equal(formatDays(365), "> 1y");
Discourse.SiteSettings.relative_date_duration = null;
equal(formatDays(1), '1d');
equal(formatDays(14), '14d');
equal(formatDays(15), shortDate(15));
Discourse.SiteSettings.relative_date_duration = originalValue;
});
test("autoUpdatingRelativeAge", function() {

View File

@ -1,3 +1,3 @@
/*jshint maxlen:10000000 */
Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","traditional_markdown_linebreaks":false,"top_menu":"latest|new|unread|read|favorited|categories","post_menu":"like|edit|flag|delete|share|bookmark|reply","share_links":"twitter|facebook|google+|email","track_external_right_clicks":false,"must_approve_users":false,"ga_tracking_code":"UA-33736483-2","ga_domain_name":"","enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"min_post_length":20,"max_post_length":16000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_search_term_length":3,"flush_timings_secs":5,"suppress_reply_directly_below":true,"email_domains_blacklist":"mailinator.com","email_domains_whitelist":null,"version_checks":true,"min_title_similar_length":10,"min_body_similar_length":15,"category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","max_upload_size_kb":1024,"category_featured_topics":6,"favicon_url":"/assets/favicon.ico","dynamic_favicon":false,"uncategorized_name":"uncategorized","uncategorized_color":"AB9364","uncategorized_text_color":"FFFFFF","invite_only":false,"login_required":false,"enable_local_logins":true,"enable_local_account_create":true,"enable_google_logins":true,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_cas_logins":false,"enable_github_logins":true,"enable_persona_logins":true,"educate_until_posts":2,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"min_private_message_post_length":5,"faq_url":"","tos_url":"","privacy_policy_url":"","authorized_extensions":".jpg|.jpeg|.png|.gif"};
Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","traditional_markdown_linebreaks":false,"top_menu":"latest|new|unread|read|favorited|categories","post_menu":"like|edit|flag|delete|share|bookmark|reply","share_links":"twitter|facebook|google+|email","track_external_right_clicks":false,"must_approve_users":false,"ga_tracking_code":"UA-33736483-2","ga_domain_name":"","enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"min_post_length":20,"max_post_length":16000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_search_term_length":3,"flush_timings_secs":5,"suppress_reply_directly_below":true,"email_domains_blacklist":"mailinator.com","email_domains_whitelist":null,"version_checks":true,"min_title_similar_length":10,"min_body_similar_length":15,"category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","max_upload_size_kb":1024,"category_featured_topics":6,"favicon_url":"/assets/favicon.ico","dynamic_favicon":false,"uncategorized_name":"uncategorized","uncategorized_color":"AB9364","uncategorized_text_color":"FFFFFF","invite_only":false,"login_required":false,"enable_local_logins":true,"enable_local_account_create":true,"enable_google_logins":true,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_cas_logins":false,"enable_github_logins":true,"enable_persona_logins":true,"educate_until_posts":2,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"min_private_message_post_length":5,"faq_url":"","tos_url":"","privacy_policy_url":"","authorized_extensions":".jpg|.jpeg|.png|.gif","relative_date_duration":14};
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);