From 92b216cbdc92960485b945979a2e4a96ea4db509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Sun, 7 May 2023 11:09:46 +0200 Subject: [PATCH 1/5] waypoint visited percentage --- src/app/component/list/list.component.html | 4 +- src/app/component/list/list.component.ts | 49 +++++++++++--- .../management/management.component.ts | 4 +- src/app/interface/WaypointsEntity.ts | 10 ++- src/app/service/http/waypoint.service.ts | 4 +- .../service/http/waypointVisited.service.ts | 2 +- src/assets/data.json | 66 ------------------- 7 files changed, 55 insertions(+), 84 deletions(-) delete mode 100644 src/assets/data.json diff --git a/src/app/component/list/list.component.html b/src/app/component/list/list.component.html index 931ec58..ab2c851 100644 --- a/src/app/component/list/list.component.html +++ b/src/app/component/list/list.component.html @@ -31,9 +31,9 @@
-
+
- 70% + {{percentage}}%
diff --git a/src/app/component/list/list.component.ts b/src/app/component/list/list.component.ts index 1ffdc25..d414560 100644 --- a/src/app/component/list/list.component.ts +++ b/src/app/component/list/list.component.ts @@ -9,6 +9,7 @@ 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"; +import {filter} from "rxjs"; @Component({ selector: 'app-list', @@ -57,8 +58,8 @@ export class ListComponent implements OnInit, OnChanges { this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => { this.waypoints = waypoints; console.log("waypoints", this.waypoints); + this.setVisited(); this.setDistance(); - //this.setVisited(); }); } @@ -70,7 +71,7 @@ export class ListComponent implements OnInit, OnChanges { }); this.getPosition(); this.positionNotFoundFunction(); - + this.setDistance(); } @@ -126,17 +127,37 @@ export class ListComponent implements OnInit, OnChanges { } } } -/* + private setVisited(): void { + console.log("setVisited") 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); + if (this.waypoints[i].id) { + this.waypointVisitedService.getWaypointByUserAndWaypoint(this.username, this.waypoints[i].id).subscribe((waypointVisited: any) => { + if (this.waypoints) { + this.waypoints[i].visited = waypointVisited; + console.log(this.waypoints[i].visited); + this.setPercentage(); + } + }); } } } + } -*/ + + /* + 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) => { @@ -162,9 +183,17 @@ export class ListComponent implements OnInit, OnChanges { */ - setPercentage() - : - void { - this.percentage = this.waypoints?.length ?? 0; + setPercentage(): void { + if (this.waypoints) { + let count: number = 0; + for (let i = 0; i < this.waypoints.length; i++) { + if (this.waypoints[i].visited) { + count++; + } + } + this.percentage = parseFloat((count / this.waypoints.length * 100).toFixed(0)); + } + console.log("percentage", this.percentage) } + } diff --git a/src/app/component/management/management.component.ts b/src/app/component/management/management.component.ts index 5910a32..560bac3 100644 --- a/src/app/component/management/management.component.ts +++ b/src/app/component/management/management.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit} from '@angular/core'; import {UserEntity} from "../../interface/UserEntity"; import {LocationEntity} from "../../interface/LocationEntity"; -import {WaypointsEntity} from "../../interface/WaypointsEntity"; +import {newWaypoint, WaypointsEntity} from "../../interface/WaypointsEntity"; import {Router} from "@angular/router"; import {LocationService} from "../../service/http/location.service"; import {UserService} from "../../service/http/user.service"; @@ -26,7 +26,7 @@ export class ManagementComponent implements OnInit { newUser: UserEntity = { password: "", username: ""}; newLocation: LocationEntity = {location: "", lat: 0, lon: 0, region: ""}; - newWaypoint: WaypointsEntity = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""}; + newWaypoint: newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""}; locations: LocationEntity[] | undefined; waypoints: WaypointsEntity[] | undefined; diff --git a/src/app/interface/WaypointsEntity.ts b/src/app/interface/WaypointsEntity.ts index bc49cea..6e00e05 100644 --- a/src/app/interface/WaypointsEntity.ts +++ b/src/app/interface/WaypointsEntity.ts @@ -1,5 +1,5 @@ export interface WaypointsEntity { - id?: number; + id: number; name: string; lat: number; lon: number; @@ -9,3 +9,11 @@ export interface WaypointsEntity { distance?: number; visited?: boolean; } +export interface newWaypoint { + name: string; + lat: number; + lon: number; + description: string; + img: string; + locationName: string; +} diff --git a/src/app/service/http/waypoint.service.ts b/src/app/service/http/waypoint.service.ts index ca0e8c0..0a67d1b 100644 --- a/src/app/service/http/waypoint.service.ts +++ b/src/app/service/http/waypoint.service.ts @@ -1,6 +1,6 @@ import {Injectable} from "@angular/core"; import {HttpClient} from "@angular/common/http"; -import {WaypointsEntity} from "../../interface/WaypointsEntity"; +import {newWaypoint, WaypointsEntity} from "../../interface/WaypointsEntity"; import {catchError, throwError} from "rxjs"; const BASE_URL = "progetto152"; @@ -35,7 +35,7 @@ export class WaypointService { return this.http.get(GET_WAYPOINT_BY_ID + id); } - createWaypoint(waypoint: WaypointsEntity) { + createWaypoint(waypoint: newWaypoint) { return this.http.post(WAYPOINT, waypoint); } diff --git a/src/app/service/http/waypointVisited.service.ts b/src/app/service/http/waypointVisited.service.ts index 17aee43..2e8e3cb 100644 --- a/src/app/service/http/waypointVisited.service.ts +++ b/src/app/service/http/waypointVisited.service.ts @@ -31,7 +31,7 @@ export class WaypointVisitedService { } getWaypointByUserAndWaypoint(user: string, waypoint: number) { - return this.http.get(GET_WAYPOINT_BY_USER + user + "/" + waypoint); + return this.http.get(WAYPOINT_VISITED+ "/"+user + "/" + waypoint); } createWaypoint(waypointvisited: WaypointsVisitedEntity) { diff --git a/src/assets/data.json b/src/assets/data.json deleted file mode 100644 index c998e47..0000000 --- a/src/assets/data.json +++ /dev/null @@ -1,66 +0,0 @@ -[ - { - "location": "Biasca", - "region": "ticino", - "lat": 46.361184, - "lon": 8.970937, - "waypoints": [ - { - "id": 1, - "name": "Cascata Santa Petronilla", - "lat": 46.35328215446709, - "lon": 8.97758397155138, - "description": "", - "img": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" - }, - { - "id": 2, - "name": "Casa Küng", - "lat": 46.363570208549994, - "lon": 8.963464722308554, - "description": "Descrizione del punto 2", - "img": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" - }, - { - "id": 3, - "name": "Punto 3", - "lat": 46.123, - "lon": 8.123, - "description": "Descrizione del punto 3", - "img": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" - } - ] - }, - { - "location": "Lugano", - "region": "TI", - "lat": 46.0036778, - "lon": 8.951052, - "waypoints": [ - { - "id": 4, - "name": "Punto 1", - "lat": 46.123, - "lon": 8.123, - "description": "un grandissimo", - "img": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" - }, - { - "id": 5, - "name": "Punto 2", - "lat": 46.123, - "lon": 8.123, - "description": "Descrizione del punto 2", - "img": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" - }, - { - "id": 6, - "name": "Punto 3", - "lat": 46.123, - "lon": 8.123, - "description": "Descrizione del punto 3", - "img": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" - } - ] - } -] From 509e2069e6257c513528ae6d8dfba3114d5b0392 Mon Sep 17 00:00:00 2001 From: grata Date: Sun, 7 May 2023 11:17:11 +0200 Subject: [PATCH 2/5] fixed translations in list component --- src/app/component/list/list.component.html | 20 ++++++++++++-------- src/app/component/list/list.component.ts | 3 +++ src/assets/i18n/list/en.json | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/app/component/list/list.component.html b/src/app/component/list/list.component.html index 931ec58..9c7d606 100644 --- a/src/app/component/list/list.component.html +++ b/src/app/component/list/list.component.html @@ -1,14 +1,18 @@

- {{translations.locationName}}{{locationParams}} + {{translations.locationName}}: {{locationParams}}

-
-

- {{locations.location}} -

-
-

{{translations.distance}}{{locations.distance}} km

-

{{translations.positionNotFoundErrorMessage}}

+
+
+
+

+ {{locations.location}} +

+
+

{{translations.distance}}{{locations.distance}} km

+

{{translations.positionNotFoundErrorMessage}}

+
+
diff --git a/src/app/component/list/list.component.ts b/src/app/component/list/list.component.ts index 1ffdc25..2acdbbd 100644 --- a/src/app/component/list/list.component.ts +++ b/src/app/component/list/list.component.ts @@ -9,6 +9,7 @@ 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"; +import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service"; @Component({ selector: 'app-list', @@ -42,10 +43,12 @@ export class ListComponent implements OnInit, OnChanges { private waypointVisitedService: WaypointVisitedService, private userService: UserService, private cookieService: cookieService, + private readTranslationJsonService: ReadTranslateJsonService, ) { } async ngOnInit() { + this.translations = this.readTranslationJsonService.getListTransaltions(); this.username = this.cookieService.getUsername(); this.route.params.subscribe(params => { this.locationParams = params['location']; diff --git a/src/assets/i18n/list/en.json b/src/assets/i18n/list/en.json index ee43f5b..040580c 100644 --- a/src/assets/i18n/list/en.json +++ b/src/assets/i18n/list/en.json @@ -1,6 +1,6 @@ { "translate": "Translate", - "locationName": "Position not found: ", - "distance": "Distance: ", + "locationName": "Position not found", + "distance": "Distance", "positionNotFoundErrorMessage": "Could not retrieve position" } From 516af816bed43c3f46456a4ffea30a3760438e4f Mon Sep 17 00:00:00 2001 From: grata Date: Sun, 7 May 2023 11:19:34 +0200 Subject: [PATCH 3/5] fixed translations in list component --- src/app/component/list/list.component.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/component/list/list.component.ts b/src/app/component/list/list.component.ts index 01393cf..8bd59b2 100644 --- a/src/app/component/list/list.component.ts +++ b/src/app/component/list/list.component.ts @@ -44,10 +44,12 @@ export class ListComponent implements OnInit, OnChanges { private waypointVisitedService: WaypointVisitedService, private userService: UserService, private cookieService: cookieService, + private readTranslationJsonService: ReadTranslateJsonService, ) { } async ngOnInit() { + this.translations = this.readTranslationJsonService.getListTransaltions(); this.username = this.cookieService.getUsername(); this.route.params.subscribe(params => { this.locationParams = params['location']; From 4d2e2fd66c46c172c49dc0fa9ec6d541c056a953 Mon Sep 17 00:00:00 2001 From: grata Date: Sun, 7 May 2023 11:21:48 +0200 Subject: [PATCH 4/5] fixed translate button style --- src/app/app.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 10bac68..b88eaf4 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -2,7 +2,7 @@