Skip to content

Commit

Permalink
adding list of routes of the user on user detail
Browse files Browse the repository at this point in the history
  • Loading branch information
dbistuer committed Jan 16, 2024
1 parent 75de528 commit d7530ec
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/app/routes/route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from "@angular/core";
import { Observable } from "rxjs/internal/Observable";
import { HateoasResourceOperation, ResourceCollection } from "@lagoshny/ngx-hateoas-client";
import { Route } from "./route";
import {User} from "../login-basic/user";

@Injectable({providedIn: "root"})
export class RouteService extends HateoasResourceOperation<Route> {
Expand All @@ -10,7 +11,7 @@ export class RouteService extends HateoasResourceOperation<Route> {
super(Route);
}

public findByCreatedBy(creator: string): Observable<ResourceCollection<Route>> {
public findByCreatedBy(creator: User): Observable<ResourceCollection<Route>> {
return this.searchCollection("findByCreatedBy", { params: { creator: creator } })
}

Expand Down
43 changes: 43 additions & 0 deletions src/app/user/user-detail/user-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,46 @@ <h6 class="card-subtitle text-muted">Role</h6>
</div>
</div>
</div>

<div class="row">
<div class="card col-lg-4 col-md-6 col-sm-12 col-xs-12" *ngFor="let route of routes">
<div class="card-block">
<div class="card-header row m-1 text-center" >
<h5>Route</h5>
</div>
<div class="card-body row m-1">
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">CreatedBy</h6>
<p class="card-text">{{route.createdBy?.username}}</p>
</div>
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">Creation date</h6>
<p class="card-text">{{route.creationDate | date: 'dd/MM/yyyy HH:mm:ss'}}</p>
</div>
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">Title</h6>
<p class="card-text">{{route.title}}</p>
</div>
<div class="col-md-6 p-3">
<h6 class="card-subtitle text-muted">Type</h6>
<p class="card-text">{{route.type}}</p>
</div>
<div class="col-lg12 col-md-12 p-3">
<h6 class="card-subtitle text-muted">Description</h6>
<p class="card-text">{{route.description}}</p>
</div>
</div>
<div class="card-footer text-right row">
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" *ngIf="currentUserEdit(route.createdBy?.username) && !isRole('admin')" [routerLink]="[route.uri+'/edit']" class="btn col-6 m-1 btn-outline-success">Edit</button>
<button type="button" *ngIf="!isRole('admin')" [routerLink]="[route.uri]" class="btn col-6 m-1 btn-outline-primary">Detail</button>
<button type="button" *ngIf="isRole('admin')" [routerLink]="[route.uri + '/delete']" class="btn col-6 m-1 btn-outline-danger">Delete</button>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<hr class="my-3">
</div>

30 changes: 29 additions & 1 deletion src/app/user/user-detail/user-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,56 @@ import { ActivatedRoute } from '@angular/router';
import { UserService } from '../user.service';
import { User } from '../../login-basic/user';
import { AuthenticationBasicService } from '../../login-basic/authentication-basic.service';
import {PagedResourceCollection} from "@lagoshny/ngx-hateoas-client";
import {Route} from "../../routes/route";
import {RouteService} from "../../routes/route.service";

@Component({
selector: 'app-user-detail',
templateUrl: './user-detail.component.html'
})
export class UserDetailComponent implements OnInit {
public user: User = new User();
public routes: Route[] = [];


constructor(private route: ActivatedRoute,
private userService: UserService,
private authenticationService: AuthenticationBasicService) {
private authenticationService: AuthenticationBasicService,
private routesService: RouteService) {
}

ngOnInit(): void {
const id = this.route.snapshot.paramMap.get('id');
this.userService.getResource(id).subscribe(
user => {
this.user = user;
this.routesService.findByCreatedBy(this.user).subscribe((page: PagedResourceCollection<Route>) => {
this.routes = page.resources;
console.log(this.routes);
this.routes.map(routes => {
routes.getRelation('createdBy')
.subscribe((user: User) => {
routes.createdBy = user;
});
});
});
});
}

getCurrentUser(): User {
return this.authenticationService.getCurrentUser();
}

getCurrentUserName(): string {
return this.getCurrentUser().id;
}

currentUserEdit(username: string){
return this.getCurrentUserName() == username;
}

isRole(role: string): boolean {
return this.authenticationService.isRole(role);
}
}

0 comments on commit d7530ec

Please sign in to comment.