Enhance export functionality in Mindnet plugin
- Introduced configurable export path for graph JSON files, allowing users to specify a custom location. - Added checks to ensure the output directory exists before exporting, improving reliability. - Updated settings interface to include export path configuration, enhancing user experience with clearer options for managing export settings.
This commit is contained in:
parent
9f051423ce
commit
15385b0129
|
|
@ -3,6 +3,7 @@ import type { Vocabulary } from "../vocab/Vocabulary";
|
||||||
import type { ParsedEdge } from "../parser/types";
|
import type { ParsedEdge } from "../parser/types";
|
||||||
import type { ExportBundle, ExportNode, ExportEdge } from "./types";
|
import type { ExportBundle, ExportNode, ExportEdge } from "./types";
|
||||||
import { parseEdgesFromCallouts } from "../parser/parseEdgesFromCallouts";
|
import { parseEdgesFromCallouts } from "../parser/parseEdgesFromCallouts";
|
||||||
|
import { ensureFolderExists } from "../mapping/folderHelpers";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export graph from vault markdown files.
|
* Export graph from vault markdown files.
|
||||||
|
|
@ -128,6 +129,14 @@ export async function exportGraph(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Ensure output directory exists
|
||||||
|
const pathParts = outputPath.split("/");
|
||||||
|
if (pathParts.length > 1) {
|
||||||
|
// Extract directory path (everything except the filename)
|
||||||
|
const directoryPath = pathParts.slice(0, -1).join("/");
|
||||||
|
await ensureFolderExists(app, directoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
const jsonContent = JSON.stringify(bundle, null, 2);
|
const jsonContent = JSON.stringify(bundle, null, 2);
|
||||||
await app.vault.adapter.write(outputPath, jsonContent);
|
await app.vault.adapter.write(outputPath, jsonContent);
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ export default class MindnetCausalAssistantPlugin extends Plugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputPath = "_system/exports/graph_export.json";
|
const outputPath = this.settings.exportPath || "_system/exports/graph_export.json";
|
||||||
await exportGraph(this.app, vocabulary, outputPath);
|
await exportGraph(this.app, vocabulary, outputPath);
|
||||||
|
|
||||||
new Notice(`Graph exported to ${outputPath}`);
|
new Notice(`Graph exported to ${outputPath}`);
|
||||||
|
|
@ -278,6 +278,12 @@ export default class MindnetCausalAssistantPlugin extends Plugin {
|
||||||
|
|
||||||
// Write report file
|
// Write report file
|
||||||
const reportPath = "_system/exports/chain_report.md";
|
const reportPath = "_system/exports/chain_report.md";
|
||||||
|
// Ensure output directory exists
|
||||||
|
const pathParts = reportPath.split("/");
|
||||||
|
if (pathParts.length > 1) {
|
||||||
|
const directoryPath = pathParts.slice(0, -1).join("/");
|
||||||
|
await ensureFolderExists(this.app, directoryPath);
|
||||||
|
}
|
||||||
await this.app.vault.adapter.write(reportPath, report);
|
await this.app.vault.adapter.write(reportPath, report);
|
||||||
|
|
||||||
// Open report
|
// Open report
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ export interface MindnetSettings {
|
||||||
inlineMicroEnabled: boolean; // default: true
|
inlineMicroEnabled: boolean; // default: true
|
||||||
inlineMaxAlternatives: number; // default: 6
|
inlineMaxAlternatives: number; // default: 6
|
||||||
inlineCancelBehavior: "keep_link"; // default: "keep_link" (future: "revert")
|
inlineCancelBehavior: "keep_link"; // default: "keep_link" (future: "revert")
|
||||||
|
// Export settings
|
||||||
|
exportPath: string; // default: "_system/exports/graph_export.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: MindnetSettings = {
|
export const DEFAULT_SETTINGS: MindnetSettings = {
|
||||||
|
|
@ -62,6 +64,7 @@ export interface MindnetSettings {
|
||||||
inlineMicroEnabled: true,
|
inlineMicroEnabled: true,
|
||||||
inlineMaxAlternatives: 6,
|
inlineMaxAlternatives: 6,
|
||||||
inlineCancelBehavior: "keep_link",
|
inlineCancelBehavior: "keep_link",
|
||||||
|
exportPath: "_system/exports/graph_export.json",
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -640,5 +640,61 @@ export class MindnetSettingTab extends PluginSettingTab {
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// 9. Export
|
||||||
|
// ============================================
|
||||||
|
containerEl.createEl("h3", { text: "📤 Export" });
|
||||||
|
containerEl.createEl("p", {
|
||||||
|
text: "Einstellungen für den Graph-Export.",
|
||||||
|
cls: "setting-item-description",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Export path
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName("Export path")
|
||||||
|
.setDesc(
|
||||||
|
"Pfad für die exportierte Graph-JSON-Datei. Die Datei enthält alle Knoten (Nodes) und Kanten (Edges) aus dem Vault."
|
||||||
|
)
|
||||||
|
.addText((text) =>
|
||||||
|
text
|
||||||
|
.setPlaceholder("_system/exports/graph_export.json")
|
||||||
|
.setValue(this.plugin.settings.exportPath)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.exportPath = value || "_system/exports/graph_export.json";
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.addButton((button) =>
|
||||||
|
button
|
||||||
|
.setButtonText("Export now")
|
||||||
|
.setCta()
|
||||||
|
.onClick(async () => {
|
||||||
|
try {
|
||||||
|
// Load vocabulary using the same method as the command
|
||||||
|
const { VocabularyLoader } = await import("../vocab/VocabularyLoader");
|
||||||
|
const { parseEdgeVocabulary } = await import("../vocab/parseEdgeVocabulary");
|
||||||
|
const { Vocabulary } = await import("../vocab/Vocabulary");
|
||||||
|
|
||||||
|
const text = await VocabularyLoader.loadText(
|
||||||
|
this.app,
|
||||||
|
this.plugin.settings.edgeVocabularyPath
|
||||||
|
);
|
||||||
|
|
||||||
|
const parsed = parseEdgeVocabulary(text);
|
||||||
|
const vocabulary = new Vocabulary(parsed);
|
||||||
|
|
||||||
|
const { exportGraph } = await import("../export/exportGraph");
|
||||||
|
await exportGraph(this.app, vocabulary, this.plugin.settings.exportPath);
|
||||||
|
|
||||||
|
new Notice(`Graph exported to ${this.plugin.settings.exportPath}`);
|
||||||
|
console.log(`Graph exported: ${this.plugin.settings.exportPath}`);
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : String(e);
|
||||||
|
new Notice(`Failed to export graph: ${msg}`);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user