Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 7685ebf

Browse files
DEV: Update to native class syntax (#230)
1 parent 4506b0b commit 7685ebf

16 files changed

+234
-224
lines changed
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
import { computed } from "@ember/object";
1+
import { action, computed } from "@ember/object";
2+
import { classNames } from "@ember-decorators/component";
23
import { makeArray } from "discourse-common/lib/helpers";
34
import MultiSelectComponent from "select-kit/components/multi-select";
45

5-
export default MultiSelectComponent.extend({
6-
classNames: ["house-ads-chooser"],
7-
filterable: true,
8-
filterPlaceholder: "admin.adplugin.house_ads.filter_placeholder",
9-
tokenSeparator: "|",
10-
allowCreate: false,
11-
allowAny: false,
12-
settingValue: "",
13-
valueAttribute: null,
14-
nameProperty: null,
6+
@classNames("house-ads-chooser")
7+
export default class HouseAdsChooser extends MultiSelectComponent {
8+
filterable = true;
9+
filterPlaceholder = "admin.adplugin.house_ads.filter_placeholder";
10+
tokenSeparator = "|";
11+
allowCreate = false;
12+
allowAny = false;
13+
settingValue = "";
14+
valueAttribute = null;
15+
nameProperty = null;
1516

16-
value: computed("settingValue", function () {
17+
@computed("settingValue")
18+
get value() {
1719
return this.settingValue
1820
.toString()
1921
.split(this.tokenSeparator)
2022
.filter(Boolean);
21-
}),
23+
}
2224

2325
// TODO: kept for legacy, remove when Discourse is 2.5
2426
mutateValues(values) {
2527
this.set("settingValue", values.join(this.tokenSeparator));
26-
},
28+
}
29+
2730
computeValues() {
2831
return this.settingValue.split(this.tokenSeparator).filter(Boolean);
29-
},
32+
}
3033

31-
content: computed("choices", function () {
34+
@computed("choices")
35+
get content() {
3236
return makeArray(this.choices);
33-
}),
37+
}
3438

35-
actions: {
36-
onChange(value) {
37-
const settingValue = makeArray(value).join(this.tokenSeparator);
38-
this.onChange?.(settingValue);
39-
},
40-
},
41-
});
39+
@action
40+
onChange(value) {
41+
const settingValue = makeArray(value).join(this.tokenSeparator);
42+
this.onChange?.(settingValue);
43+
}
44+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { mapBy } from "@ember/object/computed";
2+
import { classNames } from "@ember-decorators/component";
23
import HouseAdsSetting from "discourse/plugins/discourse-adplugin/discourse/components/house-ads-setting";
34

4-
export default HouseAdsSetting.extend({
5-
classNames: "house-ads-setting house-ads-list-setting",
6-
adNames: mapBy("allAds", "name"),
7-
});
5+
@classNames("house-ads-setting house-ads-list-setting")
6+
export default class HouseAdsListSetting extends HouseAdsSetting {
7+
@mapBy("allAds", "name") adNames;
8+
}
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
import Component from "@ember/component";
2+
import { action } from "@ember/object";
3+
import { classNames } from "@ember-decorators/component";
24
import { ajax } from "discourse/lib/ajax";
35
import { popupAjaxError } from "discourse/lib/ajax-error";
46
import { i18n, propertyNotEqual } from "discourse/lib/computed";
57
import I18n from "I18n";
68

