-
-
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 (dict component)
- Loading branch information
Showing
8 changed files
with
271 additions
and
17 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
projects/cobbler-frontend/src/app/common/key-value-editor/key-value-editor.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,24 @@ | ||
<mat-card appearance="outlined"> | ||
<mat-card-header> | ||
<mat-card-title>{{label}}</mat-card-title> | ||
</mat-card-header> | ||
@if (Object.keys(this.keyValueOptions).length === 0) { | ||
<p style="text-align: center">Empty list of options</p> | ||
} @else { | ||
<div cdkDropList [cdkDropListDisabled]="isDisabled" class="example-list" [formGroup]="keyOrderFormGroup" (cdkDropListDropped)="drop($event)"> | ||
@for (key of keyOrder; track key) { | ||
<form class="example-box" formGroupName="{{key}}FormGroup"> | ||
<mat-form-field> | ||
<input matInput formControlName="key" placeholder="Key" value="{{key}}" /> | ||
</mat-form-field> | ||
= | ||
<mat-form-field> | ||
<input matInput formControlName="value" placeholder="Value" value="{{ keyValueOptions[key] }}"/> | ||
</mat-form-field> | ||
<button mat-icon-button [disabled]="isDisabled" (click)="deleteKey(key)"><mat-icon>delete</mat-icon></button> | ||
<button mat-icon-button [disabled]="isDisabled" cdkDrag><mat-icon>menu</mat-icon></button> | ||
</form> | ||
} | ||
</div> | ||
} | ||
</mat-card> |
51 changes: 51 additions & 0 deletions
51
projects/cobbler-frontend/src/app/common/key-value-editor/key-value-editor.component.scss
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,51 @@ | ||
.example-list { | ||
width: 80%; | ||
max-width: 100%; | ||
border: solid 1px #ccc; | ||
min-height: 60px; | ||
display: block; | ||
background: white; | ||
border-radius: 4px; | ||
overflow: hidden; | ||
} | ||
|
||
.example-box { | ||
margin: 20px 10px; | ||
padding: 10px; | ||
border: solid 1px #ccc; | ||
color: rgba(0, 0, 0, 0.87); | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
box-sizing: border-box; | ||
cursor: move; | ||
background: white; | ||
font-size: 14px; | ||
} | ||
|
||
.cdk-drag-preview { | ||
border: none; | ||
box-sizing: border-box; | ||
border-radius: 4px; | ||
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2), | ||
0 8px 10px 1px rgba(0, 0, 0, 0.14), | ||
0 3px 14px 2px rgba(0, 0, 0, 0.12); | ||
} | ||
|
||
.cdk-drag-placeholder { | ||
opacity: 0; | ||
} | ||
|
||
.cdk-drag-animating { | ||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); | ||
} | ||
|
||
.example-box:last-child { | ||
border: none; | ||
} | ||
|
||
.example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) { | ||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
projects/cobbler-frontend/src/app/common/key-value-editor/key-value-editor.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 { KeyValueEditorComponent } from './key-value-editor.component'; | ||
|
||
describe('KeyValueEditorComponent', () => { | ||
let component: KeyValueEditorComponent; | ||
let fixture: ComponentFixture<KeyValueEditorComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [KeyValueEditorComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(KeyValueEditorComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
110 changes: 110 additions & 0 deletions
110
projects/cobbler-frontend/src/app/common/key-value-editor/key-value-editor.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,110 @@ | ||
import {CdkDrag, CdkDragDrop, CdkDropList, moveItemInArray} from '@angular/cdk/drag-drop'; | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import { | ||
AbstractControl, | ||
ControlValueAccessor, FormControl, FormGroup, | ||
NG_VALIDATORS, | ||
NG_VALUE_ACCESSOR, ReactiveFormsModule, | ||
ValidationErrors, | ||
Validator | ||
} from '@angular/forms'; | ||
import {MatIconButton} from '@angular/material/button'; | ||
import {MatCard, MatCardHeader, MatCardTitle} from '@angular/material/card'; | ||
import {MatFormField} from '@angular/material/form-field'; | ||
import {MatIcon} from '@angular/material/icon'; | ||
import {MatInput} from '@angular/material/input'; | ||
|
||
@Component({ | ||
selector: 'cobbler-key-value-editor', | ||
standalone: true, | ||
imports: [ | ||
MatCard, | ||
MatCardHeader, | ||
MatCardTitle, | ||
CdkDropList, | ||
CdkDrag, | ||
MatFormField, | ||
MatInput, | ||
MatIconButton, | ||
MatIcon, | ||
ReactiveFormsModule, | ||
], | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
multi: true, | ||
useExisting: KeyValueEditorComponent, | ||
}, | ||
{ | ||
provide: NG_VALIDATORS, | ||
multi: true, | ||
useExisting: KeyValueEditorComponent | ||
}, | ||
], | ||
templateUrl: './key-value-editor.component.html', | ||
styleUrl: './key-value-editor.component.scss' | ||
}) | ||
export class KeyValueEditorComponent implements ControlValueAccessor, Validator{ | ||
@Input() label = ""; | ||
@Input() keyValueOptions = {} | ||
onChange = (options: string[]) => {}; | ||
onTouched = (options: string[]) => {}; | ||
keyOrder = Object.keys(this.keyValueOptions); | ||
keyOrderFormGroup = new FormGroup({}) | ||
isDisabled = true; | ||
|
||
registerOnChange(fn: any): void { | ||
this.onChange = fn; | ||
} | ||
|
||
registerOnTouched(fn: any): void { | ||
this.onTouched = fn; | ||
} | ||
|
||
registerOnValidatorChange(fn: () => void): void { | ||
} | ||
|
||
setDisabledState(isDisabled: boolean): void { | ||
this.isDisabled = isDisabled; | ||
this.setFormGroupDisabledState(isDisabled) | ||
} | ||
|
||
setFormGroupDisabledState(isDisabled: boolean): void { | ||
if (isDisabled) { | ||
this.keyOrderFormGroup.disable(); | ||
} else { | ||
this.keyOrderFormGroup.enable(); | ||
} | ||
} | ||
|
||
validate(control: AbstractControl): ValidationErrors | null { | ||
return undefined; | ||
} | ||
|
||
writeValue(obj: any): void { | ||
this.keyValueOptions = obj | ||
this.keyOrder = Object.keys(this.keyValueOptions); | ||
this.buildFormGroup() | ||
} | ||
|
||
buildFormGroup(): void { | ||
for (let key of this.keyOrder) { | ||
const formGroupControls = { | ||
key: new FormControl({value: key, disabled: true}), | ||
value: new FormControl({value: this.keyValueOptions[key], disabled: true}), | ||
} | ||
this.keyOrderFormGroup.addControl(key + "FormGroup", new FormGroup(formGroupControls)) | ||
} | ||
this.setFormGroupDisabledState(this.isDisabled) | ||
} | ||
|
||
deleteKey(key: string): void { | ||
// TODO: Delete key | ||
} | ||
|
||
drop(event: CdkDragDrop<string[]>) { | ||
moveItemInArray(this.keyOrder, event.previousIndex, event.currentIndex); | ||
} | ||
|
||
protected readonly Object = Object; | ||
} |
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
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