-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUserPrefs.js
More file actions
42 lines (40 loc) · 1003 Bytes
/
UserPrefs.js
File metadata and controls
42 lines (40 loc) · 1003 Bytes
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
define(function () {
class UserPrefs {
constructor(roc) {
this.roc = roc;
}
/**
* Retrieves user preferences related to the current view
* @return {object} preferences
*/
async get() {
let record = await this.getRecord();
if (record && record.$content) return record.$content;
return undefined;
}
async getRecord() {
var user = await this.roc.getUser();
if (!user || !user.username) return undefined;
var firstEntry = (
await this.roc.view('entryByOwnerAndId', {
key: [user.username, 'userPrefs'],
})
)[0];
return firstEntry;
}
async set(value) {
let record = await this.getRecord();
if (record) {
record.$content = value;
return this.roc.update(record);
} else {
return this.roc.create({
$id: ['userPrefs'],
$content: value,
$kind: 'userPrefs',
});
}
}
}
return UserPrefs;
});