85 lines
2.1 KiB
TypeScript
85 lines
2.1 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ProvisionsService } from '../services/provisions.service';
|
|
import { Subscription, timer} from 'rxjs';
|
|
import { switchMap } from 'rxjs/operators';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-provisions',
|
|
templateUrl: './provisions.component.html',
|
|
styleUrls: ['./provisions.component.scss'],
|
|
providers: [ProvisionsService]
|
|
})
|
|
export class ProvisionsComponent implements OnInit {
|
|
|
|
provisions;
|
|
destroys;
|
|
subscription: Subscription;
|
|
instantSubs: Subscription;
|
|
logShow: boolean = false;
|
|
selectedprov: Object = null;
|
|
|
|
constructor(private _provisionsService: ProvisionsService) {}
|
|
|
|
private _compose(pair) {
|
|
this.destroys = pair['1'];
|
|
pair['0'].forEach(prov => {
|
|
var foundDes = this.destroys.filter(d=>{
|
|
return d.provId.toString() === prov._id.toString()
|
|
});
|
|
if (foundDes.length){
|
|
prov.destroyId = foundDes[0]._id.toString();
|
|
prov.statusDestroy = foundDes[0].status;
|
|
} else {
|
|
prov.destroyId = "-";
|
|
}
|
|
});
|
|
this.provisions = pair['0'];
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.subscription = timer(0, 5000).pipe( switchMap(() => this._provisionsService.getCombinedProvisions() ) ).subscribe(pair => {
|
|
this._compose(pair);
|
|
})
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.subscription.unsubscribe();
|
|
this.instantSubs.unsubscribe();
|
|
}
|
|
|
|
del(provision): void {
|
|
|
|
this._provisionsService.delProvision({"id": provision._id}).subscribe( res => {
|
|
console.log("Done!", res);
|
|
})
|
|
}
|
|
|
|
destroy(provision) : void{
|
|
this._provisionsService.newDestroy({"id": provision._id}).subscribe( res => {
|
|
console.log("Done!", res);
|
|
})
|
|
}
|
|
|
|
showLogs($event, provision): void {
|
|
this.logShow = false;
|
|
$event.preventDefault();
|
|
this.selectedprov = provision;
|
|
this.logShow = true;
|
|
}
|
|
|
|
onLogsClose($event): void {
|
|
this.selectedprov = null;
|
|
this.logShow = false;
|
|
}
|
|
|
|
onStartProvision($event): void {
|
|
console.log("onStartProvision");
|
|
this.instantSubs = this._provisionsService.getCombinedProvisions().subscribe( pair=>{
|
|
this._compose(pair);
|
|
this.instantSubs.unsubscribe();
|
|
})
|
|
}
|
|
|
|
}
|