Skip to content

Commit 1eef24b

Browse files
DEV: Convert to native class syntax (#88)
1 parent a1189ef commit 1eef24b

File tree

9 files changed

+78
-75
lines changed

9 files changed

+78
-75
lines changed
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import Component from "@ember/component";
2-
import { computed } from "@ember/object";
2+
import { action, computed } from "@ember/object";
3+
import { tagName } from "@ember-decorators/component";
34

4-
export default Component.extend({
5-
tagName: "",
6-
7-
completed: computed("progress.completed.[]", function () {
5+
@tagName("")
6+
export default class TeambuildChoice extends Component {
7+
@computed("progress.completed.[]")
8+
get completed() {
89
return this.progress.isComplete(this.target, this.userId);
9-
}),
10+
}
11+
12+
@action
13+
complete() {
14+
this.progress.complete(this.target, this.userId);
15+
}
1016

11-
actions: {
12-
complete() {
13-
this.progress.complete(this.target, this.userId);
14-
},
15-
undo() {
16-
this.progress.undo(this.target, this.userId);
17-
},
18-
},
19-
});
17+
@action
18+
undo() {
19+
this.progress.undo(this.target, this.userId);
20+
}
21+
}
Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
import Controller from "@ember/controller";
2+
import { action } from "@ember/object";
23
import { sort } from "@ember/object/computed";
34
import { Types } from "discourse/plugins/discourse-teambuild/discourse/models/teambuild-target";
45

5-
export default Controller.extend({
6-
targets: null,
6+
export default class TeamBuildManageController extends Controller {
7+
targets = null;
8+
targetSort = ["position"];
79

8-
targetSort: ["position"],
10+
@sort("targets", "targetSort") sortedTargets;
911

10-
sortedTargets: sort("targets", "targetSort"),
12+
@action
13+
move(idx, direction) {
14+
let item = this.sortedTargets[idx];
15+
let other = this.sortedTargets[idx + direction];
16+
if (item && other) {
17+
item.swapPosition(other);
18+
}
19+
}
1120

12-
actions: {
13-
move(idx, direction) {
14-
let item = this.sortedTargets[idx];
15-
let other = this.sortedTargets[idx + direction];
16-
if (item && other) {
17-
item.swapPosition(other);
18-
}
19-
},
21+
@action
22+
newTarget() {
23+
let maxPosition = 0;
24+
if (this.targets.length > 0) {
25+
maxPosition = Math.max(...this.targets.map((t) => t.position));
26+
}
27+
this.targets.pushObject(
28+
this.store.createRecord("teambuild-target", {
29+
target_type_id: Types.REGULAR,
30+
position: maxPosition + 1,
31+
})
32+
);
33+
}
2034

21-
newTarget() {
22-
let maxPosition = 0;
23-
if (this.targets.length > 0) {
24-
maxPosition = Math.max(...this.targets.map((t) => t.position));
25-
}
26-
this.targets.pushObject(
27-
this.store.createRecord("teambuild-target", {
28-
target_type_id: Types.REGULAR,
29-
position: maxPosition + 1,
30-
})
31-
);
32-
},
33-
34-
removeTarget(t) {
35-
this.targets.removeObject(t);
36-
},
37-
},
38-
});
35+
@action
36+
removeTarget(t) {
37+
this.targets.removeObject(t);
38+
}
39+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Controller from "@ember/controller";
22
import { propertyNotEqual } from "discourse/lib/computed";
33

4-
export default Controller.extend({
5-
readOnly: propertyNotEqual("currentUser.id", "progress.user.id"),
6-
});
4+
export default class TeamBuildProgressController extends Controller {
5+
@propertyNotEqual("currentUser.id", "progress.user.id") readOnly;
6+
}

assets/javascripts/discourse/models/teambuild-progress.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ function choiceKey(target, userId) {
55
return `${target.id}:${userId}`;
66
}
77

8-
export default RestModel.extend({
8+
export default class TeambuildProgress extends RestModel {
99
isComplete(target, userId) {
1010
return this.completed.includes(choiceKey(target, userId));
11-
},
11+
}
1212

1313
complete(target, userId) {
1414
target
@@ -17,7 +17,7 @@ export default RestModel.extend({
1717
this.completed.addObject(choiceKey(target, userId));
1818
})
1919
.catch(popupAjaxError);
20-
},
20+
}
2121

2222
undo(target, userId) {
2323
target
@@ -26,5 +26,5 @@ export default RestModel.extend({
2626
this.completed.removeObject(choiceKey(target, userId));
2727
})
2828
.catch(popupAjaxError);
29-
},
30-
});
29+
}
30+
}

assets/javascripts/discourse/models/teambuild-target.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const Types = {
66
USER_GROUP: 2,
77
};
88

9-
export default RestModel.extend({
9+
export default class TeambuildTarget extends RestModel {
1010
swapPosition(other) {
1111
let tmp = this.position;
1212
this.set("position", other.position);
@@ -16,17 +16,17 @@ export default RestModel.extend({
1616
method: "PUT",
1717
data: { other_id: other.id },
1818
});
19-
},
19+
}
2020

2121
complete(userId) {
2222
return ajax(`/team-build/complete/${this.id}/${userId}`, {
2323
method: "PUT",
2424
});
25-
},
25+
}
2626

2727
undo(userId) {
2828
return ajax(`/team-build/undo/${this.id}/${userId}`, {
2929
method: "DELETE",
3030
});
31-
},
32-
});
31+
}
32+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Route from "@ember/routing/route";
22
import { ajax } from "discourse/lib/ajax";
33

4-
export default Route.extend({
4+
export default class TeamBuildIndexRoute extends Route {
55
model() {
66
return ajax("/team-build/scores.json");
7-
},
7+
}
88

99
setupController(controller, model) {
1010
controller.set("scores", model.scores);
11-
},
12-
});
11+
}
12+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Route from "@ember/routing/route";
22

3-
export default Route.extend({
3+
export default class TeamBuildManageRoute extends Route {
44
model() {
55
return this.store.findAll("teambuild-target");
6-
},
6+
}
77

88
setupController(controller, targets) {
99
controller.setProperties({ targets, groups: targets.extras.groups });
10-
},
11-
});
10+
}
11+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Route from "@ember/routing/route";
22

3-
export default Route.extend({
3+
export default class TeamBuildProgressRoute extends Route {
44
model() {
55
return this.store.find("teambuild-progress", this.currentUser.username);
6-
},
6+
}
77

88
setupController(controller, progress) {
99
controller.setProperties({ progress });
10-
},
11-
});
10+
}
11+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Route from "@ember/routing/route";
22

3-
export default Route.extend({
3+
export default class TeamBuildShowRoute extends Route {
44
model(params) {
55
return this.store.find("teambuild-progress", params.username);
6-
},
6+
}
77

88
setupController(controller, progress) {
99
this.controllerFor("teamBuild.progress").setProperties({ progress });
10-
},
10+
}
1111

1212
renderTemplate() {
1313
this.render("teamBuild.progress");
14-
},
15-
});
14+
}
15+
}

0 commit comments

Comments
 (0)