cloud
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li *ngFor="let luogo of luoghi">
|
<li *ngFor="let luogo of luoghi">
|
||||||
{{luogo.nome}}
|
{{luogo.location}}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="menu-title">
|
<li class="menu-title">
|
||||||
|
|||||||
@@ -1 +1,22 @@
|
|||||||
<p>list works!</p>
|
<div *ngIf="isNear">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="!isNear && location">
|
||||||
|
<h1>
|
||||||
|
{{location.location}}
|
||||||
|
</h1>
|
||||||
|
<div *ngFor="let waypoinst of location.waypoints">
|
||||||
|
<h3>
|
||||||
|
{{waypoinst.name}}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<h1></h1>
|
||||||
|
|
||||||
|
<h3></h3>
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
|
import {Locations} from "../interface/data";
|
||||||
|
import {ReadjsonService} from "../service/readjson.service";
|
||||||
|
import {Observable} from "rxjs";
|
||||||
|
import {ActivatedRoute} from "@angular/router";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-list',
|
selector: 'app-list',
|
||||||
@@ -6,8 +10,45 @@ import {Component, OnInit} from '@angular/core';
|
|||||||
styleUrls: ['./list.component.css']
|
styleUrls: ['./list.component.css']
|
||||||
})
|
})
|
||||||
export class ListComponent implements OnInit {
|
export class ListComponent implements OnInit {
|
||||||
|
private locationParams: string | undefined
|
||||||
|
locations: Partial<Locations>[] | undefined;
|
||||||
|
location: Partial<Locations> | undefined;
|
||||||
|
|
||||||
|
isNear: boolean = true;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(private route: ActivatedRoute ,private readjsonService: ReadjsonService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.route.params.subscribe(params => {
|
||||||
|
this.locationParams = params['location'];
|
||||||
|
});
|
||||||
|
|
||||||
|
this.readjsonService.getLocations().subscribe(locations => {
|
||||||
|
this.locations = locations;
|
||||||
|
this.checkDataPopulated();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.locationParams != null) {
|
||||||
|
this.readjsonService.getLocation(this.locationParams).subscribe(location => {
|
||||||
|
this.location = location;
|
||||||
|
this.checkDataPopulated();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkDataPopulated(): void {
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,14 +39,15 @@ export class ReadjsonService{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getWaypoints(location: string, id: number): Observable<waypoint[]> {
|
|
||||||
return this.locations.pipe(
|
// getWaypoints(location: string, id: number): Observable<waypoint[]> {
|
||||||
map((locations) => {
|
// return this.locations.pipe(
|
||||||
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
|
// map((locations) => {
|
||||||
return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : [];
|
// const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
|
||||||
}),
|
// return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : [];
|
||||||
tap(data => console.log("data requested", data))
|
// }),
|
||||||
);
|
// tap(data => console.log("data requested", data))
|
||||||
}
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user