REFACTOR: Introduce `Discourse.computed.setting` to create a computed

property that links to a `Discourse.SiteSetting`
This commit is contained in:
Robin Ward 2014-04-24 17:39:34 -04:00
parent cdd2101e4f
commit cf6cbb955b
10 changed files with 38 additions and 41 deletions

View File

@ -20,13 +20,8 @@ Discourse.AdminUserController = Discourse.ObjectController.extend({});
Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
editingTitle: false,
showApproval: function() {
return Discourse.SiteSettings.must_approve_users;
}.property(),
showBadges: function() {
return Discourse.SiteSettings.enable_badges;
}.property(),
showApproval: Discourse.computed.setting('must_approve_users'),
showBadges: Discourse.computed.setting('enable_badges'),
primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'),

View File

@ -9,15 +9,8 @@ Discourse.HomeLogoComponent = Ember.Component.extend({
return !Discourse.Mobile.mobileView && this.get("minimized");
}.property("minimized"),
smallLogoUrl: function() {
return Discourse.SiteSettings.logo_small_url;
}.property(),
smallLogoUrl: Discourse.computed.setting('logo_small_url'),
bigLogoUrl: Discourse.computed.setting('logo_url'),
title: Discourse.computed.setting('title'),
bigLogoUrl: function() {
return Discourse.SiteSettings.logo_url;
}.property(),
title: function() {
return Discourse.SiteSettings.title;
}.property()
});

View File

@ -324,9 +324,7 @@ Discourse.CreateAccountController = Discourse.Controller.extend(Discourse.ModalF
});
},
tosAcceptRequired: function() {
return Discourse.SiteSettings.tos_accept_required;
}.property(),
tosAcceptRequired: Discourse.computed.setting('tos_accept_required'),
actions: {
createAccount: function() {

View File

@ -58,9 +58,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
return false;
}.property('saving', 'name', 'color', 'deleting'),
emailInEnabled: function() {
return Discourse.SiteSettings.email_in;
},
emailInEnabled: Discourse.computed.setting('email_in'),
deleteDisabled: function() {
return (this.get('deleting') || this.get('saving') || false);

View File

@ -20,9 +20,7 @@ Discourse.PosterExpansionController = Discourse.ObjectController.extend({
hasUserFilters: Em.computed.gt('postStream.userFilters.length', 0),
showBadges: function() {
return Discourse.SiteSettings.enable_badges;
}.property(),
showBadges: Discourse.computed.setting('enable_badges'),
moreBadgesCount: function() {
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');

View File

@ -7,13 +7,9 @@
@module Discourse
**/
Discourse.PreferencesController = Discourse.ObjectController.extend({
allowAvatarUpload: function() {
return Discourse.SiteSettings.allow_uploaded_avatars;
}.property(),
allowUserLocale: function() {
return Discourse.SiteSettings.allow_user_locale;
}.property(),
allowAvatarUpload: Discourse.computed.setting('allow_uploaded_avatars'),
allowUserLocale: Discourse.computed.setting('allow_user_locale'),
selectedCategories: function(){
return [].concat(this.get("watchedCategories"), this.get("trackedCategories"), this.get("mutedCategories"));
@ -34,9 +30,7 @@ Discourse.PreferencesController = Discourse.ObjectController.extend({
cannotDeleteAccount: Em.computed.not('can_delete_account'),
deleteDisabled: Em.computed.or('saving', 'deleting', 'cannotDeleteAccount'),
canEditName: function() {
return Discourse.SiteSettings.enable_names;
}.property(),
canEditName: Discourse.computed.setting('enable_names'),
canSelectTitle: function() {
if (!Discourse.SiteSettings.enable_badges || this.get('model.badge_count') === 0) {

View File

@ -13,9 +13,7 @@ Discourse.SiteMapController = Ember.ArrayController.extend(Discourse.HasCurrentU
return Discourse.SiteSettings.faq_url ? Discourse.SiteSettings.faq_url : Discourse.getURL('/faq');
}.property(),
showMobileToggle: function() {
return Discourse.SiteSettings.enable_mobile_theme;
}.property(),
showMobileToggle: Discourse.computed.setting('enable_mobile_theme'),
mobileViewLinkTextKey: function() {
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view";

View File

@ -31,9 +31,7 @@ Discourse.UserInvitedController = Ember.ObjectController.extend({
@property maxInvites
**/
maxInvites: function() {
return Discourse.SiteSettings.invites_shown;
}.property(),
maxInvites: Discourse.computed.setting('invites_shown'),
/**
Can the currently logged in user invite users to the site

View File

@ -128,5 +128,19 @@ Discourse.computed = {
if (typeof result !== "undefined" && result.toString() === defaultValue) { return; }
return result;
}).property(path);
},
/**
Creates a property from a SiteSetting. In the future the plan is for them to
be able to update when changed.
@method setting
@param {String} name of site setting
**/
setting: function(name) {
return Ember.computed(function() {
return Discourse.SiteSettings[name];
}).property();
}
};

View File

@ -10,6 +10,17 @@ module("Discourse.Computed", {
}
});
test("setting", function() {
var t = Em.Object.extend({
vehicle: Discourse.computed.setting('vehicle'),
missingProp: Discourse.computed.setting('madeUpThing')
}).create();
Discourse.SiteSettings.vehicle = "airplane";
equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
});
test("propertyEqual", function() {
var t = Em.Object.extend({
same: Discourse.computed.propertyEqual('cookies', 'biscuits')