]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/core/event.service.ts
Docs: merge 3.2 release notes
[Evergreen.git] / Open-ILS / src / eg2 / src / app / core / event.service.ts
1 import {Injectable} from '@angular/core';
2
3 export class EgEvent {
4     code: number;
5     textcode: string;
6     payload: any;
7     desc: string;
8     debug: string;
9     note: string;
10     servertime: string;
11     ilsperm: string;
12     ilspermloc: number;
13     success: Boolean = false;
14
15     toString(): string {
16         let s = `Event: ${this.code}:${this.textcode} -> ${this.desc}`;
17         if (this.ilsperm) {
18             s += `  ${this.ilsperm}@${this.ilspermloc}`;
19         }
20         if (this.note) {
21             s += `\n${this.note}`;
22         }
23         return s;
24     }
25 }
26
27 @Injectable({providedIn: 'root'})
28 export class EventService {
29
30     /**
31      * Returns an Event if 'thing' is an event, null otherwise.
32      */
33     parse(thing: any): EgEvent {
34
35         // All events have a textcode
36         if (thing && typeof thing === 'object' && 'textcode' in thing) {
37
38             const evt = new EgEvent();
39
40             ['textcode', 'payload', 'desc', 'note', 'servertime', 'ilsperm']
41                 .forEach(field => { evt[field] = thing[field]; });
42
43             evt.debug = thing.stacktrace;
44             evt.code = +(thing.ilsevent || -1);
45             evt.ilspermloc = +(thing.ilspermloc || -1);
46             evt.success = thing.textcode === 'SUCCESS';
47
48             return evt;
49         }
50
51         return null;
52     }
53 }
54
55