7-
export default Component.extend({
8-
classNames: "house-ads-setting",
9-
adValue: "",
10-
saving: false,
11-
savingStatus: "",
12-
title: i18n("name", "admin.adplugin.house_ads.%@.title"),
13-
help: i18n("name", "admin.adplugin.house_ads.%@.description"),
14-
changed: propertyNotEqual("adValue", "value"),
9+
@classNames("house-ads-setting")
10+
export default class HouseAdsSetting extends Component {
11+
adValue = "";
12+
saving = false;
13+
savingStatus = "";
14+
15+
@i18n("name", "admin.adplugin.house_ads.%@.title") title;
16+
@i18n("name", "admin.adplugin.house_ads.%@.description") help;
17+
@propertyNotEqual("adValue", "value") changed;
1518

1619
init() {
17-
this._super(...arguments);
20+
super.init(...arguments);
1821
this.set("adValue", this.get("value"));
19-
},
22+
}
2023

21-
actions: {
22-
save() {
23-
if (!this.get("saving")) {
24-
this.setProperties({
25-
saving: true,
26-
savingStatus: I18n.t("saving"),
27-
});
24+
@action
25+
save() {
26+
if (!this.get("saving")) {
27+
this.setProperties({
28+
saving: true,
29+
savingStatus: I18n.t("saving"),
30+
});
2831

29-
ajax(
30-
`/admin/plugins/pluginad/house_settings/${this.get("name")}.json`,
31-
{
32-
type: "PUT",
33-
data: { value: this.get("adValue") },
34-
}
35-
)
36-
.then(() => {
37-
const adSettings = this.get("adSettings");
38-
adSettings.set(this.get("name"), this.get("adValue"));
39-
this.setProperties({
40-
value: this.get("adValue"),
41-
savingStatus: I18n.t("saved"),
42-
});
43-
})
44-
.catch(popupAjaxError)
45-
.finally(() => {
46-
this.setProperties({
47-
saving: false,
48-
savingStatus: "",
49-
});
32+
ajax(`/admin/plugins/pluginad/house_settings/${this.get("name")}.json`, {
33+
type: "PUT",
34+
data: { value: this.get("adValue") },
35+
})
36+
.then(() => {
37+
const adSettings = this.get("adSettings");
38+
adSettings.set(this.get("name"), this.get("adValue"));
39+
this.setProperties({
40+
value: this.get("adValue"),
41+
savingStatus: I18n.t("saved"),
42+
});
43+
})
44+
.catch(popupAjaxError)
45+
.finally(() => {
46+
this.setProperties({
47+
saving: false,
48+
savingStatus: "",
5049
});
51-
}
52-
},
50+
});
51+
}
52+
}
5353

54-
cancel() {
55-
this.set("adValue", this.get("value"));
56-
},
57-
},
58-
});
54+
@action
55+
cancel() {
56+
this.set("adValue", this.get("value"));
57+
}
58+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Controller, { inject as controller } from "@ember/controller";
22
import { alias } from "@ember/object/computed";
33

4-
export default Controller.extend({
5-
adminPluginsHouseAds: controller("adminPlugins.houseAds"),
6-
houseAds: alias("adminPluginsHouseAds.model"),
7-
adSettings: alias("adminPluginsHouseAds.houseAdsSettings"),
8-
});
4+
export default class AdminPluginsHouseAdsIndexController extends Controller {
5+
@controller("adminPlugins.houseAds") adminPluginsHouseAds;
6+
@alias("adminPluginsHouseAds.model") houseAds;
7+
@alias("adminPluginsHouseAds.houseAdsSettings") adSettings;
8+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Controller from "@ember/controller";
22

3-
export default Controller.extend({
4-
loadingAds: true,
5-
});
3+
export default class AdminPluginsHouseAdsController extends Controller {
4+
loadingAds = true;
5+
}

admin/assets/javascripts/discourse/routes/admin-plugins-house-ads-index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { action } from "@ember/object";
22
import { service } from "@ember/service";
33
import DiscourseRoute from "discourse/routes/discourse";
44

5-
export default DiscourseRoute.extend({
6-
router: service(),
5+
export default class AdminPluginsHouseAdsIndex extends DiscourseRoute {
6+
@service router;
77

88
@action
99
moreSettings() {
1010
this.router.transitionTo("adminSiteSettingsCategory", "ad_plugin");
11-
},
12-
});
11+
}
12+
}

admin/assets/javascripts/discourse/routes/admin-plugins-house-ads-show.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TrackedObject } from "@ember-compat/tracked-built-ins";
22
import DiscourseRoute from "discourse/routes/discourse";
33
import I18n from "I18n";
44

5-
export default DiscourseRoute.extend({
5+
export default class AdminPluginsHouseAdsShow extends DiscourseRoute {
66
model(params) {
77
if (params.ad_id === "new") {
88
return new TrackedObject({
@@ -19,5 +19,5 @@ export default DiscourseRoute.extend({
1919
)
2020
);
2121
}
22-
},
23-
});
22+
}
23+
}

admin/assets/javascripts/discourse/routes/admin-plugins-house-ads.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import EmberObject from "@ember/object";
22
import { ajax } from "discourse/lib/ajax";
33
import DiscourseRoute from "discourse/routes/discourse";
44

5-
export default DiscourseRoute.extend({
6-
settings: null,
5+
export default class AdminPluginsHouseAds extends DiscourseRoute {
6+
settings = null;
77

88
model() {
99
return ajax("/admin/plugins/pluginad/house_creatives.json").then((data) => {
1010
this.set("settings", EmberObject.create(data.settings));
1111
return data.house_ads.map((ad) => EmberObject.create(ad));
1212
});
13-
},
13+
}
1414

1515
setupController(controller, model) {
1616
controller.setProperties({
1717
model,
1818
houseAdsSettings: this.get("settings"),
1919
loadingAds: false,
2020
});
21-
},
22-
});
21+
}
22+
}

