Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
tito
2023-05-06 16:49:19 +02:00
7 changed files with 114 additions and 12 deletions

View File

@@ -1 +1,21 @@
# Progetto-m125 # 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. 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.

View File

@@ -9,6 +9,8 @@ import {LocationEntity} from "../../interface/LocationEntity";
import {WaypointsEntity} from "../../interface/WaypointsEntity"; import {WaypointsEntity} from "../../interface/WaypointsEntity";
import {WaypointService} from "../../service/http/waypoint.service" import {WaypointService} from "../../service/http/waypoint.service"
import {cookieService} from "../../service/cookie.service"; import {cookieService} from "../../service/cookie.service";
import {UserService} from "../../service/http/user.service";
import {WaypointVisitedService} from "../../service/http/waypointVisited.service";
@Component({ @Component({
selector: 'app-list', selector: 'app-list',
@@ -16,6 +18,7 @@ import {cookieService} from "../../service/cookie.service";
styleUrls: ['./list.component.css'] styleUrls: ['./list.component.css']
}) })
export class ListComponent implements OnInit, OnChanges { export class ListComponent implements OnInit, OnChanges {
percentage: number = 0;
username: string = ''; username: string = '';
locationParams: string | undefined locationParams: string | undefined
locations: LocationEntity[] | undefined; locations: LocationEntity[] | undefined;
@@ -32,11 +35,14 @@ export class ListComponent implements OnInit, OnChanges {
positionNotFound: boolean = false; positionNotFound: boolean = false;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private positionService: positionService, private positionService: positionService,
private locationService: LocationService, private locationService: LocationService,
private waypointService: WaypointService, private waypointService: WaypointService,
private waypointVisitedService: WaypointVisitedService,
private userService: UserService,
private cookieService: cookieService, private cookieService: cookieService,
) { ) {
} }
@@ -52,8 +58,9 @@ export class ListComponent implements OnInit, OnChanges {
this.isNear = false; this.isNear = false;
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);
this.setDistance() this.setDistance();
//this.setVisited();
}); });
} }
@@ -63,9 +70,9 @@ export class ListComponent implements OnInit, OnChanges {
console.log("locations", this.locations) console.log("locations", this.locations)
this.setDistance() this.setDistance()
}); });
this.getPosition(); this.getPosition();
this.positionNotFoundFunction(); 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;
}
} }

View File

@@ -37,6 +37,10 @@ export class LoginComponent implements OnInit {
createNewUser(createUser: UserEntity) { createNewUser(createUser: UserEntity) {
console.log(createUser.username+" "+createUser.password); console.log(createUser.username+" "+createUser.password);
if (createUser.username == '' || createUser.password == '') {
this.errorCreateUser = true;
return;
}
this.userService.getUsers().subscribe(users => { this.userService.getUsers().subscribe(users => {
this.users = users; this.users = users;
for (let i = 0; i < this.users.length; i++) { for (let i = 0; i < this.users.length; i++) {
@@ -55,12 +59,17 @@ export class LoginComponent implements OnInit {
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);
if (user !== null) {
if (user.password == password) { if (user.password == password) {
this.cookieService.setUsername(username); this.cookieService.setUsername(username);
this.router.navigate(['/home']); this.router.navigate(['/home']);
}else { }else {
this.errorLogin = true; this.errorLogin = true;
} }
} else {
this.errorLogin = true;
}
}); });
} }
@@ -73,6 +82,8 @@ export class LoginComponent implements OnInit {
} }
switch() { switch() {
this.errorCreateUser = false;
this.errorLogin = false;
if (this.login) { if (this.login) {
this.login = false; this.login = false;
} else { } else {

View File

@@ -49,9 +49,15 @@ export class ManagementComponent implements OnInit {
this.translations = this.readTranslationJsonService.getManagementTranslations(); this.translations = this.readTranslationJsonService.getManagementTranslations();
this.username = this.cookieService.getUsername(); this.username = this.cookieService.getUsername();
this.userService.getUser(this.username).subscribe(user => { this.userService.getUser(this.username).subscribe(user => {
if (user !== null) {
if (user.admin == false) { if (user.admin == false) {
this.route.navigate(['/home']); this.route.navigate(['/home']);
} }
}else {
this.cookieService.deleteUsername();
this.route.navigate(['/login']);
}
}); });
this.locationService.getLocations().subscribe(locations => { this.locationService.getLocations().subscribe(locations => {
this.locations = locations; this.locations = locations;

View File

@@ -7,4 +7,5 @@ export interface WaypointsEntity {
img: string; img: string;
locationName: string; locationName: string;
distance?: number; distance?: number;
visited?: boolean;
} }

View File

@@ -1,6 +1,7 @@
import {Injectable} from "@angular/core"; import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {UserEntity} from "../../interface/UserEntity"; import {UserEntity} from "../../interface/UserEntity";
import {catchError, of} from "rxjs";
const BASE_URL = "progetto152"; const BASE_URL = "progetto152";
const USER = BASE_URL + "/user"; const USER = BASE_URL + "/user";
@@ -21,9 +22,20 @@ export class UserService {
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); return this.http.get<UserEntity>(USER + "/" + username).pipe(
catchError(error => {
if (error.status === 404) {
return of(null);
} else {
throw error;
} }
})
);
}
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);

View File

@@ -30,6 +30,10 @@ export class WaypointVisitedService {
return this.http.get<WaypointsVisitedEntity[]>(GET_WAYPOINT_BY_USER + user); return this.http.get<WaypointsVisitedEntity[]>(GET_WAYPOINT_BY_USER + user);
} }
getWaypointByUserAndWaypoint(user: string, waypoint: number) {
return this.http.get<boolean>(GET_WAYPOINT_BY_USER + user + "/" + waypoint);
}
createWaypoint(waypointvisited: WaypointsVisitedEntity) { createWaypoint(waypointvisited: WaypointsVisitedEntity) {
return this.http.post<WaypointsVisitedEntity>(WAYPOINT_VISITED, waypointvisited); return this.http.post<WaypointsVisitedEntity>(WAYPOINT_VISITED, waypointvisited);
} }