progress for cookie

This commit is contained in:
2023-05-03 12:15:13 +02:00
parent 0e37aad91a
commit d86cfb2e87
5 changed files with 26 additions and 78 deletions

View File

@@ -9,7 +9,7 @@
<div class="mb-4"> <div class="mb-4">
<label for="email" class="block text-gray-700 font-bold mb-2">Email:</label> <label for="email" class="block text-gray-700 font-bold mb-2">Email:</label>
<input type="email" id="email" name="email" placeholder="Inserisci la tua email" <input type="email" id="email" name="email" placeholder="Inserisci username"
class="w-full px-4 py-2 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent"> class="w-full px-4 py-2 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent">
</div> </div>

View File

@@ -1,10 +1,31 @@
import { Component } from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {Router} from "@angular/router";
import {TranslateService} from "../../service/language/translate.service";
import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service";
import {cookieService} from "../../service/cookie.service";
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
templateUrl: './login.component.html', templateUrl: './login.component.html',
styleUrls: ['./login.component.css'] styleUrls: ['./login.component.css']
}) })
export class LoginComponent { export class LoginComponent implements OnInit{
constructor(
private router: Router,
private translateService: TranslateService,
private readTranslationJsonService: ReadTranslateJsonService,
private cookieService: cookieService,
) {
}
ngOnInit(): void {
}
submit(username: string, password: string) {
}
} }

View File

@@ -1,6 +1,5 @@
import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {distinctUntilChanged, fromEvent, Subject, Subscription} from "rxjs"; import {distinctUntilChanged, fromEvent, Subject, Subscription} from "rxjs";
import {ReadjsonService} from "../service/readjson.service";
import {Router} from "@angular/router"; import {Router} from "@angular/router";
import {TranslateService} from '../service/language/translate.service'; import {TranslateService} from '../service/language/translate.service';
import {ReadTranslateJsonService} from "../service/language/readTranslateJson.service"; import {ReadTranslateJsonService} from "../service/language/readTranslateJson.service";
@@ -34,7 +33,6 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy {
constructor( constructor(
private readjsonService: ReadjsonService,
private router: Router, private router: Router,
private translateService: TranslateService, private translateService: TranslateService,
private readTranslationJsonService: ReadTranslateJsonService, private readTranslationJsonService: ReadTranslateJsonService,

View File

@@ -19,8 +19,8 @@ export class cookieService {
getUsername(): string { getUsername(): string {
let username = this.coockieService.get('username'); let username = this.coockieService.get('username');
if (username == null) { if (username == '' || username == undefined) {
this.router.navigate(['/login']); this.router.navigate(['/login']).then(r => console.log("redirect to login"));
return ''; return '';
} else { } else {
return username; return username;

View File

@@ -1,71 +0,0 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Locations, waypoint} from "../interface/data";
import {BehaviorSubject, map, Observable, tap} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class ReadjsonService{
private locations: BehaviorSubject<Locations[]> = new BehaviorSubject<Locations[]>([]);
constructor(private http: HttpClient) {
this.http.get<Locations[]>('assets/data.json').subscribe(data => {
this.locations.next(data)
console.log("data loaded", data)
});
}
getLocations(): Observable<Partial<Locations>[]> {
return this.locations.pipe(
map((locations) => {
return locations.map((loc: Locations) => ({
location: loc.location,
region: loc.region,
lat: loc.lat,
lon: loc.lon
}))
}),
tap(data => console.log("data requested", data)))
}
getLocation(location: string): Observable<Locations> {
return this.locations.pipe(
map((locations) => {
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
return foundLocation ? foundLocation : {location: '', region: '', lat: 0, lon: 0, waypoints: []};
}),
tap(data => console.log("data requested", data))
);
}
getWaypoint(location: string, id: number): Observable<waypoint[]> {
return this.locations.pipe(
map((locations) => {
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
if (foundLocation?.waypoints) {
return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : [];
} else {
return []
}
}),
tap(data => console.log("data requested", data))
);
}
getWaypoints(location: string): Observable<waypoint[]> {
return this.locations.pipe(
map((locations) => {
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
if (foundLocation?.waypoints) {
return foundLocation ? foundLocation.waypoints : [];
} else {
return []
}
}),
tap(data => console.log("data requested", data))
);
}
}