2018-11-08 20:01:25 +01:00
|
|
|
import server from "./server.js";
|
2019-08-26 20:21:43 +02:00
|
|
|
import ws from "./ws.js";
|
2018-11-08 20:01:25 +01:00
|
|
|
import treeUtils from "./tree_utils.js";
|
|
|
|
import noteAutocompleteService from "./note_autocomplete.js";
|
|
|
|
|
2019-05-04 22:44:25 +02:00
|
|
|
class Attributes {
|
|
|
|
/**
|
2019-05-08 19:55:24 +02:00
|
|
|
* @param {TabContext} ctx
|
2019-05-04 22:44:25 +02:00
|
|
|
*/
|
|
|
|
constructor(ctx) {
|
|
|
|
this.ctx = ctx;
|
|
|
|
this.attributePromise = null;
|
|
|
|
}
|
2018-11-08 20:01:25 +01:00
|
|
|
|
2019-05-04 22:44:25 +02:00
|
|
|
invalidateAttributes() {
|
|
|
|
this.attributePromise = null;
|
|
|
|
}
|
2018-11-08 20:01:25 +01:00
|
|
|
|
2019-05-04 22:44:25 +02:00
|
|
|
reloadAttributes() {
|
|
|
|
this.attributePromise = server.get(`notes/${this.ctx.note.noteId}/attributes`);
|
|
|
|
}
|
2018-12-24 23:08:43 +01:00
|
|
|
|
2019-05-04 22:44:25 +02:00
|
|
|
async refreshAttributes() {
|
|
|
|
this.reloadAttributes();
|
|
|
|
}
|
2018-11-08 20:01:25 +01:00
|
|
|
|
2019-05-04 22:44:25 +02:00
|
|
|
async getAttributes() {
|
|
|
|
if (!this.attributePromise) {
|
|
|
|
this.reloadAttributes();
|
|
|
|
}
|
2018-11-08 20:01:25 +01:00
|
|
|
|
2019-09-04 22:13:22 +02:00
|
|
|
return this.attributePromise;
|
2018-12-24 23:08:43 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 21:31:39 +02:00
|
|
|
eventReceived(name, data) {
|
2019-09-04 22:45:12 +02:00
|
|
|
if (!this.ctx.note) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:31:39 +02:00
|
|
|
if (name === 'syncData') {
|
|
|
|
if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) {
|
|
|
|
this.reloadAttributes();
|
|
|
|
}
|
2019-08-06 23:20:27 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-08 20:01:25 +01:00
|
|
|
}
|
|
|
|
|
2019-05-04 22:44:25 +02:00
|
|
|
export default Attributes;
|