[WIP] ReplaceBy in ContainerOperations.ts

This commit is contained in:
Carl Fuchs 2023-02-07 16:07:51 +01:00
parent e789300090
commit 1a9224b768

View file

@ -8,7 +8,7 @@ import Swal from 'sweetalert2';
import { PropertyType } from '../../../Enums/PropertyType';
import { TransformX, TransformY } from '../../../utils/svg';
import { Orientation } from '../../../Enums/Orientation';
import { AddContainerToSelectedContainer } from './AddContainer';
import { AddContainers } from './AddContainer';
import { IConfiguration } from '../../../Interfaces/IConfiguration';
/**
@ -130,27 +130,35 @@ export function ReplaceByContainer(
const history = GetCurrentHistory(fullHistory, historyCurrentStep);
const current = history[history.length - 1];
const historyDelete = DeleteContainer(containerId, fullHistory, historyCurrentStep);
const currentDelete = historyDelete[historyDelete.length - 1];
const selectedContainer = FindContainerById(currentDelete.containers, currentDelete.selectedContainerId);
if (selectedContainer != null) {
const historyAdd = AddContainerToSelectedContainer(newContainerId, selectedContainer, configuration, fullHistory, historyCurrentStep);
const currentAdd = historyAdd[historyAdd.length - 1];
fullHistory.push({
lastAction: `Replace ${containerId} by ${newContainerId}`,
mainContainer: currentAdd.mainContainer,
containers: currentAdd.containers,
selectedContainerId: currentAdd.selectedContainerId,
typeCounters: Object.assign({}, currentAdd.typeCounters),
symbols: current.symbols,
selectedSymbolId: current.selectedSymbolId
});
return fullHistory;
const containerToReplace = FindContainerById(current.containers, containerId);
if (containerToReplace === undefined) {
return history;
}
return history;
const containerParent = FindContainerById(current.containers,containerToReplace.properties.parentId);
if (containerParent=== undefined) {
return history;
}
const historyAdd = AddContainers(containerParent.children.indexOf(containerId), [{ Type: newContainerId }], containerParent.properties.id, configuration, fullHistory, historyCurrentStep);
// Copy des possibles enfants
if (historyAdd.newContainers[0] === undefined) {
return history;
}
historyAdd.newContainers[0].children = containerToReplace.children;
const historyDelete = DeleteContainer(containerId, historyAdd.history, historyCurrentStep + 1);
const currentDelete = historyDelete[historyDelete.length - 1];
fullHistory.push({
lastAction: `Replace ${containerId} by ${newContainerId}`,
mainContainer: currentDelete.mainContainer,
containers: currentDelete.containers,
selectedContainerId: currentDelete.selectedContainerId,
typeCounters: Object.assign({}, currentDelete.typeCounters),
symbols: current.symbols,
selectedSymbolId: current.selectedSymbolId
});
return fullHistory;
}
/**