diff --git a/src/app/adoptions/adoption-create/adoption-create.component.html b/src/app/adoptions/adoption-create/adoption-create.component.html new file mode 100644 index 0000000..3d33be6 --- /dev/null +++ b/src/app/adoptions/adoption-create/adoption-create.component.html @@ -0,0 +1,32 @@ +
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
diff --git a/src/app/adoptions/adoption-create/adoption-create.component.ts b/src/app/adoptions/adoption-create/adoption-create.component.ts new file mode 100644 index 0000000..eddcff7 --- /dev/null +++ b/src/app/adoptions/adoption-create/adoption-create.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit } from '@angular/core'; +import { Adoption } from '../adoption'; +import { Router } from '@angular/router'; +import { AdoptionService } from '../adoption.service'; + +@Component({ + selector: 'app-adoption-add', + templateUrl: './adoption-create.component.html', +}) +export class AdoptionCreateComponent implements OnInit{ + public adoption: Adoption; + public date: Date; + + constructor(private router: Router, + private adoptionService: AdoptionService) { + } + ngOnInit(): void { + this.adoption = new Adoption(); + } + + onSubmit(): void { + this.adoptionService.createResource({body: this.adoption}).subscribe( + (adoption:Adoption) => this.router.navigate([adoption.uri]) + ); + } +} diff --git a/src/app/adoptions/adoption-delete/adoption-delete.component.ts b/src/app/adoptions/adoption-delete/adoption-delete.component.ts new file mode 100644 index 0000000..27f43e8 --- /dev/null +++ b/src/app/adoptions/adoption-delete/adoption-delete.component.ts @@ -0,0 +1,31 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Adoption } from '../adoption'; +import { AdoptionService } from '../adoption.service'; + +@Component({ + selector: 'app-adoption-delete', + templateUrl: './adoption.delete.component.html' +}) +export class AdoptionDeleteComponent implements OnInit { + public adoption: Adoption = new Adoption(); + public adoptionId: string; + + constructor(private route: ActivatedRoute, + private router: Router, + private adoptionService: AdoptionService) { + } + + ngOnInit(): void { + this.adoptionId = this.route.snapshot.paramMap.get('id'); + this.adoptionService.getResource(this.adoptionId).subscribe( + adoption => this.adoption = adoption); + } + + delete(): void { + this.adoptionService.deleteResource(this.adoption).subscribe( + () => { + this.router.navigate(['id']); + }); + } +} diff --git a/src/app/adoptions/adoption-delete/adoption.delete.component.html b/src/app/adoptions/adoption-delete/adoption.delete.component.html new file mode 100644 index 0000000..97d4922 --- /dev/null +++ b/src/app/adoptions/adoption-delete/adoption.delete.component.html @@ -0,0 +1 @@ +

adoption-delete works!

diff --git a/src/app/adoptions/adoption-detail/adoption-detail.component.html b/src/app/adoptions/adoption-detail/adoption-detail.component.html new file mode 100644 index 0000000..a3ac23c --- /dev/null +++ b/src/app/adoptions/adoption-detail/adoption-detail.component.html @@ -0,0 +1 @@ +

adoptions-detail works!

diff --git a/src/app/adoptions/adoption-detail/adoption-detail.component.ts b/src/app/adoptions/adoption-detail/adoption-detail.component.ts new file mode 100644 index 0000000..657dbf4 --- /dev/null +++ b/src/app/adoptions/adoption-detail/adoption-detail.component.ts @@ -0,0 +1,25 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { AdoptionService } from '../adoption.service'; +import { Adoption } from '../adoption'; + +@Component({ + selector: 'app-adoption-detail', + templateUrl: './adoption-detail.component.html' +}) +export class AdoptionDetailComponent implements OnInit { + public adoption: Adoption = new Adoption(); + public adoptionId: string; + + constructor(private route: ActivatedRoute, + private adoptionService: AdoptionService) { + } + + ngOnInit(): void { + this.adoptionId = this.route.snapshot.paramMap.get('id'); + this.adoptionService.getResource(this.adoptionId).subscribe( + adoption => { + this.adoption = adoption; + }); + } +} diff --git a/src/app/adoptions/adoption-edit/adoption-edit.component.html b/src/app/adoptions/adoption-edit/adoption-edit.component.html new file mode 100644 index 0000000..8c0a19d --- /dev/null +++ b/src/app/adoptions/adoption-edit/adoption-edit.component.html @@ -0,0 +1 @@ +

adoptions-edit works!

