mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 00:52:55 +00:00
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Component, Input} from '@angular/core';
|
||||
import {Component, Input, OnInit} from '@angular/core';
|
||||
import {
|
||||
SCBuilding,
|
||||
SCFloor,
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
SCThings,
|
||||
} from '@openstapps/core';
|
||||
import {DataProvider} from '../../data.provider';
|
||||
import {hasValidLocation, isSCFloor} from './place-types';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -31,12 +32,17 @@ import {DataProvider} from '../../data.provider';
|
||||
selector: 'stapps-place-detail-content',
|
||||
templateUrl: 'place-detail-content.html',
|
||||
})
|
||||
export class PlaceDetailContentComponent {
|
||||
export class PlaceDetailContentComponent implements OnInit {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Input() item: SCBuilding | SCRoom | SCPointOfInterest | SCFloor;
|
||||
|
||||
/**
|
||||
* Does it have valid location or not (for showing in in a map widget)
|
||||
*/
|
||||
hasValidLocation = false;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
@@ -60,4 +66,9 @@ export class PlaceDetailContentComponent {
|
||||
(item.categories as string[]).includes('restaurant'))
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.hasValidLocation =
|
||||
!isSCFloor(this.item) && hasValidLocation(this.item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
</ion-card-content>
|
||||
</ion-card>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="item.type !== 'floor'">
|
||||
<ion-card *ngIf="item.geo" class="map-widget">
|
||||
<ng-container *ngIf="hasValidLocation">
|
||||
<ion-card class="map-widget">
|
||||
<stapps-map-widget [place]="item" expandable="true"></stapps-map-widget>
|
||||
</ion-card>
|
||||
</ng-container>
|
||||
|
||||
@@ -13,22 +13,14 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Component, Input} from '@angular/core';
|
||||
import {SCBuilding, SCFloor, SCPointOfInterest, SCRoom} from '@openstapps/core';
|
||||
import {PositionService} from '../../../map/position.service';
|
||||
import {Subscription, interval} from 'rxjs';
|
||||
|
||||
type placeTypes = (SCBuilding | SCRoom | SCPointOfInterest | SCFloor) & {
|
||||
distance?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provide information if a place is a floor
|
||||
*
|
||||
* @param place A place to check
|
||||
*/
|
||||
function isSCFloor(place: placeTypes): place is SCFloor {
|
||||
return place.type === 'floor';
|
||||
}
|
||||
import {
|
||||
hasValidLocation,
|
||||
isSCFloor,
|
||||
PlaceTypes,
|
||||
PlaceTypesWithDistance,
|
||||
} from './place-types';
|
||||
|
||||
/**
|
||||
* Shows a place as a list item
|
||||
@@ -41,16 +33,16 @@ export class PlaceListItemComponent {
|
||||
/**
|
||||
* Item getter
|
||||
*/
|
||||
get item(): placeTypes {
|
||||
get item(): PlaceTypesWithDistance {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
/**
|
||||
* An item to show (setter is used as there were issues assigning the distance to the right place in a list)
|
||||
*/
|
||||
@Input() set item(item: placeTypes) {
|
||||
@Input() set item(item: PlaceTypes) {
|
||||
this._item = item;
|
||||
if (!isSCFloor(item)) {
|
||||
if (!isSCFloor(item) && hasValidLocation(item)) {
|
||||
this.distance = this.positionService.getDistance(item.geo.point);
|
||||
this.distanceSubscription = interval(10_000).subscribe(_ => {
|
||||
this.distance = this.positionService.getDistance(item.geo.point);
|
||||
@@ -61,7 +53,7 @@ export class PlaceListItemComponent {
|
||||
/**
|
||||
* An item to show
|
||||
*/
|
||||
private _item: placeTypes;
|
||||
private _item: PlaceTypesWithDistance;
|
||||
|
||||
/**
|
||||
* Distance in meters
|
||||
|
||||
45
src/app/modules/data/types/place/place-types.ts
Normal file
45
src/app/modules/data/types/place/place-types.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCBuilding, SCFloor, SCPointOfInterest, SCRoom} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* Possible place types
|
||||
*/
|
||||
export type PlaceTypes = SCBuilding | SCRoom | SCPointOfInterest | SCFloor;
|
||||
|
||||
/**
|
||||
* Place types with their dynamic distance (from the position of the device)
|
||||
*/
|
||||
export type PlaceTypesWithDistance = PlaceTypes & {
|
||||
distance?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Detects "null island" places, which means places with point coordinates [0, 0]
|
||||
*
|
||||
* @param place A place to check
|
||||
*/
|
||||
export function hasValidLocation(place: Exclude<PlaceTypes, SCFloor>) {
|
||||
return place.geo.point.coordinates.some(coordinate => coordinate !== 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide information if a place is a floor
|
||||
*
|
||||
* @param place A place to check
|
||||
*/
|
||||
export function isSCFloor(place: PlaceTypes): place is SCFloor {
|
||||
return place.type === 'floor';
|
||||
}
|
||||
Reference in New Issue
Block a user