|
@@ -3,15 +3,13 @@ import {
|
|
|
Component,
|
|
Component,
|
|
|
ComponentFactory,
|
|
ComponentFactory,
|
|
|
Input,
|
|
Input,
|
|
|
- OnDestroy,
|
|
|
|
|
OnInit,
|
|
OnInit,
|
|
|
ViewChild,
|
|
ViewChild,
|
|
|
ViewContainerRef,
|
|
ViewContainerRef,
|
|
|
} from '@angular/core';
|
|
} from '@angular/core';
|
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
|
-import { Subscription } from 'rxjs';
|
|
|
|
|
|
|
|
|
|
-import { CustomFieldsFragment, LanguageCode, LocalizedString } from '../../../common/generated-types';
|
|
|
|
|
|
|
+import { CustomFieldsFragment } from '../../../common/generated-types';
|
|
|
import {
|
|
import {
|
|
|
CustomFieldComponentService,
|
|
CustomFieldComponentService,
|
|
|
CustomFieldControl,
|
|
CustomFieldControl,
|
|
@@ -28,7 +26,7 @@ import { DataService } from '../../../data/providers/data.service';
|
|
|
templateUrl: './custom-field-control.component.html',
|
|
templateUrl: './custom-field-control.component.html',
|
|
|
styleUrls: ['./custom-field-control.component.scss'],
|
|
styleUrls: ['./custom-field-control.component.scss'],
|
|
|
})
|
|
})
|
|
|
-export class CustomFieldControlComponent implements OnInit, OnDestroy, AfterViewInit {
|
|
|
|
|
|
|
+export class CustomFieldControlComponent implements OnInit, AfterViewInit {
|
|
|
@Input() entityName: CustomFieldEntityName;
|
|
@Input() entityName: CustomFieldEntityName;
|
|
|
@Input('customFieldsFormGroup') formGroup: FormGroup;
|
|
@Input('customFieldsFormGroup') formGroup: FormGroup;
|
|
|
@Input() customField: CustomFieldsFragment;
|
|
@Input() customField: CustomFieldsFragment;
|
|
@@ -39,8 +37,6 @@ export class CustomFieldControlComponent implements OnInit, OnDestroy, AfterView
|
|
|
@ViewChild('customComponentPlaceholder', { read: ViewContainerRef, static: false })
|
|
@ViewChild('customComponentPlaceholder', { read: ViewContainerRef, static: false })
|
|
|
private customComponentPlaceholder: ViewContainerRef;
|
|
private customComponentPlaceholder: ViewContainerRef;
|
|
|
private customComponentFactory: ComponentFactory<CustomFieldControl> | undefined;
|
|
private customComponentFactory: ComponentFactory<CustomFieldControl> | undefined;
|
|
|
- private uiLanguageCode: LanguageCode;
|
|
|
|
|
- private sub: Subscription;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
private dataService: DataService,
|
|
private dataService: DataService,
|
|
@@ -48,12 +44,6 @@ export class CustomFieldControlComponent implements OnInit, OnDestroy, AfterView
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
|
- this.sub = this.dataService.client
|
|
|
|
|
- .uiState()
|
|
|
|
|
- .mapStream(data => data.uiState.language)
|
|
|
|
|
- .subscribe(language => {
|
|
|
|
|
- this.uiLanguageCode = language;
|
|
|
|
|
- });
|
|
|
|
|
this.customComponentFactory = this.customFieldComponentService.getCustomFieldComponent(
|
|
this.customComponentFactory = this.customFieldComponentService.getCustomFieldComponent(
|
|
|
this.entityName,
|
|
this.entityName,
|
|
|
this.customField.name,
|
|
this.customField.name,
|
|
@@ -73,12 +63,6 @@ export class CustomFieldControlComponent implements OnInit, OnDestroy, AfterView
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ngOnDestroy(): void {
|
|
|
|
|
- if (this.sub) {
|
|
|
|
|
- this.sub.unsubscribe();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
get isTextInput(): boolean {
|
|
get isTextInput(): boolean {
|
|
|
if (this.customField.__typename === 'StringCustomFieldConfig') {
|
|
if (this.customField.__typename === 'StringCustomFieldConfig') {
|
|
|
return !this.customField.options;
|
|
return !this.customField.options;
|
|
@@ -101,12 +85,6 @@ export class CustomFieldControlComponent implements OnInit, OnDestroy, AfterView
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- get label(): string | undefined {
|
|
|
|
|
- if (this.showLabel) {
|
|
|
|
|
- return this.getLabel(this.customField.name, this.customField.label);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
get min(): string | number | undefined | null {
|
|
get min(): string | number | undefined | null {
|
|
|
switch (this.customField.__typename) {
|
|
switch (this.customField.__typename) {
|
|
|
case 'IntCustomFieldConfig':
|
|
case 'IntCustomFieldConfig':
|
|
@@ -139,13 +117,4 @@ export class CustomFieldControlComponent implements OnInit, OnDestroy, AfterView
|
|
|
return this.customField.datetimeStep;
|
|
return this.customField.datetimeStep;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- getLabel(defaultLabel: string, label?: LocalizedString[] | null): string {
|
|
|
|
|
- if (label) {
|
|
|
|
|
- const match = label.find(l => l.languageCode === this.uiLanguageCode);
|
|
|
|
|
- return match ? match.value : label[0].value;
|
|
|
|
|
- } else {
|
|
|
|
|
- return defaultLabel;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|