assets/javascripts/discourse/components/ad-component.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,30 @@ import {
77
isNthTopicListItem,
88
} from "discourse/plugins/discourse-adplugin/discourse/helpers/slot-position";
99

10-
export default Component.extend({
11-
router: service(),
10+
export default class AdComponent extends Component {
11+
@service router;
1212

13-
currentCategoryId: or(
13+
@or(
1414
"router.currentRoute.attributes.category.id",
1515
"router.currentRoute.parent.attributes.category_id"
16-
),
16+
)
17+
currentCategoryId;
1718

18-
currentCategorySlug: or(
19+
@or(
1920
"router.currentRoute.attributes.category.slug",
2021
"router.currentRoute.parent.attributes.category.slug"
21-
),
22+
)
23+
currentCategorySlug;
2224

2325
// Server needs to compute this in case hidden tags are being used.
24-
topicTagsDisableAds: alias(
25-
"router.currentRoute.parent.attributes.tags_disable_ads"
26-
),
26+
@alias("router.currentRoute.parent.attributes.tags_disable_ads")
27+
topicTagsDisableAds;
2728

28-
isRestrictedCategory: or(
29+
@or(
2930
"router.currentRoute.attributes.category.read_restricted",
3031
"router.currentRoute.parent.attributes.category.read_restricted"
31-
),
32+
)
33+
isRestrictedCategory;
3234

3335
@discourseComputed(
3436
"router.currentRoute.attributes.__type",
@@ -38,12 +40,12 @@ export default Component.extend({
3840
if (type === "tag" && tag) {
3941
return tag;
4042
}
41-
},
43+
}
4244

4345
@discourseComputed("router.currentRoute.parent.attributes.archetype")
4446
isPersonalMessage(topicType) {
4547
return topicType === "private_message";
46-
},
48+
}
4749

4850
@discourseComputed
4951
showToGroups() {
@@ -52,7 +54,7 @@ export default Component.extend({
5254
}
5355

5456
return this.currentUser.show_to_groups;
55-
},
57+
}
5658

5759
@discourseComputed(
5860
"currentCategoryId",
@@ -82,13 +84,13 @@ export default Component.extend({
8284
(!isRestrictedCategory ||
8385
!this.siteSettings.no_ads_for_restricted_categories)
8486
);
85-
},
87+
}
8688

8789
isNthPost(n) {
8890
return isNthPost(n, this.get("postNumber"));
89-
},
91+
}
9092

9193
isNthTopicListItem(n) {
9294
return isNthTopicListItem(n, this.get("indexNumber"));
93-
},
94-
});
95+
}
96+
}

assets/javascripts/discourse/components/ad-slot.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import EmberObject from "@ember/object";
22
import { service } from "@ember/service";
33
import { isBlank } from "@ember/utils";
4+
import { tagName } from "@ember-decorators/component";
45
import discourseComputed from "discourse-common/utils/decorators";
56
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
67
import {
@@ -173,9 +174,9 @@ export function slotContenders(
173174
return types;
174175
}
175176

176-
export default AdComponent.extend({
177-
router: service(),
178-
tagName: "",
177+
@tagName("")
178+
export default class AdSlot extends AdComponent {
179+
@service router;
179180

180181
/**
181182
* For a given ad placement and optionally a post number if in between posts,
@@ -190,7 +191,7 @@ export default AdComponent.extend({
190191
indexNumber,
191192
postNumber
192193
);
193-
},
194+
}
194195

195196
/**
196197
* Returns a list of the names of ad components that should be rendered
@@ -238,5 +239,5 @@ export default AdComponent.extend({
238239
}
239240

240241
return networkNames;
241-
},
242-
});
242+
}
243+
}

0 commit comments

Comments
 (0)