From 9e84a89f767604260aa64e810d9c8dc518d038cc Mon Sep 17 00:00:00 2001 From: Eric Berry Date: Wed, 20 Jun 2018 09:15:15 -0600 Subject: [PATCH] Refactors per review --- .../discourse/components/codefund-ad.js.es6 | 34 ++++++++++++------- .../initializers/initialize-ad-plugin.js.es6 | 12 +++---- config/locales/server.en.yml | 4 +-- config/settings.yml | 4 +-- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/assets/javascripts/discourse/components/codefund-ad.js.es6 b/assets/javascripts/discourse/components/codefund-ad.js.es6 index 9bb428e..46e985a 100644 --- a/assets/javascripts/discourse/components/codefund-ad.js.es6 +++ b/assets/javascripts/discourse/components/codefund-ad.js.es6 @@ -1,20 +1,22 @@ +import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; + var _loaded = false, _promise = null, currentUser = Discourse.User.current(), - propertyId = Discourse.SiteSettings.codefund_property_code; + propertyId = Discourse.SiteSettings.codefund_property_id; function loadCodeFund() { if (_loaded) { return Ember.RSVP.resolve(); } - + if (_promise) { return _promise; } const url = 'https://codefund.io/t/s/' + propertyId + '/details.json'; - _promise = new Promise(function(resolve, reject){ + _promise = new Promise(function(resolve, reject) { let xhr = new XMLHttpRequest(); xhr.open('GET', url); @@ -66,35 +68,41 @@ export default Ember.Component.extend({ Ember.run.scheduleOnce('afterRender', this, this._triggerAds); }, + @observes('listLoading') waitForLoad: function() { if (this.get('adRequested')) { return; } // already requested that this ad unit be populated if (!this.get('listLoading')) { Ember.run.scheduleOnce('afterRender', this, this._triggerAds); } - }.observes('listLoading'), + }, checkTrustLevels: function() { return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.codefund_through_trust_level)); }.property('trust_level'), - showAd: function() { - return Discourse.SiteSettings.codefund_property_code && this.get('checkTrustLevels'); - }.property('checkTrustLevels'), + @computed('checkTrustLevels') + showAd: function(checkTrustLevels) { + return Discourse.SiteSettings.codefund_property_id && checkTrustLevels; + }, - displayPostBottom: function() { - return this.get('placement') === 'post-bottom'; - }.property('placement'), + @computed('placement') + displayPostBottom: function(placement) { + return placement === 'post-bottom'; + }, + @computed('placement') displayTopicAbovePostStream: function() { return this.get('placement') === 'topic-above-post-stream'; - }.property('placement'), + }, + @computed('placement') displayTopicAboveSuggested: function() { return this.get('placement') === 'topic-above-suggested'; - }.property('placement'), + }, + @computed('placement') displayTopicListTop: function() { return this.get('placement') === 'topic-list-top'; - }.property('placement'), + } }); diff --git a/assets/javascripts/initializers/initialize-ad-plugin.js.es6 b/assets/javascripts/initializers/initialize-ad-plugin.js.es6 index 9e216fc..abc2274 100644 --- a/assets/javascripts/initializers/initialize-ad-plugin.js.es6 +++ b/assets/javascripts/initializers/initialize-ad-plugin.js.es6 @@ -9,23 +9,23 @@ export default { const siteSettings = container.lookup('site-settings:main'); PostModel.reopen({ - postSpecificCountDFP: function () { + postSpecificCountDFP: function() { return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code)); }.property('post_number'), - postSpecificCountAdsense: function () { + postSpecificCountAdsense: function() { return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code)); }.property('post_number'), - postSpecificCountAmazon: function () { + postSpecificCountAmazon: function() { return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code)); }.property('post_number'), - postSpecificCountCodeFund: function () { - return this.isNthPost(parseInt(siteSettings.codefund_nth_post_code)); + postSpecificCountCodeFund: function() { + return this.isNthPost(parseInt(siteSettings.codefund_nth_post)); }.property('post_number'), - isNthPost: function (n) { + isNthPost: function(n) { if (n && n > 0) { return (this.get('post_number') % n) === 0; } else { diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 0e659ea..18d8275 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -79,12 +79,12 @@ en: amazon_mobile_post_bottom_ad_height_code: "Input your ad height (mobile)" amazon_nth_post_code: "Show an ad after every N posts, where N is this value." - codefund_property_code: "Your CodeFund property ID" + codefund_property_id: "Your CodeFund property ID" codefund_advertiser_label: "Label that appears before the advertisement (e.g. Advertiser or Supporter)" codefund_advertiser_short_label: "Abbreviated label that appears before the advertisement (e.g. Ad)" codefund_display_advertiser_labels: "Show the advertiser label (e.g. 'Advertiser') on the ads" codefund_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads" - codefund_nth_post_code: "Show an ad after every N posts, where N is this value" + codefund_nth_post: "Show an ad after every N posts, where N is this value" codefund_below_post_enabled: "Show an ad below each blog post" codefund_above_post_stream_enabled: "Show an ad above the post stream" codefund_above_suggested_enabled: "Show an ad above the suggested topic list" diff --git a/config/settings.yml b/config/settings.yml index 10cade2..944f62b 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -343,7 +343,7 @@ amazon_plugin: default: '' codefund_plugin: - codefund_property_code: + codefund_property_id: client: true default: '' regex: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' @@ -357,7 +357,7 @@ codefund_plugin: client: true default: 2 enum: 'TrustLevelSetting' - codefund_nth_post_code: + codefund_nth_post: client: true default: 4 min: 1