diff --git a/src/app/adoptions/adoption-edit/adoption-edit.component.ts b/src/app/adoptions/adoption-edit/adoption-edit.component.ts new file mode 100644 index 0000000..c38c2f8 --- /dev/null +++ b/src/app/adoptions/adoption-edit/adoption-edit.component.ts @@ -0,0 +1,30 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { Router } from '@angular/router'; +import { AuthenticationBasicService } from '../../login-basic/authentication-basic.service'; +import { AdoptionService } from '../adoption.service'; +import { Adoption } from '../adoption'; + +@Component({ + selector: 'app-adoption-edit', + templateUrl: './adoption-edit.component.html', +}) +export class AdoptionEditComponent implements OnInit { + public adoption: Adoption = new Adoption(); + + constructor(private route: ActivatedRoute, + private router: Router, + private adoptionsService: AdoptionService, + private authenticationService: AuthenticationBasicService) { + } + + ngOnInit(): void { + const id = this.route.snapshot.paramMap.get('id'); + this.adoptionsService.getResource(id).subscribe( + (adoption: Adoption) => this.adoption = adoption ); + } + + getCurrentUserName(): string { + return this.authenticationService.getCurrentUser().username; + } +} diff --git a/src/app/adoptions/adoption-list/adoption-list.component.html b/src/app/adoptions/adoption-list/adoption-list.component.html new file mode 100644 index 0000000..c94c4f8 --- /dev/null +++ b/src/app/adoptions/adoption-list/adoption-list.component.html @@ -0,0 +1,26 @@ +
+
+
+
+
Adoptions ID
+ {{adoption.id}} +
+
+
Pet
+

{{adoption.pet}}

+
+
+
User
+

{{adoption.user}}

+
+
+
Time
+

{{adoption.localDateTime}}

+
+
+
+ + + diff --git a/src/app/adoptions/adoption-list/adoption-list.component.ts b/src/app/adoptions/adoption-list/adoption-list.component.ts new file mode 100644 index 0000000..0e850d9 --- /dev/null +++ b/src/app/adoptions/adoption-list/adoption-list.component.ts @@ -0,0 +1,39 @@ +import {Component, EventEmitter, OnInit, Output} from '@angular/core'; +import { Router } from '@angular/router'; +import { Adoption } from '../adoption'; +import { AdoptionService } from '../adoption.service'; +import { PagedResourceCollection } from '@lagoshny/ngx-hateoas-client'; + +@Component({ + selector: 'app-adoption-list', + templateUrl: './adoption-list.component.html' +}) +export class AdoptionListComponent implements OnInit{ + public adoption: Adoption[] = []; + public pageSize = 5; + public page = 1; + public totalAdoption = 0; + + constructor( + public router: Router, + private adoptionService: AdoptionService) { + } + + ngOnInit(): void { + this.adoptionService.getPage({ pageParams: { size: this.pageSize }, sort: { id: 'ASC' } }).subscribe( + (page: PagedResourceCollection) => { + this.adoption = page.resources; + this.totalAdoption = page.totalElements; + }); + } + + changePage(): void { + this.adoptionService.getPage({ pageParams: { page: this.page - 1, size: this.pageSize }, sort: { id: 'ASC' } }).subscribe( + (page: PagedResourceCollection) => this.adoption = page.resources); + } + + detail(adoption: Adoption): void { + this.router.navigate(['adoption', adoption.id]); + } + +} diff --git a/src/app/adoptions/adoption-search/adoption-search.component.html b/src/app/adoptions/adoption-search/adoption-search.component.html new file mode 100644 index 0000000..a0246f2 --- /dev/null +++ b/src/app/adoptions/adoption-search/adoption-search.component.html @@ -0,0 +1 @@ +

adoption-search works!

