add delay to in memory service and update check interval

This commit is contained in:
Jesse Lucas 2020-03-16 11:11:51 -04:00
parent 82f5706350
commit 37f2f2cdf6
5 changed files with 6 additions and 15 deletions

View File

@ -47,7 +47,7 @@ import { DonutChartComponent } from './donut-chart/donut-chart.component';
cookieName: 'CSRF-Token-' + deviceID(),
}),
environment.production ?
[] : HttpClientInMemoryWebApiModule.forRoot(InMemoryConfigDataService),
[] : HttpClientInMemoryWebApiModule.forRoot(InMemoryConfigDataService, { delay: 200 }),
MatCardModule,
FlexLayoutModule
],

View File

@ -19,7 +19,6 @@ export class DonutChartComponent implements OnInit {
}
ngAfterViewInit(): void {
console.log("elementID?", this.elementID)
this.canvas = document.getElementById(this.elementID);
this.ctx = this.canvas.getContext('2d');
const myChart = new Chart(this.ctx, {

View File

@ -109,7 +109,6 @@ export class InMemoryConfigDataService {
"ignoredDevices": [],
"ignoredFolders": []
}
console.log("in mem?!?!?", config)
return { config };
}
constructor() { }

View File

@ -17,7 +17,6 @@ export class StatusListComponent implements OnInit {
}
onToggle(s: Status) {
console.log("holy moly", s);
this.currentStatus = s;
}
}

View File

@ -24,7 +24,7 @@ export class SystemConfigService {
private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config';
private httpOptions;
private checkInterval: number = 500;
private checkInterval: number = 100;
constructor(private http: HttpClient, private cookieService: CookieService) {
this.httpOptions = { headers: new HttpHeaders(this.cookieService.getCSRFHeader()) };
@ -53,9 +53,10 @@ export class SystemConfigService {
} else {
// create timer to keep checking for folders
let t = setInterval(() => {
if (check(this.folders))
if (this.folders) {
clearInterval(t);
observer.next(this.folders);
observer.next(this.folders);
}
}, this.checkInterval);
}
});
@ -68,7 +69,7 @@ export class SystemConfigService {
observer.next(this.devices);
} else {
let t = setInterval(() => {
if (check(this.devices)) {
if (this.devices) {
clearInterval(t);
observer.next(this.devices);
}
@ -77,11 +78,4 @@ export class SystemConfigService {
});
return deviceObserverable;
}
}
const check = (target: any): Boolean => {
if (target) {
return true;
}
return false;
}