import { UiService } from "@services/ui/ui.service";
import { FormControl, FormGroup } from "@angular/forms";
import { MatTableDataSource } from "@angular/material/table";
-import { mergeMap } from "rxjs/operators";
+import { finalize, mergeMap, map } from "rxjs/operators";
@Component({
selector: "nrcp-policy-instance",
styleUrls: ["./policy-instance.component.scss"],
})
export class PolicyInstanceComponent implements OnInit {
+ public slice: number = 1000;
@Input() policyTypeSchema: PolicyTypeSchema;
darkMode: boolean;
instanceDataSource: MatTableDataSource<PolicyInstance>;
policyInstanceForm: FormGroup;
private policyInstanceSubject = new BehaviorSubject<PolicyInstance[]>([]);
policyInstances: PolicyInstance[] = [];
+ private loadingSubject$ = new BehaviorSubject<boolean>(false);
+ public loading$ = this.loadingSubject$.asObservable();
+ public truncated = false;
constructor(
private policySvc: PolicyService,
getPolicyInstances() {
this.policyInstances = [] as PolicyInstance[];
+ this.loadingSubject$.next(true);
this.policySvc
.getPolicyInstancesByType(this.policyTypeSchema.id)
.pipe(
+ map((data) => {
+ if (data.policy_ids.length > this.slice) {
+ this.truncated = true;
+ data.policy_ids = data.policy_ids.slice(0, this.slice);
+ }
+ return data;
+ }),
mergeMap((policyIds) =>
forkJoin(
policyIds.policy_ids.map((id) => {
]);
})
)
- )
+ ),
+ finalize(() => this.loadingSubject$.next(false))
)
.subscribe((res) => {
this.policyInstances = res.map((policy) => {
}
modifyInstance(instance: PolicyInstance): void {
- let refreshedInstance: PolicyInstance;
this.policySvc
.getPolicyInstance(instance.policy_id)
- .subscribe((refreshedJson: any) => {
- refreshedInstance = refreshedJson;
+ .subscribe((refreshedJson: PolicyInstance) => {
+ this.openInstanceDialog(refreshedJson);
});
-
- this.openInstanceDialog(refreshedInstance);
}
private openInstanceDialog(policy: PolicyInstance) {
});
}
- noInstances(): number {
+ hasInstances(): boolean {
+ return this.instanceCount() > 0;
+ }
+
+ instanceCount(): number {
return this.policyInstances.length;
}
deleteInstance(instance: PolicyInstance): void {
this.confirmDialogService
.openConfirmDialog(
+ "Delete Policy",
"Are you sure you want to delete this policy instance?"
)
.afterClosed()
}
refreshTable() {
+ this.truncated = false;
this.getPolicyInstances();
}
}