From 634f3cee0f42cf5b984ae03ff5f115ef89abda75 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:05:29 -0800 Subject: [PATCH] Saving work on slightly less ugly frontend config --- src-ui/src/app/app.module.ts | 2 + .../admin/config/config.component.html | 40 ++++++++++++------- .../admin/config/config.component.spec.ts | 4 +- .../common/input/number/number.component.html | 4 +- .../common/input/switch/switch.component.html | 27 +++++++++++++ .../common/input/switch/switch.component.scss | 0 .../input/switch/switch.component.spec.ts | 39 ++++++++++++++++++ .../common/input/switch/switch.component.ts | 21 ++++++++++ .../common/input/text/text.component.html | 4 +- 9 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 src-ui/src/app/components/common/input/switch/switch.component.html create mode 100644 src-ui/src/app/components/common/input/switch/switch.component.scss create mode 100644 src-ui/src/app/components/common/input/switch/switch.component.spec.ts create mode 100644 src-ui/src/app/components/common/input/switch/switch.component.ts diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts index dbccec0ca..6d8d58944 100644 --- a/src-ui/src/app/app.module.ts +++ b/src-ui/src/app/app.module.ts @@ -109,6 +109,7 @@ import { PdfViewerComponent } from './components/common/pdf-viewer/pdf-viewer.co import { DocumentLinkComponent } from './components/common/input/document-link/document-link.component' import { PreviewPopupComponent } from './components/common/preview-popup/preview-popup.component' import { ConfigComponent } from './components/admin/config/config.component' +import { SwitchComponent } from './components/common/input/switch/switch.component' import localeAf from '@angular/common/locales/af' import localeAr from '@angular/common/locales/ar' @@ -265,6 +266,7 @@ function initializeApp(settings: SettingsService) { DocumentLinkComponent, PreviewPopupComponent, ConfigComponent, + SwitchComponent, ], imports: [ BrowserModule, diff --git a/src-ui/src/app/components/admin/config/config.component.html b/src-ui/src/app/components/admin/config/config.component.html index fcc07ec95..630b2eb41 100644 --- a/src-ui/src/app/components/admin/config/config.component.html +++ b/src-ui/src/app/components/admin/config/config.component.html @@ -8,22 +8,34 @@ {{category}}
- @for (option of getCategoryOptions(category); track option.key) { -
-
- {{option.title}} -

See {{option.config_key}}

-
+
+ @for (option of getCategoryOptions(category); track option.key) {
- @switch (option.type) { - @case (ConfigOptionType.Select) { } - @case (ConfigOptionType.Number) { } - @case (ConfigOptionType.Boolean) { } - @case (ConfigOptionType.String) { } - } +
+
+
+
+ {{option.title}} + + + + + +
+
+
+ @switch (option.type) { + @case (ConfigOptionType.Select) { } + @case (ConfigOptionType.Number) { } + @case (ConfigOptionType.Boolean) { } + @case (ConfigOptionType.String) { } + } +
+
+
-
- } + } +
diff --git a/src-ui/src/app/components/admin/config/config.component.spec.ts b/src-ui/src/app/components/admin/config/config.component.spec.ts index a625cc1b2..746f0e041 100644 --- a/src-ui/src/app/components/admin/config/config.component.spec.ts +++ b/src-ui/src/app/components/admin/config/config.component.spec.ts @@ -11,7 +11,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { NgSelectModule } from '@ng-select/ng-select' import { TextComponent } from '../../common/input/text/text.component' import { NumberComponent } from '../../common/input/number/number.component' -import { CheckComponent } from '../../common/input/check/check.component' +import { SwitchComponent } from '../../common/input/switch/switch.component' import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { PageHeaderComponent } from '../../common/page-header/page-header.component' import { SelectComponent } from '../../common/input/select/select.component' @@ -29,7 +29,7 @@ describe('ConfigComponent', () => { TextComponent, SelectComponent, NumberComponent, - CheckComponent, + SwitchComponent, PageHeaderComponent, ], imports: [ diff --git a/src-ui/src/app/components/common/input/number/number.component.html b/src-ui/src/app/components/common/input/number/number.component.html index f194270d8..c9baf38a1 100644 --- a/src-ui/src/app/components/common/input/number/number.component.html +++ b/src-ui/src/app/components/common/input/number/number.component.html @@ -1,7 +1,9 @@
- + @if (title) { + + } @if (removable) { + } +
+ } +
+
+ + @if (!horizontal) { + + } + @if (hint) { +
{{hint}}
+ } +
+
+
+
diff --git a/src-ui/src/app/components/common/input/switch/switch.component.scss b/src-ui/src/app/components/common/input/switch/switch.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src-ui/src/app/components/common/input/switch/switch.component.spec.ts b/src-ui/src/app/components/common/input/switch/switch.component.spec.ts new file mode 100644 index 000000000..08a4598a3 --- /dev/null +++ b/src-ui/src/app/components/common/input/switch/switch.component.spec.ts @@ -0,0 +1,39 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { SwitchComponent } from './switch.component' +import { + FormsModule, + NG_VALUE_ACCESSOR, + ReactiveFormsModule, +} from '@angular/forms' + +describe('SwitchComponent', () => { + let component: SwitchComponent + let fixture: ComponentFixture + let input: HTMLInputElement + + beforeEach(async () => { + TestBed.configureTestingModule({ + declarations: [SwitchComponent], + providers: [], + imports: [FormsModule, ReactiveFormsModule], + }).compileComponents() + + fixture = TestBed.createComponent(SwitchComponent) + fixture.debugElement.injector.get(NG_VALUE_ACCESSOR) + component = fixture.componentInstance + fixture.detectChanges() + input = component.inputField.nativeElement + }) + + it('should support use of checkbox', () => { + input.checked = true + input.dispatchEvent(new Event('change')) + fixture.detectChanges() + expect(component.value).toBeTruthy() + + input.checked = false + input.dispatchEvent(new Event('change')) + fixture.detectChanges() + expect(component.value).toBeFalsy() + }) +}) diff --git a/src-ui/src/app/components/common/input/switch/switch.component.ts b/src-ui/src/app/components/common/input/switch/switch.component.ts new file mode 100644 index 000000000..44e095baa --- /dev/null +++ b/src-ui/src/app/components/common/input/switch/switch.component.ts @@ -0,0 +1,21 @@ +import { Component, forwardRef } from '@angular/core' +import { NG_VALUE_ACCESSOR } from '@angular/forms' +import { AbstractInputComponent } from '../abstract-input' + +@Component({ + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => SwitchComponent), + multi: true, + }, + ], + selector: 'pngx-input-switch', + templateUrl: './switch.component.html', + styleUrls: ['./switch.component.scss'], +}) +export class SwitchComponent extends AbstractInputComponent { + constructor() { + super() + } +} diff --git a/src-ui/src/app/components/common/input/text/text.component.html b/src-ui/src/app/components/common/input/text/text.component.html index 3b9f7e36d..4169d09db 100644 --- a/src-ui/src/app/components/common/input/text/text.component.html +++ b/src-ui/src/app/components/common/input/text/text.component.html @@ -1,7 +1,9 @@
- + @if (title) { + + } @if (removable) {