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";
|
2020-01-25 09:56:08 +01:00
|
|
|
import treeService from "./tree.js";
|
2018-11-08 20:01:25 +01:00
|
|
|
import noteAutocompleteService from "./note_autocomplete.js";
|
2020-01-15 21:36:01 +01:00
|
|
|
import Component from "../widgets/component.js";
|
|
|
|
import utils from "./utils.js";
|
2018-11-08 20:01:25 +01:00
|
|
|
|
2020-01-15 21:36:01 +01:00
|
|
|
class Attributes extends Component {
|
2019-05-04 22:44:25 +02:00
|
|
|
/**
|
2020-01-15 21:36:01 +01:00
|
|
|
* @param {AppContext} appContext
|
|
|
|
* @param {TabContext} tabContext
|
2019-05-04 22:44:25 +02:00
|
|
|
*/
|
2020-01-15 21:36:01 +01:00
|
|
|
constructor(appContext, tabContext) {
|
|
|
|
super(appContext);
|
|
|
|
this.tabContext = tabContext;
|
2019-05-04 22:44:25 +02:00
|
|
|
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() {
|
2020-01-19 09:02:18 +01:00
|
|
|
if (this.tabContext.note) {
|
|
|
|
this.attributePromise = server.get(`notes/${this.tabContext.note.noteId}/attributes`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.invalidateAttributes();
|
|
|
|
}
|
2019-05-04 22:44:25 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-01-15 21:36:01 +01:00
|
|
|
syncDataListener({data}) {
|
|
|
|
if (this.tabContext.note && data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.tabContext.note.noteId)) {
|
|
|
|
this.reloadAttributes();
|
2019-09-04 22:45:12 +02:00
|
|
|
}
|
2020-01-15 21:36:01 +01:00
|
|
|
}
|
2019-09-04 22:45:12 +02:00
|
|
|
|
2020-01-18 20:49:49 +01:00
|
|
|
tabNoteSwitchedListener() {
|
2020-01-15 21:36:01 +01:00
|
|
|
if (utils.isDesktop()) {
|
2020-01-15 22:11:30 +01:00
|
|
|
this.refreshAttributes();
|
2020-01-15 21:36:01 +01:00
|
|
|
} else {
|
|
|
|
// mobile usually doesn't need attributes so we just invalidate
|
2020-01-15 22:11:30 +01:00
|
|
|
this.invalidateAttributes();
|
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;
|