Skip to content

Commit

Permalink
Merge pull request #97 from Apes2getherStrong/96-moliwo-usunicia-map-…
Browse files Browse the repository at this point in the history
…location-z-trasy

96 moliwo usunicia map location z trasy
  • Loading branch information
Drillllll authored Jul 3, 2024
2 parents 1acea9d + 7232c8f commit 238aa92
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{mapLocationData.mapLocation.name}}
<p style="flex-grow: 1;"></p>
<button *ngIf="userMode" class="btn btn-primary" (click)="onMapLocationEdit(mapLocationData.mapLocation.id)">edit</button>
<button *ngIf="userMode" class="btn btn-danger" (click)="onMapLocationDelete(mapLocationData.mapLocation.id)">delete</button>
</li>

<!--https://github.com/filipows/angular-animations-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,16 @@ export class MapLocationListComponent implements OnInit, OnChanges {
onMapLocationEdit(mapLocationId: string) {
this.router.navigate(['point/' + mapLocationId + '/edit'])
}

onMapLocationDelete(mapLocationId: string) {
if (confirm("You are about to delete map location. Do you want to continue?")) {
this.mapLocationService.deleteMapLocationFromRoute(mapLocationId, this.route.id).subscribe( () => {
//this.router.navigate(['yourRoutes/list'])
this.mapLocations = this.mapLocations.filter(location => location.id !== mapLocationId);
this.mapLocationsAndImages = this.mapLocationsAndImages.filter(
locationData => locationData.mapLocation.id !== mapLocationId
);
});
}
}
}
34 changes: 25 additions & 9 deletions src/app/map-location/map-location.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {HttpClient, HttpErrorResponse, HttpParams} from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Page } from "../shared/page.model";
import { MapLocation } from "./map-location.model";
import { backendUrl } from "../shared/http.config";
import {catchError, of} from "rxjs";
import {Injectable} from "@angular/core";
import {Page} from "../shared/page.model";
import {MapLocation} from "./map-location.model";
import {backendUrl} from "../shared/http.config";
import {catchError, of, switchMap} from "rxjs";

@Injectable({ providedIn: 'root' })
@Injectable({providedIn: 'root'})
export class MapLocationService {

constructor(private http: HttpClient) {}
constructor(private http: HttpClient) {
}

getMapLocationsByRoute(pageNumber: number, pageSize: number, routeId: string) {
let params = new HttpParams()
.set('pageNumber', pageNumber.toString())
.set('pageSize', pageSize.toString());

const url = `${backendUrl}/routes/${routeId}/mapLocations`;
return this.http.get<Page<MapLocation>>(url, { params });
return this.http.get<Page<MapLocation>>(url, {params});
}

getMapLocationsById( mapLocationId: string) {
getMapLocationsById(mapLocationId: string) {
const url = `${backendUrl}/mapLocations/${mapLocationId}`;
return this.http.get<MapLocation>(url);
}
Expand Down Expand Up @@ -52,6 +53,21 @@ export class MapLocationService {

}

deleteMapLocationFromRoute(mapLocationId: string, routeId: string) {
let url = `${backendUrl}/mapLocation/${mapLocationId}/routeMapLocations`;
return this.http.get<any[]>(url).pipe(
switchMap(response => {
if (response.length === 1) {
url = `${backendUrl}/mapLocations/${mapLocationId}`;
} else {
const routeMapLocation = response.find(rML => rML.route.id === routeId);
url = `${backendUrl}/routeMapLocations/${routeMapLocation.id}`;
}
return this.http.delete(url);
})
);
}



}

0 comments on commit 238aa92

Please sign in to comment.