-
Notifications
You must be signed in to change notification settings - Fork 17
feat: adds global nodes management form #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacomyal
wants to merge
2
commits into
mrd/new-nodes-management-system
Choose a base branch
from
ajy/global-nodes-management
base: mrd/new-nodes-management-system
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...-edit-tools-view-component/global-nodes-management/global-nodes-management.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <section class="global-nodes-management"> | ||
| <div class="search"> | ||
| <input | ||
| #globalNodesManagementQuery | ||
| sbbInput | ||
| type="search" | ||
| [value]="query" | ||
| (input)="updateState({query: globalNodesManagementQuery.value})" | ||
| [placeholder]=" | ||
| 'app.view.editor-edit-tools-view-component.nodes-search-placeholder' | translate | ||
| " | ||
| /> | ||
| </div> | ||
| <div class="nodes-list"> | ||
| @if (matchingNodes.length) { | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| @for (column of ["nodes-expanded", "nodes"]; track column) { | ||
| <th scope="col"> | ||
| {{ "app.view.editor-edit-tools-view-component." + column | translate }} | ||
| </th> | ||
| } | ||
| </tr> | ||
| @if (matchingNodes.length > 1) { | ||
| <tr> | ||
| <td> | ||
| <sbb-checkbox | ||
| [checked]="!!getGlobalCheckboxStatus()" | ||
| [indeterminate]="getGlobalCheckboxStatus() === undefined" | ||
| (click)="onClickGlobalCheckbox($event)" | ||
| /> | ||
| </td> | ||
| </tr> | ||
| } | ||
| </thead> | ||
| <tbody> | ||
| @for (node of matchingNodes; track node.getId()) { | ||
| <tr> | ||
| <td class="offset"> | ||
| <sbb-checkbox | ||
| [checked]="!node.getIsCollapsed()" | ||
| (change)="toggleIsCollapsed(node, !$event.checked)" | ||
| /> | ||
| </td> | ||
| <td>{{ node.getBetriebspunktName() }}</td> | ||
| <td>{{ node.getFullName() }}</td> | ||
| </tr> | ||
| } | ||
| </tbody> | ||
| </table> | ||
| } @else { | ||
| <p>{{ "app.view.editor-edit-tools-view-component.nodes-no-result" | translate }}</p> | ||
| } | ||
| </div> | ||
| </section> |
59 changes: 59 additions & 0 deletions
59
...-edit-tools-view-component/global-nodes-management/global-nodes-management.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| .global-nodes-management { | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.5rem; | ||
| align-items: stretch; | ||
|
|
||
| .search { | ||
| position: relative; | ||
|
|
||
| input { | ||
| width: 100%; | ||
| } | ||
| .sbb-icon { | ||
| position: absolute; | ||
| right: 5px; | ||
| top: 50%; | ||
| transform: translateY(-50%); | ||
| } | ||
| } | ||
|
|
||
| .nodes-list { | ||
| overflow-x: auto; | ||
|
|
||
| table { | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
|
|
||
| th, | ||
| td { | ||
| font-family: var(--sbb-font-light); | ||
| font-weight: var(--sbb-font-weight-normal); | ||
| padding: 8px 0; | ||
| white-space: nowrap; | ||
| vertical-align: middle; | ||
| } | ||
|
|
||
| th { | ||
| text-align: start; | ||
| } | ||
| tbody tr { | ||
| border-top: var(--sbb-border-width-thin) solid var(--sbb-expansion-panel-border-color-open); | ||
| } | ||
| td.offset { | ||
| padding-left: 10px; | ||
| } | ||
| tbody td:last-child { | ||
| width: 99%; | ||
| } | ||
| thead th:not(:last-child) { | ||
| padding-right: 13px; | ||
| } | ||
|
|
||
| .sbb-checkbox { | ||
| display: block; | ||
| } | ||
| } | ||
| } | ||
| } |
113 changes: 113 additions & 0 deletions
113
...or-edit-tools-view-component/global-nodes-management/global-nodes-management.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import {Component} from "@angular/core"; | ||
| import {FormsModule} from "@angular/forms"; | ||
| import {SbbCheckbox} from "@sbb-esta/angular/checkbox"; | ||
| import {SbbInput} from "@sbb-esta/angular/input"; | ||
|
|
||
| import {NodeService} from "../../../services/data/node.service"; | ||
| import {I18nModule} from "../../../core/i18n/i18n.module"; | ||
| import {Node} from "../../../models/node.model"; | ||
| import {DataService} from "../../../services/data/data.service"; | ||
| import {UiInteractionService} from "../../../services/ui/ui.interaction.service"; | ||
| import {ConfirmationDialogParameter} from "../../dialogs/confirmation-dialog/confirmation-dialog.component"; | ||
|
|
||
| function normalizeStr(str: string): string { | ||
| return str | ||
| .toLowerCase() | ||
| .trim() | ||
| .normalize("NFD") | ||
| .replace(/[\u0300-\u036f]/g, ""); | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: "sbb-global-nodes-management", | ||
| standalone: true, | ||
| imports: [FormsModule, SbbCheckbox, SbbInput, I18nModule], | ||
| templateUrl: "./global-nodes-management.component.html", | ||
| styleUrl: "./global-nodes-management.component.scss", | ||
| }) | ||
| export class GlobalNodesManagementComponent { | ||
| query: string; | ||
| allNodes: Node[]; | ||
| matchingNodes: Node[]; | ||
|
|
||
| constructor( | ||
| private dataService: DataService, | ||
| private nodeService: NodeService, | ||
| private uiInteractionService: UiInteractionService, | ||
| ) { | ||
| this.query = ""; | ||
| this.allNodes = this.nodeService.getNodes(); | ||
| this.nodeService.nodes.subscribe((nodes) => this.updateState({nodes})); | ||
| } | ||
|
|
||
| updateState({nodes = this.allNodes, query = this.query}: {nodes?: Node[]; query?: string}) { | ||
| // Save state locally | ||
| this.query = query; | ||
| this.allNodes = nodes; | ||
|
|
||
| const normalizedQuery = normalizeStr(this.query); | ||
|
|
||
| this.matchingNodes = normalizedQuery | ||
| ? this.allNodes.filter( | ||
| (node) => | ||
| normalizeStr(node.getFullName()).includes(normalizedQuery) || | ||
| normalizeStr(node.getBetriebspunktName()).includes(normalizedQuery), | ||
| ) | ||
| : this.allNodes; | ||
| } | ||
|
|
||
| getGlobalCheckboxStatus(): boolean | undefined { | ||
| let allCollapsed = true; | ||
| let noneCollapsed = true; | ||
| this.matchingNodes.every((node) => { | ||
| const isCollapsed = node.getIsCollapsed(); | ||
| allCollapsed = allCollapsed && isCollapsed; | ||
| noneCollapsed = noneCollapsed && !isCollapsed; | ||
|
|
||
| // If both allCollapsed and noneCollapsed fail, stop iterating | ||
| return allCollapsed || noneCollapsed; | ||
| }); | ||
|
|
||
| if (allCollapsed) return false; | ||
| if (noneCollapsed) return true; | ||
| return undefined; | ||
| } | ||
|
|
||
| toggleIsCollapsed(node: Node, isCollapsed: boolean) { | ||
| node.setIsCollapsed(isCollapsed); | ||
| this.dataService.triggerViewUpdate(); | ||
| } | ||
| onClickGlobalCheckbox(event: MouseEvent) { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
|
|
||
| const currentGlobalCheckboxStatus = this.getGlobalCheckboxStatus(); | ||
| const newCheckboxStatus = !currentGlobalCheckboxStatus; | ||
| const newIsCollapsed = !newCheckboxStatus; | ||
|
|
||
| const allNodesImpacted = this.allNodes.length === this.matchingNodes.length; | ||
| const impactedNodesCount = this.matchingNodes.length; | ||
|
|
||
| const apply = () => { | ||
| this.matchingNodes.forEach((node) => { | ||
| node.setIsCollapsed(newIsCollapsed); | ||
| }); | ||
| }; | ||
|
|
||
| const dialogTitle = $localize`:@@app.view.editor-edit-tools-view-component.global-nodes-management:Global nodes management`; | ||
| const dialogContent = newIsCollapsed | ||
| ? allNodesImpacted | ||
| ? $localize`:@@app.view.editor-edit-tools-view-component.confirm-collapse-all:Are you sure you want to collapse all nodes?` | ||
| : $localize`:@@app.view.editor-edit-tools-view-component.confirm-collapse-matching:Are you sure you want to collapse the ${impactedNodesCount}:count: nodes matching "${this.query}:query:"?` | ||
| : allNodesImpacted | ||
| ? $localize`:@@app.view.editor-edit-tools-view-component.confirm-expand-all:Are you sure you want to expand all nodes?` | ||
| : $localize`:@@app.view.editor-edit-tools-view-component.confirm-expand-matching:Are you sure you want to expand the ${impactedNodesCount}:count: nodes matching "${this.query}:query:"?`; | ||
| const confirmationDialogParameter = new ConfirmationDialogParameter(dialogTitle, dialogContent); | ||
|
|
||
| this.uiInteractionService | ||
| .showConfirmationDiagramDialog(confirmationDialogParameter) | ||
| .subscribe((confirmed: boolean) => { | ||
| if (confirmed) apply(); | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,7 +337,15 @@ | |
| "trainruns": "Trainruns", | ||
| "notes": "Notes", | ||
| "nodes": "Nodes" | ||
| } | ||
| }, | ||
| "nodes-search-placeholder": "Search for names or trigrams", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: "trigram" (and "BetriebspunktName") will be soon renamed "Short Name" all across the application |
||
| "nodes-expanded": "Expanded", | ||
| "nodes-no-result": "There is no node matching the query.", | ||
| "global-nodes-management": "Global nodes management", | ||
| "confirm-expand-all": "Are you sure you want to expand all nodes?", | ||
| "confirm-expand-matching": "Are you sure you want to expand the {$count} nodes matching \"{$query}\"?", | ||
| "confirm-collapse-all": "Are you sure you want to collapse all nodes?", | ||
| "confirm-collapse-matching": "Are you sure you want to collapse the {$count} nodes matching \"{$query}\"?" | ||
| }, | ||
| "editor-filter-view": { | ||
| "filter": "Filter", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with standalone components, but what is the pros and cons of defining the imports here? Since all of them are already part of
src/app.module.ts?Also, all of the other components are not defined that way
What do you think @emersion?