Skip to content

Add locked property to Port and enhance port sorting logic#684

Draft
achrafmohye wants to merge 5 commits intomainfrom
ame/add-locked-property-to-port-and-enhance-port-sorting-logic
Draft

Add locked property to Port and enhance port sorting logic#684
achrafmohye wants to merge 5 commits intomainfrom
ame/add-locked-property-to-port-and-enhance-port-sorting-logic

Conversation

@achrafmohye
Copy link
Copy Markdown

@achrafmohye achrafmohye commented Dec 11, 2025

Close #634

Description

Port.locked marks a port position as user defined and immutable, automatic sorting ignore locked ports and arrange only the remaining ones around them, while preserving the locked layout across import, export

Issues

Checklist

  • This PR contains a description of the changes I'm making
  • I've read the Contribution Guidelines
  • I've added tests for changes or features I've introduced
  • I documented any high-level concepts I'm introducing in documentation/
  • CI is currently green and this is ready for review

Signed-off-by: Achrafmohye <a.mohyeddine@gmail.com>
@achrafmohye achrafmohye requested a review from Synar December 11, 2025 09:50
Signed-off-by: Alice Khoudli <alice.khoudli@polytechnique.org>
@Synar Synar assigned Synar and unassigned Synar Dec 11, 2025
Signed-off-by: Achrafmohye <a.mohyeddine@gmail.com>
@achrafmohye achrafmohye force-pushed the ame/add-locked-property-to-port-and-enhance-port-sorting-logic branch from cfc6bb0 to 399b1d3 Compare December 16, 2025 14:33
@achrafmohye achrafmohye marked this pull request as ready for review December 22, 2025 09:28
positionIndex: number; // position index starts at 0, ... for each PortAlignment group
positionAlignment: PortAlignment; // defines corresponding PortAlignment group within the node
trainrunSectionId: number; // reference to the connected trainrun section
locked: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add short commeng for what this member 'locked' is used for

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@achrafmohye achrafmohye force-pushed the ame/add-locked-property-to-port-and-enhance-port-sorting-logic branch from cf872e4 to 923f5d7 Compare December 22, 2025 10:35
originalPorts.forEach((port, index) => {
if (port.getLocked()) {
lockedIndexes.add(index);
portsToKeepLocked.push(port);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I sent you before, you can simplify by dropping portsToKeepLocked doing something like :

  sortPorts() {
    const originalPorts = this.ports;
    const lockedIndexes: Set<number> = new Set();
    const portsToReorder: Port[] = [];

    originalPorts.forEach((port, index) => {
      if (port.getLocked()) {
        lockedIndexes.add(index);
      } else {
        portsToReorder.push(port);
      }
    });

    // Sort ONLY the unlocked ports
    portsToReorder.sort((a, b) => {
      return this.comparePorts(a, b);
    });

    // Insert locked ports back in their original places
    const newPorts: Port[] = [];
    let reorderedIndex = 0;
    for (let index = 0; index < originalPorts.length; index++) {
      if (lockedIndexes.has(index)) {
        newPorts.push(originalPorts[index]);
      } else {
        newPorts.push(portsToReorder[reorderedIndex]);
        reorderedIndex += 1;
      }
    }
    this.ports = newPorts;
  }
```

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

…tions

Signed-off-by: Achrafmohye <a.mohyeddine@gmail.com>
@achrafmohye achrafmohye force-pushed the ame/add-locked-property-to-port-and-enhance-port-sorting-logic branch from 923f5d7 to ccd74d8 Compare December 22, 2025 15:07
@aiAdrian
Copy link
Copy Markdown
Contributor

I am not sure whether we have to migrate the new added locked to the data migration. Netzgrafik-Editor must ensure that elder version will get automatically updated to latest version !

Please dbl-check if required to migrate - if yes -> add it to :

static migrateNetzgrafikDto(netzgrafikDto: NetzgrafikDto) {

https://github.com/OpenRailAssociation/netzgrafik-editor-frontend/blob/main/src/app/utils/data-migration.ts#L50

…compatibility

Signed-off-by: Achrafmohye <a.mohyeddine@gmail.com>
@achrafmohye
Copy link
Copy Markdown
Author

I am not sure whether we have to migrate the new added locked to the data migration. Netzgrafik-Editor must ensure that elder version will get automatically updated to latest version !

Please dbl-check if required to migrate - if yes -> add it to :

static migrateNetzgrafikDto(netzgrafikDto: NetzgrafikDto) {

https://github.com/OpenRailAssociation/netzgrafik-editor-frontend/blob/main/src/app/utils/data-migration.ts#L50

Hi @aiAdrian,
I added locked = false in the Port constructor to handle the case where older Netzgrafik DTOs don’t include the locked field

@achrafmohye achrafmohye marked this pull request as draft January 6, 2026 10:15
@louisgreiner louisgreiner added postponed Postponed task due to other priorities or waiting for dependencies area:services Services, helpers, utils and i18n ("logical" stuff) area:data-model Data models and structures labels Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:data-model Data models and structures area:services Services, helpers, utils and i18n ("logical" stuff) postponed Postponed task due to other priorities or waiting for dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to lock ports in nodes

4 participants