diff --git a/src/app/adoptions/adoption-search/adoption-search.component.ts b/src/app/adoptions/adoption-search/adoption-search.component.ts new file mode 100644 index 0000000..70364d4 --- /dev/null +++ b/src/app/adoptions/adoption-search/adoption-search.component.ts @@ -0,0 +1,42 @@ +import { Component, EventEmitter, Output } from '@angular/core'; +import { AdoptionService } from '../adoption.service'; +import { Adoption } from '../adoption'; +import { Observable, of, OperatorFunction } from 'rxjs'; +import { catchError, debounceTime, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'; +import { ResourceCollection } from '@lagoshny/ngx-hateoas-client'; + +@Component({ + selector: 'app-adoption-search', + templateUrl: './adoption-search.component.html' +}) + +export class AdoptionSearchComponent { + @Output() emitResults: EventEmitter = new EventEmitter(); + searchFailed = false; + searching = false; + + constructor(private AdoptionService: AdoptionService) { + } + + autocomplete: OperatorFunction = (text$: Observable) => + text$.pipe( + debounceTime(500), + distinctUntilChanged(), + tap(() => this.searching = true), + switchMap(term => term.length < 3 ? of([]) : + this.AdoptionService.findById(term).pipe( + map((collection: ResourceCollection) => collection.resources), + tap(() => this.searchFailed = false), + catchError(() => { + this.searchFailed = true; + return of([]); + }) + ) + ), + tap(() => this.searching = false ) + ) + + select(item: any): void { + this.emitResults.emit(item as Adoption); + } +} diff --git a/src/app/adoptions/adoption.service.ts b/src/app/adoptions/adoption.service.ts new file mode 100644 index 0000000..d46414c --- /dev/null +++ b/src/app/adoptions/adoption.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/internal/Observable'; +import { HateoasResourceOperation, ResourceCollection } from '@lagoshny/ngx-hateoas-client'; +import { Adoption } from "./adoption" + +@Injectable({providedIn: 'root'}) +export class AdoptionService extends HateoasResourceOperation { + + constructor() { + super(Adoption); + } + + public findById(query: string): Observable> { + return this.searchCollection('findById', { params: { text: query } }); + } +} + diff --git a/src/app/adoptions/adoption.ts b/src/app/adoptions/adoption.ts new file mode 100644 index 0000000..ce2cf8c --- /dev/null +++ b/src/app/adoptions/adoption.ts @@ -0,0 +1,18 @@ +import { HateoasResource, Resource } from '@lagoshny/ngx-hateoas-client'; +import {User} from "../login-basic/user"; + +@HateoasResource('adoptions') +export class Adoption extends Resource { + localDateTime: Date; + id: string; + pet: string; + user: User; + uri: string; + + + + constructor(values: object = {}) { + super(); + Object.assign(this as any, values); + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index dad05b8..a4616a2 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -8,6 +8,12 @@ import { UserDetailComponent } from './user/user-detail/user-detail.component'; import { UserRegisterComponent } from './user/user-register/user-register.component'; import { UserEditComponent } from './user/user-edit/user-edit.component'; import { UserDeleteComponent } from './user/user-delete/user-delete.component'; +import {AdoptionSearchComponent} from './adoptions/adoption-search/adoption-search.component'; +import {AdoptionListComponent} from './adoptions/adoption-list/adoption-list.component'; +import {AdoptionEditComponent} from './adoptions/adoption-edit/adoption-edit.component'; +import {AdoptionDetailComponent} from './adoptions/adoption-detail/adoption-detail.component'; +import {AdoptionDeleteComponent} from './adoptions/adoption-delete/adoption-delete.component'; +import {AdoptionCreateComponent} from "./adoptions/adoption-create/adoption-create.component"; import { ShelterListComponent } from './shelter/shelter-list/shelter-list.component' import {ShelterCreateComponent} from "./shelter/shelter-create/shelter-create.component"; @@ -20,6 +26,12 @@ const routes: Routes = [ { path: 'about', component: AboutComponent}, { path: '404', component: NotFoundComponent}, { path: '', redirectTo: 'about', pathMatch: 'full'}, + { path: 'adoptions' , component: AdoptionListComponent }, + { path: 'adoptions/create', component: AdoptionCreateComponent }, + { path: 'adoptions/edit', component: AdoptionEditComponent }, + { path: 'adoptions/delete', component: AdoptionDeleteComponent }, + { path: 'adoptions/detail', component: AdoptionDetailComponent }, + { path: 'adoptions/search', component: AdoptionSearchComponent }, { path: 'shelters', component: ShelterListComponent}, { path: 'shelters/create', component: ShelterCreateComponent}, ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 94a04f0..bf37af6 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,6 +23,12 @@ import {HttpErrorInterceptor} from './error-handler/http-error-interceptor'; import {AuthenticationBasicService} from './login-basic/authentication-basic.service'; import {LoggedInGuard} from './login-basic/loggedin.guard'; import {UserService} from './user/user.service'; +import {AdoptionSearchComponent} from './adoptions/adoption-search/adoption-search.component'; +import {AdoptionListComponent} from './adoptions/adoption-list/adoption-list.component'; +import {AdoptionEditComponent} from './adoptions/adoption-edit/adoption-edit.component'; +import {AdoptionDetailComponent} from './adoptions/adoption-detail/adoption-detail.component'; +import {AdoptionDeleteComponent} from './adoptions/adoption-delete/adoption-delete.component'; +import {AdoptionCreateComponent} from "./adoptions/adoption-create/adoption-create.component"; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import {ShelterService} from "./shelter/shelter.service"; import {ShelterListComponent} from "./shelter/shelter-list/shelter-list.component"; @@ -41,6 +47,12 @@ import {ShelterDetailComponent} from "./shelter/shelter-detail/shelter-detail.co UserEditComponent, UserDeleteComponent, UserSearchComponent, + AdoptionSearchComponent, + AdoptionCreateComponent, + AdoptionDeleteComponent, + AdoptionDetailComponent, + AdoptionEditComponent, + AdoptionListComponent, ShelterListComponent, ShelterCreateComponent, ShelterDetailComponent