-
Notifications
You must be signed in to change notification settings - Fork 1
/
base-widget.js
62 lines (51 loc) · 1.11 KB
/
base-widget.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
const path = require('path');
const IonLogger = require('core/impl/log/IonLogger');
const sysLog = new IonLogger({});
module.exports = class Base {
static init (module) {
this.dir = path.dirname(module.filename);
}
constructor (id) {
this.id = id;
this.view = path.join(this.constructor.dir, 'view');
this.di = require('core/di');
this.scope = this.di.context('dashboard');
this.repo = this.scope.dataRepo;
}
init (cb) {
cb();
}
refresh (req, res) {
try {
this.job((err, result)=> {
if (err) {
this.logError(err);
res.status(500).send(err);
} else {
res.send(result);
}
});
} catch (err) {
res.status(500).send(err);
}
}
job (cb) {
try {
cb(null, {});
} catch (err) {
cb(err);
}
}
getUrl () {
return `/dashboard/widget/${this.id}`;
}
generateId () {
return `${this.id}-${Math.floor(Math.random() * 9999999)}`;
}
logError (err) {
let message = `Widget: ${this.id}: ${err}`;
sysLog.error(message);
console.error(err);
}
};