mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
converted branch prefix dialog to new pattern
This commit is contained in:
parent
bc87bf12cf
commit
312ffc110a
@ -1,59 +0,0 @@
|
|||||||
import treeService from '../services/tree.js';
|
|
||||||
import server from '../services/server.js';
|
|
||||||
import froca from "../services/froca.js";
|
|
||||||
import toastService from "../services/toast.js";
|
|
||||||
import utils from "../services/utils.js";
|
|
||||||
|
|
||||||
const $dialog = $("#branch-prefix-dialog");
|
|
||||||
const $form = $("#branch-prefix-form");
|
|
||||||
const $treePrefixInput = $("#branch-prefix-input");
|
|
||||||
const $noteTitle = $('#branch-prefix-note-title');
|
|
||||||
|
|
||||||
let branchId;
|
|
||||||
|
|
||||||
export async function showDialog(notePath) {
|
|
||||||
const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath);
|
|
||||||
|
|
||||||
if (!noteId || !parentNoteId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
branchId = await froca.getBranchId(parentNoteId, noteId);
|
|
||||||
const branch = froca.getBranch(branchId);
|
|
||||||
|
|
||||||
if (!branch || branch.noteId === 'root') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentNote = await froca.getNote(branch.parentNoteId);
|
|
||||||
|
|
||||||
if (parentNote.type === 'search') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.openDialog($dialog);
|
|
||||||
|
|
||||||
$treePrefixInput.val(branch.prefix);
|
|
||||||
|
|
||||||
const noteTitle = await treeService.getNoteTitle(noteId);
|
|
||||||
|
|
||||||
$noteTitle.text(" - " + noteTitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function savePrefix() {
|
|
||||||
const prefix = $treePrefixInput.val();
|
|
||||||
|
|
||||||
await server.put('branches/' + branchId + '/set-prefix', { prefix: prefix });
|
|
||||||
|
|
||||||
$dialog.modal('hide');
|
|
||||||
|
|
||||||
toastService.showMessage("Branch prefix has been saved.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$form.on('submit', () => {
|
|
||||||
savePrefix();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
$dialog.on('shown.bs.modal', () => $treePrefixInput.trigger('focus'));
|
|
@ -56,6 +56,7 @@ import NoteSourceDialog from "../dialogs/note_source.js";
|
|||||||
import HelpDialog from "../widgets/dialogs/help.js";
|
import HelpDialog from "../widgets/dialogs/help.js";
|
||||||
import RecentChangesDialog from "../widgets/dialogs/recent_changes.js";
|
import RecentChangesDialog from "../widgets/dialogs/recent_changes.js";
|
||||||
import BackendLogDialog from "../widgets/dialogs/backend_log.js";
|
import BackendLogDialog from "../widgets/dialogs/backend_log.js";
|
||||||
|
import BranchPrefixDialog from "../widgets/dialogs/branch_prefix.js";
|
||||||
|
|
||||||
export default class DesktopLayout {
|
export default class DesktopLayout {
|
||||||
constructor(customWidgets) {
|
constructor(customWidgets) {
|
||||||
@ -186,6 +187,7 @@ export default class DesktopLayout {
|
|||||||
.child(new NoteSourceDialog())
|
.child(new NoteSourceDialog())
|
||||||
.child(new HelpDialog())
|
.child(new HelpDialog())
|
||||||
.child(new RecentChangesDialog())
|
.child(new RecentChangesDialog())
|
||||||
.child(new BackendLogDialog());
|
.child(new BackendLogDialog())
|
||||||
|
.child(new BranchPrefixDialog());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,6 @@ export default class RootCommandExecutor extends Component {
|
|||||||
import("../dialogs/markdown_import.js").then(d => d.importMarkdownInline());
|
import("../dialogs/markdown_import.js").then(d => d.importMarkdownInline());
|
||||||
}
|
}
|
||||||
|
|
||||||
async editBranchPrefixCommand() {
|
|
||||||
const notePath = appContext.tabManager.getActiveContextNotePath();
|
|
||||||
|
|
||||||
if (notePath) {
|
|
||||||
const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js");
|
|
||||||
editBranchPrefixDialog.showDialog(notePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
editReadOnlyNoteCommand() {
|
editReadOnlyNoteCommand() {
|
||||||
const noteContext = appContext.tabManager.getActiveContext();
|
const noteContext = appContext.tabManager.getActiveContext();
|
||||||
noteContext.readOnlyTemporarilyDisabled = true;
|
noteContext.readOnlyTemporarilyDisabled = true;
|
||||||
|
105
src/public/app/widgets/dialogs/branch_prefix.js
Normal file
105
src/public/app/widgets/dialogs/branch_prefix.js
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import treeService from '../../services/tree.js';
|
||||||
|
import server from '../../services/server.js';
|
||||||
|
import froca from "../../services/froca.js";
|
||||||
|
import toastService from "../../services/toast.js";
|
||||||
|
import utils from "../../services/utils.js";
|
||||||
|
import BasicWidget from "../basic_widget.js";
|
||||||
|
import appContext from "../../services/app_context.js";
|
||||||
|
|
||||||
|
let branchId;
|
||||||
|
|
||||||
|
const TPL = `<div class="branch-prefix-dialog modal fade mx-auto" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog modal-lg" role="document">
|
||||||
|
<form class="branch-prefix-form">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title mr-auto">Edit branch prefix</h5>
|
||||||
|
|
||||||
|
<button class="help-button" type="button" data-help-page="Tree-concepts#prefix" title="Help on Tree prefix">?</button>
|
||||||
|
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-left: 0;">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="branch-prefix-input">Prefix: </label>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<input class="branch-prefix-input form-control">
|
||||||
|
|
||||||
|
<div class="input-group-append">
|
||||||
|
<div class="branch-prefix-note-title input-group-text"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn btn-primary btn-sm">Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
export default class BranchPrefixDialog extends BasicWidget {
|
||||||
|
doRender() {
|
||||||
|
this.$widget = $(TPL);
|
||||||
|
this.$form = this.$widget.find(".branch-prefix-form");
|
||||||
|
this.$treePrefixInput = this.$widget.find(".branch-prefix-input");
|
||||||
|
this.$noteTitle = this.$widget.find('.branch-prefix-note-title');
|
||||||
|
|
||||||
|
this.$form.on('submit', () => {
|
||||||
|
this.savePrefix();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$widget.on('shown.bs.modal', () => this.$treePrefixInput.trigger('focus'));
|
||||||
|
}
|
||||||
|
|
||||||
|
async refresh(notePath) {
|
||||||
|
const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(notePath);
|
||||||
|
|
||||||
|
if (!noteId || !parentNoteId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
branchId = await froca.getBranchId(parentNoteId, noteId);
|
||||||
|
const branch = froca.getBranch(branchId);
|
||||||
|
|
||||||
|
if (!branch || branch.noteId === 'root') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentNote = await froca.getNote(branch.parentNoteId);
|
||||||
|
|
||||||
|
if (parentNote.type === 'search') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$treePrefixInput.val(branch.prefix);
|
||||||
|
|
||||||
|
const noteTitle = await treeService.getNoteTitle(noteId);
|
||||||
|
|
||||||
|
this.$noteTitle.text(" - " + noteTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editBranchPrefixEvent() {
|
||||||
|
const notePath = appContext.tabManager.getActiveContextNotePath();
|
||||||
|
|
||||||
|
await this.refresh(notePath);
|
||||||
|
|
||||||
|
utils.openDialog(this.$widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
async savePrefix() {
|
||||||
|
const prefix = this.$treePrefixInput.val();
|
||||||
|
|
||||||
|
await server.put(`branches/${branchId}/set-prefix`, {prefix: prefix});
|
||||||
|
|
||||||
|
this.$widget.modal('hide');
|
||||||
|
|
||||||
|
toastService.showMessage("Branch prefix has been saved.");
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,6 @@
|
|||||||
<div class="dropdown-menu dropdown-menu-sm" id="context-menu-container"></div>
|
<div class="dropdown-menu dropdown-menu-sm" id="context-menu-container"></div>
|
||||||
|
|
||||||
<%- include('dialogs/add_link.ejs') %>
|
<%- include('dialogs/add_link.ejs') %>
|
||||||
<%- include('dialogs/branch_prefix.ejs') %>
|
|
||||||
<%- include('dialogs/export.ejs') %>
|
<%- include('dialogs/export.ejs') %>
|
||||||
<%- include('dialogs/import.ejs') %>
|
<%- include('dialogs/import.ejs') %>
|
||||||
<%- include('dialogs/jump_to_note.ejs') %>
|
<%- include('dialogs/jump_to_note.ejs') %>
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
<div id="branch-prefix-dialog" class="modal fade mx-auto" tabindex="-1" role="dialog">
|
|
||||||
<div class="modal-dialog modal-lg" role="document">
|
|
||||||
<form id="branch-prefix-form">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title mr-auto">Edit branch prefix</h5>
|
|
||||||
|
|
||||||
<button class="help-button" type="button" data-help-page="Tree-concepts#prefix" title="Help on Tree prefix">?</button>
|
|
||||||
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-left: 0;">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="branch-prefix-input">Prefix: </label>
|
|
||||||
|
|
||||||
<div class="input-group">
|
|
||||||
<input id="branch-prefix-input" class="form-control">
|
|
||||||
|
|
||||||
<div class="input-group-append">
|
|
||||||
<div id="branch-prefix-note-title" class="input-group-text"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button class="btn btn-primary btn-sm">Save</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
Loading…
x
Reference in New Issue
Block a user