UNPKG

1.1 kBJavaScriptView Raw
1import {cached, defineAssoc} from "./decorators.js";
2import {lib, Collection, RallyBase} from "./rally-tools.js";
3
4class 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
26defineAssoc(Notification, "id", "data.id");
27defineAssoc(Notification, "name", "data.attributes.name");
28defineAssoc(Notification, "address", "data.attributes.address");
29defineAssoc(Notification, "type", "data.attributes.type");
30defineAssoc(Notification, "remote", "meta.remote");
31Notification.endpoint = "notificationPresets"
32
33export default Notification;