From ddc2e33279b7899201b97ccee840bdc75d1254e0 Mon Sep 17 00:00:00 2001 From: genja Date: Fri, 29 May 2026 05:07:51 +0200 Subject: [PATCH] added shared state service, search bar is now active --- .../shared/services/shared-state.service.ts | 9 ++++++++ .../ui/app-layout/app-layout.component.html | 4 +++- .../ui/app-layout/app-layout.component.ts | 21 ++++++++++++++++--- .../shared/ui/app-menu/app-menu.component.ts | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 webapp/src/app/shared/services/shared-state.service.ts diff --git a/webapp/src/app/shared/services/shared-state.service.ts b/webapp/src/app/shared/services/shared-state.service.ts new file mode 100644 index 00000000..dd25b7f0 --- /dev/null +++ b/webapp/src/app/shared/services/shared-state.service.ts @@ -0,0 +1,9 @@ +import { Injectable, signal } from '@angular/core'; +import { Person } from '../../api'; +@Injectable({ providedIn: 'root' }) +export class SharedStateService { + + searchValue = signal(null); + persons = signal([]); + hasSearched = signal(false); +} \ No newline at end of file diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.html b/webapp/src/app/shared/ui/app-layout/app-layout.component.html index 8f21ec4a..b2fe1274 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.html +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.html @@ -29,7 +29,7 @@ menu } - @@ -38,8 +38,10 @@ diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts index 54911500..e246822d 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.ts +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.ts @@ -4,15 +4,18 @@ import { MatToolbarModule } from '@angular/material/toolbar'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatDrawer, MatSidenavModule } from '@angular/material/sidenav'; -import { Router, RouterLink } from '@angular/router'; +import { Router} from '@angular/router'; import { MediaMatcher } from '@angular/cdk/layout'; import { AppMenuComponent } from '../app-menu/app-menu.component'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CredentialService } from '../../services/credential.service'; +import { FormControl,ReactiveFormsModule } from '@angular/forms'; +import { SharedStateService } from '../../services/shared-state.service'; +import { Location } from '@angular/common'; @Component({ selector: 'app-layout', - imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, RouterLink, AppMenuComponent, MatTooltipModule], + imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, AppMenuComponent, MatTooltipModule,ReactiveFormsModule], templateUrl: './app-layout.component.html', styleUrl: './app-layout.component.scss', standalone: true, @@ -27,8 +30,10 @@ export class AppLayoutComponent implements OnInit, OnDestroy { mediaQueryListener: () => void; sideNavOpen = false; - + searchValue = new FormControl(''); constructor(public credentialService: CredentialService, public router: Router, + private location:Location, + private state: SharedStateService, public changeDetector: ChangeDetectorRef, media: MediaMatcher) { this.mediaQuery = media.matchMedia('(max-width: 600px)'); this.mediaQueryListener = () => { @@ -56,5 +61,15 @@ export class AppLayoutComponent implements OnInit, OnDestroy { this.credentialService.logoutAcount(); this.router.navigate(['/']) } + startSearch(){ + console.log("updated to", this.searchValue.value,this.router.url) + if (this.router.url.startsWith('/persons')) { + this.router.navigate(['/persons']); + } + this.state.searchValue.set(this.searchValue.value); + } + navigateBack(){ + this.location.back() + } } diff --git a/webapp/src/app/shared/ui/app-menu/app-menu.component.ts b/webapp/src/app/shared/ui/app-menu/app-menu.component.ts index f74d3a11..70c0ba5e 100644 --- a/webapp/src/app/shared/ui/app-menu/app-menu.component.ts +++ b/webapp/src/app/shared/ui/app-menu/app-menu.component.ts @@ -21,7 +21,7 @@ import { CredentialService } from '../../services/credential.service'; export class AppMenuComponent { navItems = [ { label: 'Dashboard', icon: 'dashboard', route: '/items', disabled: false }, - { label: 'Personen', icon: 'groups', route: '/person/0', disabled: false }, + { label: 'Personen', icon: 'groups', route: '/persons', disabled: false }, ]; constructor(public credentialService: CredentialService) {}