From 06795772d8074909cab8718541116762f7431d00 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 8 May 2024 17:56:13 +0200 Subject: [PATCH 1/5] Created shelter.ts and service --- .../shelter-list/shelter-list.component.ts | 16 ++++++++++++++ src/app/shelter/shelter.service.ts | 16 ++++++++++++++ src/app/shelter/shelter.ts | 22 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/app/shelter/shelter.service.ts create mode 100644 src/app/shelter/shelter.ts diff --git a/src/app/shelter/shelter-list/shelter-list.component.ts b/src/app/shelter/shelter-list/shelter-list.component.ts index f5943c6..ec3c342 100644 --- a/src/app/shelter/shelter-list/shelter-list.component.ts +++ b/src/app/shelter/shelter-list/shelter-list.component.ts @@ -1,4 +1,8 @@ import { Component } from '@angular/core'; +import {Shelter} from "../shelter"; +import {Router} from "@angular/router"; +import {ShelterService} from "../shelter.service"; +import {AuthenticationBasicService} from "../../login-basic/authentication-basic.service"; @Component({ selector: 'app-shelter-list', @@ -7,5 +11,17 @@ import { Component } from '@angular/core'; templateUrl: './shelter-list.component.html', }) export class ShelterListComponent { + public shelters: Shelter[] = []; + public pageSize = 5; + public page = 1; + public totalSeeds = 0; + public sortBy = 'Scientific name'; + public sortOrder = 'A-Z'; + + constructor( + public router: Router, + private shelterService: ShelterService, + private authenticationService: AuthenticationBasicService + ) {} } diff --git a/src/app/shelter/shelter.service.ts b/src/app/shelter/shelter.service.ts new file mode 100644 index 0000000..6df3803 --- /dev/null +++ b/src/app/shelter/shelter.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/internal/Observable'; +import { HateoasResourceOperation, ResourceCollection } from '@lagoshny/ngx-hateoas-client'; +import {Shelter} from "./shelter"; + +@Injectable({providedIn: 'root'}) +export class ShelterService extends HateoasResourceOperation { + + constructor() { + super(Shelter); + } + + public findByName(query: string): Observable> { + return this.searchCollection('findByName', { params: { text: query } }); + } +} diff --git a/src/app/shelter/shelter.ts b/src/app/shelter/shelter.ts new file mode 100644 index 0000000..368a723 --- /dev/null +++ b/src/app/shelter/shelter.ts @@ -0,0 +1,22 @@ +import { HateoasResource, Resource } from '@lagoshny/ngx-hateoas-client'; + +@HateoasResource('shelters') +export class Shelter extends Resource { + uri: string; + name: string; + email: string; + mobile: string; + createdAt: Date; + updatedAt: Date; + isActive: boolean; + + constructor(values: object = {}) { + super(); + Object.assign(this as any, values); + } + + public get id(): string { + let uriArray = this.uri.split('/'); + return uriArray.pop(); + } +} From d2b989a325b0cdd4a44d51c143eaaf0246eedd41 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 8 May 2024 18:52:14 +0200 Subject: [PATCH 2/5] Shelter create and shelter list --- .../shelter-create.component.html | 80 +++++++++++ .../shelter-create.component.ts | 112 +++++++++++++++ .../shelter-list/shelter-list.component.html | 24 +++- .../shelter-list/shelter-list.component.ts | 127 +++++++++++++++++- 4 files changed, 336 insertions(+), 7 deletions(-) create mode 100644 src/app/shelter/shelter-create/shelter-create.component.html create mode 100644 src/app/shelter/shelter-create/shelter-create.component.ts diff --git a/src/app/shelter/shelter-create/shelter-create.component.html b/src/app/shelter/shelter-create/shelter-create.component.html new file mode 100644 index 0000000..92f3bf2 --- /dev/null +++ b/src/app/shelter/shelter-create/shelter-create.component.html @@ -0,0 +1,80 @@ +
+
+
+ + +
+ Name is required. +
+
+ Invalid name. +
+
+ +
+ + +
+ Invalid name. +
+
+ + + + + + + + + + + + + + + + +
+ + +
+
+
diff --git a/src/app/shelter/shelter-create/shelter-create.component.ts b/src/app/shelter/shelter-create/shelter-create.component.ts new file mode 100644 index 0000000..0601c0c --- /dev/null +++ b/src/app/shelter/shelter-create/shelter-create.component.ts @@ -0,0 +1,112 @@ +import {Component, OnInit} from '@angular/core'; +import {User} from "../../login-basic/user"; +import {Router} from "@angular/router"; +import {Location} from "@angular/common"; +import {UserService} from "../../user/user.service"; +import {AuthenticationBasicService} from "../../login-basic/authentication-basic.service"; +import {ShelterService} from "../shelter.service"; +import {Shelter} from "../shelter"; +import {AbstractControl, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators} from "@angular/forms"; +import {ModalDismissReasons, NgbModal} from "@ng-bootstrap/ng-bootstrap"; +import {PagedResourceCollection} from "@lagoshny/ngx-hateoas-client"; + +@Component({ + selector: 'app-shelter-create', + templateUrl: './shelter-create.component.html', +}) +export class ShelterCreateComponent implements OnInit{ + + closeResult = ''; + public isModalSaved: boolean = false; + public shelters: Shelter[] = []; + public shelter: Shelter; + public commonNameInput: string = ''; + public commonEmailsList: any = []; + public shelterForm: FormGroup; + + constructor( + private router: Router, + private shelterService: ShelterService, + private modalService: NgbModal + ) {} + + ngOnInit(): void { + this.shelter = new Shelter(); + this.shelterForm = new FormGroup({ + name: new FormControl(this.shelter.name, [ + Validators.required, + ]), + email: new FormControl(this.shelter.email, [ + Validators.required, + this.emailValidator(), + ]), + }); + this.loadShelterList(); + } + + loadShelterList() { + this.shelterService + .getPage({ + sort: { name: 'ASC' }, + }) + .subscribe((shelters: PagedResourceCollection) => { + this.shelters = shelters.resources.sort((a, b) => + a.name.localeCompare(b.name) + ); + }); + } + + open(content) { + this.modalService + .open(content, { ariaLabelledBy: 'modal-basic-title' }) + .result.then( + (result) => { + this.closeResult = `Closed with: ${result}`; + }, + (reason) => { + this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; + } + ); + } + + private getDismissReason(reason: any): string { + if (reason === ModalDismissReasons.ESC) { + return 'by pressing ESC'; + } else if (reason === ModalDismissReasons.BACKDROP_CLICK) { + return 'by clicking on a backdrop'; + } else { + return `with: ${reason}`; + } + } + + saveAndClose(modal: any) { + this.isModalSaved = true; + modal.close('Save click'); + } + + emailValidator(): ValidatorFn { + const nameRe: RegExp = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/; + return (control: AbstractControl): ValidationErrors | null => { + const invalid = !nameRe.test(control.value); + return invalid ? { invalidName: { value: control.value } } : null; + }; + } + + get name() { + return this.shelterForm.get('name'); + } + + get email() { + return this.shelterForm.get('email'); + } + + onSubmit(): void { + this.shelterService + .createResource({ body: this.shelter }) + .subscribe((shelter: Shelter) => { + const uri = (shelter as any).uri; + this.router.navigate([uri]).then(); + }); + } + +} diff --git a/src/app/shelter/shelter-list/shelter-list.component.html b/src/app/shelter/shelter-list/shelter-list.component.html index 31ee882..334c978 100644 --- a/src/app/shelter/shelter-list/shelter-list.component.html +++ b/src/app/shelter/shelter-list/shelter-list.component.html @@ -1 +1,23 @@ -

