mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	feat(geomap): add prompt for creating child note
This commit is contained in:
		@@ -266,7 +266,10 @@ type EventMappings = {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
    exportSvg: {
 | 
					    exportSvg: {
 | 
				
			||||||
        ntxId: string;
 | 
					        ntxId: string;
 | 
				
			||||||
    }
 | 
					    };
 | 
				
			||||||
 | 
					    geoMapCreateChildNote: {
 | 
				
			||||||
 | 
					        ntxId: string | null | undefined; // TODO: deduplicate ntxId
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type EventListener<T extends EventNames> = {
 | 
					export type EventListener<T extends EventNames> = {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,7 +61,7 @@ export class TypedComponent<ChildT extends TypedComponent<ChildT>> {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    triggerEvent(name: string, data = {}): Promise<unknown> | undefined | null {
 | 
					    triggerEvent<T extends EventNames>(name: T, data: EventData<T>): Promise<unknown> | undefined | null {
 | 
				
			||||||
        return this.parent?.triggerEvent(name, data);
 | 
					        return this.parent?.triggerEvent(name, data);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,7 @@ export default class GeoMapButtons extends NoteContextAwareWidget {
 | 
				
			|||||||
        super.doRender();
 | 
					        super.doRender();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.$widget = $(TPL);
 | 
					        this.$widget = $(TPL);
 | 
				
			||||||
 | 
					        this.$widget.find(".geo-map-create-child-note").on("click", () => this.triggerEvent("geoMapCreateChildNote", { ntxId: this.ntxId }));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,6 +43,7 @@ export default class RelationMapButtons extends NoteContextAwareWidget {
 | 
				
			|||||||
        this.$zoomOutButton = this.$widget.find(".relation-map-zoom-out");
 | 
					        this.$zoomOutButton = this.$widget.find(".relation-map-zoom-out");
 | 
				
			||||||
        this.$resetPanZoomButton = this.$widget.find(".relation-map-reset-pan-zoom");
 | 
					        this.$resetPanZoomButton = this.$widget.find(".relation-map-reset-pan-zoom");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // TODO: Deduplicate object creation here.
 | 
				
			||||||
        this.$createChildNote.on("click", () => this.triggerEvent("relationMapCreateChildNote", { ntxId: this.ntxId }));
 | 
					        this.$createChildNote.on("click", () => this.triggerEvent("relationMapCreateChildNote", { ntxId: this.ntxId }));
 | 
				
			||||||
        this.$resetPanZoomButton.on("click", () => this.triggerEvent("relationMapResetPanZoom", { ntxId: this.ntxId }));
 | 
					        this.$resetPanZoomButton.on("click", () => this.triggerEvent("relationMapResetPanZoom", { ntxId: this.ntxId }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,11 @@ import type { LatLng } from "leaflet";
 | 
				
			|||||||
import type FNote from "../../entities/fnote.js";
 | 
					import type FNote from "../../entities/fnote.js";
 | 
				
			||||||
import GeoMapWidget from "../geo_map.js";
 | 
					import GeoMapWidget from "../geo_map.js";
 | 
				
			||||||
import TypeWidget from "./type_widget.js"
 | 
					import TypeWidget from "./type_widget.js"
 | 
				
			||||||
 | 
					import server from "../../services/server.js";
 | 
				
			||||||
 | 
					import toastService from "../../services/toast.js";
 | 
				
			||||||
 | 
					import dialogService from "../../services/dialog.js";
 | 
				
			||||||
 | 
					import type { EventData } from "../../components/app_context.js";
 | 
				
			||||||
 | 
					import { t } from "../../services/i18n.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TPL = `\
 | 
					const TPL = `\
 | 
				
			||||||
<div class="note-detail-geo-map note-detail-printable">
 | 
					<div class="note-detail-geo-map note-detail-printable">
 | 
				
			||||||
@@ -19,9 +24,22 @@ interface MapData {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: Deduplicate
 | 
				
			||||||
 | 
					interface CreateChildResponse {
 | 
				
			||||||
 | 
					    note: {
 | 
				
			||||||
 | 
					        noteId: string;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface Clipboard {
 | 
				
			||||||
 | 
					    noteId: string;
 | 
				
			||||||
 | 
					    title: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class GeoMapTypeWidget extends TypeWidget {
 | 
					export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private geoMapWidget: GeoMapWidget;
 | 
					    private geoMapWidget: GeoMapWidget;
 | 
				
			||||||
 | 
					    private clipboard?: Clipboard;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static getType() {
 | 
					    static getType() {
 | 
				
			||||||
        return "geoMap";
 | 
					        return "geoMap";
 | 
				
			||||||
@@ -82,6 +100,28 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async geoMapCreateChildNoteEvent({ ntxId }: EventData<"geoMapCreateChildNote">) {
 | 
				
			||||||
 | 
					        if (!this.isNoteContext(ntxId)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const title = await dialogService.prompt({ message: t("relation_map.enter_title_of_new_note"), defaultValue: t("relation_map.default_new_note_title") });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!title?.trim()) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const { note } = await server.post<CreateChildResponse>(`notes/${this.noteId}/children?target=into`, {
 | 
				
			||||||
 | 
					            title,
 | 
				
			||||||
 | 
					            content: "",
 | 
				
			||||||
 | 
					            type: "text"
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        toastService.showMessage(t("relation_map.click_on_canvas_to_place_new_note"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.clipboard = { noteId: note.noteId, title };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async doRefresh(note: FNote) {
 | 
					    async doRefresh(note: FNote) {
 | 
				
			||||||
        await this.geoMapWidget.refresh();
 | 
					        await this.geoMapWidget.refresh();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user