From 773cefe21d9bb25a3d73cbd7219b639d3e19218a Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 5 Jun 2022 22:46:37 +0200 Subject: [PATCH] refactorings of search actions to bulk actions --- db/migrations/0196__rename_bulk_actions.sql | 2 + src/public/app/services/bulk_action.js | 26 ++++---- .../bulk_actions/{ => label}/add_label.js | 8 +-- .../bulk_actions/{ => label}/delete_label.js | 4 +- .../bulk_actions/{ => label}/rename_label.js | 4 +- .../update_label_value.js} | 19 ++---- .../bulk_actions/{ => note}/delete_note.js | 2 +- .../{ => note}/delete_note_revisions.js | 2 +- .../bulk_actions/{ => note}/move_note.js | 6 +- .../bulk_actions/relation/add_relation.js | 65 +++++++++++++++++++ .../{ => relation}/delete_relation.js | 4 +- .../{ => relation}/rename_relation.js | 4 +- .../update_relation_target.js} | 14 ++-- src/services/app_info.js | 2 +- 14 files changed, 114 insertions(+), 48 deletions(-) create mode 100644 db/migrations/0196__rename_bulk_actions.sql rename src/public/app/widgets/bulk_actions/{ => label}/add_label.js (90%) rename src/public/app/widgets/bulk_actions/{ => label}/delete_label.js (89%) rename src/public/app/widgets/bulk_actions/{ => label}/rename_label.js (93%) rename src/public/app/widgets/bulk_actions/{set_label_value.js => label/update_label_value.js} (76%) rename src/public/app/widgets/bulk_actions/{ => note}/delete_note.js (88%) rename src/public/app/widgets/bulk_actions/{ => note}/delete_note_revisions.js (93%) rename src/public/app/widgets/bulk_actions/{ => note}/move_note.js (91%) create mode 100644 src/public/app/widgets/bulk_actions/relation/add_relation.js rename src/public/app/widgets/bulk_actions/{ => relation}/delete_relation.js (90%) rename src/public/app/widgets/bulk_actions/{ => relation}/rename_relation.js (93%) rename src/public/app/widgets/bulk_actions/{set_relation_target.js => relation/update_relation_target.js} (84%) diff --git a/db/migrations/0196__rename_bulk_actions.sql b/db/migrations/0196__rename_bulk_actions.sql new file mode 100644 index 000000000..fd82ae344 --- /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.js index 81c11e72d..b2de0c130 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.js similarity index 90% rename from src/public/app/widgets/bulk_actions/add_label.js rename to src/public/app/widgets/bulk_actions/label/add_label.js index 515a8ae36..e4267c88d 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 = ` @@ -38,8 +38,8 @@ const TPL = ` `; 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.js similarity index 89% rename from src/public/app/widgets/bulk_actions/delete_label.js rename to src/public/app/widgets/bulk_actions/label/delete_label.js index 6c81d5615..76490ca56 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 = ` diff --git a/src/public/app/widgets/bulk_actions/rename_label.js b/src/public/app/widgets/bulk_actions/label/rename_label.js similarity index 93% rename from src/public/app/widgets/bulk_actions/rename_label.js rename to src/public/app/widgets/bulk_actions/label/rename_label.js index 99f458c24..a215846d7 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 = ` diff --git a/src/public/app/widgets/bulk_actions/set_label_value.js b/src/public/app/widgets/bulk_actions/label/update_label_value.js similarity index 76% rename from src/public/app/widgets/bulk_actions/set_label_value.js rename to src/public/app/widgets/bulk_actions/label/update_label_value.js index 76063f693..3a0829fff 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 = `
-
Set label
+
Update label value
@@ -37,9 +32,9 @@ const TPL = ` `; -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.js similarity index 88% rename from src/public/app/widgets/bulk_actions/delete_note.js rename to src/public/app/widgets/bulk_actions/note/delete_note.js index 20bf83bc0..1580987f1 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 = ` diff --git a/src/public/app/widgets/bulk_actions/delete_note_revisions.js b/src/public/app/widgets/bulk_actions/note/delete_note_revisions.js similarity index 93% rename from src/public/app/widgets/bulk_actions/delete_note_revisions.js rename to src/public/app/widgets/bulk_actions/note/delete_note_revisions.js index 40ed8123b..6fa8ad823 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 = ` diff --git a/src/public/app/widgets/bulk_actions/move_note.js b/src/public/app/widgets/bulk_actions/note/move_note.js similarity index 91% rename from src/public/app/widgets/bulk_actions/move_note.js rename to src/public/app/widgets/bulk_actions/note/move_note.js index 03a49b8bb..ba11e9f70 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 = ` diff --git a/src/public/app/widgets/bulk_actions/relation/add_relation.js b/src/public/app/widgets/bulk_actions/relation/add_relation.js new file mode 100644 index 000000000..40ba0ab08 --- /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 = ` + + +
+
Set relation
+ + + +
to
+ +
+ +
+
+ + + + + + +`; + +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.js similarity index 90% rename from src/public/app/widgets/bulk_actions/delete_relation.js rename to src/public/app/widgets/bulk_actions/relation/delete_relation.js index 59ef5b913..86cd99c50 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 = ` diff --git a/src/public/app/widgets/bulk_actions/rename_relation.js b/src/public/app/widgets/bulk_actions/relation/rename_relation.js similarity index 93% rename from src/public/app/widgets/bulk_actions/rename_relation.js rename to src/public/app/widgets/bulk_actions/relation/rename_relation.js index c5e2094a2..9031b88a7 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 = ` diff --git a/src/public/app/widgets/bulk_actions/set_relation_target.js b/src/public/app/widgets/bulk_actions/relation/update_relation_target.js similarity index 84% rename from src/public/app/widgets/bulk_actions/set_relation_target.js rename to src/public/app/widgets/bulk_actions/relation/update_relation_target.js index a6cdf8718..5c4b98d73 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 = `
-
Set relation
+
Update relation
`; -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.js index 60fc6bc68..7d9d74129 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";