+ + +
+
+
+
+
Name
+ {{shelter.name}} +
+
+
E-mail
+

{{shelter.email}}

+
+
+
+
+ + + + + diff --git a/src/app/shelter/shelter-list/shelter-list.component.ts b/src/app/shelter/shelter-list/shelter-list.component.ts index ec3c342..a87b803 100644 --- a/src/app/shelter/shelter-list/shelter-list.component.ts +++ b/src/app/shelter/shelter-list/shelter-list.component.ts @@ -1,21 +1,20 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; import {Shelter} from "../shelter"; import {Router} from "@angular/router"; import {ShelterService} from "../shelter.service"; import {AuthenticationBasicService} from "../../login-basic/authentication-basic.service"; +import {PagedResourceCollection} from "@lagoshny/ngx-hateoas-client"; @Component({ selector: 'app-shelter-list', - standalone: true, - imports: [], templateUrl: './shelter-list.component.html', }) -export class ShelterListComponent { +export class ShelterListComponent implements OnInit { public shelters: Shelter[] = []; public pageSize = 5; public page = 1; - public totalSeeds = 0; - public sortBy = 'Scientific name'; + public totalShelters = 0; + public sortBy = 'name'; public sortOrder = 'A-Z'; constructor( @@ -24,4 +23,120 @@ export class ShelterListComponent { private authenticationService: AuthenticationBasicService ) {} + ngOnInit(): void { + this.shelterService + .getPage({ + pageParams: { size: this.pageSize }, + sort: { name: 'ASC' }, + }) + .subscribe((page: PagedResourceCollection) => { + this.shelters = page.resources; + this.totalShelters = page.totalElements; + // for (let shelter of this.shelters) { + // this.shelterService.getBeneficialFor(seed.id).subscribe((response) => { + // seed.beneficialFor = response._embedded.seeds.map( + // (seed) => seed.scientificName + // ); + // }); + // } + // this.sortShelters(); + }); + } + // + // searchShelters(shelter: Shelter): void { + // this.router.navigate(['shelters', shelter.id]); + // } + // + changePage(): void { + this.shelterService + .getPage({ + pageParams: { page: this.page - 1, size: this.pageSize }, + sort: { name: 'ASC' }, + }) + .subscribe( + (page: PagedResourceCollection) => (this.shelters = page.resources) + ); + } + // + // detail(shelter: Shelter): void { + // this.router.navigate(['seeds', seed.id]); + // } + // + // isRole(role: string): boolean { + // return this.authenticationService.isRole(role); + // } + // + // updateSelection(selection: string): void { + // this.sortBy = selection; + // this.sortShelters(); + // } + // + // updateSortOrder(order: string): void { + // this.sortOrder = order; + // this.sortShelters(); + // } + // + // sortShelters(): void { + // const returnValue = this.sortOrder === 'A-Z' ? -1 : 1; + // if (this.sortBy === 'Common name') { + // this.seeds.sort((a, b) => { + // const commonNamesA = a.commonName.join().toUpperCase(); + // const commonNamesB = b.commonName.join().toUpperCase(); + // + // if (commonNamesA === '' && commonNamesB === '') { + // return 0; + // } + // if (commonNamesA === '') { + // return 1; + // } + // if (commonNamesB === '') { + // return -1; + // } + // + // if (commonNamesA < commonNamesB) { + // return returnValue; + // } + // if (commonNamesA > commonNamesB) { + // return -returnValue; + // } + // return 0; + // }); + // } else if (this.sortBy === 'Scientific name') { + // this.seeds.sort((a, b) => { + // const scientificNameA = a.scientificName.toUpperCase(); + // const scientificNameB = b.scientificName.toUpperCase(); + // + // if (scientificNameA < scientificNameB) { + // return returnValue; + // } + // if (scientificNameA > scientificNameB) { + // return -returnValue; + // } + // return 0; + // }); + // } else if (this.sortBy === 'Beneficial for') { + // this.seeds.sort((a, b) => { + // const beneficialForA = a.beneficialFor.join().toUpperCase(); + // const beneficialForB = b.beneficialFor.join().toUpperCase(); + // + // if (beneficialForA === '' && beneficialForB === '') { + // return 0; + // } + // if (beneficialForA === '') { + // return 1; + // } + // if (beneficialForB === '') { + // return -1; + // } + // + // if (beneficialForA < beneficialForB) { + // return returnValue; + // } + // if (beneficialForA > beneficialForB) { + // return -returnValue; + // } + // return 0; + // }); + // } + // } } From 68a18ba17b05cbfc9135407e264feee9e94788c9 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 15 May 2024 17:25:18 +0200 Subject: [PATCH 3/5] Create shelter --- src/app/app-routing.module.ts | 2 ++ src/app/app.module.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 823cd78..dad05b8 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -9,6 +9,7 @@ import { UserRegisterComponent } from './user/user-register/user-register.compon import { UserEditComponent } from './user/user-edit/user-edit.component'; import { UserDeleteComponent } from './user/user-delete/user-delete.component'; import { ShelterListComponent } from './shelter/shelter-list/shelter-list.component' +import {ShelterCreateComponent} from "./shelter/shelter-create/shelter-create.component"; const routes: Routes = [ { path: 'users/create', component: UserRegisterComponent}, @@ -20,6 +21,7 @@ const routes: Routes = [ { path: '404', component: NotFoundComponent}, { path: '', redirectTo: 'about', pathMatch: 'full'}, { path: 'shelters', component: ShelterListComponent}, + { path: 'shelters/create', component: ShelterCreateComponent}, ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b813871..431bc19 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -24,6 +24,9 @@ import {AuthenticationBasicService} from './login-basic/authentication-basic.ser import {LoggedInGuard} from './login-basic/loggedin.guard'; import {UserService} from './user/user.service'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; +import {ShelterService} from "./shelter/shelter.service"; +import {ShelterListComponent} from "./shelter/shelter-list/shelter-list.component"; +import {ShelterCreateComponent} from "./shelter/shelter-create/shelter-create.component"; @NgModule({ declarations: [ @@ -37,6 +40,8 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy UserEditComponent, UserDeleteComponent, UserSearchComponent, + ShelterListComponent, + ShelterCreateComponent ], imports: [ BrowserModule, @@ -50,12 +55,12 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy LoginBasicModule, ErrorHandlerModule, NgbModule, - ReactiveFormsModule, + ReactiveFormsModule ], providers: [ { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: HttpErrorInterceptor, multi: true }, - AuthenticationBasicService, LoggedInGuard, UserService, provideAnimationsAsync() + AuthenticationBasicService, LoggedInGuard, UserService, ShelterService, provideAnimationsAsync() ], bootstrap: [AppComponent] }) From 883c8287be07e8a8ffab9305cda0279521838d47 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 15 May 2024 18:39:19 +0200 Subject: [PATCH 4/5] New list component --- src/app/app.module.ts | 4 +- src/app/navbar/navbar.component.html | 10 +++++ .../shelter-create.component.html | 19 +++++++- .../shelter-create.component.ts | 24 ++++++++-- .../shelter-detail.component.html | 45 +++++++++++++++++++ .../shelter-detail.component.ts | 29 ++++++++++++ 6 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 src/app/shelter/shelter-detail/shelter-detail.component.html create mode 100644 src/app/shelter/shelter-detail/shelter-detail.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 431bc19..94a04f0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -27,6 +27,7 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy import {ShelterService} from "./shelter/shelter.service"; import {ShelterListComponent} from "./shelter/shelter-list/shelter-list.component"; import {ShelterCreateComponent} from "./shelter/shelter-create/shelter-create.component"; +import {ShelterDetailComponent} from "./shelter/shelter-detail/shelter-detail.component"; @NgModule({ declarations: [ @@ -41,7 +42,8 @@ import {ShelterCreateComponent} from "./shelter/shelter-create/shelter-create.co UserDeleteComponent, UserSearchComponent, ShelterListComponent, - ShelterCreateComponent + ShelterCreateComponent, + ShelterDetailComponent ], imports: [ BrowserModule, diff --git a/src/app/navbar/navbar.component.html b/src/app/navbar/navbar.component.html index 55e04f2..418ef19 100644 --- a/src/app/navbar/navbar.component.html +++ b/src/app/navbar/navbar.component.html @@ -18,6 +18,16 @@ [routerLink]="['/users']"> List + diff --git a/src/app/shelter/shelter-create/shelter-create.component.html b/src/app/shelter/shelter-create/shelter-create.component.html index 92f3bf2..0d81e0b 100644 --- a/src/app/shelter/shelter-create/shelter-create.component.html +++ b/src/app/shelter/shelter-create/shelter-create.component.html @@ -39,7 +39,24 @@ />
- Invalid name. + Invalid email. +
+ + +
+ +
+ +
+
+ Invalid mobile.
diff --git a/src/app/shelter/shelter-create/shelter-create.component.ts b/src/app/shelter/shelter-create/shelter-create.component.ts index 0601c0c..ba1bdd0 100644 --- a/src/app/shelter/shelter-create/shelter-create.component.ts +++ b/src/app/shelter/shelter-create/shelter-create.component.ts @@ -1,14 +1,11 @@ import {Component, OnInit} from '@angular/core'; -import {User} from "../../login-basic/user"; import {Router} from "@angular/router"; -import {Location} from "@angular/common"; -import {UserService} from "../../user/user.service"; -import {AuthenticationBasicService} from "../../login-basic/authentication-basic.service"; import {ShelterService} from "../shelter.service"; import {Shelter} from "../shelter"; import {AbstractControl, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators} from "@angular/forms"; import {ModalDismissReasons, NgbModal} from "@ng-bootstrap/ng-bootstrap"; import {PagedResourceCollection} from "@lagoshny/ngx-hateoas-client"; +import {formatDate} from "@angular/common"; @Component({ selector: 'app-shelter-create', @@ -40,6 +37,10 @@ export class ShelterCreateComponent implements OnInit{ Validators.required, this.emailValidator(), ]), + mobile: new FormControl(this.shelter.mobile, [ + Validators.required, + this.mobileValidator(), + ]), }); this.loadShelterList(); } @@ -92,6 +93,15 @@ export class ShelterCreateComponent implements OnInit{ }; } + mobileValidator(): ValidatorFn { + const nameRe: RegExp = /^$|[0-9]{11}/; + return (control: AbstractControl): ValidationErrors | null => { + const invalid = !nameRe.test(control.value); + return invalid ? { invalidName: { value: control.value } } : null; + }; + + } + get name() { return this.shelterForm.get('name'); } @@ -100,7 +110,13 @@ export class ShelterCreateComponent implements OnInit{ return this.shelterForm.get('email'); } + get mobile() { + return this.shelterForm.get('mobile'); + } + onSubmit(): void { + this.shelter.createdAt = new Date(); + this.shelter.updatedAt = new Date(); this.shelterService .createResource({ body: this.shelter }) .subscribe((shelter: Shelter) => { diff --git a/src/app/shelter/shelter-detail/shelter-detail.component.html b/src/app/shelter/shelter-detail/shelter-detail.component.html new file mode 100644 index 0000000..8c36a99 --- /dev/null +++ b/src/app/shelter/shelter-detail/shelter-detail.component.html @@ -0,0 +1,45 @@ +
+
+

Shelter {{ shelterDetail.id }}

+
+
+
Name
+

+ {{ shelterDetail.name }} +

+
+
+
Email
+

{{ shelterDetail.email }}

+
+ +
+
+
diff --git a/src/app/shelter/shelter-detail/shelter-detail.component.ts b/src/app/shelter/shelter-detail/shelter-detail.component.ts new file mode 100644 index 0000000..6596a16 --- /dev/null +++ b/src/app/shelter/shelter-detail/shelter-detail.component.ts @@ -0,0 +1,29 @@ +import {Component, OnInit} from '@angular/core'; +import {Shelter} from "../shelter"; +import {ActivatedRoute} from "@angular/router"; +import {AuthenticationBasicService} from "../../login-basic/authentication-basic.service"; +import {ShelterService} from "../shelter.service"; + +@Component({ + selector: 'app-shelter-detail', + templateUrl: './shelter-detail.component.html', +}) +export class ShelterDetailComponent implements OnInit{ + shelterDetail: Shelter; + constructor( + private route: ActivatedRoute, + private shelterService: ShelterService, + private authenticationService: AuthenticationBasicService + ) {} + + ngOnInit(): void { + const id = this.route.snapshot.paramMap.get('id'); + this.shelterService.getResource(id).subscribe((shelter) => { + this.shelterDetail = shelter; + }); + } + + isRole(role: string): boolean { + return this.authenticationService.isRole(role); + } +} From f33c1327a44d49447b1517dd824e9a8b921bd215 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 15 May 2024 20:20:25 +0200 Subject: [PATCH 5/5] Created details page and some fixes. Added new icon on navbar --- .../shelter-create.component.ts | 1 + .../shelter-delete.component.html | 25 +++++ .../shelter-delete.component.ts | 37 +++++++ .../shelter-detail.component.html | 4 +- .../shelter-detail.component.ts | 2 +- .../shelter-list/shelter-list.component.html | 4 +- .../shelter-list/shelter-list.component.ts | 100 +----------------- 7 files changed, 68 insertions(+), 105 deletions(-) create mode 100644 src/app/shelter/shelter-delete/shelter-delete.component.html create mode 100644 src/app/shelter/shelter-delete/shelter-delete.component.ts diff --git a/src/app/shelter/shelter-create/shelter-create.component.ts b/src/app/shelter/shelter-create/shelter-create.component.ts index ba1bdd0..9a88928 100644 --- a/src/app/shelter/shelter-create/shelter-create.component.ts +++ b/src/app/shelter/shelter-create/shelter-create.component.ts @@ -120,6 +120,7 @@ export class ShelterCreateComponent implements OnInit{ this.shelterService .createResource({ body: this.shelter }) .subscribe((shelter: Shelter) => { + console.log(shelter); const uri = (shelter as any).uri; this.router.navigate([uri]).then(); }); diff --git a/src/app/shelter/shelter-delete/shelter-delete.component.html b/src/app/shelter/shelter-delete/shelter-delete.component.html new file mode 100644 index 0000000..7725f68 --- /dev/null +++ b/src/app/shelter/shelter-delete/shelter-delete.component.html @@ -0,0 +1,25 @@ +
+
+
Please, confirm deletion:
+
+
+
+ + +
+
+
diff --git a/src/app/shelter/shelter-delete/shelter-delete.component.ts b/src/app/shelter/shelter-delete/shelter-delete.component.ts new file mode 100644 index 0000000..a26d8af --- /dev/null +++ b/src/app/shelter/shelter-delete/shelter-delete.component.ts @@ -0,0 +1,37 @@ +import {Component, OnInit} from '@angular/core'; +import {ActivatedRoute, Router} from "@angular/router"; +import {Shelter} from "../shelter"; +import {ShelterService} from "../shelter.service"; + +@Component({ + selector: 'app-shelter-delete', + templateUrl: './shelter-delete.component.html', +}) +export class ShelterDeleteComponent implements OnInit { + idShelter: string; + shelter: Shelter; + constructor( + private router: Router, + private shelterService: ShelterService, + private route: ActivatedRoute + ) {} + ngOnInit(): void { + this.idShelter = this.route.snapshot.paramMap.get('id'); + } + delete() { + this.shelterService.getResource(this.idShelter).subscribe((shelter: Shelter) => { + this.shelter = shelter; + this.shelterService + .patchResource(this.shelter) + .subscribe((patchedShelter: Shelter) => { + this.shelterService.deleteResourceById(patchedShelter.id).subscribe({ + next: (e) => { + this.router.navigateByUrl('/shelters'); + }, + error: (err) => { + }, + }); + }); + }); + } +} diff --git a/src/app/shelter/shelter-detail/shelter-detail.component.html b/src/app/shelter/shelter-detail/shelter-detail.component.html index 8c36a99..13250a5 100644 --- a/src/app/shelter/shelter-detail/shelter-detail.component.html +++ b/src/app/shelter/shelter-detail/shelter-detail.component.html @@ -25,18 +25,18 @@
Email
id="editBtn" type="button" [routerLink]="['edit']" - *ngIf="isRole('admin')" class="btn m-1 btn-outline-success" > + Edit diff --git a/src/app/shelter/shelter-detail/shelter-detail.component.ts b/src/app/shelter/shelter-detail/shelter-detail.component.ts index 6596a16..8eaf462 100644 --- a/src/app/shelter/shelter-detail/shelter-detail.component.ts +++ b/src/app/shelter/shelter-detail/shelter-detail.component.ts @@ -18,7 +18,7 @@ export class ShelterDetailComponent implements OnInit{ ngOnInit(): void { const id = this.route.snapshot.paramMap.get('id'); - this.shelterService.getResource(id).subscribe((shelter) => { + this.shelterService.getResource(id).subscribe((shelter: Shelter) => { this.shelterDetail = shelter; }); } diff --git a/src/app/shelter/shelter-list/shelter-list.component.html b/src/app/shelter/shelter-list/shelter-list.component.html index 334c978..a5b98f8 100644 --- a/src/app/shelter/shelter-list/shelter-list.component.html +++ b/src/app/shelter/shelter-list/shelter-list.component.html @@ -1,11 +1,9 @@ - -
E-mail
diff --git a/src/app/shelter/shelter-list/shelter-list.component.ts b/src/app/shelter/shelter-list/shelter-list.component.ts index a87b803..30c8add 100644 --- a/src/app/shelter/shelter-list/shelter-list.component.ts +++ b/src/app/shelter/shelter-list/shelter-list.component.ts @@ -2,7 +2,6 @@ import {Component, OnInit} from '@angular/core'; import {Shelter} from "../shelter"; import {Router} from "@angular/router"; import {ShelterService} from "../shelter.service"; -import {AuthenticationBasicService} from "../../login-basic/authentication-basic.service"; import {PagedResourceCollection} from "@lagoshny/ngx-hateoas-client"; @Component({ @@ -14,13 +13,10 @@ export class ShelterListComponent implements OnInit { public pageSize = 5; public page = 1; public totalShelters = 0; - public sortBy = 'name'; - public sortOrder = 'A-Z'; constructor( public router: Router, private shelterService: ShelterService, - private authenticationService: AuthenticationBasicService ) {} ngOnInit(): void { @@ -31,22 +27,10 @@ export class ShelterListComponent implements OnInit { }) .subscribe((page: PagedResourceCollection) => { this.shelters = page.resources; + console.log(this.shelters); this.totalShelters = page.totalElements; - // for (let shelter of this.shelters) { - // this.shelterService.getBeneficialFor(seed.id).subscribe((response) => { - // seed.beneficialFor = response._embedded.seeds.map( - // (seed) => seed.scientificName - // ); - // }); - // } - // this.sortShelters(); }); } - // - // searchShelters(shelter: Shelter): void { - // this.router.navigate(['shelters', shelter.id]); - // } - // changePage(): void { this.shelterService .getPage({ @@ -57,86 +41,4 @@ export class ShelterListComponent implements OnInit { (page: PagedResourceCollection) => (this.shelters = page.resources) ); } - // - // detail(shelter: Shelter): void { - // this.router.navigate(['seeds', seed.id]); - // } - // - // isRole(role: string): boolean { - // return this.authenticationService.isRole(role); - // } - // - // updateSelection(selection: string): void { - // this.sortBy = selection; - // this.sortShelters(); - // } - // - // updateSortOrder(order: string): void { - // this.sortOrder = order; - // this.sortShelters(); - // } - // - // sortShelters(): void { - // const returnValue = this.sortOrder === 'A-Z' ? -1 : 1; - // if (this.sortBy === 'Common name') { - // this.seeds.sort((a, b) => { - // const commonNamesA = a.commonName.join().toUpperCase(); - // const commonNamesB = b.commonName.join().toUpperCase(); - // - // if (commonNamesA === '' && commonNamesB === '') { - // return 0; - // } - // if (commonNamesA === '') { - // return 1; - // } - // if (commonNamesB === '') { - // return -1; - // } - // - // if (commonNamesA < commonNamesB) { - // return returnValue; - // } - // if (commonNamesA > commonNamesB) { - // return -returnValue; - // } - // return 0; - // }); - // } else if (this.sortBy === 'Scientific name') { - // this.seeds.sort((a, b) => { - // const scientificNameA = a.scientificName.toUpperCase(); - // const scientificNameB = b.scientificName.toUpperCase(); - // - // if (scientificNameA < scientificNameB) { - // return returnValue; - // } - // if (scientificNameA > scientificNameB) { - // return -returnValue; - // } - // return 0; - // }); - // } else if (this.sortBy === 'Beneficial for') { - // this.seeds.sort((a, b) => { - // const beneficialForA = a.beneficialFor.join().toUpperCase(); - // const beneficialForB = b.beneficialFor.join().toUpperCase(); - // - // if (beneficialForA === '' && beneficialForB === '') { - // return 0; - // } - // if (beneficialForA === '') { - // return 1; - // } - // if (beneficialForB === '') { - // return -1; - // } - // - // if (beneficialForA < beneficialForB) { - // return returnValue; - // } - // if (beneficialForA > beneficialForB) { - // return -returnValue; - // } - // return 0; - // }); - // } - // } }