change on list component
This commit is contained in:
@@ -17,23 +17,23 @@
|
|||||||
<a class="link link-primary" href="location/{{locations.location}}">{{locations.location}}</a>
|
<a class="link link-primary" href="location/{{locations.location}}">{{locations.location}}</a>
|
||||||
</h3>
|
</h3>
|
||||||
<div>
|
<div>
|
||||||
<h4 *ngIf="distance[i] &&! positionNotFound">{{translations.distance}}{{distance[i]}} km</h4>
|
<h4 *ngIf="locations.distance &&! positionNotFound">{{translations.distance}}{{locations.distance}} km</h4>
|
||||||
<h4 *ngIf="positionNotFound && !distance[i]">{{translations.positionNotFoundErrorMessage}}</h4>
|
<h4 *ngIf="positionNotFound && !locations.distance">{{translations.positionNotFoundErrorMessage}}</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!isNear && location && location.waypoints" class="container">
|
<div *ngIf="!isNear && location && waypoints" class="container">
|
||||||
<h1>
|
<h1>
|
||||||
{{location.location}}
|
{{location.location}}
|
||||||
</h1>
|
</h1>
|
||||||
<div *ngFor="let waypoinst of location.waypoints, let i = index" class="row">
|
<div *ngFor="let waypoint of waypoints, let i = index" class="row">
|
||||||
<h3>
|
<h3>
|
||||||
<a class="link link-primary" href="location/{{location.location}}/{{waypoinst.id}}"> {{waypoinst.name}}</a>
|
<a class="link link-primary" href="location/{{location.location}}/{{waypoint.id}}"> {{waypoint.name}}</a>
|
||||||
</h3>
|
</h3>
|
||||||
<div class="distance">
|
<div class="distance">
|
||||||
<h4 *ngIf="distance[i] && !positionNotFound">{{translations.distance}}{{distance[i]}} km</h4>
|
<h4 *ngIf="waypoint.distance && !positionNotFound">{{translations.distance}}{{waypoint.distance}} km</h4>
|
||||||
<h4 *ngIf="positionNotFound && !distance[i]">{{translations.positionNotFoundErrorMessage}}</h4>
|
<h4 *ngIf="positionNotFound && !waypoint.distance">{{translations.positionNotFoundErrorMessage}}</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import {Component, OnInit, SimpleChanges, OnChanges} from '@angular/core';
|
import {Component, OnInit, SimpleChanges, OnChanges} from '@angular/core';
|
||||||
import {Locations} from "../../interface/data";
|
|
||||||
import {ReadjsonService} from "../../service/readjson.service";
|
|
||||||
import {ActivatedRoute} from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
import {positionService} from "../../service/position.service";
|
import {positionService} from "../../service/position.service";
|
||||||
import {listTranslations} from "../../interface/translations";
|
import {listTranslations} from "../../interface/translations";
|
||||||
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";
|
||||||
|
import {LocationService} from "../../service/http/location.service";
|
||||||
|
import {LocationEntity} from "../../interface/LocationEntity";
|
||||||
|
import {WaypointsEntity} from "../../interface/WaypointsEntity";
|
||||||
|
import {WaypointService} from "../../service/http/waypoint.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-list',
|
selector: 'app-list',
|
||||||
@@ -14,8 +16,10 @@ import {ReadTranslateJsonService} from "../../service/language/readTranslateJson
|
|||||||
})
|
})
|
||||||
export class ListComponent implements OnInit, OnChanges {
|
export class ListComponent implements OnInit, OnChanges {
|
||||||
locationParams: string | undefined
|
locationParams: string | undefined
|
||||||
locations: Partial<Locations>[] | undefined;
|
locations: LocationEntity[] | undefined;
|
||||||
location: Partial<Locations> | undefined;
|
location: LocationEntity | undefined;
|
||||||
|
|
||||||
|
waypoints: WaypointsEntity[] | undefined;
|
||||||
|
|
||||||
positionCord: any;
|
positionCord: any;
|
||||||
|
|
||||||
@@ -27,7 +31,14 @@ export class ListComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
positionNotFound: boolean = false;
|
positionNotFound: boolean = false;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private readjsonService: ReadjsonService, private positionService: positionService, private translateService: TranslateService, private readTranslationJsonService: ReadTranslateJsonService) {
|
constructor(
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private positionService: positionService,
|
||||||
|
private translateService: TranslateService,
|
||||||
|
private readTranslationJsonService: ReadTranslateJsonService,
|
||||||
|
private locationService: LocationService,
|
||||||
|
private waypointService: WaypointService,
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
@@ -35,27 +46,36 @@ export class ListComponent implements OnInit, OnChanges {
|
|||||||
this.route.params.subscribe(params => {
|
this.route.params.subscribe(params => {
|
||||||
this.locationParams = params['location'];
|
this.locationParams = params['location'];
|
||||||
});
|
});
|
||||||
this.readjsonService.getLocations().subscribe(locations => {
|
this.locationService.getLocation(this.locationParams ?? "").subscribe(location => {
|
||||||
this.locations = locations;
|
this.location = location;
|
||||||
if (this.locationParams != null) {
|
console.log("location", this.location)
|
||||||
this.readjsonService.getLocation(this.locationParams ?? "").subscribe(async location => {
|
if (this.location != null) {
|
||||||
this.location = location;
|
this.isNear = false;
|
||||||
this.readjsonService.getWaypoints(this.locationParams ?? "").subscribe(waypoints => {
|
this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => {
|
||||||
if (this.location) {
|
this.waypoints = waypoints;
|
||||||
this.location.waypoints = waypoints ?? []
|
console.log("waypoints", this.waypoints)
|
||||||
}
|
this.setDistance()
|
||||||
});
|
});
|
||||||
await this.checkDataPopulated();
|
} else {
|
||||||
|
this.locationService.getLocations().subscribe(locations => {
|
||||||
|
this.locations = locations;
|
||||||
|
console.log("locations", this.locations)
|
||||||
|
this.setDistance()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.getPosition();
|
this.getPosition();
|
||||||
this.positionNotFoundFunction();
|
//this.positionNotFoundFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
positionNotFoundFunction() {
|
positionNotFoundFunction() {
|
||||||
if (!this.positionNotFound) {
|
if (!this.positionNotFound) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (this.waypoints||this.locations) {
|
||||||
|
if (!this.waypoints[0].distance||!this.locations[0].distance) {
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!this.distance[0]) {
|
if (!this.distance[0]) {
|
||||||
this.positionNotFound = true;
|
this.positionNotFound = true;
|
||||||
|
|
||||||
@@ -63,7 +83,7 @@ export class ListComponent implements OnInit, OnChanges {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
if (changes['positionCord'] && (changes['positionCord'])) {
|
if (changes['positionCord'] && (changes['positionCord'])) {
|
||||||
console.log("onChanges")
|
console.log("onChanges")
|
||||||
@@ -88,26 +108,25 @@ export class ListComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setDistance(): void {
|
private setDistance(): void {
|
||||||
if (this.locations && this.location) {
|
if (this.waypoints){
|
||||||
if (this.isNear) {
|
console.log("setDistance")
|
||||||
|
console.log("waypoints lenght " + this.waypoints.length);
|
||||||
|
for (let i = 0; i < this.waypoints.length; i++) {
|
||||||
|
console.log("for" + i);
|
||||||
|
console.log("lat" + this.waypoints[i].lat);
|
||||||
|
this.waypoints[i].distance = this.positionService.getDistanceBetweenCoordinates(this.waypoints[i].lat, this.waypoints[i].lon, this.positionCord.lat, this.positionCord.lon);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
if (this.locations && this.location) {
|
||||||
|
console.log("setDistance")
|
||||||
console.log("location lenght " + this.locations.length);
|
console.log("location lenght " + this.locations.length);
|
||||||
for (let i = 0; i < this.locations.length; i++) {
|
for (let i = 0; i < this.locations.length; i++) {
|
||||||
console.log("for" + i);
|
console.log("for" + i);
|
||||||
console.log("lat" + this.locations[i].lat);
|
console.log("lat" + this.locations[i].lat);
|
||||||
this.distance.push(this.positionService.getDistanceBetweenCoordinates(this.locations[i].lat, this.locations[i].lon, this.positionCord.lat, this.positionCord.lon));
|
this.locations[i].distance = this.positionService.getDistanceBetweenCoordinates(this.locations[i].lat, this.locations[i].lon, this.positionCord.lat, this.positionCord.lon);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.location?.waypoints) {
|
|
||||||
console.log("waypoints lenght " + this.location.waypoints.length);
|
|
||||||
for (let i = 0; i < this.location.waypoints.length; i++) {
|
|
||||||
console.log("for" + i);
|
|
||||||
console.log("lat" + this.location.waypoints[i].lat);
|
|
||||||
this.distance.push(this.positionService.getDistanceBetweenCoordinates(this.location.waypoints[i].lat, this.location.waypoints[i].lon, this.positionCord.lat, this.positionCord.lon));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("ciao" + this.distance[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPosition(): any {
|
getPosition(): any {
|
||||||
|
|||||||
Reference in New Issue
Block a user