REFACTOR: applies discourse core coding practices (#82)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
export default Ember.Component.extend({
|
||||
router: Ember.inject.service(),
|
||||
@@ -23,7 +23,7 @@ export default Ember.Component.extend({
|
||||
"router.currentRoute.parent.attributes.category.read_restricted"
|
||||
),
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"router.currentRoute.attributes.__type",
|
||||
"router.currentRoute.attributes.id"
|
||||
)
|
||||
@@ -33,12 +33,12 @@ export default Ember.Component.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@computed("router.currentRoute.parent.attributes.archetype")
|
||||
@discourseComputed("router.currentRoute.parent.attributes.archetype")
|
||||
isPersonalMessage(topicType) {
|
||||
return topicType === "private_message";
|
||||
},
|
||||
|
||||
@computed("currentUser.groups")
|
||||
@discourseComputed("currentUser.groups")
|
||||
showToGroups(groups) {
|
||||
const currentUser = Discourse.User.current();
|
||||
|
||||
@@ -67,7 +67,7 @@ export default Ember.Component.extend({
|
||||
return !currentGroups.any(g => noAdsGroups.includes(g));
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"currentCategoryId",
|
||||
"topicTagsDisableAds",
|
||||
"topicListTag",
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
const adConfig = Ember.Object.create({
|
||||
"google-adsense": {
|
||||
@@ -85,7 +82,7 @@ export default AdComponent.extend({
|
||||
* For a given ad placement and optionally a post number if in between posts,
|
||||
* list all ad network names that are configured to show there.
|
||||
*/
|
||||
@computed("placement", "postNumber")
|
||||
@discourseComputed("placement", "postNumber")
|
||||
availableAdTypes(placement, postNumber) {
|
||||
let types = [];
|
||||
const houseAds = this.site.get("house_creatives"),
|
||||
@@ -167,7 +164,7 @@ export default AdComponent.extend({
|
||||
* in the given ad placement. It handles alternating between house ads
|
||||
* and other ad networks.
|
||||
*/
|
||||
@computed("placement", "availableAdTypes", "needsUpdate")
|
||||
@discourseComputed("placement", "availableAdTypes", "needsUpdate")
|
||||
adComponents(placement, availableAdTypes) {
|
||||
if (
|
||||
!availableAdTypes.includes("house-ad") ||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
const publisherId = Discourse.SiteSettings.adbutler_publisher_id;
|
||||
@@ -117,7 +114,7 @@ export default AdComponent.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
@@ -125,7 +122,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
@@ -141,7 +138,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
const data = {
|
||||
"topic-list-top": {},
|
||||
@@ -157,32 +157,32 @@ export default AdComponent.extend({
|
||||
this._super();
|
||||
},
|
||||
|
||||
@computed("amazon_width", "amazon_height")
|
||||
@discourseComputed("amazon_width", "amazon_height")
|
||||
adWrapperStyle(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("mobile_amazon_width", "mobile_amazon_height")
|
||||
@discourseComputed("mobile_amazon_width", "mobile_amazon_height")
|
||||
adWrapperStyleMobile(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("mobile_amazon_width")
|
||||
@discourseComputed("mobile_amazon_width")
|
||||
adTitleStyleMobile(w) {
|
||||
return `width: ${w}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("user_input")
|
||||
@discourseComputed("user_input")
|
||||
userInput(userInput) {
|
||||
return `${userInput}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("user_input_mobile")
|
||||
@discourseComputed("user_input_mobile")
|
||||
userInputMobile(userInput) {
|
||||
return `${userInput}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
@@ -190,7 +190,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import { default as computed } from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
const serve_id = Discourse.SiteSettings.carbonads_serve_id,
|
||||
placement = Discourse.SiteSettings.carbonads_placement;
|
||||
@@ -10,12 +10,12 @@ export default AdComponent.extend({
|
||||
this._super();
|
||||
},
|
||||
|
||||
@computed("serve_id")
|
||||
@discourseComputed("serve_id")
|
||||
url(serveId) {
|
||||
return `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
@@ -23,7 +23,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("showToTrustLevel", "showToGroups", "showOnCurrentPage")
|
||||
@discourseComputed("showToTrustLevel", "showToGroups", "showOnCurrentPage")
|
||||
showAd(showToTrustLevel, showToGroups, showOnCurrentPage) {
|
||||
return (
|
||||
placement &&
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import { Promise } from "rsvp";
|
||||
|
||||
let _loaded = false,
|
||||
@@ -108,14 +105,14 @@ export default AdComponent.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.codefund_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
@@ -131,7 +128,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
let _loaded = false,
|
||||
@@ -173,41 +170,41 @@ export default AdComponent.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@computed("ad_width")
|
||||
@discourseComputed("ad_width")
|
||||
isResponsive(adWidth) {
|
||||
return adWidth === "auto";
|
||||
},
|
||||
|
||||
@computed("placement", "showAd")
|
||||
@discourseComputed("placement", "showAd")
|
||||
classForSlot(placement, showAd) {
|
||||
return showAd ? `adsense-${placement}`.htmlSafe() : "";
|
||||
},
|
||||
|
||||
@computed("isResponsive")
|
||||
@discourseComputed("isResponsive")
|
||||
autoAdFormat(isResponsive) {
|
||||
return isResponsive ? "auto".htmlSafe() : false;
|
||||
},
|
||||
|
||||
@computed("ad_width", "ad_height", "isResponsive")
|
||||
@discourseComputed("ad_width", "ad_height", "isResponsive")
|
||||
adWrapperStyle(w, h, isResponsive) {
|
||||
return (isResponsive ? "" : `width: ${w}; height: ${h};`).htmlSafe();
|
||||
},
|
||||
|
||||
@computed("adWrapperStyle", "isResponsive")
|
||||
@discourseComputed("adWrapperStyle", "isResponsive")
|
||||
adInsStyle(adWrapperStyle, isResponsive) {
|
||||
return `display: ${
|
||||
isResponsive ? "block" : "inline-block"
|
||||
}; ${adWrapperStyle}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.adsense_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
@@ -223,7 +220,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
on
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { on } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
let _loaded = false,
|
||||
@@ -246,7 +243,7 @@ export default AdComponent.extend({
|
||||
width: Ember.computed.alias("size.width"),
|
||||
height: Ember.computed.alias("size.height"),
|
||||
|
||||
@computed()
|
||||
@discourseComputed
|
||||
size() {
|
||||
return getWidthAndHeight(
|
||||
this.get("placement"),
|
||||
@@ -255,7 +252,7 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"siteSettings.dfp_publisher_id",
|
||||
"siteSettings.dfp_publisher_id_mobile",
|
||||
"site.mobileView"
|
||||
@@ -268,7 +265,7 @@ export default AdComponent.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@computed("placement", "postNumber")
|
||||
@discourseComputed("placement", "postNumber")
|
||||
divId(placement, postNumber) {
|
||||
let slotNum = getNextSlotNum();
|
||||
if (postNumber) {
|
||||
@@ -278,26 +275,26 @@ export default AdComponent.extend({
|
||||
}
|
||||
},
|
||||
|
||||
@computed("placement", "showAd")
|
||||
@discourseComputed("placement", "showAd")
|
||||
adUnitClass(placement, showAd) {
|
||||
return showAd ? `dfp-ad-${placement}` : "";
|
||||
},
|
||||
|
||||
@computed("width", "height")
|
||||
@discourseComputed("width", "height")
|
||||
adWrapperStyle(w, h) {
|
||||
if (w !== "fluid") {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
}
|
||||
},
|
||||
|
||||
@computed("width")
|
||||
@discourseComputed("width")
|
||||
adTitleStyleMobile(w) {
|
||||
if (w !== "fluid") {
|
||||
return `width: ${w}px;`.htmlSafe();
|
||||
}
|
||||
},
|
||||
|
||||
@computed(
|
||||
@discourseComputed(
|
||||
"publisherId",
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
@@ -323,14 +320,14 @@ export default AdComponent.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("currentUser.trust_level")
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.dfp_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
const adIndex = {
|
||||
topic_list_top: null,
|
||||
@@ -16,17 +13,17 @@ export default AdComponent.extend({
|
||||
classNameBindings: ["adUnitClass"],
|
||||
adHtml: "",
|
||||
|
||||
@computed("placement", "showAd")
|
||||
@discourseComputed("placement", "showAd")
|
||||
adUnitClass(placement, showAd) {
|
||||
return showAd ? `house-${placement}` : "";
|
||||
},
|
||||
|
||||
@computed("showToGroups", "showAfterPost", "showOnCurrentPage")
|
||||
@discourseComputed("showToGroups", "showAfterPost", "showOnCurrentPage")
|
||||
showAd(showToGroups, showAfterPost, showOnCurrentPage) {
|
||||
return showToGroups && showAfterPost && showOnCurrentPage;
|
||||
},
|
||||
|
||||
@computed("postNumber")
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user