trigger execute bulk actions

This commit is contained in:
zadam 2022-06-12 00:05:46 +02:00
parent 041b4ea442
commit 63f0e441b9
6 changed files with 48 additions and 6 deletions

View File

@ -130,7 +130,17 @@ class TreeContextMenu {
this.treeWidget.triggerCommand("openNewNoteSplit", {ntxId, notePath});
}
else {
this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath});
const selectedOrActiveBranchIds = this.treeWidget.getSelectedOrActiveBranchIds(this.node);
const selectedOrActiveNoteIds = selectedOrActiveBranchIds
.map(branchId => froca.getBranch(branchId).noteId)
.filter(noteId => !!noteId);
this.treeWidget.triggerCommand(command, {
node: this.node,
notePath: notePath,
selectedOrActiveBranchIds,
selectedOrActiveNoteIds
});
}
}
}

View File

@ -55,7 +55,7 @@ export default class AddLabelBulkAction extends AbstractBulkAction {
labelName: $labelName.val(),
labelValue: $labelValue.val()
});
}, 1000)
}, 1000);
$labelName.on('input', () => spacedUpdate.scheduleUpdate());
$labelValue.on('input', () => spacedUpdate.scheduleUpdate());

View File

@ -2,6 +2,8 @@ import BasicWidget from "../basic_widget.js";
import froca from "../../services/froca.js";
import bulkActionService from "../../services/bulk_action.js";
import utils from "../../services/utils.js";
import server from "../../services/server.js";
import toastService from "../../services/toast.js";
const TPL = `
<div class="bulk-assign-attributes-dialog modal mx-auto" tabindex="-1" role="dialog">
@ -60,7 +62,7 @@ const TPL = `
<table class="bulk-existing-action-list"></table>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Execute bulk actions</button>
<button type="submit" class="execute-bulk-actions btn btn-primary">Execute bulk actions</button>
</div>
</div>
</div>
@ -79,6 +81,15 @@ export default class BulkActionsDialog extends BasicWidget {
await this.refresh();
});
this.$executeButton = this.$widget.find(".execute-bulk-actions");
this.$executeButton.on("click", async () => {
await server.post("bulk-action", { noteIds: this.selectedOrActiveNoteIds });
toastService.showMessage("Bulk actions have been executed successfully.", 3000);
utils.closeActiveDialog();
});
}
async refresh() {
@ -119,12 +130,15 @@ export default class BulkActionsDialog extends BasicWidget {
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.getAttributes().find(attr => attr.type === 'label' && attr.name === 'action')) {
// only refreshing deleted attrs, otherwise components update themselves
if (loadResults.getAttributes().find(attr => attr.type === 'label' && attr.name === 'action' && attr.isDeleted)) {
this.refresh();
}
}
async bulkActionsEvent({node}) {
async bulkActionsEvent({selectedOrActiveNoteIds}) {
this.selectedOrActiveNoteIds = selectedOrActiveNoteIds;
await this.refresh();
utils.openDialog(this.$widget);

View File

@ -307,7 +307,8 @@ export default class SearchDefinitionWidget extends NoteContextAwareWidget {
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.getAttributes().find(attr => attr.type === 'label' && attr.name === 'action')) {
// only refreshing deleted attrs, otherwise components update themselves
if (loadResults.getAttributes().find(attr => attr.type === 'label' && attr.name === 'action' && attr.isDeleted)) {
this.refresh();
}
}

View File

@ -0,0 +1,14 @@
const becca = require("../../becca/becca");
const bulkActionService = require("../../services/bulk_actions");
function execute(req) {
const {noteIds} = req.body;
const bulkActionNote = becca.getNote('bulkaction');
bulkActionService.executeActions(bulkActionNote, noteIds);
}
module.exports = {
execute
};

View File

@ -31,6 +31,7 @@ const scriptRoute = require('./api/script');
const senderRoute = require('./api/sender');
const filesRoute = require('./api/files');
const searchRoute = require('./api/search');
const bulkActionRoute = require('./api/bulk_action');
const specialNotesRoute = require('./api/special_notes');
const noteMapRoute = require('./api/note_map');
const clipperRoute = require('./api/clipper');
@ -357,6 +358,8 @@ function register(app) {
apiRoute(GET, '/api/search/:searchString', searchRoute.search);
apiRoute(GET, '/api/search-templates', searchRoute.searchTemplates);
apiRoute(POST, '/api/bulk-action', bulkActionRoute.execute);
route(POST, '/api/login/sync', [], loginApiRoute.loginSync, apiResultHandler);
// this is for entering protected mode so user has to be already logged-in (that's the reason we don't require username)
apiRoute(POST, '/api/login/protected', loginApiRoute.loginToProtectedSession);