-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cobbler-Frontend: Progress View/Edit screens (list component)
- Loading branch information
Showing
20 changed files
with
521 additions
and
103 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
projects/cobbler-frontend/src/app/common/dialog-text-input/dialog-text-input.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h2 mat-dialog-title>Add new Option:</h2> | ||
<mat-dialog-content> | ||
<mat-form-field> | ||
<mat-label>New Option</mat-label> | ||
<input matInput [(ngModel)]="dialogCloseSignal" /> | ||
</mat-form-field> | ||
</mat-dialog-content> | ||
<mat-dialog-actions> | ||
<button mat-button (click)="onNoClick()">No Thanks</button> | ||
<button mat-button [mat-dialog-close]="dialogCloseSignal()" cdkFocusInitial>Ok</button> | ||
</mat-dialog-actions> |
Empty file.
39 changes: 39 additions & 0 deletions
39
...cts/cobbler-frontend/src/app/common/dialog-text-input/dialog-text-input.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import {MAT_DIALOG_DATA, MatDialogModule, MatDialogRef} from '@angular/material/dialog'; | ||
import {NoopAnimationsModule} from '@angular/platform-browser/animations'; | ||
|
||
import { DialogTextInputComponent } from './dialog-text-input.component'; | ||
|
||
describe('DialogTextInputComponent', () => { | ||
let component: DialogTextInputComponent; | ||
let fixture: ComponentFixture<DialogTextInputComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
DialogTextInputComponent, | ||
MatDialogModule, | ||
NoopAnimationsModule, | ||
], | ||
providers: [ | ||
{ | ||
provide: MatDialogRef, | ||
useValue: {} | ||
}, | ||
{ | ||
provide: MAT_DIALOG_DATA, | ||
useValue: {text: ""} | ||
} | ||
] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DialogTextInputComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
projects/cobbler-frontend/src/app/common/dialog-text-input/dialog-text-input.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {Component, inject, model} from '@angular/core'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {MatButton} from '@angular/material/button'; | ||
import { | ||
MAT_DIALOG_DATA, | ||
MatDialogActions, | ||
MatDialogClose, | ||
MatDialogContent, MatDialogRef, | ||
MatDialogTitle | ||
} from '@angular/material/dialog'; | ||
import {MatFormField, MatLabel} from '@angular/material/form-field'; | ||
import {MatInput} from '@angular/material/input'; | ||
|
||
export interface DialogTextInputData { | ||
text: string; | ||
} | ||
|
||
|
||
@Component({ | ||
selector: 'cobbler-dialog-text-input', | ||
standalone: true, | ||
imports: [ | ||
MatDialogContent, | ||
MatDialogTitle, | ||
MatFormField, | ||
MatDialogActions, | ||
MatButton, | ||
MatDialogClose, | ||
MatInput, | ||
MatLabel, | ||
FormsModule, | ||
], | ||
templateUrl: './dialog-text-input.component.html', | ||
styleUrl: './dialog-text-input.component.scss' | ||
}) | ||
export class DialogTextInputComponent { | ||
readonly dialogRef = inject(MatDialogRef<DialogTextInputComponent>); | ||
readonly data = inject<DialogTextInputData>(MAT_DIALOG_DATA); | ||
readonly dialogCloseSignal = model(this.data.text) | ||
|
||
onNoClick(): void { | ||
this.dialogRef.close(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
projects/cobbler-frontend/src/app/common/multi-select/multi-select.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<mat-card appearance="outlined"> | ||
<mat-card-header> | ||
<mat-card-title>{{label}}</mat-card-title> | ||
</mat-card-header> | ||
@if (multiSelectOptions.length === 0) { | ||
<p style="text-align: center">Empty list of options</p> | ||
} @else { | ||
<!-- TODO: See https://github.com/cobbler/cobbler-web/issues/270 | ||
<mat-form-field style="margin: 0 1em"> | ||
<mat-label>Search for option</mat-label> | ||
<input matInput type="text"> | ||
</mat-form-field> | ||
--> | ||
<ng-container [formGroup]="matSelectOptionsFormGroup"> | ||
<mat-checkbox *ngFor="let option of multiSelectOptions" (change)="changeValues($event)" [formControlName]=option [value]="option">{{option}}</mat-checkbox> | ||
</ng-container> | ||
} | ||
<button mat-button [disabled]="isDisabled" (click)="addOption()">Add option</button> | ||
</mat-card> |
Empty file.
23 changes: 23 additions & 0 deletions
23
projects/cobbler-frontend/src/app/common/multi-select/multi-select.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { MultiSelectComponent } from './multi-select.component'; | ||
|
||
describe('MultiSelectComponent', () => { | ||
let component: MultiSelectComponent; | ||
let fixture: ComponentFixture<MultiSelectComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [MultiSelectComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(MultiSelectComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
145 changes: 145 additions & 0 deletions
145
projects/cobbler-frontend/src/app/common/multi-select/multi-select.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import {AsyncPipe, NgForOf} from '@angular/common'; | ||
import {ChangeDetectionStrategy, Component, forwardRef, inject, Input, OnInit, signal} from '@angular/core'; | ||
import { | ||
AbstractControl, | ||
ControlValueAccessor, | ||
FormControl, FormGroup, NG_VALIDATORS, NG_VALUE_ACCESSOR, | ||
ReactiveFormsModule, | ||
ValidationErrors, | ||
Validator | ||
} from '@angular/forms'; | ||
import {MatButton, MatFabButton, MatIconButton} from '@angular/material/button'; | ||
import {MatCard, MatCardHeader, MatCardTitle} from '@angular/material/card'; | ||
import {MatCheckbox, MatCheckboxChange} from '@angular/material/checkbox'; | ||
import {MatDialog} from '@angular/material/dialog'; | ||
import {MatFormFieldModule, MatLabel} from '@angular/material/form-field'; | ||
import {MatIcon} from '@angular/material/icon'; | ||
import {MatInput} from '@angular/material/input'; | ||
import {MatListItem} from '@angular/material/list'; | ||
import {MatOption, MatSelectModule} from '@angular/material/select'; | ||
import {DialogTextInputComponent} from '../dialog-text-input/dialog-text-input.component'; | ||
|
||
|
||
|
||
@Component({ | ||
selector: 'cobbler-multi-select', | ||
standalone: true, | ||
imports: [ | ||
MatFormFieldModule, | ||
MatSelectModule, | ||
MatOption, | ||
MatLabel, | ||
ReactiveFormsModule, | ||
AsyncPipe, | ||
MatListItem, | ||
NgForOf, | ||
MatCheckbox, | ||
MatButton, | ||
MatIconButton, | ||
MatIcon, | ||
MatCard, | ||
MatCardHeader, | ||
MatCardTitle, | ||
MatFabButton, | ||
MatInput, | ||
], | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
multi: true, | ||
useExisting: MultiSelectComponent, | ||
}, | ||
{ | ||
provide: NG_VALIDATORS, | ||
multi: true, | ||
useExisting: MultiSelectComponent | ||
} | ||
], | ||
templateUrl: './multi-select.component.html', | ||
styleUrl: './multi-select.component.scss' | ||
}) | ||
export class MultiSelectComponent implements OnInit, ControlValueAccessor, Validator { | ||
@Input() multiSelectOptions: Array<string> = []; | ||
@Input() label = ""; | ||
matSelectOptionsFormGroup: FormGroup<{}> = new FormGroup({}) | ||
onChange = (options: string[]) => {}; | ||
onTouched = (options: string[]) => {}; | ||
readonly dialog = inject(MatDialog); | ||
readonly optionSignal = signal(''); | ||
isDisabled = true; | ||
|
||
ngOnInit(): void { | ||
this.buildFormGroup(this.multiSelectOptions) | ||
} | ||
|
||
buildFormGroup(options: string[], checked = false): void { | ||
options.forEach(value => { | ||
this.matSelectOptionsFormGroup.addControl(value, new FormControl({value: checked, disabled: this.isDisabled})) | ||
}) | ||
} | ||
|
||
updateFormGroup(options: string[], checked = false): void { | ||
options.forEach(value => { | ||
this.matSelectOptionsFormGroup.get(value).setValue(checked) | ||
}) | ||
} | ||
|
||
registerOnChange(fn: any): void { | ||
this.onChange = fn; | ||
} | ||
|
||
registerOnTouched(fn: any): void { | ||
this.onTouched = fn; | ||
} | ||
|
||
setDisabledState(isDisabled: boolean): void { | ||
this.isDisabled = isDisabled; | ||
if (this.isDisabled) { | ||
this.matSelectOptionsFormGroup.disable(); | ||
} else { | ||
this.matSelectOptionsFormGroup.enable(); | ||
} | ||
} | ||
|
||
writeValue(obj: string[]): void { | ||
this.buildFormGroup(obj) | ||
this.updateFormGroup(obj, true) | ||
} | ||
|
||
registerOnValidatorChange(fn: () => void): void { | ||
} | ||
|
||
validate(control: AbstractControl): ValidationErrors | null { | ||
return undefined; | ||
} | ||
|
||
changeValues(e: MatCheckboxChange) { | ||
let options: string[] = [] | ||
Object.keys(this.matSelectOptionsFormGroup.controls).forEach(key => { | ||
const control = this.matSelectOptionsFormGroup.get(key) | ||
if (control instanceof FormControl) { | ||
if (control.value) { | ||
options.push(key) | ||
} | ||
} | ||
}) | ||
|
||
this.onTouched(options) | ||
this.onChange(options) | ||
} | ||
|
||
addOption(): void { | ||
const dialogRef = this.dialog.open(DialogTextInputComponent, { | ||
data: {data: this.optionSignal()}, | ||
}); | ||
|
||
dialogRef.afterClosed().subscribe(result => { | ||
if (result !== undefined) { | ||
this.optionSignal.set(result); | ||
this.multiSelectOptions.push(result) | ||
this.buildFormGroup(this.multiSelectOptions) | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.