Skip to content

Web converter update #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/features/serialize/loadDFDandDD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,11 @@ export class LoadDFDandDDCommand extends Command {
const dataflowFileContent = await this.readFileContent(dataflowFile);
const dictionaryFileContent = await this.readFileContent(dictionaryFile);

// Send each file's content in separate WebSocket messages
sendMessage(
"DFD:" +
this.getFileNameWithoutExtension(dataflowFile) +
":" +
dataflowFileContent +
"\n:DD:\n" +
dictionaryFileContent,
);
setModelFileName(dataflowFile.name.substring(0, dataflowFile.name.lastIndexOf(".")));

// Send each file's content in separate WebSocket messages
sendMessage("DFD:" + dataflowFileContent + "\n:DD:\n" + dictionaryFileContent);

setFileNameInPageTitle(dataflowFile.name);
return context.root;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/serialize/saveDFDandDD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SaveDFDandDDCommand extends Command {
mode: this.editorModeController?.getCurrentMode(),
};
const diagramJson = JSON.stringify(diagram, undefined, 4);
sendMessage("Json2DFD:" + getModelFileName() + ":" + diagramJson);
sendMessage("Json2DFD:" + diagramJson);
return context.root;
}

Expand Down
13 changes: 10 additions & 3 deletions src/features/serialize/webSocketHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getModelFileName, logger, setModelSource, loadingIndicator } from "../../index";
import { SaveDFDandDD } from "./saveDFDandDD";

//Debug
//const webSocketAdress = `ws://localhost:3000/events/`;
const webSocketAdress = `wss://websocket.dataflowanalysis.org/events/`;

let ws: WebSocket;
Expand Down Expand Up @@ -47,16 +49,21 @@ function initWebSocket() {
loadingIndicator.hideIndicator();
return;
}

let message = event.data;
const name = message.split(":")[0];
message = message.replace(name + ":", "");

if (event.data.trim().endsWith("</datadictionary:DataDictionary>")) {
const saveDFDandDD = new SaveDFDandDD(event.data);
const saveDFDandDD = new SaveDFDandDD(message);
saveDFDandDD.saveDiagramAsDFD();
loadingIndicator.hideIndicator();
return;
}

// Otherwise, treat incoming data as JSON for model source:
setModelSource(
new File([new Blob([event.data], { type: "application/json" })], getModelFileName() + ".json", {
new File([new Blob([message], { type: "application/json" })], name + ".json", {
type: "application/json",
}),
);
Expand All @@ -65,7 +72,7 @@ function initWebSocket() {
}

export function sendMessage(message: string) {
ws.send(wsId + ":" + message);
ws.send(wsId + ":" + getModelFileName() + ":" + message);
}

// Initialize immediately upon module load
Expand Down