Skip to content

Commit

Permalink
Merge branch 'main' into Delete-RouteVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
rogargon authored Jan 24, 2024
2 parents 004ac83 + fbea958 commit ed1c576
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
</div>
</div>

<!-- Select coordinate -->
<div class="form-group mb-3">
<label class="control-label" for="locate">Coordinate</label>
<select id="locate" name="locate" formControlName="locate" class="form-control">
<option *ngFor="let coordinate of coordinates" [ngValue]="coordinate">{{ coordinate.coordinate }}</option>
</select>
</div>

<!-- Description input -->
<div class="form-group mb-3">
<label class="control-label" for="description">Description</label>
Expand Down
50 changes: 18 additions & 32 deletions src/app/waypoint/waypoint-create/waypoint-create.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {FormControl, FormGroup, Validators,} from '@angular/forms';
import {ModalDismissReasons, NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {PagedResourceCollection} from '@lagoshny/ngx-hateoas-client';
import {Coordinate} from "../../coordinate/coordinate.entity";
import {CoordinateService} from "../../coordinate/coordinate.service";

@Component({
selector: 'app-waypoint-create',
Expand All @@ -16,21 +17,23 @@ import {Coordinate} from "../../coordinate/coordinate.entity";
export class WaypointCreateComponent implements OnInit {
closeResult = '';
public isModalSaved: boolean = false;
public location: Coordinate = new Coordinate();
public coordinates: Coordinate[] = [];
public waypoints: Waypoint[] = [];
public waypoint: Waypoint;
public titleInput: string = '';
public selectedWaypoint: String | undefined = undefined;
public showModal: boolean = false;
public waypointForm: FormGroup;
public types: string[] = ['Summit', 'Lake', 'River', 'Waterfall', 'Fountain',
'Cave', 'Risk', 'Valley', 'Panoramic view', 'Wildlife observation', 'Parking', 'Cliff', 'Shelter', 'Other'];
'Cave', 'Risk', 'Valley', 'Panoramic view', 'Wildlife observation', 'Parking',
'Cliff', 'Shelter', 'Other'];

constructor(
private router: Router,
private waypointService: WaypointService,
private authenticationService: AuthenticationBasicService,
private modalService: NgbModal
private modalService: NgbModal,
private coordinateService: CoordinateService
) {
}

Expand All @@ -42,11 +45,19 @@ export class WaypointCreateComponent implements OnInit {
]),
description: new FormControl(this.titleInput),
type: new FormControl(''),
locate: new FormControl(''),
});

this.loadCoordinateList();
this.loadWaypointList();
}

loadCoordinateList() {
this.coordinateService.getPage({ pageParams: { size: 10 }, sort: { name: 'ASC' } })
.subscribe((coordinates: PagedResourceCollection<Coordinate>) => {
this.coordinates = coordinates.resources;
});
}

loadWaypointList() {
this.waypointService
.getPage({
Expand All @@ -59,34 +70,6 @@ export class WaypointCreateComponent implements OnInit {
});
}

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');
}

get title() {
return this.waypointForm.get('title');
}
Expand All @@ -98,6 +81,9 @@ export class WaypointCreateComponent implements OnInit {
onSubmit(): void {
this.waypoint.title = this.title?.value;
this.waypoint.type = this.waypointForm.get('type')?.value;
this.waypoint.description = this.description?.value;
this.waypoint.location = this.waypointForm.get('locate')?.value;

this.waypointService
.createResource({body: this.waypoint})
.subscribe(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/app/waypoint/waypoint-list/waypoint-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ <h6 class="card-subtitle text-muted">Description</h6>
<h6 class="card-subtitle text-muted">Type</h6>
<p class="card-text">{{ waypoint.type }}</p>
</div>
<!-- <div class="col-6">-->
<!-- <h6 class="card-subtitle text-muted">Coordinate</h6>-->
<!-- <p class="card-text">{{ waypoint.location }}</p>-->
<!-- </div>-->
<div class="col-12 text-right" *ngIf="isRole('admin')">
<a [routerLink]="[waypoint.uri.endsWith('/') ? waypoint.uri.slice(0, -1) : waypoint.uri, 'delete']" class="btn btn-primary btn-delete">Delete</a>
</div>
Expand Down
25 changes: 13 additions & 12 deletions src/app/waypoint/waypoint-list/waypoint-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ export class WaypointListComponent implements OnInit{
this.waypoints = page.resources;
this.totalWaypoints = page.totalElements;
this.waypointsPagedResource = page;
this.waypoints.map(waypoints => {
waypoints.getRelation('coordinate')
.subscribe((coordinate: Coordinate) => {
waypoints.coordinate = coordinate;
});
});

// this.waypoints.map(waypoints => {
// waypoints.getRelation('coordinate')
// .subscribe((coordinate: Coordinate) => {
// waypoints.location = coordinate;
// });
// });
});
}

Expand All @@ -56,12 +57,12 @@ export class WaypointListComponent implements OnInit{
sort: {name: 'ASC'}}).subscribe(
(page: PagedResourceCollection<Waypoint>) => {
this.waypoints = page.resources;
this.waypoints.map(waypoint => {
waypoint.getRelation('coordinate')
.subscribe((coordinate: Coordinate) => {
waypoint.coordinate = coordinate;
});
});
// this.waypoints.map(waypoint => {
// waypoint.getRelation('coordinate')
// .subscribe((coordinate: Coordinate) => {
// waypoint.location = coordinate;
// });
// });
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/waypoint/waypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Waypoint extends Resource {
title: string;
description: string;
type: string;
coordinate: Coordinate;
location: Coordinate;
_links: any;

constructor(values: object = {}) {
Expand Down

0 comments on commit ed1c576

Please sign in to comment.