Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactorings of search actions to bulk actions
zadam773cefe21d9b
diff --git a/db/migrations/0196__rename_bulk_actions.sql b/db/migrations/0196__rename_bulk_actions.sqlnew file mode 100644index 0000000000..fd82ae3442--- /dev/null+++ b/db/migrations/0196__rename_bulk_actions.sql@@ -0,0 +1,2 @@+UPDATE attributes SET name = 'updateLabelValue' WHERE name = 'setLabelValue' AND type = 'label';+UPDATE attributes SET name = 'updateRelationTarget' WHERE name = 'setRelationTarget' AND type = 'label';diff --git a/src/public/app/services/bulk_action.js b/src/public/app/services/bulk_action.jsindex 81c11e72d9..b2de0c1306 100644--- a/src/public/app/services/bulk_action.js+++ b/src/public/app/services/bulk_action.js@@ -1,15 +1,17 @@import server from "./server.js";import ws from "./ws.js";-import MoveNoteBulkAction from "../widgets/bulk_actions/move_note.js";-import DeleteNoteBulkAction from "../widgets/bulk_actions/delete_note.js";-import DeleteNoteRevisionsBulkAction from "../widgets/bulk_actions/delete_note_revisions.js";-import DeleteLabelBulkAction from "../widgets/bulk_actions/delete_label.js";-import DeleteRelationBulkAction from "../widgets/bulk_actions/delete_relation.js";-import RenameLabelBulkAction from "../widgets/bulk_actions/rename_label.js";-import RenameRelationBulkAction from "../widgets/bulk_actions/rename_relation.js";-import SetLabelValueBulkAction from "../widgets/bulk_actions/set_label_value.js";-import SetRelationTargetSearchAction from "../widgets/bulk_actions/set_relation_target.js";+import MoveNoteBulkAction from "../widgets/bulk_actions/note/move_note.js";+import DeleteNoteBulkAction from "../widgets/bulk_actions/note/delete_note.js";+import DeleteNoteRevisionsBulkAction from "../widgets/bulk_actions/note/delete_note_revisions.js";+import DeleteLabelBulkAction from "../widgets/bulk_actions/label/delete_label.js";+import DeleteRelationBulkAction from "../widgets/bulk_actions/relation/delete_relation.js";+import RenameLabelBulkAction from "../widgets/bulk_actions/label/rename_label.js";+import RenameRelationBulkAction from "../widgets/bulk_actions/relation/rename_relation.js";+import UpdateLabelValueBulkAction from "../widgets/bulk_actions/label/update_label_value.js";+import UpdateRelationTargetBulkAction from "../widgets/bulk_actions/relation/update_relation_target.js";import ExecuteScriptBulkAction from "../widgets/bulk_actions/execute_script.js";+import AddLabelBulkAction from "../widgets/bulk_actions/label/add_label.js";+import AddRelationBulkAction from "../widgets/bulk_actions/relation/add_relation.js";const ACTION_CLASSES = [MoveNoteBulkAction,@@ -19,8 +21,10 @@ const ACTION_CLASSES = [DeleteRelationBulkAction,RenameLabelBulkAction,RenameRelationBulkAction,- SetLabelValueBulkAction,- SetRelationTargetSearchAction,+ AddLabelBulkAction,+ AddRelationBulkAction,+ UpdateLabelValueBulkAction,+ UpdateRelationTargetBulkAction,ExecuteScriptBulkAction];diff --git a/src/public/app/widgets/bulk_actions/add_label.js b/src/public/app/widgets/bulk_actions/label/add_label.jssimilarity index 90%rename from src/public/app/widgets/bulk_actions/add_label.jsrename to src/public/app/widgets/bulk_actions/label/add_label.jsindex 515a8ae369..e4267c88db 100644--- a/src/public/app/widgets/bulk_actions/add_label.js+++ b/src/public/app/widgets/bulk_actions/label/add_label.js@@ -1,5 +1,5 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>@@ -38,8 +38,8 @@ const TPL = `</tr>`;export default class AddLabelBulkAction extends AbstractBulkAction {- static get actionName() { return "setLabelValue"; }- static get actionTitle() { return "Set label value"; }+ static get actionName() { return "addLabel"; }+ static get actionTitle() { return "Add label"; }doRender() {const $action = $(TPL);diff --git a/src/public/app/widgets/bulk_actions/delete_label.js b/src/public/app/widgets/bulk_actions/label/delete_label.jssimilarity index 89%rename from src/public/app/widgets/bulk_actions/delete_label.jsrename to src/public/app/widgets/bulk_actions/label/delete_label.jsindex 6c81d56152..76490ca56f 100644--- a/src/public/app/widgets/bulk_actions/delete_label.js+++ b/src/public/app/widgets/bulk_actions/label/delete_label.js@@ -1,5 +1,5 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/rename_label.js b/src/public/app/widgets/bulk_actions/label/rename_label.jssimilarity index 93%rename from src/public/app/widgets/bulk_actions/rename_label.jsrename to src/public/app/widgets/bulk_actions/label/rename_label.jsindex 99f458c248..a215846d7f 100644--- a/src/public/app/widgets/bulk_actions/rename_label.js+++ b/src/public/app/widgets/bulk_actions/label/rename_label.js@@ -1,5 +1,5 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/set_label_value.js b/src/public/app/widgets/bulk_actions/label/update_label_value.jssimilarity index 76%rename from src/public/app/widgets/bulk_actions/set_label_value.jsrename to src/public/app/widgets/bulk_actions/label/update_label_value.jsindex 76063f6937..3a0829fff5 100644--- a/src/public/app/widgets/bulk_actions/set_label_value.js+++ b/src/public/app/widgets/bulk_actions/label/update_label_value.js@@ -1,11 +1,11 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr><td colspan="2"><div style="display: flex; align-items: center">- <div style="margin-right: 10px;" class="text-nowrap">Set label</div>+ <div style="margin-right: 10px;" class="text-nowrap">Update label value</div><input type="text"class="form-control label-name"@@ -22,12 +22,7 @@ const TPL = `<div class="dropdown help-dropdown"><span class="bx bx-help-circle icon-action" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span><div class="dropdown-menu dropdown-menu-right p-4">- <p>On all matched notes:</p>-- <ul>- <li>create given label if note doesn't have one yet</li>- <li>or change value of the existing label</li>- </ul>+ <p>On all matched notes, change value of the existing label.</p><p>You can also call this method without value, in such case label will be assigned to the note without value.</p></div>@@ -37,9 +32,9 @@ const TPL = `</td></tr>`;-export default class SetLabelValueBulkAction extends AbstractBulkAction {- static get actionName() { return "setLabelValue"; }- static get actionTitle() { return "Set label value"; }+export default class UpdateLabelValueBulkAction extends AbstractBulkAction {+ static get actionName() { return "updateLabelValue"; }+ static get actionTitle() { return "Update label value"; }doRender() {const $action = $(TPL);diff --git a/src/public/app/widgets/bulk_actions/delete_note.js b/src/public/app/widgets/bulk_actions/note/delete_note.jssimilarity index 88%rename from src/public/app/widgets/bulk_actions/delete_note.jsrename to src/public/app/widgets/bulk_actions/note/delete_note.jsindex 20bf83bc01..1580987f1e 100644--- a/src/public/app/widgets/bulk_actions/delete_note.js+++ b/src/public/app/widgets/bulk_actions/note/delete_note.js@@ -1,4 +1,4 @@-import AbstractBulkAction from "./abstract_bulk_action.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/delete_note_revisions.js b/src/public/app/widgets/bulk_actions/note/delete_note_revisions.jssimilarity index 93%rename from src/public/app/widgets/bulk_actions/delete_note_revisions.jsrename to src/public/app/widgets/bulk_actions/note/delete_note_revisions.jsindex 40ed8123b7..6fa8ad8233 100644--- a/src/public/app/widgets/bulk_actions/delete_note_revisions.js+++ b/src/public/app/widgets/bulk_actions/note/delete_note_revisions.js@@ -1,4 +1,4 @@-import AbstractBulkAction from "./abstract_bulk_action.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/move_note.js b/src/public/app/widgets/bulk_actions/note/move_note.jssimilarity index 91%rename from src/public/app/widgets/bulk_actions/move_note.jsrename to src/public/app/widgets/bulk_actions/note/move_note.jsindex 03a49b8bb4..ba11e9f701 100644--- a/src/public/app/widgets/bulk_actions/move_note.js+++ b/src/public/app/widgets/bulk_actions/note/move_note.js@@ -1,6 +1,6 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";-import noteAutocompleteService from "../../services/note_autocomplete.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";+import noteAutocompleteService from "../../../services/note_autocomplete.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/relation/add_relation.js b/src/public/app/widgets/bulk_actions/relation/add_relation.jsnew file mode 100644index 0000000000..40ba0ab085--- /dev/null+++ b/src/public/app/widgets/bulk_actions/relation/add_relation.js@@ -0,0 +1,65 @@+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";+import noteAutocompleteService from "../../../services/note_autocomplete.js";++const TPL = `+<tr>+ <td colspan="2">+ <div style="display: flex; align-items: center">+ <div style="margin-right: 10px;" class="text-nowrap">Set relation</div>++ <input type="text"+ class="form-control relation-name"+ placeholder="relation name"+ pattern="[\\p{L}\\p{N}_:]+"+ style="flex-shrink: 3"+ title="Alphanumeric characters, underscore and colon are allowed characters."/>++ <div style="margin-right: 10px; margin-left: 10px;" class="text-nowrap">to</div>++ <div class="input-group" style="flex-shrink: 2">+ <input type="text" class="form-control target-note" placeholder="target note"/>+ </div>+ </div>+ </td>+ <td class="button-column">+ <div class="dropdown help-dropdown">+ <span class="bx bx-help-circle icon-action" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>+ <div class="dropdown-menu dropdown-menu-right p-4">+ <p>On all matched notes create given relation.</p>+ </div>+ </div>++ <span class="bx bx-x icon-action action-conf-del"></span>+ </td>+</tr>`;++export default class AddRelationBulkAction extends AbstractBulkAction {+ static get actionName() { return "addRelation"; }+ static get actionTitle() { return "Add relation"; }++ doRender() {+ const $action = $(TPL);++ const $relationName = $action.find('.relation-name');+ $relationName.val(this.actionDef.relationName || "");++ const $targetNote = $action.find('.target-note');+ noteAutocompleteService.initNoteAutocomplete($targetNote);+ $targetNote.setNote(this.actionDef.targetNoteId);++ $targetNote.on('autocomplete:closed', () => spacedUpdate.scheduleUpdate());++ const spacedUpdate = new SpacedUpdate(async () => {+ await this.saveAction({+ relationName: $relationName.val(),+ targetNoteId: $targetNote.getSelectedNoteId()+ });+ }, 1000)++ $relationName.on('input', () => spacedUpdate.scheduleUpdate());+ $targetNote.on('input', () => spacedUpdate.scheduleUpdate());++ return $action;+ }+}diff --git a/src/public/app/widgets/bulk_actions/delete_relation.js b/src/public/app/widgets/bulk_actions/relation/delete_relation.jssimilarity index 90%rename from src/public/app/widgets/bulk_actions/delete_relation.jsrename to src/public/app/widgets/bulk_actions/relation/delete_relation.jsindex 59ef5b9136..86cd99c500 100644--- a/src/public/app/widgets/bulk_actions/delete_relation.js+++ b/src/public/app/widgets/bulk_actions/relation/delete_relation.js@@ -1,5 +1,5 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/rename_relation.js b/src/public/app/widgets/bulk_actions/relation/rename_relation.jssimilarity index 93%rename from src/public/app/widgets/bulk_actions/rename_relation.jsrename to src/public/app/widgets/bulk_actions/relation/rename_relation.jsindex c5e2094a2f..9031b88a76 100644--- a/src/public/app/widgets/bulk_actions/rename_relation.js+++ b/src/public/app/widgets/bulk_actions/relation/rename_relation.js@@ -1,5 +1,5 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";const TPL = `<tr>diff --git a/src/public/app/widgets/bulk_actions/set_relation_target.js b/src/public/app/widgets/bulk_actions/relation/update_relation_target.jssimilarity index 84%rename from src/public/app/widgets/bulk_actions/set_relation_target.jsrename to src/public/app/widgets/bulk_actions/relation/update_relation_target.jsindex a6cdf87182..5c4b98d731 100644--- a/src/public/app/widgets/bulk_actions/set_relation_target.js+++ b/src/public/app/widgets/bulk_actions/relation/update_relation_target.js@@ -1,12 +1,12 @@-import SpacedUpdate from "../../services/spaced_update.js";-import AbstractBulkAction from "./abstract_bulk_action.js";-import noteAutocompleteService from "../../services/note_autocomplete.js";+import SpacedUpdate from "../../../services/spaced_update.js";+import AbstractBulkAction from "../abstract_bulk_action.js";+import noteAutocompleteService from "../../../services/note_autocomplete.js";const TPL = `<tr><td colspan="2"><div style="display: flex; align-items: center">- <div style="margin-right: 10px;" class="text-nowrap">Set relation</div>+ <div style="margin-right: 10px;" class="text-nowrap">Update relation</div><input type="text"class="form-control relation-name"@@ -39,9 +39,9 @@ const TPL = `</td></tr>`;-export default class SetRelationTargetSearchAction extends AbstractBulkAction {- static get actionName() { return "setRelationTarget"; }- static get actionTitle() { return "Set relation target"; }+export default class UpdateRelationTargetBulkAction extends AbstractBulkAction {+ static get actionName() { return "updateRelationTarget"; }+ static get actionTitle() { return "Update relation target"; }doRender() {const $action = $(TPL);diff --git a/src/services/app_info.js b/src/services/app_info.jsindex 60fc6bc68a..7d9d741294 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -4,7 +4,7 @@ const build = require('./build');const packageJson = require('../../package');const {TRILIUM_DATA_DIR} = require('./data_dir');-const APP_DB_VERSION = 195;+const APP_DB_VERSION = 196;const SYNC_VERSION = 25;const CLIPPER_PROTOCOL_VERSION = "1.0";