2024-08-06 10:39:15 +08:00
|
|
|
import { t } from "../../services/i18n.js";
|
2021-01-30 15:50:46 +01:00
|
|
|
import server from "../../services/server.js";
|
2021-05-22 12:35:41 +02:00
|
|
|
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
2021-04-16 23:01:56 +02:00
|
|
|
import froca from "../../services/froca.js";
|
2021-01-30 15:50:46 +01:00
|
|
|
import ws from "../../services/ws.js";
|
|
|
|
|
import toastService from "../../services/toast.js";
|
2021-06-06 11:01:10 +02:00
|
|
|
import treeService from "../../services/tree.js";
|
2021-01-24 22:30:53 +01:00
|
|
|
|
2021-01-30 15:50:46 +01:00
|
|
|
import SearchString from "../search_options/search_string.js";
|
|
|
|
|
import FastSearch from "../search_options/fast_search.js";
|
|
|
|
|
import Ancestor from "../search_options/ancestor.js";
|
|
|
|
|
import IncludeArchivedNotes from "../search_options/include_archived_notes.js";
|
|
|
|
|
import OrderBy from "../search_options/order_by.js";
|
|
|
|
|
import SearchScript from "../search_options/search_script.js";
|
2021-02-13 23:52:52 +01:00
|
|
|
import Limit from "../search_options/limit.js";
|
2021-02-18 22:10:49 +01:00
|
|
|
import Debug from "../search_options/debug.js";
|
2025-02-24 13:45:36 +02:00
|
|
|
import appContext, { type EventData } from "../../components/app_context.js";
|
2022-06-03 17:29:08 +02:00
|
|
|
import bulkActionService from "../../services/bulk_action.js";
|
2025-02-21 20:41:00 +01:00
|
|
|
import { Dropdown } from "bootstrap";
|
2025-02-24 13:45:36 +02:00
|
|
|
import type FNote from "../../entities/fnote.js";
|
|
|
|
|
import type { AttributeType } from "../../entities/fattribute.js";
|
2025-08-20 21:50:06 +03:00
|
|
|
import { renderReactWidget } from "../react/react_utils.jsx";
|
2020-11-26 23:00:27 +01:00
|
|
|
|
2025-04-01 23:24:21 +03:00
|
|
|
const TPL = /*html*/`
|
2025-08-24 11:38:50 +03:00
|
|
|
<div class="">
|
|
|
|
|
<div class="">
|
2020-11-26 23:00:27 +01:00
|
|
|
<tr>
|
2025-08-24 11:38:50 +03:00
|
|
|
<td>
|
2021-01-08 19:57:49 +01:00
|
|
|
<div class="dropdown" style="display: inline-block;">
|
2024-09-03 17:08:07 +02:00
|
|
|
<button class="btn btn-sm dropdown-toggle action-add-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
2021-01-08 19:57:49 +01:00
|
|
|
<span class="bx bxs-zap"></span>
|
2025-01-09 18:07:02 +02:00
|
|
|
${t("search_definition.action")}
|
2021-01-08 19:57:49 +01:00
|
|
|
</button>
|
2022-06-03 17:29:08 +02:00
|
|
|
<div class="dropdown-menu action-list"></div>
|
2021-01-08 19:57:49 +01:00
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
2021-01-24 22:30:53 +01:00
|
|
|
<tbody class="search-options"></tbody>
|
2021-01-19 22:10:24 +01:00
|
|
|
<tbody class="action-options"></tbody>
|
2020-11-26 23:00:27 +01:00
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const OPTION_CLASSES = [SearchString, SearchScript, Ancestor, FastSearch, IncludeArchivedNotes, OrderBy, Limit, Debug];
|
2021-01-24 22:30:53 +01:00
|
|
|
|
2021-05-22 12:35:41 +02:00
|
|
|
export default class SearchDefinitionWidget extends NoteContextAwareWidget {
|
2025-02-24 13:45:36 +02:00
|
|
|
|
|
|
|
|
private $component!: JQuery<HTMLElement>;
|
|
|
|
|
private $actionList!: JQuery<HTMLElement>;
|
|
|
|
|
private $searchOptions!: JQuery<HTMLElement>;
|
|
|
|
|
private $searchButton!: JQuery<HTMLElement>;
|
|
|
|
|
private $searchAndExecuteButton!: JQuery<HTMLElement>;
|
|
|
|
|
private $saveToNoteButton!: JQuery<HTMLElement>;
|
|
|
|
|
private $actionOptions!: JQuery<HTMLElement>;
|
|
|
|
|
|
2022-06-08 23:44:43 +02:00
|
|
|
get name() {
|
|
|
|
|
return "searchDefinition";
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 23:00:27 +01:00
|
|
|
doRender() {
|
|
|
|
|
this.$widget = $(TPL);
|
2021-06-13 22:55:31 +02:00
|
|
|
this.contentSized();
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$component = this.$widget.find(".search-definition-widget");
|
|
|
|
|
this.$actionList = this.$widget.find(".action-list");
|
2022-06-03 17:29:08 +02:00
|
|
|
|
2022-06-05 23:36:46 +02:00
|
|
|
for (const actionGroup of bulkActionService.ACTION_GROUPS) {
|
|
|
|
|
this.$actionList.append($('<h6 class="dropdown-header">').append(actionGroup.title));
|
|
|
|
|
|
|
|
|
|
for (const action of actionGroup.actions) {
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$actionList.append($('<a class="dropdown-item" href="#">').attr("data-action-add", action.actionName).text(action.actionTitle));
|
2022-06-05 23:36:46 +02:00
|
|
|
}
|
2022-06-03 17:29:08 +02:00
|
|
|
}
|
2021-01-17 21:11:01 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$widget.on("click", "[data-action-add]", async (event) => {
|
2025-02-24 13:45:36 +02:00
|
|
|
Dropdown.getOrCreateInstance(this.$widget.find(".action-add-toggle")[0]);
|
2021-01-25 21:24:02 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const actionName = $(event.target).attr("data-action-add");
|
2022-06-03 17:29:08 +02:00
|
|
|
|
2025-02-24 13:45:36 +02:00
|
|
|
if (this.noteId && actionName) {
|
|
|
|
|
await bulkActionService.addAction(this.noteId, actionName);
|
|
|
|
|
}
|
2021-01-25 21:24:02 +01:00
|
|
|
|
|
|
|
|
this.refresh();
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$searchOptions = this.$widget.find(".search-options");
|
|
|
|
|
this.$actionOptions = this.$widget.find(".action-options");
|
2020-11-26 23:00:27 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-24 13:45:36 +02:00
|
|
|
async refreshWithNote(note: FNote) {
|
|
|
|
|
if (!this.note) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 17:29:08 +02:00
|
|
|
const actions = bulkActionService.parseActions(this.note);
|
2025-02-24 13:45:36 +02:00
|
|
|
const renderedEls = actions
|
2025-08-10 14:06:14 +03:00
|
|
|
.map((action) => renderReactWidget(this, action.doRender()))
|
2025-02-24 13:45:36 +02:00
|
|
|
.filter((e) => e) as JQuery<HTMLElement>[];
|
2021-01-18 22:52:07 +01:00
|
|
|
|
2025-02-24 13:45:36 +02:00
|
|
|
this.$actionOptions.empty().append(...renderedEls);
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$searchAndExecuteButton.css("visibility", actions.length > 0 ? "visible" : "_hidden");
|
2020-12-04 22:57:54 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-26 23:00:27 +01:00
|
|
|
}
|