2025-03-18 12:55:00 +00:00
|
|
|
import { Component, inject } from '@angular/core';
|
2024-10-17 08:48:15 +00:00
|
|
|
import { PolicyTableComponent } from "../policy-table/policy-table.component";
|
2025-03-18 12:55:00 +00:00
|
|
|
import { Policy } from '../../shared/models/policy';
|
|
|
|
import { ActivatedRoute, RouterModule } from '@angular/router';
|
|
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
|
|
import { PolicyAddButtonComponent } from "../policy-add-button/policy-add-button.component";
|
|
|
|
import { Group } from '../../shared/models/group';
|
2024-10-17 08:48:15 +00:00
|
|
|
|
|
|
|
@Component({
|
2025-03-18 12:55:00 +00:00
|
|
|
selector: 'policy',
|
|
|
|
imports: [MatButtonModule, MatIconModule, PolicyTableComponent, RouterModule, PolicyAddButtonComponent],
|
|
|
|
templateUrl: './policy.component.html',
|
|
|
|
styleUrl: './policy.component.scss'
|
2024-10-17 08:48:15 +00:00
|
|
|
})
|
2025-03-18 12:55:00 +00:00
|
|
|
export class PolicyComponent {
|
|
|
|
private readonly route = inject(ActivatedRoute);
|
|
|
|
private _policies: Policy[] = [];
|
|
|
|
groups: Group[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.route.data.subscribe((data) => {
|
|
|
|
const policies = [...data['policies']];
|
|
|
|
policies.sort(this.compare);
|
|
|
|
this._policies = policies;
|
|
|
|
|
|
|
|
this.groups = [...data['groups']];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get policies() {
|
|
|
|
return this._policies;
|
|
|
|
}
|
|
|
|
|
|
|
|
addPolicy(policy: Policy) {
|
|
|
|
let index = -1;
|
|
|
|
for (let i = 0; i < this._policies.length; i++) {
|
|
|
|
const comp = this.compare(policy, this._policies[i]);
|
|
|
|
if (comp < 0) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
2024-10-17 08:48:15 +00:00
|
|
|
}
|
2025-03-18 12:55:00 +00:00
|
|
|
this._policies.splice(index >= 0 ? index : this._policies.length, 0, policy);
|
|
|
|
}
|
2024-10-17 08:48:15 +00:00
|
|
|
|
2025-03-18 12:55:00 +00:00
|
|
|
compare(a: Policy, b: Policy) {
|
|
|
|
return a.path.localeCompare(b.path);
|
|
|
|
}
|
2024-10-17 08:48:15 +00:00
|
|
|
}
|