[WIP] ReplaceBy in ContainerOperations.ts
This commit is contained in:
parent
e789300090
commit
1a9224b768
1 changed files with 29 additions and 21 deletions
|
@ -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 containerToReplace = FindContainerById(current.containers, containerId);
|
||||
if (containerToReplace === undefined) {
|
||||
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 currentAdd = historyAdd[historyAdd.length - 1];
|
||||
const historyDelete = DeleteContainer(containerId, historyAdd.history, historyCurrentStep + 1);
|
||||
const currentDelete = historyDelete[historyDelete.length - 1];
|
||||
|
||||
fullHistory.push({
|
||||
lastAction: `Replace ${containerId} by ${newContainerId}`,
|
||||
mainContainer: currentAdd.mainContainer,
|
||||
containers: currentAdd.containers,
|
||||
selectedContainerId: currentAdd.selectedContainerId,
|
||||
typeCounters: Object.assign({}, currentAdd.typeCounters),
|
||||
mainContainer: currentDelete.mainContainer,
|
||||
containers: currentDelete.containers,
|
||||
selectedContainerId: currentDelete.selectedContainerId,
|
||||
typeCounters: Object.assign({}, currentDelete.typeCounters),
|
||||
symbols: current.symbols,
|
||||
selectedSymbolId: current.selectedSymbolId
|
||||
});
|
||||
|
||||
return fullHistory;
|
||||
}
|
||||
return history;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue