Skip to content

Commit

Permalink
auto refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Wilson committed Nov 1, 2024
1 parent a287710 commit 0112b6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</form>
</div>
<button style="margin-right: 1rem;" pButton (click)="scanNetwork()" [disabled]="scanning">{{scanning ? 'Scanning...' : 'Automatic Scan'}}</button>
<button pButton severity="secondary" (click)="refreshList()" [disabled]="scanning">Refresh List</button>
<button pButton severity="secondary" (click)="refreshList()" [disabled]="scanning">Refresh List ({{refreshIntervalTime}})</button>
<div>
<table cellspacing="0" cellpadding="0" >
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { BehaviorSubject, catchError, combineLatest, debounce, debounceTime, forkJoin, from, interval, map, mergeAll, mergeMap, Observable, of, startWith, switchMap, take, timeout, toArray } from 'rxjs';
import { LocalStorageService } from 'src/app/local-storage.service';
import { SystemService } from 'src/app/services/system.service';

const REFRESH_TIME_SECONDS = 30;
const SWARM_DATA = 'SWARM_DATA'
@Component({
selector: 'app-swarm',
templateUrl: './swarm.component.html',
styleUrls: ['./swarm.component.scss']
})
export class SwarmComponent implements OnInit {
export class SwarmComponent implements OnInit, OnDestroy {

public swarm: any[] = [];

Expand All @@ -23,6 +23,9 @@ export class SwarmComponent implements OnInit {

public scanning = false;

public refreshIntervalRef!: number;
public refreshIntervalTime = REFRESH_TIME_SECONDS;

constructor(
private fb: FormBuilder,
private systemService: SystemService,
Expand All @@ -36,6 +39,7 @@ export class SwarmComponent implements OnInit {
})

}

ngOnInit(): void {
const swarmData = this.localStorageService.getObject(SWARM_DATA);
console.log(swarmData);
Expand All @@ -45,8 +49,19 @@ export class SwarmComponent implements OnInit {
} else {
this.swarm = swarmData;
}

this.refreshIntervalRef = window.setInterval(() => {
this.refreshIntervalTime --;
if(this.refreshIntervalTime <= 0){
this.refreshIntervalTime = REFRESH_TIME_SECONDS;
this.refreshList();
}
}, 1000);
}

ngOnDestroy(): void {
window.clearInterval(this.refreshIntervalRef);
}



Expand Down Expand Up @@ -142,7 +157,7 @@ export class SwarmComponent implements OnInit {
}),
timeout(5000),
catchError(error => {
return this.swarm.find(axeOs => axeOs.IP == ipAddr);
return of(this.swarm.find(axeOs => axeOs.IP == ipAddr));
})
),
256 // Limit concurrency to avoid overload
Expand Down

0 comments on commit 0112b6c

Please sign in to comment.