Skip to content
Merged
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
58 changes: 58 additions & 0 deletions frontend/webEditor/src/serialize/LoadUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Action } from "sprotty-protocol";
import { FileData, LoadJsonCommand } from "./loadJson";
import { inject } from "inversify";
import { TYPES, ILogger, ActionDispatcher } from "sprotty";
import { EditorModeController } from "../settings/editorMode";
import { LabelTypeRegistry } from "../labels/LabelTypeRegistry";
import { SavedDiagram } from "./SavedDiagram";
import { FileName } from "../fileName/fileName";
import { SETTINGS } from "../settings/Settings";
import { ConstraintRegistry } from "../constraint/constraintRegistry";
import { LoadingIndicator } from "../loadingIndicator/loadingIndicator";

interface LoadFromUrlAction extends Action {
url: string;
}

export namespace LoadFromUrlAction {
export const KIND = "loadUrl";

export function create(url: string): LoadFromUrlAction {
return { kind: KIND, url };
}
}

export class LoadFromUrlCommand extends LoadJsonCommand {
static readonly KIND = LoadFromUrlAction.KIND;

constructor(
@inject(TYPES.Action) private readonly action: LoadFromUrlAction,
@inject(TYPES.ILogger) logger: ILogger,
@inject(LabelTypeRegistry) labelTypeRegistry: LabelTypeRegistry,
@inject(ConstraintRegistry) constraintRegistry: ConstraintRegistry,
@inject(SETTINGS.Mode) editorModeController: EditorModeController,
@inject(TYPES.IActionDispatcher) actionDispatcher: ActionDispatcher,
@inject(FileName) fileName: FileName,
@inject(LoadingIndicator) loadingIndicator: LoadingIndicator,
) {
super(
logger,
labelTypeRegistry,
constraintRegistry,
editorModeController,
actionDispatcher,
fileName,
loadingIndicator,
);
}

protected async getFile(): Promise<FileData<SavedDiagram> | undefined> {
const content = await fetch(this.action.url).then((response) => response.json() as Promise<SavedDiagram>);
const urlParts = this.action.url.split("/");
const fileName = urlParts[urlParts.length - 1];
return {
content,
fileName,
};
}
}
2 changes: 2 additions & 0 deletions frontend/webEditor/src/serialize/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { DfdModelFactory } from "./ModelFactory";
import { SaveJsonFileCommand } from "./saveJsonFile";
import { SaveDfdAndDdFileCommand } from "./saveDfdAndDdFile";
import { AnalyzeCommand } from "./analyze";
import { LoadFromUrlCommand } from "./LoadUrl";

export const serializeModule = new ContainerModule((bind, unbind, isBound, rebind) => {
const context = { bind, unbind, isBound, rebind };
configureCommand(context, LoadDefaultDiagramCommand);
configureCommand(context, LoadJsonFileCommand);
configureCommand(context, LoadDfdAndDdFileCommand);
configureCommand(context, LoadPalladioFileCommand);
configureCommand(context, LoadFromUrlCommand);
configureCommand(context, SaveJsonFileCommand);
configureCommand(context, SaveDfdAndDdFileCommand);
configureCommand(context, AnalyzeCommand);
Expand Down
9 changes: 8 additions & 1 deletion frontend/webEditor/src/startUpAgent/LoadDefaultDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import { ActionDispatcher, TYPES } from "sprotty";
import { IStartUpAgent } from "./StartUpAgent";
import { LoadDefaultDiagramAction } from "../serialize/loadDefaultDiagram";
import { inject } from "inversify";
import { LoadFromUrlAction } from "../serialize/LoadUrl";

export class LoadDefaultDiagramStartUpAgent implements IStartUpAgent {
constructor(@inject(TYPES.IActionDispatcher) private actionDispatcher: ActionDispatcher) {}

run(): void {
this.actionDispatcher.dispatch(LoadDefaultDiagramAction.create());
const urlParams = new URLSearchParams(window.location.search);
const fileUrlParameter = urlParams.get("file");
this.actionDispatcher.dispatch(
fileUrlParameter != undefined
? LoadFromUrlAction.create(fileUrlParameter)
: LoadDefaultDiagramAction.create(),
);
}
}