Skip to content

Commit

Permalink
WIP refactor extension loading
Browse files Browse the repository at this point in the history
Probably this should be inside branch v12-load-old-extensions
  • Loading branch information
Philipp Kuhlmay committed Apr 5, 2024
1 parent 7c8e69e commit b43a95e
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 4,395 deletions.
22 changes: 19 additions & 3 deletions Build/Sources/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import initialProperties from "./initialValues/properties";
import defaultAuthor from "./initialValues/author";
import defaultModule from "./initialValues/module";
import defaultPlugin from "./initialValues/plugin";
import convertModulesToNodes from "./helper/converter/convertModulesToNodes";

export const NodesContext = createContext([]);
export const EdgesContext = createContext([]);
Expand Down Expand Up @@ -54,7 +55,7 @@ function App() {
}

const toggleAdvcancedOptions = () => {
console.log("toggle advanced options", isAdvancedOptionsVisible)
// console.log("toggle advanced options", isAdvancedOptionsVisible)
setAdvancedOptionsVisible(!isAdvancedOptionsVisible);
}

Expand Down Expand Up @@ -194,7 +195,7 @@ function App() {
};

const removeAuthorHandler = (authorIndex) => {
console.log(authorIndex);
// console.log(authorIndex);
setAuthors((prevAuthors) => {
return prevAuthors.filter((author, index) => index !== authorIndex);
});
Expand Down Expand Up @@ -232,8 +233,14 @@ function App() {
const moveModule = (index, direction) => moveElement(index, direction, modules, setModules);

const handleOpenExtension = (extension) => {
// TODO working.modules is not set here, instead, working.nodes is set and there is no uid for the module. The module uid is only inside working.modules
// The nodes has a data property, this has no uid, but needs it. Maybe I need to add the uid to the data property of the nodes.
// Instead the modules could be handed into the nodes but needs to be converted to the correct format. This could be a lot of work.
const working = JSON.parse(extension.working);

console.log("working inside handleOpenExtension:");
console.log(working);

// Sets properties.
setProperties(prev => ({...prev, ...working.properties}));

Expand All @@ -242,8 +249,17 @@ function App() {
setPlugins(working.properties.plugins);
setModules(working.properties.backendModules);

// console.log("working.modules");
// console.log(working.modules);

// console.log("working.nodes");
// console.log(working.nodes);

// First convert the given modules from .json file into nodes which are needed for the react flow component.
// let modules = convertModuleToNode(working.modules);
let modules = convertModulesToNodes(working.modules);
// Check if nodes or edges are available, and update them.
setNodes(working.nodes ? working.nodes: []);
setNodes(modules ? modules: []);
setEdges(working.edges ? working.edges : []);

// Set the custom model node index depending on the amount of nodes.
Expand Down
10 changes: 8 additions & 2 deletions Build/Sources/components/ActionButtonsComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export const ActionButtonsComponent = (props) => {
);
});

console.log("node actionbuttosncompoentn");
console.log(node);
let module = {
"config": {
"position": [
Expand Down Expand Up @@ -148,7 +150,7 @@ export const ActionButtonsComponent = (props) => {
"parentClass": node.data.extendExistingModelClass,
"sorting": node.data.enableSorting,
"type": "Entity",
"uid": uuidv4()
"uid": node?.uid ?? uuidv4()
},
"propertyGroup": {
"properties": properties
Expand All @@ -158,6 +160,8 @@ export const ActionButtonsComponent = (props) => {
}
}
};
console.log("modul");
console.log(module);
modules.push(module);
});

Expand Down Expand Up @@ -220,7 +224,7 @@ export const ActionButtonsComponent = (props) => {
"vendorName": props.properties.vendorName
},
"wires": wires,
"nodes": nodes,
/*"nodes": nodes,*/
"edges": edges
};

Expand Down Expand Up @@ -296,6 +300,8 @@ export const ActionButtonsComponent = (props) => {
// error = null, if no error occurs
// success = true, when the request was successful
// result with the array of extensions
console.log("available extensions");
console.log(extensions);

if(extensions.error !== null && extensions.success === false) {
console.log("fetching failed");
Expand Down
147 changes: 147 additions & 0 deletions Build/Sources/helper/converter/convertModulesToNodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
function convertModulesToNodes(modules) {
// needed for the node
/*
{
id,
type,
position: {
x,
y
},
data: {
label,
objectType,
isAggregateRoot,
enableSorting,
addDeletedField,
addHiddenField,
addStarttimeEndtimeFields,
enableCategorization,
description,
mapToExistingTable,
extendExistingModelClass,
actions: {
actionIndex,
actionList,
actionShow,
actionNewCreate,
actionEditUpdate,
actionDelete
},
customActions -> Array,
properties -> Array,
relations -> Array
},
positionAbsolute: {
x,
y
}
}
*/

for (let i = 0; i < modules.length; i++) {
console.log(`Element ${i}:`, modules[i]);
// Hier kannst du auf einzelne Eigenschaften des aktuellen Objekts zugreifen, z.B.:
console.log(`Name: ${modules[i].name}`);
// Und weitere Verarbeitungen für jedes Objekt im Array durchführen...
}

console.log('convertModuleToNodes');
console.log(modules);

let result = modules.map((item, index) => ({
id: `dndnode_${index}`,
uid: item.value.objectsettings.uid,
type: "customModel",
position: {
x: item.config.position[0],
y: item.config.position[1]
},
data: {
label: item.name,
objectType: "foobar",
isAggregateRoot: item.value.objectsettings.aggregateRoot,
enableSorting: item.value.objectsettings.sorting,
addDeletedField: item.value.objectsettings.addDeletedField,
addHiddenField: item.value.objectsettings.addHiddenField,
addStarttimeEndtimeFields: item.value.objectsettings.addStarttimeEndtimeFields,
enableCategorization: item.value.objectsettings.categorizable,
description: item.value.objectsettings.description,
mapToExistingTable: item.value.objectsettings.mapToTable,
extendExistingModelClass: item.value.objectsettings.parentClass,
actions: {
actionIndex: item.value.actionGroup._default0_index,
actionList: item.value.actionGroup._default1_list,
actionShow: item.value.actionGroup._default2_show,
actionNewCreate: item.value.actionGroup._default3_new_create,
actionEditUpdate: item.value.actionGroup._default4_edit_update,
actionDelete: item.value.actionGroup._default5_delete
},
customActions: item.value.actionGroup.customActions,
properties: item.value.propertyGroup.properties,
relations: item.value.relationGroup.relations
},
dragHandle: ".drag-handle",
draggable: true,
width: 300,
height: 257,
selected: false,
positionAbsolute: {
x: item.config.position[0],
y: item.config.position[1]
},
dragging: false
}));

console.log('result');
console.log(result);

return result;
}

export default convertModulesToNodes;

/*
{
"id": "dndnode_0",
"type": "customModel",
"position": {
"x": 550,
"y": 131
},
"data": {
"label": "Testmodule",
"objectType": "",
"isAggregateRoot": true,
"enableSorting": false,
"addDeletedField": true,
"addHiddenField": true,
"addStarttimeEndtimeFields": true,
"enableCategorization": false,
"description": "",
"mapToExistingTable": "",
"extendExistingModelClass": "",
"actions": {
"actionIndex": true,
"actionList": true,
"actionShow": false,
"actionNewCreate": false,
"actionEditUpdate": false,
"actionDelete": false
},
"customActions": [],
"properties": [],
"relations": []
},
"dragHandle": ".drag-handle",
"draggable": true,
"width": 300,
"height": 257,
"selected": true,
"positionAbsolute": {
"x": 550,
"y": 131
},
"dragging": false
}
*/
Loading

0 comments on commit b43a95e

Please sign in to comment.