Skip to content

Commit

Permalink
Save relations for the models
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kuhlmay committed Oct 19, 2023
1 parent 3301ccb commit c32be58
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 62 deletions.
8 changes: 8 additions & 0 deletions Build/Sources/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ const initialEdges = [];
function App() {
// Nodes for ReactFlow
const [nodes, setNodes] = useState([]);
const [edges, setEdges] = useState([]);

const onNodesChanged = (nodes) => {
// Dont use prev
setNodes(nodes);
}

const onEdgesChanged = (edges) => {
// Dont use prev
setEdges(edges);
}

// Zustand für das Ein- und Ausklappen der linken Spalte
const [isLeftColumnVisible, setLeftColumnVisible] = useState(true);

Expand Down Expand Up @@ -289,6 +295,7 @@ const updatePluginHandler = (pluginId, field, value) => {
plugins={plugins}
modules={modules}
nodes={nodes}
edges={edges}
addNewAuthorHandler={addNewAuthorHandler}
addNewModuleHandler={addNewModuleHandler}
addNewPluginHandler={addNewPluginHandler}
Expand All @@ -310,6 +317,7 @@ const updatePluginHandler = (pluginId, field, value) => {
<div >
<RightContentComponent
onNodesChanged={onNodesChanged}
onEdgesChanged={onEdgesChanged}
/>
</div>
</div>
Expand Down
58 changes: 55 additions & 3 deletions Build/Sources/components/ActionButtonsComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const ActionButtonsComponent = (props) => {

let properties = [];
node.data.properties.map((property) => {
console.log("Property");
console.log(property);
properties.push(
{
"allowedFileTypes": "",
Expand All @@ -57,7 +59,7 @@ export const ActionButtonsComponent = (props) => {
"propertyIsExcludeField": relation.propertyIsExcludeField || false,
"relationDescription": relation.relationDescription || "",
"relationName": relation.relationName || "",
"relationType": relation.relationType || "oneToMany",
"relationType": relation.relationType || "anyToMany",
"relationWire": "[wired]",
"renderType": "selectSingle",
"uid": uuidv4()
Expand Down Expand Up @@ -112,6 +114,28 @@ export const ActionButtonsComponent = (props) => {
console.log(props.nodes);
console.log("-Nodes END-")

let wires = props.edges.map((edge) => {
return {
"src": {
// Get module index from array
"moduleId": modules.findIndex(node => node.name === props.nodes.find(n => n.id === edge.source).data.label),
"terminal": "relationWire_0",
"uid": edge.id
},
"tgt": {
// Get module index from array
"moduleId": modules.findIndex(node => node.name === props.nodes.find(n => n.id === edge.target).data.label),
"terminal": "SOURCES",
"uid": edge.source
}
}
});

console.log("-Edges-")
console.log(props.edges);
console.log("Wires");
console.log(wires);

let working = {
"modules": modules,
"properties": {
Expand Down Expand Up @@ -139,9 +163,37 @@ export const ActionButtonsComponent = (props) => {
"plugins": props.plugins,
"vendorName": props.properties.vendorName || "MyVendor"
},
"wires": []
"wires": wires
};

/*
ReactFlow:
[
{
"source": "dndnode_0",
"sourceHandle": null,
"target": "dndnode_1",
"targetHandle": null,
"id": "reactflow__edge-dndnode_0-dndnode_1"
}
]
v11:
[
{
"src": {
"moduleId": 0, // Position aus Array
"terminal": "relationWire_0", // Statisch
"uid": "516486350492" // Relation ID
},
"tgt": {
"moduleId": 1, // Position aus Array
"terminal": "SOURCES", // Statisch
"uid": "473391177367" // Zielobjekt ID
}
}
]
*/

let payload = {
"id": 4,
"method": "saveWiring",
Expand Down Expand Up @@ -169,7 +221,7 @@ export const ActionButtonsComponent = (props) => {
console.log("Successfull saved");
console.log(response.data.success);
if(response.data.success === null || response.data.success === undefined) {
top.TYPO3.Modal.confirm('Successfull saved but ...', '... Something went wrong on server side');
top.TYPO3.Modal.confirm('Successfull saved but ...', '... Something went wrong on server side' + JSON.stringify(response.data));
} else {
top.TYPO3.Modal.confirm('Successfull saved', response.data.success);
}
Expand Down
4 changes: 4 additions & 0 deletions Build/Sources/components/ReactFlow/ReactFlowComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const ReactFlowComponent = (props) => {
props.onNodesChanged(nodes);
}, [nodes]);

useEffect(() => {
props.onEdgesChanged(edges);
}, [edges]);

const onDragOver = useCallback((event) => {
event.preventDefault();
event.dataTransfer.dropEffect = 'move';
Expand Down
10 changes: 10 additions & 0 deletions Build/Sources/components/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>$Title$</title>
</head>
<body>
$END$
</body>
</html>
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions Build/Sources/components/jsonstring-v122.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":4,"method":"saveWiring","name":"Test","params":{"language":"extbaseModeling","working":"{\"modules\":[{\"config\":{\"position\":[481.10227262733883,2.9610739963837034]},\"name\":\"Foos\",\"value\":{\"actionGroup\":{\"_default0_index\":false,\"_default1_list\":false,\"_default2_show\":false,\"_default3_new_create\":false,\"_default4_edit_update\":false,\"_default5_delete\":false,\"customActions\":[]},\"name\":\"Foos\",\"objectsettings\":{\"addDeletedField\":true,\"addHiddenField\":true,\"addStarttimeEndtimeFields\":true,\"aggregateRoot\":false,\"categorizable\":false,\"description\":\"\",\"mapToTable\":\"\",\"parentClass\":\"\",\"sorting\":false,\"type\":\"Entity\",\"uid\":\"1173301976935\"},\"propertyGroup\":{\"properties\":[]},\"relationGroup\":{\"relations\":[{\"foreignRelationClass\":\"\",\"lazyLoading\":true,\"propertyIsExcludeField\":true,\"relationDescription\":\"\",\"relationName\":\"rel\",\"relationType\":\"zeroToOne\",\"relationWire\":\"[wired]\",\"renderType\":\"selectSingle\",\"uid\":\"dd71d893-8fa0-49b9-9aef-e230627803e3\"}]}}},{\"config\":{\"position\":[880.6535299657737,298.42529023958286]},\"name\":\"Bar\",\"value\":{\"actionGroup\":{\"_default0_index\":false,\"_default1_list\":false,\"_default2_show\":false,\"_default3_new_create\":false,\"_default4_edit_update\":false,\"_default5_delete\":false,\"customActions\":[]},\"name\":\"Bar\",\"objectsettings\":{\"addDeletedField\":true,\"addHiddenField\":true,\"addStarttimeEndtimeFields\":true,\"aggregateRoot\":false,\"categorizable\":false,\"description\":\"\",\"mapToTable\":\"\",\"parentClass\":\"\",\"sorting\":false,\"type\":\"Entity\",\"uid\":\"1173301976935\"},\"propertyGroup\":{\"properties\":[]},\"relationGroup\":{\"relations\":[]}}}],\"properties\":{\"backendModules\":[],\"description\":\"\",\"emConf\":{\"category\":\"backend\",\"custom_category\":\"\",\"dependsOn\":\"\",\"disableLocalization\":false,\"disableVersioning\":false,\"generateDocumentationTemplate\":false,\"generateEditorConfig\":true,\"generateEmptyGitRepository\":true,\"sourceLanguage\":\"en\",\"state\":\"alpha\",\"targetVersion\":\"12.4.0-12.4.99\",\"version\":\"1.0.0\"},\"extensionKey\":\"test\",\"name\":\"Test\",\"originalExtensionKey\":\"\",\"originalVendorName\":\"\",\"persons\":[],\"plugins\":[],\"vendorName\":\"Test\"},\"wires\":[]}"},"version":"json-rpc-2.0"}
2 changes: 1 addition & 1 deletion Build/Sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ root.render(
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
reportWebVitals(console.log);

library.add(fab, fas)

7 changes: 2 additions & 5 deletions Build/Sources/styles/ReactFlow/Nodes/customModel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ $custom-model-accordion-padding-y: 0.5rem;

.accordion-header {
.accordion-button {
padding-top: 5px;
padding-bottom: 5px;
padding-left: $custom-model-accordion-padding-x;
padding-right: $custom-model-accordion-padding-x;
padding: 5px $custom-model-accordion-padding-x;
}
}

.accordion-body {
padding-left: $custom-model-accordion-padding-x;
padding-rigth: $custom-model-accordion-padding-x;
padding-right: $custom-model-accordion-padding-x;
}
}
49 changes: 25 additions & 24 deletions Classes/Configuration/ExtensionBuilderConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,30 +374,31 @@ protected function resetOutboundedPositions(array $jsonConfig): array
*/
protected function reArrangeRelations(array $jsonConfig): array
{
foreach ($jsonConfig['wires'] as &$wire) {
// format: relation_1
$parts = explode('_', $wire['src']['terminal']);
$supposedRelationIndex = (int)$parts[1];

// Source
$uid = $wire['src']['uid'];
$wire['src'] = $this->findModuleIndexByRelationUid(
$wire['src']['uid'],
$jsonConfig['modules'],
$wire['src']['moduleId'],
$supposedRelationIndex
);
$wire['src']['uid'] = $uid;

// Target
$uid = $wire['tgt']['uid'];
$wire['tgt'] = $this->findModuleIndexByRelationUid(
$wire['tgt']['uid'],
$jsonConfig['modules'],
$wire['tgt']['moduleId']
);
$wire['tgt']['uid'] = $uid;
}
// TODO check this code. This one removes the terminal array key inside the src array, this mustn't happen
// foreach ($jsonConfig['wires'] as &$wire) {
// // format: relation_1
// $parts = explode('_', $wire['src']['terminal']);
// $supposedRelationIndex = (int)$parts[1];
//
// // Source
// $uid = $wire['src']['uid'];
// $wire['src'] = $this->findModuleIndexByRelationUid(
// $wire['src']['uid'],
// $jsonConfig['modules'],
// $wire['src']['moduleId'],
// $supposedRelationIndex
// );
// $wire['src']['uid'] = $uid;
//
// // Target
// $uid = $wire['tgt']['uid'];
// $wire['tgt'] = $this->findModuleIndexByRelationUid(
// $wire['tgt']['uid'],
// $jsonConfig['modules'],
// $wire['tgt']['moduleId']
// );
// $wire['tgt']['uid'] = $uid;
// }
return $jsonConfig;
}

Expand Down
26 changes: 0 additions & 26 deletions Classes/Controller/BuilderModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,34 +397,8 @@ public function dispatchRpcAction(ServerRequestInterface $request): ResponseInte

// $response = $response->withStatus(200);
return $this->jsonResponse(json_encode($response));


/*
if ($input === null) {
throw new \InvalidArgumentException('Please provide a number', 1580585107);
}
$result = $input ** 2;
$response = $this->responseFactory->createResponse()
->withHeader('Content-Type', 'application/json; charset=utf-8');
$response->getBody()->write(json_encode(['result' => $result], JSON_THROW_ON_ERROR));
// add status code to response
$response = $response->withStatus(500);
return $response;
*/
// return Response with success message
// return $this->jsonResponse(json_encode(['error' => 'Action dispatched.'], 300));
// our previous computation
// $response = $this->responseFactory->createResponse()->withHeader('Content-Type', 'application/json; charset=utf-8');
// $response->getBody()->write(json_encode(['result' => 'test'], JSON_THROW_ON_ERROR));
// return $response;


}


/**
* Generate the code files according to the transferred JSON configuration.
*
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Css/backend.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c32be58

Please sign in to comment.