Skip to content

Commit

Permalink
added working frontend side nested dependencies script
Browse files Browse the repository at this point in the history
  • Loading branch information
BkPankaj committed Aug 10, 2024
1 parent fc55f24 commit 212c03a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
7 changes: 5 additions & 2 deletions frontend/src/components/blocks/common/factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LinkModel, NodeModel, PortModel } from "@projectstorm/react-diagrams";
import { DefaultPortModel } from "@projectstorm/react-diagrams-defaults";
import { RightAngleLinkModel } from "@projectstorm/react-diagrams-routing";
import { PortTypes, ProjectInfo } from '../../../core/constants';
import { ProjectDesign } from '../../../core/serialiser/interfaces';
import { Dependency, ProjectDesign } from '../../../core/serialiser/interfaces';
import createCodeDialog from '../../dialogs/code-block-dialog';
import createConstantDialog from "../../dialogs/constant-block-dialog";
import createIODialog from '../../dialogs/input-output-block-dialog';
Expand Down Expand Up @@ -156,10 +156,13 @@ export const loadPackage = (jsonModel: any) => {
const model = jsonModel.editor;
const design = jsonModel.design as ProjectDesign;
const info = jsonModel.package as ProjectInfo;
const dependencies = jsonModel.dependencies as Dependency;

return new PackageBlockModel({
model: model,
design: design,
info: info
info: info,
dependencies: dependencies
});
}

Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/blocks/package/package-model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BaseModel from "../common/base-model";
import { NodeModelGenerics, PortModelAlignment } from "@projectstorm/react-diagrams";
import { BaseModelOptions, DeserializeEvent } from '@projectstorm/react-canvas-core';
import { ProjectDesign } from "../../../core/serialiser/interfaces";
import { Dependency, ProjectDesign } from "../../../core/serialiser/interfaces";
import { createPortModel } from "../common/factory";
import { PortTypes, ProjectInfo } from "../../../core/constants";

Expand All @@ -19,6 +19,7 @@ export interface PackageBlockModelOptions extends BaseModelOptions {
design: ProjectDesign;
model: any;
info: ProjectInfo;
dependencies: Dependency;
}

/**
Expand All @@ -31,6 +32,7 @@ export class PackageBlockModel extends BaseModel<PackageBlockData, NodeModelGene
public design: ProjectDesign;
private inputs: string[] = [];
private outputs: string[] = [];
public dependencies: Dependency;

constructor(options: PackageBlockModelOptions) {
super({
Expand All @@ -40,6 +42,7 @@ export class PackageBlockModel extends BaseModel<PackageBlockData, NodeModelGene
this.model = options.model;
this.info = options.info;
this.design = options.design;
this.dependencies = options.dependencies;
// Generate input port for each Input block present
// and output port for each Output block present in the
// internal project (model) structure
Expand Down Expand Up @@ -104,7 +107,8 @@ export class PackageBlockModel extends BaseModel<PackageBlockData, NodeModelGene
data: this.getData(),
model: this.model,
info: this.info,
design: this.design
design: this.design,
dependencies: this.dependencies
}
}

Expand All @@ -118,6 +122,7 @@ export class PackageBlockModel extends BaseModel<PackageBlockData, NodeModelGene
this.model = event.data.model;
this.info = event.data.info;
this.design = event.data.design;
this.dependencies = event.data.dependencies;
}

}
31 changes: 14 additions & 17 deletions frontend/src/core/serialiser/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ function getWires(model: DiagramModel): Wire[] {
const port2 = link.getTargetPort();

if (port1 instanceof BasePortModel && port2 instanceof BasePortModel) {
// Source should correspond to the block which is giving the output
// Target should correspond to the block receiving the input.
// So source is the port of type Output and target is the port of type Input or Parameter
const source = port1.getType() === PortTypes.OUTPUT ? port1 : port2;
const target = port1.getType() !== PortTypes.OUTPUT ? port1 : port2;
wires.push(
Expand Down Expand Up @@ -80,34 +77,34 @@ function getWires(model: DiagramModel): Wire[] {
function getBlocksAndDependencies(model: DiagramModel) {
const blocks: Block[] = [];
const dependencies: { [k: string]: Dependency } = {};
// Iterate over all the nodes and separate them into normal blocks and dependency blocks

model.getNodes().forEach((node) => {
console.log("node",node,node.getType())
if (node instanceof BaseModel) {
const block = {
const block: Block = {
id: node.getID(),
type: node.getType(),
data: node.getData(),
position: {
x: node.getPosition().x,
y: node.getPosition().y
}
}
// If a node is of Package type then its included in Dependencies
};

if (node instanceof PackageBlockModel) {
// The type is changed to a random string because a single package can be used multiple times
// with its own parameters and data. So making it a unique ID prevents any interference of data.
block.type = makeid(40);
// Add the design and package info of the package blocks under dependencies
const packageBlockModel = node as PackageBlockModel;
block.type = makeid(40); // Generate a unique identifier for the dependency

// Add the package information, design, and nested dependencies to the dependencies object
dependencies[block.type] = {
package: node.info,
design: node.design
design: node.design,
dependencies: node.dependencies
}

}

blocks.push(block);
}
})

});
// Return the blocks and dependencies as an object
return { blocks: blocks, dependencies: dependencies };
}
}
3 changes: 2 additions & 1 deletion frontend/src/core/serialiser/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ProjectDesign {
export interface Dependency {
// Meta info about project (model)
package: ProjectInfo;
// Data about blocks and connections.
// Data about blocks, connections and nested dependency.
design: ProjectDesign;
dependencies: Dependency;
}

0 comments on commit 212c03a

Please sign in to comment.