From 2b97f429490489043a33dd175a836761f1cb6cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sat, 6 May 2023 12:31:10 +0200 Subject: [PATCH 1/4] changes --- src/app/component/list/list.component.ts | 56 +++++++++++++++++-- src/app/interface/WaypointsEntity.ts | 1 + .../service/http/waypointVisited.service.ts | 4 ++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/app/component/list/list.component.ts b/src/app/component/list/list.component.ts index 0fb6303..d5edf8b 100644 --- a/src/app/component/list/list.component.ts +++ b/src/app/component/list/list.component.ts @@ -9,6 +9,8 @@ import {LocationEntity} from "../../interface/LocationEntity"; import {WaypointsEntity} from "../../interface/WaypointsEntity"; import {WaypointService} from "../../service/http/waypoint.service" import {cookieService} from "../../service/cookie.service"; +import {UserService} from "../../service/http/user.service"; +import {WaypointVisitedService} from "../../service/http/waypointVisited.service"; @Component({ selector: 'app-list', @@ -16,6 +18,7 @@ import {cookieService} from "../../service/cookie.service"; styleUrls: ['./list.component.css'] }) export class ListComponent implements OnInit, OnChanges { + percentage: number = 0; username: string = ''; locationParams: string | undefined locations: LocationEntity[] | undefined; @@ -32,17 +35,20 @@ export class ListComponent implements OnInit, OnChanges { positionNotFound: boolean = false; + constructor( private route: ActivatedRoute, private positionService: positionService, private locationService: LocationService, private waypointService: WaypointService, + private waypointVisitedService: WaypointVisitedService, + private userService: UserService, private cookieService: cookieService, ) { } async ngOnInit() { - this.username = this.cookieService.getUsername(); + this.username = this.cookieService.getUsername(); this.route.params.subscribe(params => { this.locationParams = params['location']; }); @@ -52,8 +58,9 @@ export class ListComponent implements OnInit, OnChanges { this.isNear = false; this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => { this.waypoints = waypoints; - console.log("waypoints", this.waypoints) - this.setDistance() + console.log("waypoints", this.waypoints); + this.setDistance(); + //this.setVisited(); }); } @@ -63,9 +70,9 @@ export class ListComponent implements OnInit, OnChanges { console.log("locations", this.locations) this.setDistance() }); - this.getPosition(); this.positionNotFoundFunction(); + } @@ -121,4 +128,45 @@ export class ListComponent implements OnInit, OnChanges { } } } +/* + 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 { + this.percentage = this.waypoints?.length ?? 0; + } } diff --git a/src/app/interface/WaypointsEntity.ts b/src/app/interface/WaypointsEntity.ts index 7c52dba..bc49cea 100644 --- a/src/app/interface/WaypointsEntity.ts +++ b/src/app/interface/WaypointsEntity.ts @@ -7,4 +7,5 @@ export interface WaypointsEntity { img: string; locationName: string; distance?: number; + visited?: boolean; } diff --git a/src/app/service/http/waypointVisited.service.ts b/src/app/service/http/waypointVisited.service.ts index 0ff3143..17aee43 100644 --- a/src/app/service/http/waypointVisited.service.ts +++ b/src/app/service/http/waypointVisited.service.ts @@ -30,6 +30,10 @@ export class WaypointVisitedService { return this.http.get(GET_WAYPOINT_BY_USER + user); } + getWaypointByUserAndWaypoint(user: string, waypoint: number) { + return this.http.get(GET_WAYPOINT_BY_USER + user + "/" + waypoint); + } + createWaypoint(waypointvisited: WaypointsVisitedEntity) { return this.http.post(WAYPOINT_VISITED, waypointvisited); } From 1175c00790945b28d9195874c5ae5bda7d6d1859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sat, 6 May 2023 13:16:01 +0200 Subject: [PATCH 2/4] partial fix login error message --- src/app/component/login/login.component.ts | 17 ++++++++++++++--- .../management/management.component.ts | 10 ++++++++-- src/app/service/http/user.service.ts | 16 ++++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/app/component/login/login.component.ts b/src/app/component/login/login.component.ts index 620afd5..3d6c50a 100644 --- a/src/app/component/login/login.component.ts +++ b/src/app/component/login/login.component.ts @@ -37,6 +37,10 @@ export class LoginComponent implements OnInit { createNewUser(createUser: UserEntity) { console.log(createUser.username+" "+createUser.password); + if (createUser.username == '' || createUser.password == '') { + this.errorCreateUser = true; + return; + } this.userService.getUsers().subscribe(users => { this.users = users; for (let i = 0; i < this.users.length; i++) { @@ -55,9 +59,14 @@ export class LoginComponent implements OnInit { loginFunction(username: string, password: string) { this.userService.getUser(username).subscribe(user => { - if (user.password == password) { - this.cookieService.setUsername(username); - this.router.navigate(['/home']); + console.log(user); + if (user !== null) { + if (user.password == password) { + this.cookieService.setUsername(username); + this.router.navigate(['/home']); + }else { + this.errorLogin = true; + } } else { this.errorLogin = true; } @@ -73,6 +82,8 @@ export class LoginComponent implements OnInit { } switch() { + this.errorCreateUser = false; + this.errorLogin = false; if (this.login) { this.login = false; } else { diff --git a/src/app/component/management/management.component.ts b/src/app/component/management/management.component.ts index 1400946..5910a32 100644 --- a/src/app/component/management/management.component.ts +++ b/src/app/component/management/management.component.ts @@ -49,9 +49,15 @@ export class ManagementComponent implements OnInit { this.translations = this.readTranslationJsonService.getManagementTranslations(); this.username = this.cookieService.getUsername(); this.userService.getUser(this.username).subscribe(user => { - if (user.admin == false) { - this.route.navigate(['/home']); + if (user !== null) { + if (user.admin == false) { + this.route.navigate(['/home']); + } + }else { + this.cookieService.deleteUsername(); + this.route.navigate(['/login']); } + }); this.locationService.getLocations().subscribe(locations => { this.locations = locations; diff --git a/src/app/service/http/user.service.ts b/src/app/service/http/user.service.ts index 01f40d7..26bb379 100644 --- a/src/app/service/http/user.service.ts +++ b/src/app/service/http/user.service.ts @@ -1,6 +1,7 @@ import {Injectable} from "@angular/core"; import {HttpClient} from "@angular/common/http"; import {UserEntity} from "../../interface/UserEntity"; +import {catchError, of} from "rxjs"; const BASE_URL = "progetto152"; const USER = BASE_URL + "/user"; @@ -21,16 +22,27 @@ export class UserService { return this.http.get(USER); } + getUser(username: string) { - return this.http.get(USER + "/" + username); + return this.http.get(USER + "/" + username).pipe( + catchError(error => { + if (error.status === 404) { + return of(null); + } else { + throw error; + } + }) + ); } + + getUserById(id: number) { return this.http.get(GET_USER_BY_ID + "/" + id); } createUser(user: UserEntity) { - console.log("create "+user); + console.log("create " + user); return this.http.post(USER, user); } From 760d7179e22ad4a7f0d0c4d2927a232ed6be5740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sat, 6 May 2023 14:02:35 +0200 Subject: [PATCH 3/4] readme changes --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f22d68..361f798 100644 --- a/README.md +++ b/README.md @@ -1 +1,20 @@ -# Progetto-m125 \ No newline at end of file +# Progetto-m152-Angular + +Questa repository fa parte del progetto finale per il modulo125 in particolare si tratta del front-end necessario per il corretto funzionamento del back-end ([Progetto-m152-Java](https://github.com/joekueng/Progetto-m152-Java)). + +## Requisiti +* Node.js (v16.14.0 o superiore) +* npm (v8.3.0 o superiore) +* Angular CLI (v15.0.3 o superiore) +* Un IDE come WebStorm o Visual Studio Code +* Back-end ([Progetto-m152-Java](https://github.com/joekueng/Progetto-m152-Java)) in esecuzione + +## Installazione +1. Clonare il repository +2. Installare le dipendenze del progetto ```npm install``` +3. Assicurarsi si avere il proxy configurato correttamente +4. Eseguire il progetto ```npm start``` oppure configurando run configuration nel vostro IDE (attenzione a configurare il proxy anche qui) +5. Aprire il browser e digitare l'indirizzo http://localhost:4200. + +## Utilizzo +L'applicazione é stata progettatata per essere utilizzata come front-end del progetto finale del modulo 152. In particolare é usata come interfaccia per l'utente finale. From 21d697d17c5be5fd618f7b036bdfc9d6d8c1446d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sat, 6 May 2023 14:11:39 +0200 Subject: [PATCH 4/4] readme changes --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 361f798..f945b78 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,11 @@ Questa repository fa parte del progetto finale per il modulo125 in particolare s ## Installazione 1. Clonare il repository -2. Installare le dipendenze del progetto ```npm install``` -3. Assicurarsi si avere il proxy configurato correttamente -4. Eseguire il progetto ```npm start``` oppure configurando run configuration nel vostro IDE (attenzione a configurare il proxy anche qui) -5. Aprire il browser e digitare l'indirizzo http://localhost:4200. +2. Inserire le api-key di Deepl nel file ```src/environments/environment.ts```e inserire le api di google maps nel file ```src/app/component/detail/detail.component.ts``` +3. Installare le dipendenze del progetto ```npm install``` +4. Assicurarsi si avere il proxy configurato correttamente +5. Eseguire il progetto ```npm start``` oppure configurando run configuration nel vostro IDE (attenzione a configurare il proxy anche qui) +6. Aprire il browser e digitare l'indirizzo http://localhost:4200. ## Utilizzo L'applicazione é stata progettatata per essere utilizzata come front-end del progetto finale del modulo 152. In particolare é usata come interfaccia per l'utente finale.