Fixed error when re-selecting policies tab.
This commit is contained in:
parent
2692294b4b
commit
07db9000d8
@ -17,6 +17,7 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
@Input() policies: Policy[] = []
|
@Input() policies: Policy[] = []
|
||||||
displayedColumns = ['path', 'group', 'usage', 'span', 'actions']
|
displayedColumns = ['path', 'group', 'usage', 'span', 'actions']
|
||||||
groups: { [id: string]: { id: string, name: string, priority: number } }
|
groups: { [id: string]: { id: string, name: string, priority: number } }
|
||||||
|
private readonly _subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
@ViewChild(MatTable) table: MatTable<Policy>;
|
@ViewChild(MatTable) table: MatTable<Policy>;
|
||||||
private subscription: Subscription | undefined;
|
private subscription: Subscription | undefined;
|
||||||
@ -27,7 +28,7 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.subscription = this.events.listen('addPolicy', (payload) => {
|
this._subscriptions.push(this.events.listen('addPolicy', (payload) => {
|
||||||
if (!payload)
|
if (!payload)
|
||||||
return;
|
return;
|
||||||
if (this.policies.map(p => p.path).includes(payload)) {
|
if (this.policies.map(p => p.path).includes(payload)) {
|
||||||
@ -36,12 +37,14 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.policies.push(new Policy("", "", payload, 1, 5000, "", true, true));
|
this.policies.push(new Policy("", "", payload, 1, 5000, "", true, true));
|
||||||
this.table.renderRows();
|
this.table.renderRows();
|
||||||
});
|
}));
|
||||||
this.hermes.subscribe(4, (response: any) => {
|
|
||||||
|
const subscription = this.hermes.subscribe(4, (response: any) => {
|
||||||
if (response.request.type == "get_policies") {
|
if (response.request.type == "get_policies") {
|
||||||
for (let policy of response.data) {
|
for (let policy of response.data) {
|
||||||
this.policies.push(new Policy(policy.id, policy.group_id, policy.path, policy.usage, policy.span, "", false, false));
|
this.policies.push(new Policy(policy.id, policy.group_id, policy.path, policy.usage, policy.span, "", false, false));
|
||||||
}
|
}
|
||||||
|
console.log('getting policies', response.data);
|
||||||
this.table.renderRows();
|
this.table.renderRows();
|
||||||
} else if (response.request.type == "create_policy") {
|
} else if (response.request.type == "create_policy") {
|
||||||
const policy = this.policies.find(p => this.groups[response.data.group_id].name == p.temp_group_name && p.path == response.data.path);
|
const policy = this.policies.find(p => this.groups[response.data.group_id].name == p.temp_group_name && p.path == response.data.path);
|
||||||
@ -79,13 +82,18 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
this.groups = Object.assign({}, ...response.data.groups.map((g: any) => ({ [g.id]: g })));
|
this.groups = Object.assign({}, ...response.data.groups.map((g: any) => ({ [g.id]: g })));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (subscription) {
|
||||||
|
this._subscriptions.push(subscription);
|
||||||
|
}
|
||||||
|
|
||||||
this.hermes.fetchPolicies();
|
this.hermes.fetchPolicies();
|
||||||
this.hermes.fetchPermissionsAndGroups();
|
this.hermes.fetchPermissionsAndGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
if (this.subscription)
|
if (this._subscriptions.length > 0)
|
||||||
this.subscription.unsubscribe();
|
this._subscriptions.forEach(s => s.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel(policy: Policy) {
|
cancel(policy: Policy) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user