trilium/src/public/app/widgets/search_actions/abstract_search_action.js
2021-01-26 10:48:28 +01:00

51 lines
1.4 KiB
JavaScript

import server from "../../services/server.js";
import ws from "../../services/ws.js";
import Component from "../component.js";
export default class AbstractSearchAction extends Component {
constructor(attribute, actionDef) {
super();
this.attribute = attribute;
this.actionDef = actionDef;
}
render() {
try {
const $rendered = this.doRender();
$rendered.find('.action-conf-del').on('click', () => this.deleteAction())
return $rendered;
}
catch (e) {
logError(`Failed rendering search action: ${JSON.stringify(this.attribute.dto)} with error: ${e.message} ${e.stack}`);
return null;
}
}
// to be overriden
doRender() {}
async saveAction(data) {
const actionObject = Object.assign({ name: this.constructor.actionName }, data);
await server.put(`notes/${this.attribute.noteId}/attribute`, {
attributeId: this.attribute.attributeId,
type: 'label',
name: 'action',
value: JSON.stringify(actionObject)
});
await ws.waitForMaxKnownEntityChangeId();
}
async deleteAction() {
await server.remove(`notes/${this.attribute.noteId}/attributes/${this.attribute.attributeId}`);
await ws.waitForMaxKnownEntityChangeId();
await this.triggerCommand('refreshSearchDefinition');
}
}