-
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
base: mrd/new-nodes-management-system
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <section class="global-nodes-management"> | ||
| <div class="search"> | ||
| <input | ||
| sbbInput | ||
| type="search" | ||
| [(ngModel)]="query" | ||
| [placeholder]=" | ||
| 'app.view.editor-edit-tools-view-component.nodes-search-placeholder' | translate | ||
| " | ||
| /> | ||
| </div> | ||
| <div class="nodes-list"> | ||
| @if (getVisibleNodes().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> | ||
| <tr> | ||
| <td> | ||
| <sbb-checkbox | ||
| [checked]="!!getGlobalCheckboxStatus()" | ||
| [indeterminate]="getGlobalCheckboxStatus() === undefined" | ||
| (change)="toggleIsCollapsedOnAllVisibleNodes(!$event.checked)" | ||
| /> | ||
| </td> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| @for (node of getVisibleNodes(); track node.getId()) { | ||
| <tr> | ||
| <td class="offset"> | ||
| <sbb-checkbox | ||
| [checked]="!node.getIsCollapsed()" | ||
| (change)="node.setIsCollapsed(!$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> | ||
| 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; | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| 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"; | ||
|
|
||
| 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], | ||
|
Comment on lines
+23
to
+24
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. 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 What do you think @emersion? |
||
| templateUrl: "./global-nodes-management.component.html", | ||
| styleUrl: "./global-nodes-management.component.scss", | ||
| }) | ||
| export class GlobalNodesManagementComponent { | ||
| query: string; | ||
|
|
||
| constructor(private nodeService: NodeService) { | ||
| this.query = ""; | ||
| } | ||
|
|
||
| toggleIsCollapsedOnAllVisibleNodes(newValue: boolean) { | ||
| this.getVisibleNodes().forEach((node) => { | ||
| node.setIsCollapsed(newValue); | ||
| }); | ||
| } | ||
|
|
||
| getVisibleNodes() { | ||
louisgreiner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const allNodes = this.nodeService.getNodes(); | ||
| const normalizedQuery = normalizeStr(this.query); | ||
| if (!normalizedQuery) return allNodes; | ||
|
|
||
| return allNodes.filter( | ||
| (node) => | ||
| normalizeStr(node.getFullName()).includes(normalizedQuery) || | ||
| normalizeStr(node.getBetriebspunktName()).includes(normalizedQuery), | ||
| ); | ||
| } | ||
| getGlobalCheckboxStatus(): boolean | undefined { | ||
| let allCollapsed = true; | ||
| let noneCollapsed = true; | ||
| this.getVisibleNodes().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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,7 +337,10 @@ | |
| "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." | ||
| }, | ||
| "editor-filter-view": { | ||
| "filter": "Filter", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.