|
1 | 1 | import Controller from "@ember/controller"; |
| 2 | +import { action } from "@ember/object"; |
2 | 3 | import { sort } from "@ember/object/computed"; |
3 | 4 | import { Types } from "discourse/plugins/discourse-teambuild/discourse/models/teambuild-target"; |
4 | 5 |
|
5 | | -export default Controller.extend({ |
6 | | - targets: null, |
| 6 | +export default class TeamBuildManageController extends Controller { |
| 7 | + targets = null; |
| 8 | + targetSort = ["position"]; |
7 | 9 |
|
8 | | - targetSort: ["position"], |
| 10 | + @sort("targets", "targetSort") sortedTargets; |
9 | 11 |
|
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 | + } |
11 | 20 |
|
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 | + } |
20 | 34 |
|
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 | +} |
0 commit comments