From 512771932a6f154e1368ea5108c48cb84bed1067 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 23 May 2014 12:25:16 -0400 Subject: [PATCH] Show a warning to admins if the site has fewer than 5 topics. --- app/assets/javascripts/discourse.js | 9 +++++++++ app/assets/javascripts/discourse/models/composer.js | 5 +++++ config/locales/client.en.yml | 1 + 3 files changed, 15 insertions(+) diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index eddd1b1e9..d6659f596 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -164,6 +164,15 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { notices.push(I18n.t("read_only_mode.enabled")); } + if(Discourse.User.currentProp('admin')) { + var topic_count = _.reduce(Discourse.Site.currentProp('categories'), function(sum,c) { + return sum + (c.get('read_restricted') ? 0 : c.get('topic_count')); + }, 0); + if (topic_count < 5) { + notices.push(I18n.t("too_few_topics_notice")); + } + } + if(!_.isEmpty(Discourse.SiteSettings.global_notice)){ notices.push(Discourse.SiteSettings.global_notice); } diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 6269dc124..f5843d365 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -498,6 +498,11 @@ Discourse.Composer = Discourse.Model.extend({ // We created a new topic, let's show it. composer.set('composeState', CLOSED); saving = false; + + // Update topic_count for the category + var category = Discourse.Site.currentProp('categories').find(function(x) { return x.get('id') === (parseInt(createdPost.get('category'),10) || 1); }); + if (category) category.incrementProperty('topic_count'); + Discourse.notifyPropertyChange('globalNotice'); } composer.clearState(); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 5ad96b04f..a6388ca5c 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -442,6 +442,7 @@ en: read_only_mode: enabled: "An administrator has enabled read-only mode. You can continue to browse the site but interactions won't work properly." login_disabled: "Login is disabled while the site is in read only mode." + too_few_topics_notice: "Create at least 5 topics to get discussion started. New users will not be able to earn trust levels unless there's content for them to read." learn_more: "learn more..."