projects/cobbler-frontend/src/app/actions/sync/sync.component.ts
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | cobbler-sync |
| standalone | true |
| imports |
MatButton
MatCheckbox
MatInput
MatIconButton
MatIcon
MatFormField
MatPrefix
MatSuffix
|
| styleUrls | ./sync.component.css |
| templateUrl | ./sync.component.html |
No results matching.
RouterOutlet
MatButton
ReactiveFormsModule
MatCheckbox
MatInput
MatIconButton
MatIcon
MatFormField
MatPrefix
MatSuffix
OnDestroy
Properties |
|
Methods |
Accessors |
| addNewKeyValueFG |
addNewKeyValueFG()
|
|
Returns :
void
|
| ngOnDestroy |
ngOnDestroy()
|
|
Returns :
void
|
| removeNewKeyValueFG | ||||||
removeNewKeyValueFG(index: number)
|
||||||
|
Parameters :
Returns :
void
|
| syncFullSubmit |
syncFullSubmit()
|
|
Returns :
void
|
| syncSystemsSubmit |
syncSystemsSubmit()
|
|
Returns :
void
|
| Private Readonly _formBuilder |
Type : unknown
|
Default value : inject(FormBuilder)
|
| Private _snackBar |
Type : unknown
|
Default value : inject(MatSnackBar)
|
| Private cobblerApiService |
Type : unknown
|
Default value : inject(CobblerApiService)
|
| Readonly fullSync |
Type : unknown
|
Default value : this._formBuilder.group({
fullSyncDhcp: false,
fullSyncDns: false,
fullSyncVerbose: false,
})
|
| keyValueFA |
Type : unknown
|
Default value : new FormArray([])
|
| Private ngUnsubscribe |
Type : unknown
|
Default value : new Subject<void>()
|
| systemsSync |
Type : unknown
|
Default value : this._formBuilder.group({
keyValue: this.keyValueFA,
systemsSyncVerbose: false,
})
|
| Private userService |
Type : unknown
|
Default value : inject(UserService)
|
| newKeyValueFG |
getnewKeyValueFG()
|
| keyValueArrayFGControls |
getkeyValueArrayFGControls()
|
import {
ChangeDetectionStrategy,
Component,
inject,
OnDestroy,
} from '@angular/core';
import {
FormArray,
FormBuilder,
FormControl,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { MatButton, MatIconButton } from '@angular/material/button';
import { MatCheckbox } from '@angular/material/checkbox';
import { MatIcon } from '@angular/material/icon';
import {
MatFormField,
MatInput,
MatPrefix,
MatSuffix,
} from '@angular/material/input';
import { MatSnackBar } from '@angular/material/snack-bar';
import { RouterOutlet } from '@angular/router';
import { CobblerApiService } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';
@Component({
selector: 'cobbler-sync',
templateUrl: './sync.component.html',
styleUrls: ['./sync.component.css'],
imports: [
RouterOutlet,
MatButton,
ReactiveFormsModule,
MatCheckbox,
MatInput,
MatIconButton,
MatIcon,
MatFormField,
MatPrefix,
MatSuffix,
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SyncComponent implements OnDestroy {
private cobblerApiService = inject(CobblerApiService);
private userService = inject(UserService);
private _snackBar = inject(MatSnackBar);
// Unsubscribe
private ngUnsubscribe = new Subject<void>();
// Form
private readonly _formBuilder = inject(FormBuilder);
readonly fullSync = this._formBuilder.group({
fullSyncDhcp: false,
fullSyncDns: false,
fullSyncVerbose: false,
});
keyValueFA = new FormArray([]);
systemsSync = this._formBuilder.group({
keyValue: this.keyValueFA,
systemsSyncVerbose: false,
});
ngOnDestroy(): void {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
get newKeyValueFG(): FormGroup {
return new FormGroup({
systemName: new FormControl(null, [Validators.required]),
});
}
get keyValueArrayFGControls(): FormGroup[] {
return this.keyValueFA.controls as FormGroup[];
}
addNewKeyValueFG(): void {
this.keyValueFA.push(this.newKeyValueFG);
}
removeNewKeyValueFG(index: number): void {
this.keyValueFA.removeAt(index);
}
syncFullSubmit(): void {
const syncOptions = {
dhcp: this.fullSync.controls.fullSyncDhcp.value,
dns: this.fullSync.controls.fullSyncDns.value,
verbose: this.fullSync.controls.fullSyncVerbose.value,
};
this.fullSync.controls.fullSyncDhcp.reset(false);
this.fullSync.controls.fullSyncDns.reset(false);
this.fullSync.controls.fullSyncVerbose.reset(false);
this.cobblerApiService
.background_sync(syncOptions, this.userService.token)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(value) => {
console.log(value);
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
);
}
syncSystemsSubmit(): void {
if (this.systemsSync.invalid) {
for (let control of this.systemsSync.controls.keyValue.controls) {
control.markAsTouched();
}
this._snackBar.open(
$localize`:@@validation.system-name-required:Please give all inputs a system name!`,
$localize`:@@snackbar.action.close:Close`,
{ duration: 2000 },
);
return;
}
let systemNames: Array<string> = [];
for (let control of this.systemsSync.controls.keyValue.controls) {
if (control instanceof FormGroup) {
systemNames.push(control.value.systemName);
}
}
const syncOptions = {
systems: systemNames,
verbose: this.systemsSync.controls.systemsSyncVerbose.value,
};
this.systemsSync.controls.systemsSyncVerbose.reset(false);
this.systemsSync.controls.keyValue.reset([]);
this.cobblerApiService
.background_syncsystems(syncOptions, this.userService.token)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(value) => {
console.log(value);
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(
Utils.toHTML(error.message),
$localize`:@@snackbar.action.close:Close`,
);
},
);
}
}
<div class="right-column" id="dataScreen">
<router-outlet></router-outlet>
<div class="Sync-div">
<h1 class="title" i18n="@@action.sync.title">SYNC</h1>
<h2 i18n="@@action.sync.full-sync.heading">Full Sync</h2>
<section class="sync-section" [formGroup]="fullSync">
<p>
<mat-checkbox
formControlName="fullSyncDhcp"
i18n="@@action.sync.full-sync.dhcp"
>DHCP</mat-checkbox
>
<mat-checkbox
formControlName="fullSyncDns"
i18n="@@action.sync.full-sync.dns"
>DNS</mat-checkbox
>
<mat-checkbox
formControlName="fullSyncVerbose"
i18n="@@action.sync.full-sync.verbose"
>Verbose</mat-checkbox
>
</p>
<button
mat-button
(click)="syncFullSubmit()"
i18n="@@action.sync.full-sync.sync-button"
>
Sync
</button>
</section>
<h2 i18n="@@action.sync.systems-sync.heading">Systems Sync</h2>
<form class="systems-sync-section" [formGroup]="systemsSync">
<button mat-button (click)="addNewKeyValueFG()">
@if (keyValueArrayFGControls.length === 0) {
<ng-container i18n="@@action.sync.systems-sync.sync-specific"
>Sync specific Systems</ng-container
>
}
@if (keyValueArrayFGControls.length > 0) {
<ng-container i18n="@@action.sync.systems-sync.add-system"
>Add system</ng-container
>
}
</button>
@for (fg of keyValueArrayFGControls; track fg; let i = $index) {
<div formArrayName="keyValue">
<div [formGroup]="fg">
<mat-form-field>
<span matTextPrefix>{{ i + 1 }}. </span>
<input
matInput
required
type="text"
formControlName="systemName"
placeholder="System Name"
i18n-placeholder="
@@action.sync.systems-sync.placeholder.system-name"
/>
<button
mat-icon-button
matSuffix
(click)="removeNewKeyValueFG(i)"
>
<mat-icon>remove</mat-icon>
</button>
@if (
systemsSync.controls.keyValue.controls[i].hasError("required")
) {
<mat-error
i18n="@@action.sync.systems-sync.error.system-name-required"
>System name is <strong>required</strong></mat-error
>
}
</mat-form-field>
</div>
</div>
} @empty {
<p i18n="@@action.sync.systems-sync.syncing-all">Syncing All Systems</p>
}
<mat-checkbox
formControlName="systemsSyncVerbose"
i18n="@@action.sync.systems-sync.verbose"
>Verbose</mat-checkbox
>
</form>
<button
mat-button
(click)="syncSystemsSubmit()"
i18n="@@action.sync.systems-sync.sync-button"
>
Sync
</button>
</div>
</div>
./sync.component.css