Add project transfer controls
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
createRoom,
|
||||
deleteProjectDevice,
|
||||
disconnectProjectDeviceRows,
|
||||
exportProjectTransfer,
|
||||
getProjectDeviceSyncPreview,
|
||||
listCircuitLists,
|
||||
listDistributionBoards,
|
||||
@@ -20,6 +21,7 @@ import {
|
||||
listProjectDevices,
|
||||
listProjects,
|
||||
listRooms,
|
||||
importProjectTransfer,
|
||||
synchronizeProjectDeviceRows,
|
||||
updateProjectDevice,
|
||||
updateProjectSettings,
|
||||
@@ -349,6 +351,67 @@ export default function ProjectDetailPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExportProject() {
|
||||
if (!project) {
|
||||
return;
|
||||
}
|
||||
setIsSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
const transfer = await exportProjectTransfer(project.id);
|
||||
const blob = new Blob([JSON.stringify(transfer, null, 2)], {
|
||||
type: "application/json",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = url;
|
||||
anchor.download = `${project.name.replace(/[^a-zA-Z0-9_-]+/g, "-") || "projekt"}.leistungsbilanz.json`;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Projekt konnte nicht exportiert werden."
|
||||
);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleImportProject(
|
||||
transfer: unknown,
|
||||
mode: "replace" | "duplicate"
|
||||
) {
|
||||
if (!project) {
|
||||
return;
|
||||
}
|
||||
setIsSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await importProjectTransfer(
|
||||
project.id,
|
||||
mode,
|
||||
project.currentRevision,
|
||||
transfer
|
||||
);
|
||||
if (mode === "duplicate" && "projectId" in result) {
|
||||
window.location.href = `/projects/${result.projectId}`;
|
||||
return;
|
||||
}
|
||||
window.location.reload();
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Projektdatei konnte nicht importiert werden."
|
||||
);
|
||||
setIsProjectSettingsOpen(false);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function openProjectDeviceSyncPreview(projectDeviceId: string) {
|
||||
if (!projectId) {
|
||||
return;
|
||||
@@ -1015,6 +1078,8 @@ export default function ProjectDetailPage() {
|
||||
<ProjectSettingsModal
|
||||
isSaving={isSaving}
|
||||
onClose={() => setIsProjectSettingsOpen(false)}
|
||||
onExport={handleExportProject}
|
||||
onImport={handleImportProject}
|
||||
onSave={handleSaveProjectSettings}
|
||||
project={project}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user