From eb40badb9c3bdf26e9e3cf7ed3af7af229f6b747 Mon Sep 17 00:00:00 2001 From: SchoolGuy Date: Tue, 16 Jul 2024 13:07:30 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20cobbler/?= =?UTF-8?q?cobbler-web@0c8a348457e5d57f8ac66f4ced8dcedaed51b091=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/RepoSyncComponent.html | 677 +++++++++++++++++++++++++++++- coverage.html | 2 +- js/search/search_index.js | 4 +- 3 files changed, 660 insertions(+), 23 deletions(-) diff --git a/components/RepoSyncComponent.html b/components/RepoSyncComponent.html index 3ab138bc..9ebbb07b 100644 --- a/components/RepoSyncComponent.html +++ b/components/RepoSyncComponent.html @@ -159,6 +159,19 @@

Metadata

RouterOutlet MatListModule + MatButton + FormsModule + MatCheckbox + MatFormField + MatIcon + MatIconButton + MatInput + MatPrefix + MatSuffix + MatLabel + MatInputModule + MatFormFieldModule + ReactiveFormsModule @@ -185,6 +198,85 @@

Metadata

+
+

Index

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Properties
+
+ +
+
Methods
+
+ +
+
Accessors
+
+ +
+

Constructor

@@ -192,15 +284,69 @@

Constructor

-constructor() +constructor(userService: UserService, cobblerApiService: CobblerApiService, _snackBar: MatSnackBar) - + + + +
+ Parameters : + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptional
userService + UserService + + No +
cobblerApiService + CobblerApiService + + No +
_snackBar + MatSnackBar + + No +
+
+ +
@@ -209,43 +355,534 @@

Constructor

+
+ +

+ Methods +

+ + + + + + + + + + + + + + + + + + + +
+ + + addNewRepoFG + + +
+addNewRepoFG() +
+ +
+ +
+ Returns : void + +
+
+ + + + + + + + + + + + + + + + + + + +
+ + + removeNewRepoFG + + +
+removeNewRepoFG(index: number) +
+ +
+ +
+ Parameters : + + + + + + + + + + + + + + + + + + + +
NameTypeOptional
index + number + + No +
+
+
+ Returns : void + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + +
+ + + runReposync + + +
+runReposync() +
+ +
+ +
+ Returns : void + +
+
+ + + + + + + + + + + + + + + + + +
+ + + toHTML + + +
+toHTML(input: string) +
+ +
+ +
+ Parameters : + + + + + + + + + + + + + + + + + + + +
NameTypeOptional
input + string + + No +
+
+
+ Returns : any + +
+
+ +
+
+
+
+ +

+ Properties +

+ + + + + + + + + + + + + + +
+ + + Private + Readonly + _formBuilder + + +
+ Default value : inject(FormBuilder) +
+ +
+ + + + + + + + + + + + + + +
+ + + repositoryFormArray + + +
+ Default value : new FormArray([]) +
+ +
+ + + + + + + + + + + + + + +
+ + + reposyncFormGroup + + +
+ Default value : this._formBuilder.group({ + repoName: this.repositoryFormArray, + reposyncNoFail: false, + reposyncTries: 3, + }) +
+ +
+ + + + + + + + + + + + + + +
+ + + Public + userService + + +
+ Type : UserService + +
+ +
+
+ +
+

+ Accessors +

