@kms-ngx-ui/presentational 16.3.0 → 16.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +27 -0
- package/ng-package.json +13 -0
- package/package.json +3 -17
- package/src/lib/directives/directives.module.ts +28 -0
- package/src/lib/directives/mousewheel.directive.ts +43 -0
- package/src/lib/directives/sum-of-height.directive.ts +73 -0
- package/src/lib/directives/swipe.directive.ts +193 -0
- package/{lib/directives/swipe.model.d.ts → src/lib/directives/swipe.model.ts} +6 -0
- package/src/lib/directives/tooltip.directive.spec.ts.BAK +8 -0
- package/src/lib/directives/tooltip.directive.ts +121 -0
- package/src/lib/kms-ngx-ui-presentational.component.spec.ts +25 -0
- package/src/lib/kms-ngx-ui-presentational.component.ts +20 -0
- package/src/lib/kms-ngx-ui-presentational.module.ts +124 -0
- package/src/lib/kms-ngx-ui-presentational.service.spec.ts +16 -0
- package/src/lib/kms-ngx-ui-presentational.service.ts +9 -0
- package/src/lib/models/address.model.ts +16 -0
- package/src/lib/models/iconSize.enum.ts +17 -0
- package/src/lib/models/image-snippet.model.ts +17 -0
- package/src/lib/models/is-value.function.ts +20 -0
- package/src/lib/models/salutation.enum.ts +6 -0
- package/{lib/models/types/attached-file-dto.model.d.ts → src/lib/models/types/attached-file-dto.model.ts} +1 -1
- package/{lib/models/types/nullable.type.d.ts → src/lib/models/types/nullable.type.ts} +1 -0
- package/src/lib/parent-components/actions.component.ts +43 -0
- package/src/lib/parent-components/form-control.component.ts +77 -0
- package/src/lib/parent-components/form.component.ts +79 -0
- package/src/lib/pipes/custom-pipes.module.ts +48 -0
- package/src/lib/pipes/decode-uri.pipe.ts +15 -0
- package/src/lib/pipes/encode-uri.pipe.ts +14 -0
- package/src/lib/pipes/integer-currency.pipe.ts +22 -0
- package/src/lib/pipes/prettyjson.pipe.ts +104 -0
- package/src/lib/pipes/safe-html.pipe.ts +17 -0
- package/src/lib/pipes/safe-resource-url.pipe.ts +17 -0
- package/src/lib/pipes/safe-style.pipe.ts +17 -0
- package/src/lib/pipes/safe-url.pipe.ts +17 -0
- package/src/lib/pipes/to-number.pipe.ts +19 -0
- package/src/lib/pipes/trim.pipe.ts +16 -0
- package/src/lib/pipes/typeof.pipe.ts +10 -0
- package/src/lib/services/viewport.service.ts +241 -0
- package/src/lib/ui/back-to-top/back-to-top.component.html +7 -0
- package/src/lib/ui/back-to-top/back-to-top.component.ts +43 -0
- package/src/lib/ui/back-to-top/back-to-top.stories.ts +19 -0
- package/src/lib/ui/button-with-confirm-dialog/button-response-types.enum.ts +4 -0
- package/src/lib/ui/button-with-confirm-dialog/button-with-confirm-dialog.component.html +8 -0
- package/src/lib/ui/button-with-confirm-dialog/button-with-confirm-dialog.component.spec.ts.BAK +25 -0
- package/src/lib/ui/button-with-confirm-dialog/button-with-confirm-dialog.component.ts +55 -0
- package/src/lib/ui/button-with-confirm-dialog/button-with-confirm-dialog.stories.ts +21 -0
- package/{lib/ui/button-with-confirm-dialog/dialog-data.model.d.ts → src/lib/ui/button-with-confirm-dialog/dialog-data.model.ts} +4 -3
- package/src/lib/ui/checkbox/checkbox.component.html +15 -0
- package/src/lib/ui/checkbox/checkbox.component.stories.ts +19 -0
- package/src/lib/ui/checkbox/checkbox.component.ts +75 -0
- package/src/lib/ui/color-input/color-input.component.html +11 -0
- package/src/lib/ui/color-input/color-input.component.spec.ts +44 -0
- package/src/lib/ui/color-input/color-input.component.ts +67 -0
- package/src/lib/ui/dropdown-from-data/dropdown-from-data.component.html +23 -0
- package/src/lib/ui/dropdown-from-data/dropdown-from-data.component.ts +174 -0
- package/src/lib/ui/enum-radiogroup/enum-radiogroup.component.html +6 -0
- package/src/lib/ui/enum-radiogroup/enum-radiogroup.component.spec.ts.BAK +25 -0
- package/src/lib/ui/enum-radiogroup/enum-radiogroup.component.ts +43 -0
- package/src/lib/ui/file-input/file-input.component.html +45 -0
- package/src/lib/ui/file-input/file-input.component.spec.ts.BAK +25 -0
- package/src/lib/ui/file-input/file-input.component.ts +236 -0
- package/src/lib/ui/flyout/flyout.component.html +35 -0
- package/src/lib/ui/flyout/flyout.component.spec.ts.BAK +30 -0
- package/src/lib/ui/flyout/flyout.component.ts +95 -0
- package/src/lib/ui/generic-dialog/generic-dialog.component.html +24 -0
- package/src/lib/ui/generic-dialog/generic-dialog.component.spec.ts.BAK +43 -0
- package/src/lib/ui/generic-dialog/generic-dialog.component.ts +54 -0
- package/src/lib/ui/icon/icon.component.html +22 -0
- package/src/lib/ui/icon/icon.component.spec.ts.BAK +31 -0
- package/src/lib/ui/icon/icon.component.ts +67 -0
- package/src/lib/ui/icon/iconSize.enum.ts +17 -0
- package/src/lib/ui/image-slider/image-slider.component.html +54 -0
- package/src/lib/ui/image-slider/image-slider.component.ts +205 -0
- package/src/lib/ui/kms-accordion-item/kms-accordion-item.component.html +22 -0
- package/src/lib/ui/kms-accordion-item/kms-accordion-item.component.spec.ts +61 -0
- package/src/lib/ui/kms-accordion-item/kms-accordion-item.component.ts +32 -0
- package/src/lib/ui/loader/loader.component.html +3 -0
- package/src/lib/ui/loader/loader.component.spec.ts.BAK +26 -0
- package/src/lib/ui/loader/loader.component.ts +16 -0
- package/src/lib/ui/map/map.component.html +18 -0
- package/src/lib/ui/map/map.component.spec.ts.BAK +31 -0
- package/src/lib/ui/map/map.component.ts +138 -0
- package/src/lib/ui/radiobutton/radiobutton.component.html +42 -0
- package/src/lib/ui/radiobutton/radiobutton.component.ts +71 -0
- package/src/lib/ui/salutation-dropdown/salutation-dropdown.component.html +9 -0
- package/src/lib/ui/salutation-dropdown/salutation-dropdown.component.spec.ts.BAK +26 -0
- package/src/lib/ui/salutation-dropdown/salutation-dropdown.component.ts +48 -0
- package/src/lib/ui/salutation-radiogroup/salutation-radiogroup.component.html +13 -0
- package/src/lib/ui/salutation-radiogroup/salutation-radiogroup.component.spec.ts.BAK +25 -0
- package/src/lib/ui/salutation-radiogroup/salutation-radiogroup.component.ts +41 -0
- package/src/lib/ui/time-input/time-input.component.html +5 -0
- package/src/lib/ui/time-input/time-input.component.spec.ts +28 -0
- package/src/lib/ui/time-input/time-input.component.ts +88 -0
- package/src/lib/ui/tooltip/tooltip.component.html +1 -0
- package/src/lib/ui/tooltip/tooltip.component.spec.ts.BAK +26 -0
- package/src/lib/ui/tooltip/tooltip.component.ts +10 -0
- package/src/lib/ui/tooltip-icon/tooltip-icon.component.html +11 -0
- package/src/lib/ui/tooltip-icon/tooltip-icon.component.spec.ts.BAK +28 -0
- package/src/lib/ui/tooltip-icon/tooltip-icon.component.ts +19 -0
- package/src/lib/ui/yes-no-radiogroup/yes-no-radiogroup.component.html +7 -0
- package/src/lib/ui/yes-no-radiogroup/yes-no-radiogroup.component.scss +17 -0
- package/src/lib/ui/yes-no-radiogroup/yes-no-radiogroup.component.spec.ts.BAK +25 -0
- package/src/lib/ui/yes-no-radiogroup/yes-no-radiogroup.component.ts +79 -0
- package/{public-api.d.ts → src/public-api.ts} +8 -0
- package/src/styles/styles.scss +3 -1
- package/src/test-setup.ts +2 -0
- package/tsconfig.lib.json +26 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/tslint.json +17 -0
- package/esm2022/kms-ngx-ui-presentational.mjs +0 -5
- package/esm2022/lib/directives/directives.module.mjs +0 -40
- package/esm2022/lib/directives/mousewheel.directive.mjs +0 -56
- package/esm2022/lib/directives/sum-of-height.directive.mjs +0 -74
- package/esm2022/lib/directives/swipe.directive.mjs +0 -183
- package/esm2022/lib/directives/swipe.model.mjs +0 -5
- package/esm2022/lib/directives/tooltip.directive.mjs +0 -144
- package/esm2022/lib/kms-ngx-ui-presentational.component.mjs +0 -22
- package/esm2022/lib/kms-ngx-ui-presentational.module.mjs +0 -211
- package/esm2022/lib/kms-ngx-ui-presentational.service.mjs +0 -14
- package/esm2022/lib/models/address.model.mjs +0 -6
- package/esm2022/lib/models/iconSize.enum.mjs +0 -17
- package/esm2022/lib/models/image-snippet.model.mjs +0 -18
- package/esm2022/lib/models/index.mjs +0 -5
- package/esm2022/lib/models/is-value.function.mjs +0 -17
- package/esm2022/lib/models/salutation.enum.mjs +0 -8
- package/esm2022/lib/models/types/attached-file-dto.model.mjs +0 -6
- package/esm2022/lib/models/types/nullable.type.mjs +0 -5
- package/esm2022/lib/parent-components/actions.component.mjs +0 -56
- package/esm2022/lib/parent-components/form-control.component.mjs +0 -75
- package/esm2022/lib/parent-components/form.component.mjs +0 -78
- package/esm2022/lib/pipes/custom-pipes.module.mjs +0 -71
- package/esm2022/lib/pipes/decode-uri.pipe.mjs +0 -19
- package/esm2022/lib/pipes/encode-uri.pipe.mjs +0 -19
- package/esm2022/lib/pipes/integer-currency.pipe.mjs +0 -27
- package/esm2022/lib/pipes/safe-html.pipe.mjs +0 -23
- package/esm2022/lib/pipes/safe-resource-url.pipe.mjs +0 -23
- package/esm2022/lib/pipes/safe-style.pipe.mjs +0 -23
- package/esm2022/lib/pipes/safe-url.pipe.mjs +0 -23
- package/esm2022/lib/pipes/to-number.pipe.mjs +0 -23
- package/esm2022/lib/pipes/trim.pipe.mjs +0 -20
- package/esm2022/lib/pipes/typeof.pipe.mjs +0 -16
- package/esm2022/lib/services/viewport.service.mjs +0 -216
- package/esm2022/lib/ui/back-to-top/back-to-top.component.mjs +0 -49
- package/esm2022/lib/ui/button-with-confirm-dialog/button-response-types.enum.mjs +0 -6
- package/esm2022/lib/ui/button-with-confirm-dialog/button-with-confirm-dialog.component.mjs +0 -58
- package/esm2022/lib/ui/button-with-confirm-dialog/dialog-data.model.mjs +0 -2
- package/esm2022/lib/ui/checkbox/checkbox.component.mjs +0 -71
- package/esm2022/lib/ui/color-input/color-input.component.mjs +0 -76
- package/esm2022/lib/ui/dropdown-from-data/dropdown-from-data.component.mjs +0 -157
- package/esm2022/lib/ui/enum-radiogroup/enum-radiogroup.component.mjs +0 -53
- package/esm2022/lib/ui/file-input/file-input.component.mjs +0 -232
- package/esm2022/lib/ui/flyout/flyout.component.mjs +0 -119
- package/esm2022/lib/ui/generic-dialog/generic-dialog.component.mjs +0 -55
- package/esm2022/lib/ui/icon/icon.component.mjs +0 -48
- package/esm2022/lib/ui/icon/iconSize.enum.mjs +0 -17
- package/esm2022/lib/ui/image-slider/image-slider.component.mjs +0 -189
- package/esm2022/lib/ui/kms-accordion-item/kms-accordion-item.component.mjs +0 -40
- package/esm2022/lib/ui/loader/loader.component.mjs +0 -21
- package/esm2022/lib/ui/map/map.component.mjs +0 -116
- package/esm2022/lib/ui/radiobutton/radiobutton.component.mjs +0 -73
- package/esm2022/lib/ui/salutation-dropdown/salutation-dropdown.component.mjs +0 -55
- package/esm2022/lib/ui/salutation-radiogroup/salutation-radiogroup.component.mjs +0 -49
- package/esm2022/lib/ui/time-input/time-input.component.mjs +0 -83
- package/esm2022/lib/ui/tooltip/tooltip.component.mjs +0 -16
- package/esm2022/lib/ui/tooltip-icon/tooltip-icon.component.mjs +0 -35
- package/esm2022/lib/ui/yes-no-radiogroup/yes-no-radiogroup.component.mjs +0 -82
- package/esm2022/public-api.mjs +0 -49
- package/fesm2022/kms-ngx-ui-presentational.mjs +0 -3003
- package/fesm2022/kms-ngx-ui-presentational.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/directives/directives.module.d.ts +0 -11
- package/lib/directives/mousewheel.directive.d.ts +0 -15
- package/lib/directives/sum-of-height.directive.d.ts +0 -31
- package/lib/directives/swipe.directive.d.ts +0 -45
- package/lib/directives/tooltip.directive.d.ts +0 -29
- package/lib/kms-ngx-ui-presentational.component.d.ts +0 -8
- package/lib/kms-ngx-ui-presentational.module.d.ts +0 -47
- package/lib/kms-ngx-ui-presentational.service.d.ts +0 -6
- package/lib/models/address.model.d.ts +0 -14
- package/lib/models/iconSize.enum.d.ts +0 -15
- package/lib/models/image-snippet.model.d.ts +0 -15
- package/lib/models/is-value.function.d.ts +0 -9
- package/lib/models/salutation.enum.d.ts +0 -5
- package/lib/parent-components/actions.component.d.ts +0 -31
- package/lib/parent-components/form-control.component.d.ts +0 -27
- package/lib/parent-components/form.component.d.ts +0 -34
- package/lib/pipes/custom-pipes.module.d.ts +0 -17
- package/lib/pipes/decode-uri.pipe.d.ts +0 -10
- package/lib/pipes/encode-uri.pipe.d.ts +0 -10
- package/lib/pipes/integer-currency.pipe.d.ts +0 -13
- package/lib/pipes/safe-html.pipe.d.ts +0 -13
- package/lib/pipes/safe-resource-url.pipe.d.ts +0 -13
- package/lib/pipes/safe-style.pipe.d.ts +0 -13
- package/lib/pipes/safe-url.pipe.d.ts +0 -13
- package/lib/pipes/to-number.pipe.d.ts +0 -10
- package/lib/pipes/trim.pipe.d.ts +0 -10
- package/lib/pipes/typeof.pipe.d.ts +0 -7
- package/lib/services/viewport.service.d.ts +0 -74
- package/lib/ui/back-to-top/back-to-top.component.d.ts +0 -10
- package/lib/ui/button-with-confirm-dialog/button-response-types.enum.d.ts +0 -4
- package/lib/ui/button-with-confirm-dialog/button-with-confirm-dialog.component.d.ts +0 -19
- package/lib/ui/checkbox/checkbox.component.d.ts +0 -31
- package/lib/ui/color-input/color-input.component.d.ts +0 -19
- package/lib/ui/dropdown-from-data/dropdown-from-data.component.d.ts +0 -55
- package/lib/ui/enum-radiogroup/enum-radiogroup.component.d.ts +0 -17
- package/lib/ui/file-input/file-input.component.d.ts +0 -89
- package/lib/ui/flyout/flyout.component.d.ts +0 -32
- package/lib/ui/generic-dialog/generic-dialog.component.d.ts +0 -26
- package/lib/ui/icon/icon.component.d.ts +0 -42
- package/lib/ui/icon/iconSize.enum.d.ts +0 -15
- package/lib/ui/image-slider/image-slider.component.d.ts +0 -62
- package/lib/ui/kms-accordion-item/kms-accordion-item.component.d.ts +0 -22
- package/lib/ui/loader/loader.component.d.ts +0 -9
- package/lib/ui/map/map.component.d.ts +0 -71
- package/lib/ui/radiobutton/radiobutton.component.d.ts +0 -26
- package/lib/ui/salutation-dropdown/salutation-dropdown.component.d.ts +0 -17
- package/lib/ui/salutation-radiogroup/salutation-radiogroup.component.d.ts +0 -15
- package/lib/ui/time-input/time-input.component.d.ts +0 -22
- package/lib/ui/tooltip/tooltip.component.d.ts +0 -6
- package/lib/ui/tooltip-icon/tooltip-icon.component.d.ts +0 -13
- package/lib/ui/yes-no-radiogroup/yes-no-radiogroup.component.d.ts +0 -27
- /package/{lib/models/index.d.ts → src/lib/models/index.ts} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* tslint:disable:no-unused-variable */
|
|
2
|
+
import { Component, Input } from '@angular/core';
|
|
3
|
+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
4
|
+
import { ReactiveFormsModule } from '@angular/forms';
|
|
5
|
+
import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field';
|
|
6
|
+
import { DirectivesModule } from '../../directives/directives.module';
|
|
7
|
+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
8
|
+
|
|
9
|
+
import { ColorInputComponent } from './color-input.component';
|
|
10
|
+
import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input';
|
|
11
|
+
|
|
12
|
+
@Component({ selector: 'kms-tooltip-icon', template: '' })
|
|
13
|
+
class TooltipIconComponentMock { @Input() public tooltipText: any; }
|
|
14
|
+
|
|
15
|
+
describe('ColorInputComponent', () => {
|
|
16
|
+
let component: ColorInputComponent;
|
|
17
|
+
let fixture: ComponentFixture<ColorInputComponent>;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
TestBed.configureTestingModule({
|
|
21
|
+
imports : [
|
|
22
|
+
ReactiveFormsModule,
|
|
23
|
+
DirectivesModule,
|
|
24
|
+
MatFormFieldModule,
|
|
25
|
+
BrowserAnimationsModule,
|
|
26
|
+
MatInputModule
|
|
27
|
+
],
|
|
28
|
+
declarations: [
|
|
29
|
+
ColorInputComponent,
|
|
30
|
+
TooltipIconComponentMock,
|
|
31
|
+
],
|
|
32
|
+
}).compileComponents();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
fixture = TestBed.createComponent(ColorInputComponent);
|
|
37
|
+
component = fixture.componentInstance;
|
|
38
|
+
fixture.detectChanges();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should create', () => {
|
|
42
|
+
expect(component).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Component, forwardRef, Input, OnInit, Renderer2 } from '@angular/core';
|
|
2
|
+
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
3
|
+
import { FormControlParentComponent } from './../../parent-components/form-control.component';
|
|
4
|
+
|
|
5
|
+
@Component({
|
|
6
|
+
selector: 'kms-color-input',
|
|
7
|
+
templateUrl: './color-input.component.html',
|
|
8
|
+
styleUrls: ['./color-input.component.scss'],
|
|
9
|
+
providers: [
|
|
10
|
+
{
|
|
11
|
+
provide: NG_VALUE_ACCESSOR,
|
|
12
|
+
useExisting: forwardRef(() => ColorInputComponent),
|
|
13
|
+
multi: true,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
})
|
|
17
|
+
export class ColorInputComponent extends FormControlParentComponent implements OnInit, ControlValueAccessor {
|
|
18
|
+
|
|
19
|
+
@Input() label = '';
|
|
20
|
+
@Input() tooltipText = '';
|
|
21
|
+
@Input() placeholder = '';
|
|
22
|
+
valid: boolean | null | undefined;
|
|
23
|
+
|
|
24
|
+
constructor(public formBuilder: UntypedFormBuilder, public renderer: Renderer2) {
|
|
25
|
+
super(formBuilder, renderer);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ngOnInit() {
|
|
29
|
+
this.form = this.formBuilder.group({
|
|
30
|
+
color: '',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
super.ngOnInit();
|
|
34
|
+
|
|
35
|
+
this.formInitialized = true;
|
|
36
|
+
|
|
37
|
+
this.form.valueChanges.subscribe((value) => {
|
|
38
|
+
this.internalValue = value.color;
|
|
39
|
+
this.onChange(value.color);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
validate(_: UntypedFormControl) {
|
|
45
|
+
// TODO fix to validate complete form
|
|
46
|
+
this.valid = this.matchesHex(this.form.value) ? null : false;
|
|
47
|
+
return this.valid && {
|
|
48
|
+
invalid: !this.valid
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
matchesHex(match?: string){
|
|
53
|
+
if(match){
|
|
54
|
+
const ret = match.match(/^#[0-9a-f]{6}$/i);
|
|
55
|
+
this.valid = ret && ret.length>0;
|
|
56
|
+
return ret;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
updateSelectedColor(value: any){
|
|
62
|
+
const color = value.target.value;
|
|
63
|
+
this.value = color;
|
|
64
|
+
this.internalValue = color;
|
|
65
|
+
this.change(color);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<form [formGroup]="form">
|
|
2
|
+
<mat-form-field
|
|
3
|
+
[attr.required]="required"
|
|
4
|
+
[floatLabel]="placeholder ? 'always' : 'auto'"
|
|
5
|
+
>
|
|
6
|
+
<mat-label>{{ label }}</mat-label>
|
|
7
|
+
<mat-select
|
|
8
|
+
placeholder="{{ placeholder }}"
|
|
9
|
+
disableOptionCentering
|
|
10
|
+
[(value)]="value"
|
|
11
|
+
(selectionChange)="valueChanged($event?.value)"
|
|
12
|
+
#child
|
|
13
|
+
[disabled]="disabled"
|
|
14
|
+
[multiple]="multiple"
|
|
15
|
+
>
|
|
16
|
+
<mat-option *ngFor="let key of keys; let i = index" [value]="values[i]">
|
|
17
|
+
<span *ngIf="(hasNullOption && i != 0) || !hasNullOption">{{
|
|
18
|
+
setDisplayKey(key)
|
|
19
|
+
}}</span>
|
|
20
|
+
</mat-option>
|
|
21
|
+
</mat-select>
|
|
22
|
+
</mat-form-field>
|
|
23
|
+
</form>
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
forwardRef,
|
|
4
|
+
Input,
|
|
5
|
+
OnInit,
|
|
6
|
+
OnChanges,
|
|
7
|
+
SimpleChanges,
|
|
8
|
+
Renderer2,
|
|
9
|
+
} from '@angular/core';
|
|
10
|
+
import {
|
|
11
|
+
ControlValueAccessor,
|
|
12
|
+
UntypedFormBuilder,
|
|
13
|
+
NG_VALUE_ACCESSOR,
|
|
14
|
+
} from '@angular/forms';
|
|
15
|
+
import { EnumValues } from 'enum-values/src/enumValues';
|
|
16
|
+
import { FormControlParentComponent } from '../../parent-components/form-control.component';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Dropdown from data component {@link https://leaseplan-dev.rentoffice.de/styleguide#ui-elements}
|
|
20
|
+
*/
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'kms-dropdown-from-data',
|
|
23
|
+
templateUrl: './dropdown-from-data.component.html',
|
|
24
|
+
providers: [
|
|
25
|
+
{
|
|
26
|
+
provide: NG_VALUE_ACCESSOR,
|
|
27
|
+
useExisting: forwardRef(() => DropdownFromDataComponent),
|
|
28
|
+
multi: true,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
export class DropdownFromDataComponent
|
|
33
|
+
extends FormControlParentComponent
|
|
34
|
+
implements OnInit, ControlValueAccessor, OnChanges
|
|
35
|
+
{
|
|
36
|
+
// structured data as a enum set. Can be used in combination with 'optionsPlainArray' to set diferent values by index
|
|
37
|
+
@Input() optionsEnum: any;
|
|
38
|
+
|
|
39
|
+
// structured data as a simple array of elements
|
|
40
|
+
@Input() optionsPlainArray: any;
|
|
41
|
+
|
|
42
|
+
// structured data as an array of objects used in combination with the input 'mapKey' and 'mapValue'
|
|
43
|
+
@Input() optionsObjArray: any;
|
|
44
|
+
// key identifier of the obj. If mapValue doesnt exist, mapKey is also the value
|
|
45
|
+
@Input() mapKey?: any;
|
|
46
|
+
// value identifier of the obj
|
|
47
|
+
@Input() mapValue?: any;
|
|
48
|
+
|
|
49
|
+
// options for the dropdown have a null value at the beginning of the array
|
|
50
|
+
@Input() hasNullOption = false;
|
|
51
|
+
|
|
52
|
+
// translation object for the label and placeholder
|
|
53
|
+
@Input() translation?: ITranslation;
|
|
54
|
+
@Input() placeholder = '';
|
|
55
|
+
@Input() label = '';
|
|
56
|
+
@Input() required = false;
|
|
57
|
+
@Input() useEnumIndexAsValue = false;
|
|
58
|
+
|
|
59
|
+
// multiple selection
|
|
60
|
+
@Input() multiple = false;
|
|
61
|
+
|
|
62
|
+
public keys: any[] = [];
|
|
63
|
+
public values: any[] = [];
|
|
64
|
+
|
|
65
|
+
Object = Object;
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
public formBuilder: UntypedFormBuilder,
|
|
69
|
+
public renderer: Renderer2
|
|
70
|
+
) {
|
|
71
|
+
super(formBuilder, renderer);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Hook used to sync changes on set Label and Type
|
|
76
|
+
* @param changes
|
|
77
|
+
*/
|
|
78
|
+
ngOnChanges(changes: SimpleChanges) {
|
|
79
|
+
if (changes.optionsPlainArray) {
|
|
80
|
+
this.values = this.optionsPlainArray;
|
|
81
|
+
this.keys = this.optionsPlainArray;
|
|
82
|
+
}
|
|
83
|
+
this.setKeyValues();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
ngOnInit() {
|
|
87
|
+
this.form = this.formBuilder.group({
|
|
88
|
+
dropdownData: [],
|
|
89
|
+
});
|
|
90
|
+
this.formInitialized = true;
|
|
91
|
+
|
|
92
|
+
this.form.valueChanges.subscribe((value) => {
|
|
93
|
+
this.internalValue = value.dropdownData;
|
|
94
|
+
this.onChange(value.dropdownData);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
super.ngOnInit();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* transofrms the data values to the correct format for be used by the template
|
|
102
|
+
* @param value
|
|
103
|
+
*/
|
|
104
|
+
private setKeyValues(): void {
|
|
105
|
+
if (this.optionsObjArray && this.mapKey && this.mapValue) {
|
|
106
|
+
this.keys = this.optionsObjArray.map((obj: any) => obj[`${this.mapKey}`]);
|
|
107
|
+
this.values = this.optionsObjArray.map(
|
|
108
|
+
(obj: any) => obj[`${this.mapValue}`]
|
|
109
|
+
);
|
|
110
|
+
} else if (this.optionsObjArray && this.mapKey) {
|
|
111
|
+
this.keys = this.optionsObjArray.map((obj: any) => obj[`${this.mapKey}`]);
|
|
112
|
+
this.values = this.optionsObjArray.map(
|
|
113
|
+
(obj: any) => obj[`${this.mapKey}`]
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (this.optionsEnum) {
|
|
117
|
+
this.keys = EnumValues.getNames(this.optionsEnum);
|
|
118
|
+
if (this.optionsPlainArray) {
|
|
119
|
+
this.values = this.optionsPlainArray;
|
|
120
|
+
} else {
|
|
121
|
+
const values = EnumValues.getValues(this.optionsEnum);
|
|
122
|
+
|
|
123
|
+
// var who defines if enum is componed just with keys or keyValues. E.g enum KeyEnum { VALUE1, VALUE2 } or enum KeyValueEnum { VALUE4 = 'V4', VALUE5 = 'V5' }
|
|
124
|
+
let keyValueEnum = false;
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < this.keys.length; i++) {
|
|
127
|
+
if (i !== values[i]) {
|
|
128
|
+
keyValueEnum = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (keyValueEnum || this.useEnumIndexAsValue) {
|
|
132
|
+
this.values = values;
|
|
133
|
+
} else {
|
|
134
|
+
this.values = EnumValues.getNames(this.optionsEnum);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (this.hasNullOption === true) this.keys.unshift(null);
|
|
139
|
+
if (this.hasNullOption === true) this.values.unshift(null);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* set the value of the dropdown based if translation is set
|
|
144
|
+
* @param key
|
|
145
|
+
*/
|
|
146
|
+
public setDisplayKey(key: any) {
|
|
147
|
+
if (this.translation) {
|
|
148
|
+
if (this.translation.isPrefix) {
|
|
149
|
+
return this.translation.service?.instant?.(
|
|
150
|
+
this.translation.path + '.' + key
|
|
151
|
+
);
|
|
152
|
+
} else {
|
|
153
|
+
return this.translation.service?.instant?.(this.translation.path);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return key;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
valueChanged(value: any) {
|
|
160
|
+
this.form.patchValue({
|
|
161
|
+
dropdownData: value,
|
|
162
|
+
});
|
|
163
|
+
this.onSelectItemEmitter.emit(value);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Interface that defines the translation object in template
|
|
169
|
+
*/
|
|
170
|
+
interface ITranslation {
|
|
171
|
+
path: string;
|
|
172
|
+
isPrefix?: boolean;
|
|
173
|
+
service: any;
|
|
174
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<form [formGroup]="form">
|
|
2
|
+
<div>{{ header }}</div>
|
|
3
|
+
<mat-radio-group [formControl]="form.controls['enumData']" [disabled]="disabled" #child>
|
|
4
|
+
<mat-radio-button [value]="choice" [checked]="value === choice" *ngFor="let choice of optionValues">{{ translationPrefix + '.' + choice | translate }}</mat-radio-button>
|
|
5
|
+
</mat-radio-group>
|
|
6
|
+
</form>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* tslint:disable:no-unused-variable */
|
|
2
|
+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
3
|
+
|
|
4
|
+
import { EnumRadiogroupComponent } from './enum-radiogroup.component';
|
|
5
|
+
|
|
6
|
+
describe('EnumRadiogroupComponent', () => {
|
|
7
|
+
let component: EnumRadiogroupComponent;
|
|
8
|
+
let fixture: ComponentFixture<EnumRadiogroupComponent>;
|
|
9
|
+
|
|
10
|
+
beforeEach(async(() => {
|
|
11
|
+
TestBed.configureTestingModule({
|
|
12
|
+
declarations: [EnumRadiogroupComponent],
|
|
13
|
+
}).compileComponents();
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
fixture = TestBed.createComponent(EnumRadiogroupComponent);
|
|
18
|
+
component = fixture.componentInstance;
|
|
19
|
+
fixture.detectChanges();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should create', () => {
|
|
23
|
+
expect(component).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Component, forwardRef, Input, OnInit, Renderer2 } from '@angular/core';
|
|
2
|
+
import { ControlValueAccessor, UntypedFormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
3
|
+
import { NullAble } from '../../models';
|
|
4
|
+
|
|
5
|
+
import { FormControlParentComponent } from './../../parent-components/form-control.component';
|
|
6
|
+
|
|
7
|
+
@Component({
|
|
8
|
+
selector: 'kms-enum-radiogroup',
|
|
9
|
+
templateUrl: './enum-radiogroup.component.html',
|
|
10
|
+
providers: [
|
|
11
|
+
{
|
|
12
|
+
provide: NG_VALUE_ACCESSOR,
|
|
13
|
+
useExisting: forwardRef(() => EnumRadiogroupComponent),
|
|
14
|
+
multi: true,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
export class EnumRadiogroupComponent extends FormControlParentComponent implements OnInit, ControlValueAccessor {
|
|
19
|
+
@Input() header: NullAble<String>;
|
|
20
|
+
@Input() optionsEnum: any;
|
|
21
|
+
@Input() translationPrefix = '';
|
|
22
|
+
|
|
23
|
+
public optionValues: any;
|
|
24
|
+
|
|
25
|
+
constructor(public formBuilder: UntypedFormBuilder, public renderer: Renderer2) {
|
|
26
|
+
super(formBuilder, renderer);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
ngOnInit(){
|
|
30
|
+
this.optionValues = Object.keys(this.optionsEnum).filter(x => !(parseInt(x) >= 0));
|
|
31
|
+
this.form = this.formBuilder.group({
|
|
32
|
+
enumData: [],
|
|
33
|
+
});
|
|
34
|
+
this.formInitialized = true;
|
|
35
|
+
|
|
36
|
+
this.form.valueChanges.subscribe((value) => {
|
|
37
|
+
this.internalValue = value.enumData;
|
|
38
|
+
this.onChange(value.enumData);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
super.ngOnInit();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<form [formGroup]="form" (change)="newImageLoading=true" class="fileInput">
|
|
2
|
+
|
|
3
|
+
<div *ngIf="form.value.Filename && previewImage">
|
|
4
|
+
<div *ngIf="newImageLoading">
|
|
5
|
+
{{ 'file-input.loading' | translate }}
|
|
6
|
+
</div>
|
|
7
|
+
<div *ngIf="!newImageLoading">
|
|
8
|
+
<div class="">
|
|
9
|
+
<div class="">
|
|
10
|
+
<img *ngIf="form.value.ImageLink && form.value.ImageLink !== '' && !(form.value.ImageAsDataURL && form.value.ImageAsDataURL !== '')" [src]="form.value.ImageAsDataURL" [src]="form.value.ImageLink" style="height: 40px; width: fit-content;" />
|
|
11
|
+
<img *ngIf="form.value.ImageAsDataURL && form.value.ImageAsDataURL !== ''" [src]="form.value.ImageAsDataURL" style="height: 40px; width: fit-content;" />
|
|
12
|
+
</div>
|
|
13
|
+
<div class="">{{form.value.Filename}}</div>
|
|
14
|
+
<div class="">
|
|
15
|
+
<div (click)="removeFromList()" *ngIf="allowRemove">
|
|
16
|
+
<kms-icon icon="trash" [iconSize]="IconSize.TINY" iconClass="color-black"></kms-icon>
|
|
17
|
+
{{ 'file-input.remove' }}
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div *ngIf="!previewImage">
|
|
24
|
+
<div class="">{{form.value.Filename}}</div>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<button (click)="selectImageOverlay()" class="button-primary-font-color" mat-stroked-button>
|
|
28
|
+
<span>{{ label }}</span>
|
|
29
|
+
</button>
|
|
30
|
+
<input
|
|
31
|
+
type="file"
|
|
32
|
+
[accept]="acceptedFileMimetypes"
|
|
33
|
+
style="display: none"
|
|
34
|
+
#fileInput
|
|
35
|
+
(click)="clearInputValue($event)"
|
|
36
|
+
(change)="selectImage($event)"
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
<input type="hidden" [formControl]="form.controls['ImageIdent']" />
|
|
40
|
+
<input type="hidden" [formControl]="form.controls['ImageLink']" />
|
|
41
|
+
<input type="hidden" [formControl]="form.controls['Filename']" />
|
|
42
|
+
<input type="hidden" [formControl]="form.controls['ImageAsDataURL']" />
|
|
43
|
+
<input type="hidden" [formControl]="form.controls['Text']" />
|
|
44
|
+
|
|
45
|
+
</form>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* tslint:disable:no-unused-variable */
|
|
2
|
+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
3
|
+
|
|
4
|
+
import { FileInputComponent } from './file-input.component';
|
|
5
|
+
|
|
6
|
+
describe('FileInputComponent', () => {
|
|
7
|
+
let component: FileInputComponent;
|
|
8
|
+
let fixture: ComponentFixture<FileInputComponent>;
|
|
9
|
+
|
|
10
|
+
beforeEach(async(() => {
|
|
11
|
+
TestBed.configureTestingModule({
|
|
12
|
+
declarations: [FileInputComponent],
|
|
13
|
+
}).compileComponents();
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
fixture = TestBed.createComponent(FileInputComponent);
|
|
18
|
+
component = fixture.componentInstance;
|
|
19
|
+
fixture.detectChanges();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should create', () => {
|
|
23
|
+
expect(component).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { Component, Input, forwardRef, OnInit, ViewChild, Renderer2, EventEmitter, Output, ApplicationRef, ChangeDetectorRef } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ControlValueAccessor,
|
|
5
|
+
UntypedFormBuilder,
|
|
6
|
+
UntypedFormControl,
|
|
7
|
+
UntypedFormGroup,
|
|
8
|
+
NG_VALIDATORS,
|
|
9
|
+
NG_VALUE_ACCESSOR,
|
|
10
|
+
} from '@angular/forms';
|
|
11
|
+
import { Subscription } from 'rxjs';
|
|
12
|
+
|
|
13
|
+
//import { TranslateService } from '@ngx-translate/core';
|
|
14
|
+
import { IconSize } from '../../models/iconSize.enum';
|
|
15
|
+
import { AttachedFileDTO } from '../../models/types/attached-file-dto.model';
|
|
16
|
+
import { isValue } from '../../models/is-value.function';
|
|
17
|
+
|
|
18
|
+
// Max size in bytes of uploaded image
|
|
19
|
+
const MAX_SIZE_BYTES = 2097152;
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'kms-file-input',
|
|
23
|
+
templateUrl: './file-input.component.html',
|
|
24
|
+
styleUrls: ['./file-input.component.scss'],
|
|
25
|
+
providers: [
|
|
26
|
+
{
|
|
27
|
+
provide: NG_VALUE_ACCESSOR,
|
|
28
|
+
useExisting: forwardRef(() => FileInputComponent),
|
|
29
|
+
multi: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
provide: NG_VALIDATORS,
|
|
33
|
+
useExisting: forwardRef(() => FileInputComponent),
|
|
34
|
+
multi: true,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export class FileInputComponent implements ControlValueAccessor, OnInit {
|
|
40
|
+
|
|
41
|
+
@ViewChild('fileInput') public fileInput: any;
|
|
42
|
+
|
|
43
|
+
@Input() label = '';
|
|
44
|
+
|
|
45
|
+
@Input() previewImage = true;
|
|
46
|
+
@Input() allowRemove = true;
|
|
47
|
+
@Input() previewImageText = '';
|
|
48
|
+
@Input() maxSizeBytes = MAX_SIZE_BYTES;
|
|
49
|
+
@Input() resizePixels = 0;
|
|
50
|
+
@Input() acceptedFileMimetypes = 'image/jpeg, image/jpg, image/png';
|
|
51
|
+
|
|
52
|
+
form= this.formBuilder.group({
|
|
53
|
+
ImageIdent: new UntypedFormControl(''),
|
|
54
|
+
ImageLink: new UntypedFormControl(''),
|
|
55
|
+
Filename: new UntypedFormControl(''),
|
|
56
|
+
ImageAsDataURL: new UntypedFormControl(''),
|
|
57
|
+
Text: new UntypedFormControl(''),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
subscriptions: Subscription[] = [];
|
|
61
|
+
newImageLoading = false
|
|
62
|
+
|
|
63
|
+
IconSize = IconSize;
|
|
64
|
+
|
|
65
|
+
@Output() formDataChanged: EventEmitter<UntypedFormGroup> = new EventEmitter();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Constructor
|
|
69
|
+
* @param formBuilder
|
|
70
|
+
* @param appRef
|
|
71
|
+
* @param cd
|
|
72
|
+
* @param translateService
|
|
73
|
+
* @param renderer
|
|
74
|
+
*/
|
|
75
|
+
constructor(
|
|
76
|
+
public formBuilder: UntypedFormBuilder,
|
|
77
|
+
public appRef: ApplicationRef,
|
|
78
|
+
public cd: ChangeDetectorRef,
|
|
79
|
+
//private translateService: TranslateService,
|
|
80
|
+
public renderer: Renderer2
|
|
81
|
+
) {
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Click on button triggers file-input to open OS file dialog
|
|
87
|
+
*/
|
|
88
|
+
selectImageOverlay() {
|
|
89
|
+
this.fileInput.nativeElement.click();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Function to manage the input image
|
|
94
|
+
* Returns an error if the file exceeds maximum wanted filesize (Mb).
|
|
95
|
+
* @param ev
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
selectImage(ev: any) {
|
|
99
|
+
if (ev.target.files && ev.target.files[0]) {
|
|
100
|
+
const file:File = ev.target.files[0];
|
|
101
|
+
|
|
102
|
+
if (file.size > this.maxSizeBytes) {
|
|
103
|
+
this.clearInputValue(ev);
|
|
104
|
+
//alert(this.translateService.instant('errors.fileTooBig'));
|
|
105
|
+
return;
|
|
106
|
+
} else {
|
|
107
|
+
this.newImageLoading = true;
|
|
108
|
+
|
|
109
|
+
if(this.resizePixels > 0){
|
|
110
|
+
const logoUrl = URL.createObjectURL(file);
|
|
111
|
+
const imgEl = document.createElement('img');
|
|
112
|
+
imgEl.addEventListener('load', () => {
|
|
113
|
+
const resizedLogo = this.resizeImage(imgEl, this.resizePixels);
|
|
114
|
+
const newFile = this.generateModel(file.name, resizedLogo, this.value.ImageIdent, this.value.ImageLink, this.value.Text);
|
|
115
|
+
this.value=newFile;
|
|
116
|
+
this.newImageLoading = false;
|
|
117
|
+
this.cd.markForCheck();
|
|
118
|
+
});
|
|
119
|
+
imgEl.src = logoUrl;
|
|
120
|
+
}else{
|
|
121
|
+
const reader = new FileReader();
|
|
122
|
+
reader.readAsDataURL(file);
|
|
123
|
+
reader.onload = (e: any) => {
|
|
124
|
+
const newFile = this.generateModel(file.name, e.target.result, this.value.ImageIdent, this.value.ImageLink, this.value.Text);
|
|
125
|
+
this.value=newFile;
|
|
126
|
+
this.newImageLoading = false;
|
|
127
|
+
this.cd.markForCheck();
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
}else{
|
|
133
|
+
console.warn("No file selected");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resize an image
|
|
139
|
+
* @param imgEl
|
|
140
|
+
* @param wantedWidth as number
|
|
141
|
+
* @returns string
|
|
142
|
+
*/
|
|
143
|
+
private resizeImage(imgEl: any, wantedWidth: number) {
|
|
144
|
+
const canvas = document.createElement('canvas');
|
|
145
|
+
const ctx = canvas.getContext('2d');
|
|
146
|
+
const aspect = imgEl.width / imgEl.height;
|
|
147
|
+
canvas.width = wantedWidth;
|
|
148
|
+
canvas.height = wantedWidth / aspect;
|
|
149
|
+
if (isValue(ctx)) ctx.drawImage(imgEl, 0, 0, canvas.width, canvas.height);
|
|
150
|
+
return canvas.toDataURL();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Generate default object
|
|
155
|
+
* @param name as string
|
|
156
|
+
* @param content as string
|
|
157
|
+
* @returns AttachedFileDTO
|
|
158
|
+
*/
|
|
159
|
+
generateModel(name?: string, content?: string, ident?: string, imageLink?: string, text?: string){
|
|
160
|
+
return {
|
|
161
|
+
ImageIdent: ident ? ident : '',
|
|
162
|
+
Filename: name ? name : '',
|
|
163
|
+
ImageAsDataURL: content ? content : '',
|
|
164
|
+
ImageLink: imageLink ? imageLink : '',
|
|
165
|
+
Text: text ? text : ''
|
|
166
|
+
} as AttachedFileDTO;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Remove image
|
|
171
|
+
*/
|
|
172
|
+
removeFromList(){
|
|
173
|
+
this.value= this.generateModel('','', '', '');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* get value
|
|
178
|
+
*/
|
|
179
|
+
get value(): AttachedFileDTO {
|
|
180
|
+
return this.form.value;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* set value
|
|
185
|
+
*/
|
|
186
|
+
set value(value: AttachedFileDTO) {
|
|
187
|
+
this.form.setValue(value);
|
|
188
|
+
this.onChange(value);
|
|
189
|
+
this.formDataChanged.emit(this.form);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
193
|
+
onChange: any = () => {};
|
|
194
|
+
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
196
|
+
onTouch: any = () => {};
|
|
197
|
+
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
199
|
+
ngOnInit() {}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
ngOnDestroy() {
|
|
203
|
+
this.subscriptions.forEach(s => s.unsubscribe());
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
registerOnChange(fn: any) {
|
|
207
|
+
this.onChange = fn;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
registerOnTouched(fn: any) {
|
|
211
|
+
this.onTouch = fn;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
writeValue(value: AttachedFileDTO | null) {
|
|
215
|
+
if (value) {
|
|
216
|
+
this.value = value;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (value === null) {
|
|
220
|
+
this.form.reset();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/adjacent-overload-signatures
|
|
225
|
+
validate(_: UntypedFormControl) {
|
|
226
|
+
return this.form.valid ? null : { styles: { valid: false } };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* OnClick event listener of input#fileInput to clear his input value
|
|
231
|
+
*/
|
|
232
|
+
clearInputValue(ev: any) {
|
|
233
|
+
const element = ev.target as HTMLInputElement;
|
|
234
|
+
element.value = '';
|
|
235
|
+
}
|
|
236
|
+
}
|