-
Notifications
You must be signed in to change notification settings - Fork 5
/
scope.js
38 lines (32 loc) · 985 Bytes
/
scope.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { attr, belongsTo, hasMany } from "@ember-data/model";
import localizedAttr from "ember-emeis/decorators/localized-attr";
import LocalizedModel from "ember-emeis/models/localized";
export default class ScopeModel extends LocalizedModel {
@localizedAttr name;
@localizedAttr fullName;
@localizedAttr description;
@attr level;
@attr metainfo;
@attr isActive;
@belongsTo("scope", { inverse: "children", async: false }) parent;
@hasMany("scope", { inverse: "parent", async: false }) children;
@hasMany("acl") acls;
findParents() {
const anchestors = [];
let node = this;
while (node.parent) {
anchestors.push(node.parent);
node = node.parent;
}
return anchestors;
}
findChildren() {
const getAllChildren = (members) => {
return members.flatMap((member) => [
member,
...getAllChildren(member.children?.toArray()),
]);
};
return getAllChildren(this.children.toArray() ?? []);
}
}