From 7e2a490b6704bebcc1c347ec898ed15aac697cfc Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sun, 6 Mar 2022 19:52:19 +0100 Subject: [PATCH] DEV: Fix imports (#132) --- .prettierrc | 1 + .../discourse/components/ad-component.js | 15 +++++++++------ .../javascripts/discourse/components/ad-slot.js | 10 ++++++---- .../discourse/components/adbutler-ad.js | 11 +++++++---- .../discourse/components/amazon-product-links.js | 3 ++- .../discourse/components/google-adsense.js | 11 +++++++---- .../discourse/components/google-dfp-ad.js | 11 +++++++---- .../javascripts/discourse/components/house-ad.js | 6 ++---- .../components/house-ads-list-setting.js | 3 ++- .../discourse/components/house-ads-setting.js | 3 ++- .../controllers/admin-plugins-house-ads-index.js | 11 +++++++---- .../controllers/admin-plugins-house-ads-show.js | 11 +++++++---- .../controllers/admin-plugins-house-ads.js | 4 +++- .../routes/admin-plugins-house-ads-show.js | 3 ++- .../discourse/routes/admin-plugins-house-ads.js | 5 +++-- package.json | 2 +- yarn.lock | 8 ++++---- 17 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/assets/javascripts/discourse/components/ad-component.js b/assets/javascripts/discourse/components/ad-component.js index 1bc40f9..e165560 100644 --- a/assets/javascripts/discourse/components/ad-component.js +++ b/assets/javascripts/discourse/components/ad-component.js @@ -1,24 +1,27 @@ +import Component from "@ember/component"; +import { inject as service } from "@ember/service"; +import { alias, or } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; -export default Ember.Component.extend({ - router: Ember.inject.service(), +export default Component.extend({ + router: service(), - currentCategoryId: Ember.computed.or( + currentCategoryId: or( "router.currentRoute.attributes.category.id", "router.currentRoute.parent.attributes.category_id" ), - currentCategorySlug: Ember.computed.or( + currentCategorySlug: or( "router.currentRoute.attributes.category.slug", "router.currentRoute.parent.attributes.category.slug" ), // Server needs to compute this in case hidden tags are being used. - topicTagsDisableAds: Ember.computed.alias( + topicTagsDisableAds: alias( "router.currentRoute.parent.attributes.tags_disable_ads" ), - isRestrictedCategory: Ember.computed.or( + isRestrictedCategory: or( "router.currentRoute.attributes.category.read_restricted", "router.currentRoute.parent.attributes.category.read_restricted" ), diff --git a/assets/javascripts/discourse/components/ad-slot.js b/assets/javascripts/discourse/components/ad-slot.js index 10cf850..1de7b9d 100644 --- a/assets/javascripts/discourse/components/ad-slot.js +++ b/assets/javascripts/discourse/components/ad-slot.js @@ -1,7 +1,9 @@ +import EmberObject from "@ember/object"; import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; +import { isBlank } from "@ember/utils"; -const adConfig = Ember.Object.create({ +const adConfig = EmberObject.create({ "google-adsense": { settingPrefix: "adsense", // settings follow naming convention enabledSetting: "adsense_publisher_code", @@ -82,7 +84,7 @@ export default AdComponent.extend({ if ( Object.keys(houseAds.creatives).length > 0 && - !Ember.isBlank(adsForSlot) && + !isBlank(adsForSlot) && (!postNumber || this.isNthPost(parseInt(houseAds.settings.after_nth_post, 10))) ) { @@ -97,7 +99,7 @@ export default AdComponent.extend({ if ( ((config.enabledSetting && - !Ember.isBlank(this.siteSettings[config.enabledSetting])) || + !isBlank(this.siteSettings[config.enabledSetting])) || config.enabledSetting === false) && (!postNumber || !config.nthPost || @@ -123,7 +125,7 @@ export default AdComponent.extend({ if ( name !== false && this.siteSettings[name] !== false && - !Ember.isBlank(this.siteSettings[name]) + !isBlank(this.siteSettings[name]) ) { types.push(adNetwork); } diff --git a/assets/javascripts/discourse/components/adbutler-ad.js b/assets/javascripts/discourse/components/adbutler-ad.js index de63aea..fb3e730 100644 --- a/assets/javascripts/discourse/components/adbutler-ad.js +++ b/assets/javascripts/discourse/components/adbutler-ad.js @@ -1,6 +1,9 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; import loadScript from "discourse/lib/load-script"; +import RSVP from "rsvp"; +import { scheduleOnce } from "@ember/runloop"; +import { isTesting } from "discourse-common/config/environment"; let _loaded = false, _promise = null, @@ -8,7 +11,7 @@ let _loaded = false, function loadAdbutler(adserverHostname) { if (_loaded) { - return Ember.RSVP.resolve(); + return RSVP.resolve(); } if (_promise) { @@ -71,7 +74,7 @@ export default AdComponent.extend({ }, _triggerAds() { - if (Ember.testing) { + if (isTesting()) { return; // Don't load external JS during tests } @@ -105,7 +108,7 @@ export default AdComponent.extend({ didInsertElement() { this._super(); - Ember.run.scheduleOnce("afterRender", this, this._triggerAds); + scheduleOnce("afterRender", this, this._triggerAds); }, @observes("listLoading") @@ -114,7 +117,7 @@ export default AdComponent.extend({ return; } // already requested that this ad unit be populated if (!this.get("listLoading")) { - Ember.run.scheduleOnce("afterRender", this, this._triggerAds); + scheduleOnce("afterRender", this, this._triggerAds); } }, diff --git a/assets/javascripts/discourse/components/amazon-product-links.js b/assets/javascripts/discourse/components/amazon-product-links.js index fc4247d..5a91c6e 100644 --- a/assets/javascripts/discourse/components/amazon-product-links.js +++ b/assets/javascripts/discourse/components/amazon-product-links.js @@ -1,10 +1,11 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component"; import discourseComputed from "discourse-common/utils/decorators"; +import { and } from "@ember/object/computed"; export default AdComponent.extend({ classNames: ["amazon-product-links"], - showAd: Ember.computed.and( + showAd: and( "showToTrustLevel", "showToGroups", "showAfterPost", diff --git a/assets/javascripts/discourse/components/google-adsense.js b/assets/javascripts/discourse/components/google-adsense.js index df2286a..5712fd8 100644 --- a/assets/javascripts/discourse/components/google-adsense.js +++ b/assets/javascripts/discourse/components/google-adsense.js @@ -1,6 +1,9 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; import loadScript from "discourse/lib/load-script"; +import RSVP from "rsvp"; +import { scheduleOnce } from "@ember/runloop"; +import { isTesting } from "discourse-common/config/environment"; let _loaded = false, _promise = null, @@ -38,7 +41,7 @@ function parseAdHeight(value) { function loadAdsense() { if (_loaded) { - return Ember.RSVP.resolve(); + return RSVP.resolve(); } if (_promise) { @@ -138,7 +141,7 @@ export default AdComponent.extend({ }, _triggerAds() { - if (Ember.testing) { + if (isTesting()) { return; // Don't load external JS during tests } @@ -163,7 +166,7 @@ export default AdComponent.extend({ return; } - Ember.run.scheduleOnce("afterRender", this, this._triggerAds); + scheduleOnce("afterRender", this, this._triggerAds); }, @observes("listLoading") @@ -172,7 +175,7 @@ export default AdComponent.extend({ return; } // already requested that this ad unit be populated if (!this.get("listLoading")) { - Ember.run.scheduleOnce("afterRender", this, this._triggerAds); + scheduleOnce("afterRender", this, this._triggerAds); } }, diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js b/assets/javascripts/discourse/components/google-dfp-ad.js index 0fdff20..4d60d88 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js +++ b/assets/javascripts/discourse/components/google-dfp-ad.js @@ -1,6 +1,9 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component"; import discourseComputed, { on } from "discourse-common/utils/decorators"; import loadScript from "discourse/lib/load-script"; +import { alias } from "@ember/object/computed"; +import RSVP from "rsvp"; +import { isTesting } from "discourse-common/config/environment"; let _loaded = false, _promise = null, @@ -200,7 +203,7 @@ function loadGoogle() { */ if (_loaded) { - return Ember.RSVP.resolve(); + return RSVP.resolve(); } if (_promise) { @@ -240,8 +243,8 @@ export default AdComponent.extend({ loadedGoogletag: false, refreshOnChange: null, lastAdRefresh: null, - width: Ember.computed.alias("size.width"), - height: Ember.computed.alias("size.height"), + width: alias("size.width"), + height: alias("size.height"), @discourseComputed size() { @@ -372,7 +375,7 @@ export default AdComponent.extend({ @on("didInsertElement") _initGoogleDFP() { - if (Ember.testing) { + if (isTesting()) { return; // Don't load external JS during tests } diff --git a/assets/javascripts/discourse/components/house-ad.js b/assets/javascripts/discourse/components/house-ad.js index faa21a6..d22d4bc 100644 --- a/assets/javascripts/discourse/components/house-ad.js +++ b/assets/javascripts/discourse/components/house-ad.js @@ -1,5 +1,6 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; +import { isBlank } from "@ember/utils"; const adIndex = { topic_list_top: null, @@ -60,10 +61,7 @@ export default AdComponent.extend({ const adsForSlot = houseAds.settings[placement]; - if ( - Object.keys(houseAds.creatives).length > 0 && - !Ember.isBlank(adsForSlot) - ) { + if (Object.keys(houseAds.creatives).length > 0 && !isBlank(adsForSlot)) { return adsForSlot.split("|"); } else { return []; diff --git a/assets/javascripts/discourse/components/house-ads-list-setting.js b/assets/javascripts/discourse/components/house-ads-list-setting.js index 96ddaa6..6ece8cc 100644 --- a/assets/javascripts/discourse/components/house-ads-list-setting.js +++ b/assets/javascripts/discourse/components/house-ads-list-setting.js @@ -1,6 +1,7 @@ import HouseAdsSetting from "discourse/plugins/discourse-adplugin/discourse/components/house-ads-setting"; +import { mapBy } from "@ember/object/computed"; export default HouseAdsSetting.extend({ classNames: "house-ads-setting house-ads-list-setting", - adNames: Ember.computed.mapBy("allAds", "name"), + adNames: mapBy("allAds", "name"), }); diff --git a/assets/javascripts/discourse/components/house-ads-setting.js b/assets/javascripts/discourse/components/house-ads-setting.js index 7951d45..6f55e07 100644 --- a/assets/javascripts/discourse/components/house-ads-setting.js +++ b/assets/javascripts/discourse/components/house-ads-setting.js @@ -1,9 +1,10 @@ +import Component from "@ember/component"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { i18n, propertyNotEqual } from "discourse/lib/computed"; import I18n from "I18n"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: "house-ads-setting", adValue: "", saving: false, diff --git a/assets/javascripts/discourse/controllers/admin-plugins-house-ads-index.js b/assets/javascripts/discourse/controllers/admin-plugins-house-ads-index.js index 271eea8..93b1920 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-house-ads-index.js +++ b/assets/javascripts/discourse/controllers/admin-plugins-house-ads-index.js @@ -1,5 +1,8 @@ -export default Ember.Controller.extend({ - adminPluginsHouseAds: Ember.inject.controller("adminPlugins.houseAds"), - houseAds: Ember.computed.alias("adminPluginsHouseAds.model"), - adSettings: Ember.computed.alias("adminPluginsHouseAds.houseAdsSettings"), +import Controller, { inject as controller } from "@ember/controller"; +import { alias } from "@ember/object/computed"; + +export default Controller.extend({ + adminPluginsHouseAds: controller("adminPlugins.houseAds"), + houseAds: alias("adminPluginsHouseAds.model"), + adSettings: alias("adminPluginsHouseAds.houseAdsSettings"), }); diff --git a/assets/javascripts/discourse/controllers/admin-plugins-house-ads-show.js b/assets/javascripts/discourse/controllers/admin-plugins-house-ads-show.js index 293cf15..15d1434 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-house-ads-show.js +++ b/assets/javascripts/discourse/controllers/admin-plugins-house-ads-show.js @@ -3,17 +3,20 @@ import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { propertyNotEqual } from "discourse/lib/computed"; import { bufferedProperty } from "discourse/mixins/buffered-content"; +import bootbox from "bootbox"; +import Controller, { inject as controller } from "@ember/controller"; +import { not, or } from "@ember/object/computed"; -export default Ember.Controller.extend(bufferedProperty("model"), { - adminPluginsHouseAds: Ember.inject.controller("adminPlugins.houseAds"), +export default Controller.extend(bufferedProperty("model"), { + adminPluginsHouseAds: controller("adminPlugins.houseAds"), saving: false, savingStatus: "", nameDirty: propertyNotEqual("buffered.name", "model.name"), htmlDirty: propertyNotEqual("buffered.html", "model.html"), - dirty: Ember.computed.or("nameDirty", "htmlDirty"), - disableSave: Ember.computed.not("dirty"), + dirty: or("nameDirty", "htmlDirty"), + disableSave: not("dirty"), actions: { save() { diff --git a/assets/javascripts/discourse/controllers/admin-plugins-house-ads.js b/assets/javascripts/discourse/controllers/admin-plugins-house-ads.js index 35eb48e..382125e 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-house-ads.js +++ b/assets/javascripts/discourse/controllers/admin-plugins-house-ads.js @@ -1,3 +1,5 @@ -export default Ember.Controller.extend({ +import Controller from "@ember/controller"; + +export default Controller.extend({ loadingAds: true, }); diff --git a/assets/javascripts/discourse/routes/admin-plugins-house-ads-show.js b/assets/javascripts/discourse/routes/admin-plugins-house-ads-show.js index e2ab9a9..5dd45a6 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-house-ads-show.js +++ b/assets/javascripts/discourse/routes/admin-plugins-house-ads-show.js @@ -1,10 +1,11 @@ import DiscourseRoute from "discourse/routes/discourse"; +import EmberObject from "@ember/object"; import I18n from "I18n"; export default DiscourseRoute.extend({ model(params) { if (params.ad_id === "new") { - return Ember.Object.create({ + return EmberObject.create({ name: I18n.t("admin.adplugin.house_ads.new_name"), html: "", }); diff --git a/assets/javascripts/discourse/routes/admin-plugins-house-ads.js b/assets/javascripts/discourse/routes/admin-plugins-house-ads.js index 00c806d..9bd5c0a 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-house-ads.js +++ b/assets/javascripts/discourse/routes/admin-plugins-house-ads.js @@ -1,13 +1,14 @@ import { ajax } from "discourse/lib/ajax"; import DiscourseRoute from "discourse/routes/discourse"; +import EmberObject from "@ember/object"; export default DiscourseRoute.extend({ settings: null, model() { return ajax("/admin/plugins/pluginad/house_creatives.json").then((data) => { - this.set("settings", Ember.Object.create(data.settings)); - return data.house_ads.map((ad) => Ember.Object.create(ad)); + this.set("settings", EmberObject.create(data.settings)); + return data.house_ads.map((ad) => EmberObject.create(ad)); }); }, diff --git a/package.json b/package.json index b46957e..a5e402a 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,6 @@ "author": "Discourse", "license": "MIT", "devDependencies": { - "eslint-config-discourse": "^1.1.8" + "eslint-config-discourse": "^2.0.0" } } diff --git a/yarn.lock b/yarn.lock index ba89755..60c3a38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -498,10 +498,10 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -eslint-config-discourse@^1.1.8: - version "1.1.8" - resolved "https://registry.yarnpkg.com/eslint-config-discourse/-/eslint-config-discourse-1.1.8.tgz#c297831876811ea08203aa348d1ba2a963b2ae78" - integrity sha512-ZSQfhliiO5Cfa7WcKoMkN4wW/1rBJpecpMJpfjiFsElfgPj4EV4Pzksi5CvFnRbJDoZh6DYYrQfO+tW062VOUA== +eslint-config-discourse@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/eslint-config-discourse/-/eslint-config-discourse-2.0.0.tgz#811ab2cf4e32c1f0d41bd57d9736d578fe80b741" + integrity sha512-enjsLU++iibJXM64YM6Y/yUM5580wKtkti9fQdrJDFkfLJnvv8/f2j7QmNbX//MoqWfIQfY2RkHH6VTfRUg4Mw== dependencies: babel-eslint "^10.1.0" ember-template-lint "^2.11.0"