-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathABScopeCore.js
More file actions
60 lines (48 loc) · 1.57 KB
/
ABScopeCore.js
File metadata and controls
60 lines (48 loc) · 1.57 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const ABApplication = require("../platform/ABApplication");
module.exports = class ABScopeCore {
constructor(values) {
// this.application = application;
this.fromValues(values);
}
fromValues(values = {}) {
this.id = values.uuid || values.id;
this.uuid = values.uuid || values.id;
this.name = values.name;
this.description = values.description;
this.translations = values.translations;
// username
this.createdBy = values.createdBy;
// json
this.filter = values.filter;
// boolean
this.allowAll = JSON.parse(values.allowAll || false);
// object ids
this.objectIds = values.objectIds;
this._objects = [];
if (values.objects) {
let mockApp = new ABApplication({});
(values.objects || []).forEach((o) => {
let obj = mockApp.objectNew(o);
this._objects.push(obj);
});
}
// multilingual fields: name, description
// this.application.translate(this, this, ['name', 'description']);
}
toObj() {
// this.application.unTranslate(this, this, ['name', 'description']);
return {
id: this.uuid || this.id,
uuid: this.uuid || this.id,
translations: this.translations,
createdBy: this.createdBy,
filter: this.filter,
allowAll: this.allowAll || false,
objectIds: this.objects().map((o) => o.id),
};
}
objects(filterFn) {
if (filterFn == null) return this._objects || [];
else return (this._objects || []).filter(filterFn);
}
};