cables_dev/cables_ui/src/ui/components/tabs/tab_electronopdirs.js
- import { ele, Logger, TalkerAPI } from "cables-shared-client";
- import Tab from "../../elements/tabpanel/tab.js";
- import { getHandleBarHtml } from "../../utils/handlebars.js";
- import ModalDialog from "../../dialogs/modaldialog.js";
- import { gui } from "../../gui.js";
- import { platform } from "../../platform.js";
- export default class ElectronOpDirs
- {
- constructor(tabs)
- {
- this._log = new Logger("ElectronOpDirsTab");
- this._count = 0;
- this._timeout = null;
- this._tab = new Tab("op directories", { "icon": "folder", "singleton": true, "infotext": "tab_profiler", "padding": true });
- tabs.addTab(this._tab, true);
- this.show();
- this._tab.on("onActivate", this.show);
- }
- show()
- {
- if (!this._tab) return;
- platform.talkerAPI.send(TalkerAPI.CMD_ELECTRON_GET_PROJECT_OPDIRS, {}, (err, r) =>
- {
- if (!err && r.data)
- {
- const html = getHandleBarHtml("tab_electron_opdirs", { "dirs": r.data });
- this._tab.html(html);
- const listEle = ele.byId("dirlist");
- const infoBlock = listEle.querySelector(".highlightBlock");
- const addButton = this._tab.contentEle.querySelector("#addOpProjectDir");
- if (addButton)
- {
- addButton.addEventListener("click", () =>
- {
- platform.talkerAPI.send(TalkerAPI.CMD_ELECTRON_ADD_PROJECT_OPDIR, {}, (dirErr, _dirRes) =>
- {
- if (!dirErr)
- {
- this.show();
- this._loadOpsInDirs();
- }
- else
- {
- new ModalDialog({ "showOkButton": true, "warning": true, "title": "Warning", "text": dirErr.msg });
- this._log.info(dirErr.msg);
- }
- });
- });
- }
- const packageButton = this._tab.contentEle.querySelector("#addOpPackage");
- if (packageButton)
- {
- packageButton.addEventListener("click", () =>
- {
- platform.talkerAPI.send(TalkerAPI.CMD_ADD_OP_PACKAGE, {}, (dirErr, _dirRes) =>
- {
- if (!dirErr)
- {
- this.show();
- this._loadOpsInDirs();
- }
- else
- {
- new ModalDialog({ "showOkButton": true, "warning": true, "title": "Warning", "text": dirErr.msg });
- this._log.info(dirErr.msg);
- }
- });
- });
- }
- const removeButtons = this._tab.contentEle.querySelectorAll(".removeOpProjectDir");
- removeButtons.forEach((removeButton) =>
- {
- removeButton.addEventListener("click", () =>
- {
- const dir = removeButton.dataset.dir;
- platform.talkerAPI.send(TalkerAPI.CMD_ELECTRON_REMOVE_PROJECT_OPDIR, dir, () =>
- {
- this.show();
- this._loadOpsInDirs();
- });
- });
- });
- ele.hide(infoBlock);
- new Sortable(listEle, {
- "animation": 150,
- "handle": ".handle",
- "ghostClass": "ghost",
- "dragClass": "dragActive",
- "onEnd": () =>
- {
- infoBlock.classList.add("info");
- infoBlock.classList.remove("error");
- const order = [];
- const dirs = listEle.querySelectorAll("[data-dir]");
- dirs.forEach((dirEle) =>
- {
- order.push(dirEle.dataset.dir);
- });
- platform.talkerAPI.send(TalkerAPI.CMD_ELECTRON_SAVE_PROJECT_OPDIRS_ORDER, order, (orderErr, orderRes) =>
- {
- if (orderRes && orderRes.success)
- {
- infoBlock.innerHTML = "Saved, please reload the patch to see the changes";
- ele.show(infoBlock);
- }
- else
- {
- infoBlock.classList.remove("info");
- infoBlock.classList.add("error");
- infoBlock.innerHTML = orderErr;
- ele.show(infoBlock);
- }
- });
- }
- });
- }
- });
- }
- _loadOpsInDirs()
- {
- platform.talkerAPI.send(TalkerAPI.CMD_GET_ALL_OPDOCS, { "projectId": gui.patchId }, (_err, _data) =>
- {
- if (_err)
- {
- this._log.error("preloading error", _err);
- }
- else
- {
- if (gui.opDocs)
- {
- gui.opDocs.addOpDocs(_data.opDocs);
- }
- gui.opSelect().reload();
- }
- }, (response) =>
- {
- this._log.error("preloading error", response);
- });
- }
- }