+ + + + + + + + + + + + + + +
+ + newRepositoryFormGroup +
+ getnewRepositoryFormGroup() +
+ +
+ + + + + + + + + + + + + + +
+ + repositoryArrayFGControls +
+ getrepositoryArrayFGControls() +
+ +
+
-
import { Component } from '@angular/core';
-import { MatListModule } from '@angular/material/list';
-import { RouterOutlet } from '@angular/router';
+        
import {Component, inject} from '@angular/core';
+import {MatListModule} from '@angular/material/list';
+import {RouterOutlet} from '@angular/router';
+import {UserService} from "../../services/user.service";
+import {CobblerApiService} from "cobbler-api";
+import {MatSnackBar} from "@angular/material/snack-bar";
+import {MatButton, MatIconButton} from "@angular/material/button";
+import {BackgroundReposyncOptions} from "cobbler-api";
+import {
+  FormArray,
+  FormBuilder,
+  FormControl,
+  FormGroup,
+  FormsModule,
+  ReactiveFormsModule,
+  Validators
+} from "@angular/forms";
+import {MatCheckbox} from "@angular/material/checkbox";
+import {MatFormField, MatFormFieldModule, MatLabel, MatPrefix, MatSuffix} from "@angular/material/form-field";
+import {MatIcon} from "@angular/material/icon";
+import {MatInput, MatInputModule} from "@angular/material/input";
 
 @Component({
   selector: 'cobbler-repo-sync',
   templateUrl: './repo-sync.component.html',
   styleUrls: ['./repo-sync.component.css'],
   standalone: true,
-  imports: [RouterOutlet, MatListModule],
+  imports: [
+    RouterOutlet,
+    MatListModule,
+    MatButton,
+    FormsModule,
+    MatCheckbox,
+    MatFormField,
+    MatIcon,
+    MatIconButton,
+    MatInput,
+    MatPrefix,
+    MatSuffix,
+    MatLabel,
+    MatInputModule,
+    MatFormFieldModule,
+    ReactiveFormsModule,
+  ],
 })
 export class RepoSyncComponent {
-  constructor() {}
+  private readonly _formBuilder = inject(FormBuilder);
+  repositoryFormArray = new FormArray([]);
+
+  reposyncFormGroup = this._formBuilder.group({
+    repoName: this.repositoryFormArray,
+    reposyncNoFail: false,
+    reposyncTries: 3,
+  });
+  constructor(
+    public userService: UserService,
+    private cobblerApiService: CobblerApiService,
+    private _snackBar: MatSnackBar
+  ) {
+  }
+
+  get newRepositoryFormGroup(): FormGroup {
+    return new FormGroup({
+      repoName: new FormControl(null, [Validators.required]),
+    });
+  }
+
+  get repositoryArrayFGControls(): FormGroup[] {
+    return this.repositoryFormArray.controls as FormGroup[];
+  }
+
+  addNewRepoFG(): void {
+    this.repositoryFormArray.push(this.newRepositoryFormGroup);
+  }
+
+  removeNewRepoFG(index: number): void {
+    this.repositoryFormArray.removeAt(index);
+  }
+
+  runReposync(): void {
+    let repoNames: Array<string> = []
+    for (let control of this.reposyncFormGroup.controls.repoName.controls) {
+      if (control instanceof FormGroup) {
+        repoNames.push(control.value.repoName)
+      }
+    }
+    const reposyncOptions: BackgroundReposyncOptions = {
+      repos: repoNames,
+      only: "",
+      tries: this.reposyncFormGroup.controls.reposyncTries.value,
+      nofail: this.reposyncFormGroup.controls.reposyncNoFail.value,
+    }
+    this.cobblerApiService.background_reposync(reposyncOptions, this.userService.token).subscribe(
+      value => {
+        // TODO
+        console.log(value)
+      },
+      error => {
+        // HTML encode the error message since it originates from XML
+        this._snackBar.open(this.toHTML(error.message), 'Close');
+      })
+  }
+
+  toHTML(input: string): any {
+    // FIXME: Deduplicate method
+    return new DOMParser().parseFromString(input, 'text/html').documentElement.textContent;
+  }
 }
 
-
<div class="right-column" id="dataScreen">
-  <router-outlet></router-outlet>
-  <div class="RepoSync-div">
-    <h1 class="title">SYNC REPO</h1>
-    <div class="list-group">
-      <mat-list>
-        <mat-list-item>data 01</mat-list-item>
-        <mat-list-item>data 02</mat-list-item>
-        <mat-list-item>data 03</mat-list-item>
-      </mat-list>
+        
<h1 class="title">SYNC REPOSITORIES</h1>
+
+<form class="systems-sync-section" [formGroup]="reposyncFormGroup">
+  <button mat-button (click)="addNewRepoFG()">
+    @if (repositoryArrayFGControls.length === 0) {
+      Sync specific Repositories
+    }
+    @if (repositoryArrayFGControls.length > 0) {
+      Add repository
+    }
+  </button>
+  @for (fg of repositoryArrayFGControls; track fg; let i = $index) {
+    <div formArrayName="repoName">
+      <div [formGroup]="fg">
+        <mat-form-field>
+          <span matTextPrefix>{{ i + 1 }}.&nbsp;</span>
+          <input matInput required type="text" formControlName="repoName" placeholder="Repository Name"/>
+          <button mat-icon-button matSuffix (click)="removeNewRepoFG(i)"><mat-icon>remove</mat-icon></button>
+          @if (reposyncFormGroup.controls.repoName.controls[i].hasError('required')) {
+            <mat-error>Repository name is <strong>required</strong></mat-error>
+          }
+        </mat-form-field>
+      </div>
     </div>
-  </div>
-</div>
+  } @empty {
+    <p>Syncing All Repositories</p>
+  }
+  <mat-form-field>
+    <mat-label>Tries</mat-label>
+    <input matInput formControlName="reposyncTries" placeholder="3" type="number" />
+  </mat-form-field>
+  <mat-checkbox formControlName="reposyncNoFail">No Fail</mat-checkbox>
+</form>
+<button mat-button (click)="runReposync()">RUN</button>
 
@@ -281,7 +918,7 @@

Constructor