#11093 VC items movement like grid when its enable

This commit is contained in:
Jonathan 2023-06-09 08:45:32 +02:00
parent 0463d3bea3
commit 2c0d716caa
5 changed files with 49 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -850,9 +850,11 @@ if ($edit_capable === true) {
size = $('#grid_size').val(); size = $('#grid_size').val();
display_grid(color,size); display_grid(color,size);
$('#grid_img').removeClass('invisible'); $('#grid_img').removeClass('invisible');
visualConsoleManager.visualConsole.updateGridSelected(true);
} else { } else {
$('#div-grid').remove(); $('#div-grid').remove();
$('#grid_img').addClass('invisible'); $('#grid_img').addClass('invisible');
visualConsoleManager.visualConsole.updateGridSelected(false);
} }
}); });
@ -925,6 +927,7 @@ if ($edit_capable === true) {
console.error(err); console.error(err);
} }
}); });
visualConsoleManager.visualConsole.updateGridSize(size);
} }
// Enable/disable the maintenance mode. // Enable/disable the maintenance mode.

View File

@ -239,7 +239,7 @@ export function titleItem(id: number): string {
*/ */
abstract class VisualConsoleItem<Props extends ItemProps> { abstract class VisualConsoleItem<Props extends ItemProps> {
// Properties of the item. // Properties of the item.
private itemProps: Props; public itemProps: Props;
// Metadata of the item. // Metadata of the item.
private _metadata: ItemMeta; private _metadata: ItemMeta;
// Reference to the DOM element which will contain the item. // Reference to the DOM element which will contain the item.
@ -955,8 +955,10 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
if (!prevMeta || prevMeta.isSelected !== this.meta.isSelected) { if (!prevMeta || prevMeta.isSelected !== this.meta.isSelected) {
if (this.meta.isSelected) { if (this.meta.isSelected) {
this.elementRef.classList.add("is-selected"); this.elementRef.classList.add("is-selected");
this.elementRef.setAttribute("id", "item-selected-move");
} else { } else {
this.elementRef.classList.remove("is-selected"); this.elementRef.classList.remove("is-selected");
this.elementRef.removeAttribute("id");
} }
} }
} }

View File

@ -160,6 +160,8 @@ export interface VisualConsoleProps extends Size {
isFavorite: boolean; isFavorite: boolean;
relationLineWidth: number; relationLineWidth: number;
maintenanceMode: MaintenanceModeInterface | null; maintenanceMode: MaintenanceModeInterface | null;
gridSize: number | 10;
gridSelected: boolean | false | false;
} }
export interface MaintenanceModeInterface { export interface MaintenanceModeInterface {
@ -188,7 +190,9 @@ export function visualConsolePropsDecoder(
backgroundColor, backgroundColor,
isFavorite, isFavorite,
relationLineWidth, relationLineWidth,
maintenanceMode maintenanceMode,
gridSize,
gridSelected
} = data; } = data;
if (id == null || isNaN(parseInt(id))) { if (id == null || isNaN(parseInt(id))) {
@ -210,6 +214,8 @@ export function visualConsolePropsDecoder(
isFavorite: parseBoolean(isFavorite), isFavorite: parseBoolean(isFavorite),
relationLineWidth: parseIntOr(relationLineWidth, 0), relationLineWidth: parseIntOr(relationLineWidth, 0),
maintenanceMode: maintenanceMode, maintenanceMode: maintenanceMode,
gridSize: parseIntOr(gridSize, 10),
gridSelected: false,
...sizePropsDecoder(data) ...sizePropsDecoder(data)
}; };
} }
@ -279,6 +285,24 @@ export default class VisualConsole {
* @param e Event object. * @param e Event object.
*/ */
private handleElementMovement: (e: ItemMovedEvent) => void = e => { private handleElementMovement: (e: ItemMovedEvent) => void = e => {
var type = e.item.itemProps.type;
if (type !== 13 && type !== 21 && this.props.gridSelected === true) {
var gridSize = this.props.gridSize;
var positionX = e.newPosition.x;
var positionY = e.newPosition.y;
if (positionX % gridSize !== 0 || positionY % gridSize !== 0) {
var x = Math.floor(positionX / gridSize) * gridSize;
var y = Math.floor(positionY / gridSize) * gridSize;
let elemntSelected = document.getElementById(
"item-selected-move"
) as HTMLElement;
elemntSelected.setAttribute(
"style",
"top:" + y + "px !important; left:" + x + "px !important"
);
return;
}
}
// Move their relation lines. // Move their relation lines.
const itemId = e.item.props.id; const itemId = e.item.props.id;
const relations = this.getItemRelations(itemId); const relations = this.getItemRelations(itemId);
@ -1269,6 +1293,22 @@ export default class VisualConsole {
this.containerRef.classList.add("is-editing"); this.containerRef.classList.add("is-editing");
} }
/**
* Update the gridSize.
*/
public updateGridSize(gridSize: string): void {
this._props.gridSize = parseInt(gridSize);
this.props.gridSize = parseInt(gridSize);
}
/**
* Update the gridSize.
*/
public updateGridSelected(gridSelected: boolean): void {
this._props.gridSelected = gridSelected;
this.props.gridSelected = gridSelected;
}
/** /**
* Select an item. * Select an item.
* @param itemId Item Id. * @param itemId Item Id.