-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from UdL-EPS-SoftArch/adoptions-angular
Adoptions frontend
- Loading branch information
Showing
16 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/app/adoptions/adoption-create/adoption-create.component.html
This file contains 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,32 @@ | ||
<form id="adoptions-form" (ngSubmit)="onSubmit()" #form="ngForm"> | ||
<fieldset> | ||
|
||
<div class="form-group mb-3" [class.was-validated]="id.invalid && (id.dirty || id.touched)"> | ||
<label class="control-label" for="id">Id</label> | ||
<input id="id" name="id" type="number" class="form-control" [(ngModel)]="adoption.id" | ||
#id="ngModel"> | ||
</div> | ||
|
||
<div class="form-group mb-3"> | ||
<label class="control-label" for="pet">Pet</label> | ||
<input id="pet" name="pet" type="text" class="form-control" [(ngModel)]="adoption.pet" | ||
#time="ngModel"> | ||
</div> | ||
|
||
<div class="form-group mb-3"> | ||
<label class="control-label" for="time">Time</label> | ||
<input id="time" name="time" type="Date" class="form-control" [(ngModel)]="adoption.localDateTime" | ||
#time="ngModel"> | ||
</div> | ||
|
||
<div class=" form-group fa-pull-right"> | ||
<button id="listBtn" type="button" [routerLink]="['/adoptions']" | ||
class="btn btn-outline-primary pull-right">Back | ||
</button> | ||
<button id="submit" type="submit" [disabled]="!form.form.valid" | ||
class="btn ms-3 btn-success pull-right">Submit | ||
</button> | ||
</div> | ||
|
||
</fieldset> | ||
</form> |
26 changes: 26 additions & 0 deletions
26
src/app/adoptions/adoption-create/adoption-create.component.ts
This file contains 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,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]) | ||
); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/app/adoptions/adoption-delete/adoption-delete.component.ts
This file contains 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,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']); | ||
}); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/app/adoptions/adoption-delete/adoption.delete.component.html
This file contains 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 @@ | ||
<p>adoption-delete works!</p> |
1 change: 1 addition & 0 deletions
1
src/app/adoptions/adoption-detail/adoption-detail.component.html
This file contains 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 @@ | ||
<p>adoptions-detail works!</p> |
25 changes: 25 additions & 0 deletions
25
src/app/adoptions/adoption-detail/adoption-detail.component.ts
This file contains 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,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; | ||
}); | ||
} | ||
} |
This file contains 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 @@ | ||
<p>adoptions-edit works!</p> |
30 changes: 30 additions & 0 deletions
30
src/app/adoptions/adoption-edit/adoption-edit.component.ts
This file contains 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,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; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/app/adoptions/adoption-list/adoption-list.component.html
This file contains 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,26 @@ | ||
<div class="card mb-1" *ngFor="let adoption of adoption"> | ||
<div class="card-block row m-1 col-12"> | ||
<div class="card-body row align-items-center"> | ||
<div class="col-6 mt-1"> | ||
<h6 class="card-subtitle text-muted">Adoptions ID</h6> | ||
<a class="card-text" [routerLink]="['/adoptions', adoption.id]">{{adoption.id}}</a> | ||
</div> | ||
<div class="col-6 mt-1"> | ||
<h6 class="card-subtitle text-muted">Pet</h6> | ||
<p class="card-text">{{adoption.pet}}</p> | ||
</div> | ||
<div class="col-6 mt-1"> | ||
<h6 class="card-subtitle text-muted">User</h6> | ||
<p class="card-text">{{adoption.user}}</p> | ||
</div> | ||
<div class="col-6 mt-1"> | ||
<h6 class="card-subtitle text-muted">Time</h6> | ||
<p class="card-text">{{adoption.localDateTime}}</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<ngb-pagination class="d-flex justify-content-center" | ||
[(page)]="page" [pageSize]="pageSize" [collectionSize]="totalAdoption" | ||
(pageChange)="changePage()"></ngb-pagination> |
39 changes: 39 additions & 0 deletions
39
src/app/adoptions/adoption-list/adoption-list.component.ts
This file contains 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,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<Adoption>) => { | ||
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<Adoption>) => this.adoption = page.resources); | ||
} | ||
|
||
detail(adoption: Adoption): void { | ||
this.router.navigate(['adoption', adoption.id]); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/app/adoptions/adoption-search/adoption-search.component.html
This file contains 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 @@ | ||
<p>adoption-search works!</p> |
42 changes: 42 additions & 0 deletions
42
src/app/adoptions/adoption-search/adoption-search.component.ts
This file contains 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,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<Adoption> = new EventEmitter(); | ||
searchFailed = false; | ||
searching = false; | ||
|
||
constructor(private AdoptionService: AdoptionService) { | ||
} | ||
|
||
autocomplete: OperatorFunction<string, readonly Adoption[]> = (text$: Observable<string>) => | ||
text$.pipe( | ||
debounceTime(500), | ||
distinctUntilChanged(), | ||
tap(() => this.searching = true), | ||
switchMap(term => term.length < 3 ? of([]) : | ||
this.AdoptionService.findById(term).pipe( | ||
map((collection: ResourceCollection<Adoption>) => 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); | ||
} | ||
} |
This file contains 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,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<Adoption> { | ||
|
||
constructor() { | ||
super(Adoption); | ||
} | ||
|
||
public findById(query: string): Observable<ResourceCollection<Adoption>> { | ||
return this.searchCollection('findById', { params: { text: query } }); | ||
} | ||
} | ||
|
This file contains 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,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); | ||
} | ||
} |
This file contains 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 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