1 | import {cached, defineAssoc} from "./decorators.js";
|
2 | import {lib, Collection, RallyBase} from "./rally-tools.js";
|
3 |
|
4 | class Notification extends RallyBase{
|
5 | constructor({data, remote}){
|
6 | super();
|
7 | this.data = data;
|
8 | this.meta = {};
|
9 | this.remote = remote;
|
10 | }
|
11 |
|
12 | static async getAllPreCollect(notifications){
|
13 | return notifications.sort((a, b) => {
|
14 | return a.attributes.type.localeCompare(b.attributes.type) ||
|
15 | a.attributes.name.localeCompare(b.attributes.name);
|
16 | });
|
17 | }
|
18 |
|
19 | chalkPrint(pad=false){
|
20 | let id = String("N-" + this.id)
|
21 | if(pad) id = id.padStart(4);
|
22 | return chalk`{green ${id}}: {blue ${this.type}} - {green ${this.name}}`;
|
23 | }
|
24 | }
|
25 |
|
26 | defineAssoc(Notification, "id", "data.id");
|
27 | defineAssoc(Notification, "name", "data.attributes.name");
|
28 | defineAssoc(Notification, "address", "data.attributes.address");
|
29 | defineAssoc(Notification, "type", "data.attributes.type");
|
30 | defineAssoc(Notification, "remote", "meta.remote");
|
31 | Notification.endpoint = "notificationPresets"
|
32 |
|
33 | export default Notification;
|