This commit is contained in:
2023-05-08 14:20:37 +02:00
parent bc47b15e70
commit a0a2ffb6c1
6 changed files with 71 additions and 125 deletions

View File

@@ -1,5 +1,5 @@
import {Component, OnInit, ViewChild, ElementRef} from '@angular/core'; import {Component, OnInit, ViewChild, ElementRef} from '@angular/core';
import { Router } from '@angular/router'; import {Router} from '@angular/router';
import {ActivatedRoute} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {positionService} from "../../service/position.service"; import {positionService} from "../../service/position.service";
import {WaypointService} from "../../service/http/waypoint.service" import {WaypointService} from "../../service/http/waypoint.service"
@@ -10,9 +10,6 @@ import {WaypointsVisitedEntity} from "../../interface/WaypointsVisitedEntity";
import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service"; import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service";
import {cookieService} from "../../service/cookie.service"; import {cookieService} from "../../service/cookie.service";
import {UserService} from "../../service/http/user.service"; import {UserService} from "../../service/http/user.service";
import {UserEntity} from "../../interface/UserEntity";
import { trigger, state, transition, animate } from '@angular/animations';
@Component({ @Component({
selector: 'app-detail', selector: 'app-detail',
@@ -21,32 +18,30 @@ import { trigger, state, transition, animate } from '@angular/animations';
}) })
export class DetailComponent implements OnInit { export class DetailComponent implements OnInit {
@ViewChild('myModal', {static: true}) myModal!: ElementRef<HTMLInputElement>; @ViewChild('myModal', {static: true}) myModal!: ElementRef<HTMLInputElement>;
private location: string | undefined; private location: string | undefined;
private id: number | undefined; private id: number | undefined;
private URLParams: any; private URLParams: any;
waypointInfo: any; waypointInfo: any;
embed: any; embed: any;
cord: any; cord: any;
detailTranslations: detailTranslations = {} as detailTranslations; detailTranslations: detailTranslations = {} as detailTranslations;
/*
showNav = true;
*/
distance: number | undefined; distance: number | undefined;
displayedDistance = 0;
img: any; img: any;
iframeLoded: boolean = false;
intervalID: any; intervalID: any;
constructor(private route: ActivatedRoute, private positionService: positionService, private waypointService: WaypointService, private waypointVisitedService: WaypointVisitedService, private readTranslationJsonService: ReadTranslateJsonService, constructor(
private userService: UserService, private cookieService: cookieService, private router: Router) { private route: ActivatedRoute,
private positionService: positionService,
private waypointService: WaypointService,
private waypointVisitedService: WaypointVisitedService,
private readTranslationJsonService: ReadTranslateJsonService,
private userService: UserService,
private cookieService: cookieService,
private router: Router) {
} }
async ngOnInit() { async ngOnInit() {
@@ -55,16 +50,12 @@ export class DetailComponent implements OnInit {
this.URLParams = params; this.URLParams = params;
console.log("params", params); console.log("params", params);
}); });
console.log("params", this.URLParams.location); // {location: "lugano", id: "1"} console.log("params", this.URLParams.location); // {location: "lugano", id: "1"}
this.waypointService.getWaypoint(this.URLParams.location, this.URLParams.id).subscribe(waypoint => { this.waypointService.getWaypoint(this.URLParams.location, this.URLParams.id).subscribe(waypoint => {
console.log("waypoint", waypoint) console.log("waypoint", waypoint)
this.waypointInfo = waypoint; this.waypointInfo = waypoint;
console.log("waypointInfo", this.waypointInfo.locationName) console.log("waypointInfo", this.waypointInfo.locationName)
}); });
//this.URLParams = this.route.snapshot.url.slice(-2).map(segment => segment.path); //this.URLParams = this.route.snapshot.url.slice(-2).map(segment => segment.path);
console.log("getting your location: wait..."); console.log("getting your location: wait...");
this.cord = await this.positionService.getLocation(); this.cord = await this.positionService.getLocation();
@@ -84,7 +75,6 @@ export class DetailComponent implements OnInit {
} }
} }
async checkDistanceTimer() { async checkDistanceTimer() {
//set interval //set interval
this.intervalID = setInterval(() => { this.intervalID = setInterval(() => {
@@ -99,7 +89,7 @@ export class DetailComponent implements OnInit {
this.myModal.nativeElement.checked = true; this.myModal.nativeElement.checked = true;
this.userService.getUser(this.cookieService.getUsername()).subscribe(user => { this.userService.getUser(this.cookieService.getUsername()).subscribe(user => {
if (user?.id !== undefined) { if (user?.id !== undefined) {
let waypointVisited: WaypointsVisitedEntity = {userId: user.id , waypointId: this.waypointInfo.id} let waypointVisited: WaypointsVisitedEntity = {userId: user.id, waypointId: this.waypointInfo.id}
console.log("waypointVisited", waypointVisited) console.log("waypointVisited", waypointVisited)
this.waypointVisitedService.createWaypoint(waypointVisited).subscribe(waypointVisited => { this.waypointVisitedService.createWaypoint(waypointVisited).subscribe(waypointVisited => {
console.log("waypointVisited request return", waypointVisited) console.log("waypointVisited request return", waypointVisited)
@@ -128,14 +118,13 @@ export class DetailComponent implements OnInit {
throw new Error('Error generating QR code'); throw new Error('Error generating QR code');
} }
} }
async addSvgToImage(imageUrl: string, svgString: string): Promise<string> { async addSvgToImage(imageUrl: string, svgString: string): Promise<string> {
const image = new Image(); const image = new Image();
image.crossOrigin = 'anonymous'; image.crossOrigin = 'anonymous';
image.src = imageUrl; image.src = imageUrl;
const svgBlob = new Blob([svgString], {type: 'image/svg+xml'}); const svgBlob = new Blob([svgString], {type: 'image/svg+xml'});
const svgUrl = URL.createObjectURL(svgBlob); const svgUrl = URL.createObjectURL(svgBlob);
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
if (!ctx) { if (!ctx) {
@@ -147,10 +136,8 @@ export class DetailComponent implements OnInit {
image.onload = () => { image.onload = () => {
canvas.width = image.width; canvas.width = image.width;
canvas.height = image.height; canvas.height = image.height;
ctx.drawImage(image, 0, 0); ctx.drawImage(image, 0, 0);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
let isAllWhite = true; let isAllWhite = true;
for (let i = 0; i < imageData.data.length; i += 4) { for (let i = 0; i < imageData.data.length; i += 4) {
if (imageData.data[i] !== 255 || imageData.data[i + 1] !== 255 || imageData.data[i + 2] !== 255) { if (imageData.data[i] !== 255 || imageData.data[i + 1] !== 255 || imageData.data[i + 2] !== 255) {
@@ -158,21 +145,17 @@ export class DetailComponent implements OnInit {
break; break;
} }
} }
if (isAllWhite) { if (isAllWhite) {
const svgImage = new Image(); const svgImage = new Image();
svgImage.crossOrigin = 'anonymous'; svgImage.crossOrigin = 'anonymous';
svgImage.src = svgUrl; svgImage.src = svgUrl;
svgImage.onload = () => { svgImage.onload = () => {
canvas.width = svgImage.width; canvas.width = svgImage.width;
canvas.height = svgImage.height; canvas.height = svgImage.height;
ctx.drawImage(svgImage, 0, 0); ctx.drawImage(svgImage, 0, 0);
const outputImageUrl = canvas.toDataURL('image/png'); const outputImageUrl = canvas.toDataURL('image/png');
resolve(outputImageUrl); resolve(outputImageUrl);
}; };
svgImage.onerror = () => { svgImage.onerror = () => {
reject('Error loading SVG'); reject('Error loading SVG');
}; };
@@ -180,22 +163,18 @@ export class DetailComponent implements OnInit {
const svgImage = new Image(); const svgImage = new Image();
svgImage.crossOrigin = 'anonymous'; svgImage.crossOrigin = 'anonymous';
svgImage.src = svgUrl; svgImage.src = svgUrl;
svgImage.onload = () => { svgImage.onload = () => {
const x = image.width - (image.width * 0.2 + 5); const x = image.width - (image.width * 0.2 + 5);
const y = image.height - (image.width * 0.2 + 5); const y = image.height - (image.width * 0.2 + 5);
ctx.drawImage(svgImage, x, y, image.width * 0.2, image.width * 0.2); ctx.drawImage(svgImage, x, y, image.width * 0.2, image.width * 0.2);
const outputImageUrl = canvas.toDataURL('image/png'); const outputImageUrl = canvas.toDataURL('image/png');
resolve(outputImageUrl); resolve(outputImageUrl);
}; };
svgImage.onerror = () => { svgImage.onerror = () => {
reject('Error loading SVG'); reject('Error loading SVG');
}; };
} }
}; };
image.onerror = () => { image.onerror = () => {
reject('Error loading image'); reject('Error loading image');
}; };
@@ -203,32 +182,19 @@ export class DetailComponent implements OnInit {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
return canvas.toDataURL('image/png'); return canvas.toDataURL('image/png');
} }
async generateQR() { async generateQR() {
console.log("generating QR code"); console.log("generating QR code");
//console.log(this.URLParams.value);
let url = `http://localhost:4200/location/${this.URLParams.location}/${this.URLParams.id}`; let url = `http://localhost:4200/location/${this.URLParams.location}/${this.URLParams.id}`;
let qrCode = await this.generateQRCode(url); let qrCode = await this.generateQRCode(url);
//console.log(qrCode);
const imageUrl = this.waypointInfo.img; const imageUrl = this.waypointInfo.img;
this.addSvgToImage(imageUrl, qrCode).then((outputImageUrl) => { this.addSvgToImage(imageUrl, qrCode).then((outputImageUrl) => {
this.img = outputImageUrl // Output the URL of the output image this.img = outputImageUrl // Output the URL of the output image
//console.log(outputImageUrl);
}).catch((error) => { }).catch((error) => {
console.error(error); // Handle any errors that occur console.error(error); // Handle any errors that occur
}); });
} }
public downloadImage(): void { public downloadImage(): void {
@@ -243,6 +209,4 @@ export class DetailComponent implements OnInit {
this.myModal.nativeElement.checked = false; this.myModal.nativeElement.checked = false;
this.router.navigate(['/location/', this.URLParams.location]); this.router.navigate(['/location/', this.URLParams.location]);
} }
} }

View File

@@ -1,5 +1,5 @@
import {Component, OnChanges, OnInit, SimpleChanges} from '@angular/core'; import {Component, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {positionService} from "../../service/position.service"; import {positionService} from "../../service/position.service";
import {listTranslations} from "../../interface/translations"; import {listTranslations} from "../../interface/translations";
import {LocationService} from "../../service/http/location.service"; import {LocationService} from "../../service/http/location.service";
@@ -10,7 +10,6 @@ import {cookieService} from "../../service/cookie.service";
import {UserService} from "../../service/http/user.service"; import {UserService} from "../../service/http/user.service";
import {WaypointVisitedService} from "../../service/http/waypointVisited.service"; import {WaypointVisitedService} from "../../service/http/waypointVisited.service";
import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service"; import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service";
import {filter} from "rxjs";
@Component({ @Component({
selector: 'app-list', selector: 'app-list',
@@ -18,21 +17,16 @@ import {filter} from "rxjs";
styleUrls: ['./list.component.css'] styleUrls: ['./list.component.css']
}) })
export class ListComponent implements OnInit, OnChanges { export class ListComponent implements OnInit, OnChanges {
percentage: number = 0; percentage: number = 0;
username: string = ''; username: string = '';
locationParams: string | undefined locationParams: string | undefined
locations: LocationEntity[] | undefined; locations: LocationEntity[] | undefined;
location: LocationEntity | undefined; location: LocationEntity | undefined;
waypoints: WaypointsEntity[] | undefined; waypoints: WaypointsEntity[] | undefined;
positionCord: any; positionCord: any;
isNear: boolean = true; isNear: boolean = true;
translations: listTranslations = {} as listTranslations translations: listTranslations = {} as listTranslations
positionNotFound: boolean = false; positionNotFound: boolean = false;
@@ -49,15 +43,19 @@ export class ListComponent implements OnInit, OnChanges {
} }
async ngOnInit() { async ngOnInit() {
// get translations
this.translations = this.readTranslationJsonService.getListTransaltions(); this.translations = this.readTranslationJsonService.getListTransaltions();
// get username by cookie
this.username = this.cookieService.getUsername(); this.username = this.cookieService.getUsername();
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.locationParams = params['location']; this.locationParams = params['location'];
}); });
// get location by locationParams
this.locationService.getLocation(this.locationParams ?? "").subscribe(location => { this.locationService.getLocation(this.locationParams ?? "").subscribe(location => {
this.location = location; this.location = location;
if (this.location.location != null || this.location.location != undefined) { if (this.location.location != null || this.location.location != undefined) {
this.isNear = false; this.isNear = false;
// get waypoints by location
this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => { this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => {
this.waypoints = waypoints; this.waypoints = waypoints;
console.log("waypoints", this.waypoints); console.log("waypoints", this.waypoints);
@@ -65,29 +63,35 @@ export class ListComponent implements OnInit, OnChanges {
this.setDistance(); this.setDistance();
}); });
} }
}); });
// get locations
this.locationService.getLocations().subscribe(locations => { this.locationService.getLocations().subscribe(locations => {
this.locations = locations; this.locations = locations;
console.log("locations", this.locations) console.log("locations", this.locations)
this.setDistance() this.setDistance()
}); });
// get position of user
this.getPosition(); this.getPosition();
// set percentage of visited waypoints
this.positionNotFoundFunction(); this.positionNotFoundFunction();
// set distance between user and waypoints
this.setDistance(); this.setDistance();
} }
// set percentage of visited waypoints
positionNotFoundFunction() { positionNotFoundFunction() {
if (!this.positionNotFound) { if (!this.positionNotFound) {
setTimeout(() => { setInterval(() => {
if (!this.positionCord) { if (!this.positionCord) {
this.positionNotFound = true; this.positionNotFound = true;
}else {
this.positionNotFound = false;
} }
}, 5000); }, 5000);
} }
} }
// check if positionCord is changed
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (changes['positionCord'] && (changes['positionCord'])) { if (changes['positionCord'] && (changes['positionCord'])) {
console.log("onChanges") console.log("onChanges")
@@ -95,6 +99,7 @@ export class ListComponent implements OnInit, OnChanges {
} }
} }
// get position of user
getPosition(): any { getPosition(): any {
setInterval(async () => { setInterval(async () => {
this.positionCord = await this.positionService.getLocation(); this.positionCord = await this.positionService.getLocation();
@@ -102,21 +107,7 @@ export class ListComponent implements OnInit, OnChanges {
}, 2000); }, 2000);
} }
private checkDataPopulated(): void { // set distance between user and waypoints
if (this.locations && this.location) {
console.log("Dati popolati correttamente:", this.locations, this.location);
for (let i = 0; i < this.locations.length; i++) {
if (this.locations[i].location === this.locationParams) {
this.location = this.locations[i];
console.log("Location trovata:", this.location);
this.isNear = false;
this.setDistance();
break;
}
}
}
}
private setDistance(): void { private setDistance(): void {
if (this.waypoints) { if (this.waypoints) {
for (let i = 0; i < this.waypoints.length; i++) { for (let i = 0; i < this.waypoints.length; i++) {
@@ -131,6 +122,7 @@ export class ListComponent implements OnInit, OnChanges {
} }
} }
// set visited waypoints by user
private setVisited(): void { private setVisited(): void {
console.log("setVisited") console.log("setVisited")
if (this.username && this.waypoints) { if (this.username && this.waypoints) {
@@ -139,53 +131,15 @@ export class ListComponent implements OnInit, OnChanges {
this.waypointVisitedService.getWaypointByUserAndWaypoint(this.username, this.waypoints[i].id).subscribe((waypointVisited: any) => { this.waypointVisitedService.getWaypointByUserAndWaypoint(this.username, this.waypoints[i].id).subscribe((waypointVisited: any) => {
if (this.waypoints) { if (this.waypoints) {
this.waypoints[i].visited = waypointVisited; this.waypoints[i].visited = waypointVisited;
console.log(this.waypoints[i].visited);
this.setPercentage(); this.setPercentage();
} }
}); });
} }
} }
} }
} }
/* // set percentage of visited waypoints by user
private setVisited(): void {
if (this.username && this.waypoints) {
for (let i = 0; i < this.waypoints.length; i++) {
if (this.waypoints[i].id !== undefined) {
this.waypoints[i].visited == this.waypointVisitedService.getWaypointByUserAndWaypoint(this.username, this.waypoints[i].id);
}
}
}
}
*/
/*
private setVisited(): void {
this.userService.getUser(this.username).subscribe((user: any) => {
if (this.waypoints && user.id) {
let userid: string = user.id.toString();
for (let i = 0; i < this.waypoints.length; i++) {
let waypoint: number;
if (this.waypoints[i].id!==undefined) {
waypoint = this.waypoints[i].id;
} else {
waypoint = 0;
}
this.waypointVisitedService.getWaypointByUserAndWaypoint(userid, waypoint).subscribe((waypointVisited: any) => {
if (waypointVisited) {
this.waypoints[i].visited = true;
this.setPercentage();
}
});
}
}
});
}
*/
setPercentage(): void { setPercentage(): void {
if (this.waypoints) { if (this.waypoints) {
let count: number = 0; let count: number = 0;
@@ -196,7 +150,5 @@ export class ListComponent implements OnInit, OnChanges {
} }
this.percentage = parseFloat((count / this.waypoints.length * 100).toFixed(0)); this.percentage = parseFloat((count / this.waypoints.length * 100).toFixed(0));
} }
console.log("percentage", this.percentage)
} }
} }

View File

@@ -32,9 +32,11 @@ export class LoginComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
// get login translations
this.loginTranslation = this.readTranslationJsonService.getLoginTranslations(); this.loginTranslation = this.readTranslationJsonService.getLoginTranslations();
} }
// create new user
createNewUser(createUser: newUser) { createNewUser(createUser: newUser) {
console.log(createUser.username+" "+createUser.password); console.log(createUser.username+" "+createUser.password);
if (createUser.username == '' || createUser.password == '') { if (createUser.username == '' || createUser.password == '') {
@@ -57,6 +59,7 @@ export class LoginComponent implements OnInit {
}); });
} }
// login function
loginFunction(username: string, password: string) { loginFunction(username: string, password: string) {
this.userService.getUser(username).subscribe(user => { this.userService.getUser(username).subscribe(user => {
console.log(user); console.log(user);
@@ -73,6 +76,7 @@ export class LoginComponent implements OnInit {
}); });
} }
// submit function
submit() { submit() {
if (this.login) { if (this.login) {
this.loginFunction(this.newUser.username, this.newUser.password); this.loginFunction(this.newUser.username, this.newUser.password);
@@ -81,6 +85,7 @@ export class LoginComponent implements OnInit {
} }
} }
// switch between login and create user
switch() { switch() {
this.errorCreateUser = false; this.errorCreateUser = false;
this.errorLogin = false; this.errorLogin = false;

View File

@@ -29,11 +29,9 @@ export class ManagementComponent implements OnInit {
newUser: newUser = {password: "", username: ""}; newUser: newUser = {password: "", username: ""};
newLocation: LocationEntity = {location: "", lat: 0, lon: 0, region: ""}; newLocation: LocationEntity = {location: "", lat: 0, lon: 0, region: ""};
newWaypoint: newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""}; newWaypoint: newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""};
locations: LocationEntity[] | undefined; locations: LocationEntity[] | undefined;
waypoints: WaypointsEntity[] | undefined; waypoints: WaypointsEntity[] | undefined;
users: UserEntity[] | undefined; users: UserEntity[] | undefined;
translations: managementTranslations = {} as managementTranslations translations: managementTranslations = {} as managementTranslations
constructor( constructor(
@@ -50,6 +48,7 @@ export class ManagementComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.translations = this.readTranslationJsonService.getManagementTranslations(); this.translations = this.readTranslationJsonService.getManagementTranslations();
this.username = this.cookieService.getUsername(); this.username = this.cookieService.getUsername();
// check if user is admin
this.userService.getUser(this.username).subscribe(user => { this.userService.getUser(this.username).subscribe(user => {
if (user !== null) { if (user !== null) {
if (user.admin == false) { if (user.admin == false) {
@@ -59,8 +58,8 @@ export class ManagementComponent implements OnInit {
this.cookieService.deleteUsername(); this.cookieService.deleteUsername();
this.route.navigate(['/login']); this.route.navigate(['/login']);
} }
}); });
// get all locations, waypoints and users
this.locationService.getLocations().subscribe(locations => { this.locationService.getLocations().subscribe(locations => {
this.locations = locations; this.locations = locations;
}); });
@@ -72,6 +71,7 @@ export class ManagementComponent implements OnInit {
}); });
} }
// show user form
formUser(username: string, password: string) { formUser(username: string, password: string) {
if (this.edit) { if (this.edit) {
const user: UserEntity = {id: this.id, username: username, password: password}; const user: UserEntity = {id: this.id, username: username, password: password};
@@ -82,6 +82,7 @@ export class ManagementComponent implements OnInit {
} }
} }
// show location form
formLocation(name: string, region: string, lat: number, lon: number) { formLocation(name: string, region: string, lat: number, lon: number) {
if (this.edit) { if (this.edit) {
const location: LocationEntity = {location: name, region: region, lat: lat, lon: lon}; const location: LocationEntity = {location: name, region: region, lat: lat, lon: lon};
@@ -92,6 +93,7 @@ export class ManagementComponent implements OnInit {
} }
} }
// show waypoint form
formWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) { formWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) {
if (this.edit) { if (this.edit) {
const waypoint: WaypointsEntity = { const waypoint: WaypointsEntity = {
@@ -110,6 +112,7 @@ export class ManagementComponent implements OnInit {
} }
} }
// add user to database
addUser(username: string, password: string) { addUser(username: string, password: string) {
this.newUser = {username: username, password: password}; this.newUser = {username: username, password: password};
this.userService.createUser(this.newUser).subscribe(user => { this.userService.createUser(this.newUser).subscribe(user => {
@@ -118,6 +121,7 @@ export class ManagementComponent implements OnInit {
this.closeUserForm(); this.closeUserForm();
} }
// add location to database
addLocation(name: string, region: string, lat: number, lon: number) { addLocation(name: string, region: string, lat: number, lon: number) {
this.newLocation = {location: name, region: region, lat: lat, lon: lon}; this.newLocation = {location: name, region: region, lat: lat, lon: lon};
console.log("newLocation") console.log("newLocation")
@@ -128,6 +132,7 @@ export class ManagementComponent implements OnInit {
this.closeLocationForm() this.closeLocationForm()
} }
// add waypoint to database
addWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) { addWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) {
this.newWaypoint = { this.newWaypoint = {
description: description, description: description,
@@ -143,24 +148,28 @@ export class ManagementComponent implements OnInit {
this.closeWaypointForm(); this.closeWaypointForm();
} }
// delete location from database
deleteLocation(location: string) { deleteLocation(location: string) {
this.locationService.deleteLocation(location).subscribe(location => { this.locationService.deleteLocation(location).subscribe(location => {
this.locations?.splice(this.locations?.indexOf(location), 1); this.locations?.splice(this.locations?.indexOf(location), 1);
}); });
} }
// delete waypoint from database
deleteWaypoint(id: number) { deleteWaypoint(id: number) {
this.waypointService.deleteWaypoint(id).subscribe(waypoint => { this.waypointService.deleteWaypoint(id).subscribe(waypoint => {
this.waypoints?.splice(this.waypoints?.indexOf(waypoint), 1); this.waypoints?.splice(this.waypoints?.indexOf(waypoint), 1);
}); });
} }
// delete user from database
deleteUser(id: number) { deleteUser(id: number) {
this.userService.deleteUser(id).subscribe(user => { this.userService.deleteUser(id).subscribe(user => {
this.users?.splice(this.users?.indexOf(user), 1); this.users?.splice(this.users?.indexOf(user), 1);
}); });
} }
// edit location in database
editLocation(location: LocationEntity) { editLocation(location: LocationEntity) {
this.locationService.updateLocation(location).subscribe(location => { this.locationService.updateLocation(location).subscribe(location => {
this.locations?.splice(this.locations?.indexOf(location), 1, location); this.locations?.splice(this.locations?.indexOf(location), 1, location);
@@ -168,6 +177,7 @@ export class ManagementComponent implements OnInit {
this.closeLocationForm() this.closeLocationForm()
} }
// edit waypoint in database
editWaypoint(waypoint: WaypointsEntity) { editWaypoint(waypoint: WaypointsEntity) {
this.waypointService.updateWaypoint(waypoint, waypoint.id).subscribe(waypoint => { this.waypointService.updateWaypoint(waypoint, waypoint.id).subscribe(waypoint => {
this.waypoints?.splice(this.waypoints?.indexOf(waypoint), 1, waypoint); this.waypoints?.splice(this.waypoints?.indexOf(waypoint), 1, waypoint);
@@ -175,6 +185,7 @@ export class ManagementComponent implements OnInit {
this.closeWaypointForm() this.closeWaypointForm()
} }
// edit user in database
editUser(user: UserEntity) { editUser(user: UserEntity) {
this.userService.updateUser(user, user.id).subscribe(user => { this.userService.updateUser(user, user.id).subscribe(user => {
this.users?.splice(this.users?.indexOf(user), 1, user); this.users?.splice(this.users?.indexOf(user), 1, user);
@@ -182,12 +193,15 @@ export class ManagementComponent implements OnInit {
this.closeUserForm() this.closeUserForm()
} }
// open edit location forms
openEditLocationForm(location: LocationEntity) { openEditLocationForm(location: LocationEntity) {
this.newLocation = location; this.newLocation = location;
this.edit = true; this.edit = true;
this.showLocationForm = true; this.showLocationForm = true;
} }
// open edit waypoint forms
openEditWaypointForm(waypoint: WaypointsEntity) { openEditWaypointForm(waypoint: WaypointsEntity) {
this.newWaypoint = waypoint; this.newWaypoint = waypoint;
this.id = waypoint.id; this.id = waypoint.id;
@@ -195,6 +209,7 @@ export class ManagementComponent implements OnInit {
this.showWaypointForm = true; this.showWaypointForm = true;
} }
// open edit user forms
openEditUserForm(user: UserEntity) { openEditUserForm(user: UserEntity) {
this.newUser = user; this.newUser = user;
this.id = user.id; this.id = user.id;
@@ -202,28 +217,34 @@ export class ManagementComponent implements OnInit {
this.showUserForm = true; this.showUserForm = true;
} }
// open user form
openUserForm() { openUserForm() {
this.showUserForm = true; this.showUserForm = true;
} }
// open waypoint form
openWaypointForm() { openWaypointForm() {
this.showWaypointForm = true; this.showWaypointForm = true;
} }
// open location form
openLocationForm() { openLocationForm() {
this.showLocationForm = true; this.showLocationForm = true;
} }
// close user forms
closeUserForm() { closeUserForm() {
this.showUserForm = false; this.showUserForm = false;
this.newUser = {username: '', password: ''}; this.newUser = {username: '', password: ''};
} }
// close location forms
closeLocationForm() { closeLocationForm() {
this.showLocationForm = false; this.showLocationForm = false;
this.newLocation = {location: '', region: '', lat: 0, lon: 0}; this.newLocation = {location: '', region: '', lat: 0, lon: 0};
} }
// close waypoint forms
closeWaypointForm() { closeWaypointForm() {
this.showWaypointForm = false; this.showWaypointForm = false;
this.newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""}; this.newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""};

View File

@@ -10,28 +10,34 @@ const LOCATION = BASE_URL + "/location";
providedIn: 'root', providedIn: 'root',
}) })
export class LocationService { export class LocationService {
constructor( constructor(
private http: HttpClient, private http: HttpClient,
) { ) {
} }
// get all locations
getLocations() { getLocations() {
return this.http.get<LocationEntity[]>(LOCATION); return this.http.get<LocationEntity[]>(LOCATION);
} }
// get location by location
getLocation(location: string) { getLocation(location: string) {
return this.http.get<LocationEntity>(LOCATION + "/" + location); return this.http.get<LocationEntity>(LOCATION + "/" + location);
} }
// create location
createLocation(location: LocationEntity) { createLocation(location: LocationEntity) {
return this.http.post<LocationEntity>(LOCATION, location); return this.http.post<LocationEntity>(LOCATION, location);
} }
// update location
updateLocation(location: LocationEntity) { updateLocation(location: LocationEntity) {
return this.http.put<LocationEntity>(LOCATION+"/"+location.location, location); return this.http.put<LocationEntity>(LOCATION+"/"+location.location, location);
} }
// delete location
deleteLocation(location: string) { deleteLocation(location: string) {
return this.http.delete<LocationEntity>(LOCATION +"/"+ location); return this.http.delete<LocationEntity>(LOCATION +"/"+ location);
} }

View File

@@ -18,11 +18,11 @@ export class UserService {
) { ) {
} }
// get all users
getUsers() { getUsers() {
return this.http.get<UserEntity[]>(USER); return this.http.get<UserEntity[]>(USER);
} }
getUser(username: string) { getUser(username: string) {
return this.http.get<UserEntity>(USER + "/" + username).pipe( return this.http.get<UserEntity>(USER + "/" + username).pipe(
catchError(error => { catchError(error => {
@@ -35,8 +35,6 @@ export class UserService {
); );
} }
getUserById(id: number) { getUserById(id: number) {
return this.http.get<UserEntity>(GET_USER_BY_ID + "/" + id); return this.http.get<UserEntity>(GET_USER_BY_ID + "/" + id);
} }