Refactors per review

This commit is contained in:
Eric Berry 2018-06-20 09:15:15 -06:00
parent 1b7f642da6
commit 9e84a89f76
4 changed files with 31 additions and 23 deletions

View File

@ -1,20 +1,22 @@
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
var _loaded = false, var _loaded = false,
_promise = null, _promise = null,
currentUser = Discourse.User.current(), currentUser = Discourse.User.current(),
propertyId = Discourse.SiteSettings.codefund_property_code; propertyId = Discourse.SiteSettings.codefund_property_id;
function loadCodeFund() { function loadCodeFund() {
if (_loaded) { if (_loaded) {
return Ember.RSVP.resolve(); return Ember.RSVP.resolve();
} }
if (_promise) { if (_promise) {
return _promise; return _promise;
} }
const url = 'https://codefund.io/t/s/' + propertyId + '/details.json'; 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(); let xhr = new XMLHttpRequest();
xhr.open('GET', url); xhr.open('GET', url);
@ -66,35 +68,41 @@ export default Ember.Component.extend({
Ember.run.scheduleOnce('afterRender', this, this._triggerAds); Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
}, },
@observes('listLoading')
waitForLoad: function() { waitForLoad: function() {
if (this.get('adRequested')) { return; } // already requested that this ad unit be populated if (this.get('adRequested')) { return; } // already requested that this ad unit be populated
if (!this.get('listLoading')) { if (!this.get('listLoading')) {
Ember.run.scheduleOnce('afterRender', this, this._triggerAds); Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
} }
}.observes('listLoading'), },
checkTrustLevels: function() { checkTrustLevels: function() {
return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.codefund_through_trust_level)); return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.codefund_through_trust_level));
}.property('trust_level'), }.property('trust_level'),
showAd: function() { @computed('checkTrustLevels')
return Discourse.SiteSettings.codefund_property_code && this.get('checkTrustLevels'); showAd: function(checkTrustLevels) {
}.property('checkTrustLevels'), return Discourse.SiteSettings.codefund_property_id && checkTrustLevels;
},
displayPostBottom: function() { @computed('placement')
return this.get('placement') === 'post-bottom'; displayPostBottom: function(placement) {
}.property('placement'), return placement === 'post-bottom';
},
@computed('placement')
displayTopicAbovePostStream: function() { displayTopicAbovePostStream: function() {
return this.get('placement') === 'topic-above-post-stream'; return this.get('placement') === 'topic-above-post-stream';
}.property('placement'), },
@computed('placement')
displayTopicAboveSuggested: function() { displayTopicAboveSuggested: function() {
return this.get('placement') === 'topic-above-suggested'; return this.get('placement') === 'topic-above-suggested';
}.property('placement'), },
@computed('placement')
displayTopicListTop: function() { displayTopicListTop: function() {
return this.get('placement') === 'topic-list-top'; return this.get('placement') === 'topic-list-top';
}.property('placement'), }
}); });

View File

@ -9,23 +9,23 @@ export default {
const siteSettings = container.lookup('site-settings:main'); const siteSettings = container.lookup('site-settings:main');
PostModel.reopen({ PostModel.reopen({
postSpecificCountDFP: function () { postSpecificCountDFP: function() {
return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code)); return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code));
}.property('post_number'), }.property('post_number'),
postSpecificCountAdsense: function () { postSpecificCountAdsense: function() {
return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code)); return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code));
}.property('post_number'), }.property('post_number'),
postSpecificCountAmazon: function () { postSpecificCountAmazon: function() {
return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code)); return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code));
}.property('post_number'), }.property('post_number'),
postSpecificCountCodeFund: function () { postSpecificCountCodeFund: function() {
return this.isNthPost(parseInt(siteSettings.codefund_nth_post_code)); return this.isNthPost(parseInt(siteSettings.codefund_nth_post));
}.property('post_number'), }.property('post_number'),
isNthPost: function (n) { isNthPost: function(n) {
if (n && n > 0) { if (n && n > 0) {
return (this.get('post_number') % n) === 0; return (this.get('post_number') % n) === 0;
} else { } else {

View File

@ -79,12 +79,12 @@ en:
amazon_mobile_post_bottom_ad_height_code: "Input your ad height (mobile)" 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." 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_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_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_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_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_below_post_enabled: "Show an ad below each blog post"
codefund_above_post_stream_enabled: "Show an ad above the post stream" codefund_above_post_stream_enabled: "Show an ad above the post stream"
codefund_above_suggested_enabled: "Show an ad above the suggested topic list" codefund_above_suggested_enabled: "Show an ad above the suggested topic list"

View File

@ -343,7 +343,7 @@ amazon_plugin:
default: '' default: ''
codefund_plugin: codefund_plugin:
codefund_property_code: codefund_property_id:
client: true client: true
default: '' default: ''
regex: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' 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 client: true
default: 2 default: 2
enum: 'TrustLevelSetting' enum: 'TrustLevelSetting'
codefund_nth_post_code: codefund_nth_post:
client: true client: true
default: 4 default: 4
min: 1 min: 1