Skip to content

Commit

Permalink
Merge pull request HyperIoT-Labs#143 from GionaMartignani/bugfix/area…
Browse files Browse the repository at this point in the history
…s-navigation-update

Fixed area navigation update
  • Loading branch information
degrelle authored Jan 9, 2025
2 parents fdfbbfe + 2ee1734 commit 8b76bd6
Showing 1 changed file with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from '@angular/core';
import {CdkDragEnd} from '@angular/cdk/drag-drop';
import {Area, AreaDevice, AreasService, Logger, LoggerService} from 'core';
import {PageStatus} from '../../../models/pageStatus';
Expand All @@ -15,7 +15,7 @@ import {MapTypeKey} from "../../../../../projects/components/src/lib/hyt-map/mod
templateUrl: './container-area-map.component.html',
styleUrls: ['./container-area-map.component.scss']
})
export class ContainerAreaMapComponent implements OnInit, OnDestroy {
export class ContainerAreaMapComponent implements OnInit, OnChanges, OnDestroy {
/**
* Hook to track the map element
*/
Expand Down Expand Up @@ -126,19 +126,13 @@ export class ContainerAreaMapComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.areaService.findArea(this.areaId)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe({
next: (area: Area) => {
this.logger.debug('Found area corresponding to the searched ID: '+this.areaId, area);
this.loadArea(area);
},
error: (error) => {
this.logger.error('There is no area matching the ID you are looking for: '+this.areaId, error);
this.pageStatus = PageStatus.Error
}
}
);
this.findArea();
}

ngOnChanges(changes: SimpleChanges): void {
if (changes?.areaId && !changes?.areaId?.firstChange) {
this.findArea();
}
}

ngOnDestroy() {
Expand All @@ -148,6 +142,22 @@ export class ContainerAreaMapComponent implements OnInit, OnDestroy {
}
}

findArea() {
this.areaService.findArea(this.areaId)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe({
next: (area: Area) => {
this.logger.debug('Found area corresponding to the searched ID: '+this.areaId, area);
this.loadArea(area);
},
error: (error) => {
this.logger.error('There is no area matching the ID you are looking for: '+this.areaId, error);
this.pageStatus = PageStatus.Error
}
}
);
}

/**
* Set Treeview overlay status and message
* @param value
Expand Down Expand Up @@ -231,10 +241,6 @@ export class ContainerAreaMapComponent implements OnInit, OnDestroy {
this.logger.debug('onTreeNodeClick start', node);
if(node.data.item.id !== this.areaId){
this.router.navigate(['areas', this.projectId, node.data.item.id])
.then(() => {
//TODO: Change method to navigate
this.loadArea(node.data.item);
})
}
}

Expand Down

0 comments on commit 8b76bd6

Please sign in to comment.