Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rest-on-couch/Roc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define([
'src/util/IDBKeyValue',
'eventEmitter',
'./UserViewPrefs',
'./UserPrefs',
'./UserAnalysisResults'
], function (
Datas,
Expand All @@ -27,6 +28,7 @@ define([
IDB,
EventEmitter,
UserViewPrefs,
UserViewPrefs,
UserAnalysisResults
) {
const DataObject = Datas.DataObject;
Expand Down Expand Up @@ -198,6 +200,7 @@ define([
this.__ready = Promise.resolve();

this.UserViewPrefs = new UserViewPrefs(this);
this.UserPrefs = new UserPrefs(this);
this.UserAnalysisResults = new UserAnalysisResults(this);
}

Expand Down
42 changes: 42 additions & 0 deletions rest-on-couch/UserPrefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
});