Skip to content

Commit

Permalink
Remove event emitters, select node event and
Browse files Browse the repository at this point in the history
selected tree node property, and use the activeFeature subscription
instead to pull the file name. Added a function to extract file name from
activeFeature display_path.
  • Loading branch information
sophia-massie committed Nov 28, 2023
1 parent e00ffab commit 75d2550
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
16 changes: 11 additions & 5 deletions angular/src/app/components/asset-detail/asset-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class AssetDetailComponent implements OnInit {
featureSource: string;
activeProject: Project;
safePointCloudUrl: SafeResourceUrl;
selectedTreeNode: PathTree<Feature>;
title: string;
constructor(
private geoDataService: GeoDataService,
Expand All @@ -42,6 +41,12 @@ export class AssetDetailComponent implements OnInit {
featureSource = featureSource.replace(/([^:])(\/{2,})/g, '$1/');
this.featureSource = featureSource;

if (this.feature.assets.length && this.feature.assets[0].display_path) {
const fileName = this.extractFileName(this.feature.assets[0].display_path);
this.title = fileName;
} else {
this.title = this.feature.id.toString();
}
if (this.feature.featureType() === 'point_cloud') {
this.safePointCloudUrl = this.sanitizer.bypassSecurityTrustResourceUrl(featureSource + '/preview.html');
} else {
Expand All @@ -55,10 +60,6 @@ export class AssetDetailComponent implements OnInit {
this.projectsService.activeProject.subscribe((current) => {
this.activeProject = current;
});
this.geoDataService.selectNodeEvent.subscribe((selectedNode: PathTree<Feature>) => {
this.selectedTreeNode = selectedNode;
this.title = selectedNode.getPath();
});
}

openFileBrowserModal() {
Expand Down Expand Up @@ -88,6 +89,11 @@ export class AssetDetailComponent implements OnInit {
this.bsModalService.show(ModalQuestionnaireViewerComponent, modalConfig);
}

extractFileName(path: string): string {
const pathSegments = path.split('/');
return pathSegments.pop();
}

close() {
this.geoDataService.activeFeature = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class AssetsPanelComponent implements OnInit {
displayFeatures: Array<Feature>;
activeProject: Project;
currentTreeListing: PathTree<Feature>;
selectedTreeNode: PathTree<Feature>;

constructor(
private geoDataService: GeoDataService,
Expand Down Expand Up @@ -55,9 +54,6 @@ export class AssetsPanelComponent implements OnInit {
this.geoDataService.featureTree$.subscribe((next) => {
this.currentTreeListing = next;
});
this.geoDataService.selectNodeEvent.subscribe((selectedNode) => {
this.selectedTreeNode = selectedNode;
});
}

scrollToActiveFeature() {
Expand Down Expand Up @@ -98,7 +94,6 @@ export class AssetsPanelComponent implements OnInit {
} else {
this.streetviewService.activeAsset = null;
this.geoDataService.activeFeature = node.getPayload();
this.geoDataService.selectNodeEvent.emit(node);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class FileTreeNodeComponent implements OnInit, OnDestroy {
@Input() isPublicView = false;
@Input() node: PathTree<Feature>;
@Output() clickEvent: EventEmitter<PathTree<Feature>> = new EventEmitter<PathTree<Feature>>();
@Output() selectNodeEvent: EventEmitter<PathTree<Feature>> = new EventEmitter<PathTree<Feature>>();
public activeFeature: Feature;
public activeStreetviewAsset: any;
private activeFeatureSub: Subscription;
Expand Down Expand Up @@ -84,13 +83,11 @@ export class FileTreeNodeComponent implements OnInit, OnDestroy {
this.displayChildren = !this.displayChildren;
} else {
this.clickEvent.emit(node);
this.selectNodeEvent.emit(node);
}
}

onClickChild(item: PathTree<Feature>) {
this.clickEvent.emit(item);
this.selectNodeEvent.emit(item);
}

delete(item: PathTree<Feature>) {
Expand Down
3 changes: 1 addition & 2 deletions angular/src/app/services/geo-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, EventEmitter } from '@angular/core';
import { Injectable } from '@angular/core';
import { HttpClient, HttpEventType } from '@angular/common/http';
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
import { LatLng } from 'leaflet';
Expand Down Expand Up @@ -61,7 +61,6 @@ export class GeoDataService {

private _existingFeatureTypes: BehaviorSubject<Record<string, boolean>> = new BehaviorSubject<Record<string, boolean>>(existingFeatures);
public readonly existingFeatureTypes: Observable<Record<string, boolean>> = this._existingFeatureTypes.asObservable();
public readonly selectNodeEvent: EventEmitter<PathTree<Feature>> = new EventEmitter<PathTree<Feature>>();

constructor(
private http: HttpClient,
Expand Down

0 comments on commit 75d2550

Please sign in to comment.