|
|
@ -14,7 +14,7 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import { Component, Inject, OnDestroy, OnInit, SkipSelf, ViewChild } from '@angular/core'; |
|
|
import { Component, DestroyRef, Inject, OnInit, SkipSelf, ViewChild } from '@angular/core'; |
|
|
import { ErrorStateMatcher } from '@angular/material/core'; |
|
|
import { ErrorStateMatcher } from '@angular/material/core'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
@ -28,7 +28,6 @@ import { |
|
|
ValidatorFn, |
|
|
ValidatorFn, |
|
|
Validators |
|
|
Validators |
|
|
} from '@angular/forms'; |
|
|
} from '@angular/forms'; |
|
|
import { Subject } from 'rxjs'; |
|
|
|
|
|
import { Router } from '@angular/router'; |
|
|
import { Router } from '@angular/router'; |
|
|
import { DialogComponent } from '@app/shared/components/dialog.component'; |
|
|
import { DialogComponent } from '@app/shared/components/dialog.component'; |
|
|
import { |
|
|
import { |
|
|
@ -44,14 +43,17 @@ import { |
|
|
defaultWidgetAction, |
|
|
defaultWidgetAction, |
|
|
WidgetActionSource, |
|
|
WidgetActionSource, |
|
|
WidgetActionType, |
|
|
WidgetActionType, |
|
|
|
|
|
WidgetHeaderActionButtonType, |
|
|
|
|
|
WidgetHeaderActionButtonTypes, |
|
|
|
|
|
widgetHeaderActionButtonTypeTranslationMap, |
|
|
widgetType |
|
|
widgetType |
|
|
} from '@shared/models/widget.models'; |
|
|
} from '@shared/models/widget.models'; |
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
import { CustomActionEditorCompleter } from '@home/components/widget/lib/settings/common/action/custom-action.models'; |
|
|
import { CustomActionEditorCompleter } from '@home/components/widget/lib/settings/common/action/custom-action.models'; |
|
|
import { WidgetService } from '@core/http/widget.service'; |
|
|
import { WidgetService } from '@core/http/widget.service'; |
|
|
import { isDefinedAndNotNull, isNotEmptyStr } from '@core/utils'; |
|
|
import { isDefinedAndNotNull, isNotEmptyStr } from '@core/utils'; |
|
|
import { MatSelect } from '@angular/material/select'; |
|
|
import { MatSelect } from '@angular/material/select'; |
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
|
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|
|
|
|
|
|
|
|
export interface WidgetActionDialogData { |
|
|
export interface WidgetActionDialogData { |
|
|
isAdd: boolean; |
|
|
isAdd: boolean; |
|
|
@ -69,9 +71,7 @@ export interface WidgetActionDialogData { |
|
|
styleUrls: [] |
|
|
styleUrls: [] |
|
|
}) |
|
|
}) |
|
|
export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDialogComponent, |
|
|
export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDialogComponent, |
|
|
WidgetActionDescriptorInfo> implements OnInit, OnDestroy, ErrorStateMatcher { |
|
|
WidgetActionDescriptorInfo> implements OnInit, ErrorStateMatcher { |
|
|
|
|
|
|
|
|
private destroy$ = new Subject<void>(); |
|
|
|
|
|
|
|
|
|
|
|
widgetActionFormGroup: FormGroup; |
|
|
widgetActionFormGroup: FormGroup; |
|
|
|
|
|
|
|
|
@ -87,6 +87,10 @@ export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDia |
|
|
configuredColumns: Array<CellClickColumnInfo> = []; |
|
|
configuredColumns: Array<CellClickColumnInfo> = []; |
|
|
usedCellClickColumns: Array<number> = []; |
|
|
usedCellClickColumns: Array<number> = []; |
|
|
|
|
|
|
|
|
|
|
|
widgetHeaderActionButtonType = WidgetHeaderActionButtonType |
|
|
|
|
|
widgetHeaderActionButtonTypes = WidgetHeaderActionButtonTypes; |
|
|
|
|
|
widgetHeaderActionButtonTypeTranslationMap = widgetHeaderActionButtonTypeTranslationMap; |
|
|
|
|
|
|
|
|
@ViewChild('columnIndexSelect') columnIndexSelect: MatSelect; |
|
|
@ViewChild('columnIndexSelect') columnIndexSelect: MatSelect; |
|
|
columnIndexPlaceholderText = this.translate.instant('widget-config.select-column-index'); |
|
|
columnIndexPlaceholderText = this.translate.instant('widget-config.select-column-index'); |
|
|
|
|
|
|
|
|
@ -98,7 +102,8 @@ export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDia |
|
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
|
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
|
|
public dialogRef: MatDialogRef<WidgetActionDialogComponent, WidgetActionDescriptorInfo>, |
|
|
public dialogRef: MatDialogRef<WidgetActionDialogComponent, WidgetActionDescriptorInfo>, |
|
|
public fb: FormBuilder, |
|
|
public fb: FormBuilder, |
|
|
private translate: TranslateService) { |
|
|
private translate: TranslateService, |
|
|
|
|
|
private destroyRef: DestroyRef) { |
|
|
super(store, router, dialogRef); |
|
|
super(store, router, dialogRef); |
|
|
this.isAdd = data.isAdd; |
|
|
this.isAdd = data.isAdd; |
|
|
if (this.isAdd) { |
|
|
if (this.isAdd) { |
|
|
@ -122,14 +127,21 @@ export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDia |
|
|
actionSourceId: [this.action.actionSourceId, Validators.required], |
|
|
actionSourceId: [this.action.actionSourceId, Validators.required], |
|
|
columnIndex: [{value: this.checkColumnIndex(this.action.columnIndex), disabled: true}, Validators.required], |
|
|
columnIndex: [{value: this.checkColumnIndex(this.action.columnIndex), disabled: true}, Validators.required], |
|
|
name: [this.action.name, [this.validateActionName(), Validators.required]], |
|
|
name: [this.action.name, [this.validateActionName(), Validators.required]], |
|
|
|
|
|
buttonType: [isDefinedAndNotNull(this.action.buttonType) ? this.action.buttonType : WidgetHeaderActionButtonType.icon, []], |
|
|
|
|
|
showIcon: [isDefinedAndNotNull(this.action.showIcon) ? this.action.showIcon : true, []], |
|
|
icon: [this.action.icon, Validators.required], |
|
|
icon: [this.action.icon, Validators.required], |
|
|
|
|
|
buttonColor: [isDefinedAndNotNull(this.action.buttonColor) ? this.action.buttonColor : 'rgba(0, 0, 0, 0.87)', []], |
|
|
|
|
|
buttonFillColor: [isDefinedAndNotNull(this.action.buttonFillColor) ? this.action.buttonFillColor : '#3F52DD', []], |
|
|
|
|
|
buttonBorderColor: [isDefinedAndNotNull(this.action.buttonBorderColor) ? this.action.buttonBorderColor : '#3F52DD', []], |
|
|
|
|
|
customButtonStyle: [isDefinedAndNotNull(this.action.customButtonStyle) ? this.action.customButtonStyle : null, []], |
|
|
useShowWidgetActionFunction: [this.action.useShowWidgetActionFunction], |
|
|
useShowWidgetActionFunction: [this.action.useShowWidgetActionFunction], |
|
|
showWidgetActionFunction: [this.action.showWidgetActionFunction || 'return true;'], |
|
|
showWidgetActionFunction: [this.action.showWidgetActionFunction || 'return true;'], |
|
|
widgetAction: [actionDescriptorToAction(toWidgetActionDescriptor(this.action)), Validators.required] |
|
|
widgetAction: [actionDescriptorToAction(toWidgetActionDescriptor(this.action)), Validators.required] |
|
|
}); |
|
|
}); |
|
|
this.updateShowWidgetActionForm(); |
|
|
this.updateShowWidgetActionForm(); |
|
|
|
|
|
this.widgetHeaderButtonValidators(); |
|
|
this.widgetActionFormGroup.get('actionSourceId').valueChanges.pipe( |
|
|
this.widgetActionFormGroup.get('actionSourceId').valueChanges.pipe( |
|
|
takeUntil(this.destroy$) |
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
).subscribe((value) => { |
|
|
).subscribe((value) => { |
|
|
this.widgetActionFormGroup.get('name').updateValueAndValidity(); |
|
|
this.widgetActionFormGroup.get('name').updateValueAndValidity(); |
|
|
this.updateShowWidgetActionForm(); |
|
|
this.updateShowWidgetActionForm(); |
|
|
@ -141,10 +153,13 @@ export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDia |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
this.widgetActionFormGroup.get('useShowWidgetActionFunction').valueChanges.pipe( |
|
|
this.widgetActionFormGroup.get('useShowWidgetActionFunction').valueChanges.pipe( |
|
|
takeUntil(this.destroy$) |
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
).subscribe(() => { |
|
|
).subscribe(() => { |
|
|
this.updateShowWidgetActionForm(); |
|
|
this.updateShowWidgetActionForm(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
this.widgetActionFormGroup.get('buttonType').valueChanges.pipe( |
|
|
|
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
|
|
|
).subscribe(() => this.widgetHeaderButtonValidators()); |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
if (this.action?.actionSourceId === 'cellClick') { |
|
|
if (this.action?.actionSourceId === 'cellClick') { |
|
|
this.widgetActionFormGroup.get('columnIndex').enable(); |
|
|
this.widgetActionFormGroup.get('columnIndex').enable(); |
|
|
@ -156,10 +171,29 @@ export class WidgetActionDialogComponent extends DialogComponent<WidgetActionDia |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnDestroy() { |
|
|
widgetHeaderButtonValidators() { |
|
|
this.destroy$.next(); |
|
|
const buttonType = this.widgetActionFormGroup.get('buttonType').value; |
|
|
this.destroy$.complete(); |
|
|
this.widgetActionFormGroup.get('showIcon').disable({emitEvent: false}); |
|
|
super.ngOnDestroy(); |
|
|
this.widgetActionFormGroup.get('buttonFillColor').disable({emitEvent: false}); |
|
|
|
|
|
this.widgetActionFormGroup.get('buttonBorderColor').disable({emitEvent: false}); |
|
|
|
|
|
switch (buttonType) { |
|
|
|
|
|
case WidgetHeaderActionButtonType.basic: |
|
|
|
|
|
this.widgetActionFormGroup.get('showIcon').enable({emitEvent: false}); |
|
|
|
|
|
break; |
|
|
|
|
|
case WidgetHeaderActionButtonType.raised: |
|
|
|
|
|
this.widgetActionFormGroup.get('showIcon').enable({emitEvent: false}); |
|
|
|
|
|
this.widgetActionFormGroup.get('buttonFillColor').enable({emitEvent: false}); |
|
|
|
|
|
break; |
|
|
|
|
|
case WidgetHeaderActionButtonType.stroked: |
|
|
|
|
|
case WidgetHeaderActionButtonType.flat: |
|
|
|
|
|
this.widgetActionFormGroup.get('showIcon').enable({emitEvent: false}); |
|
|
|
|
|
this.widgetActionFormGroup.get('buttonFillColor').enable({emitEvent: false}); |
|
|
|
|
|
this.widgetActionFormGroup.get('buttonBorderColor').enable({emitEvent: false}); |
|
|
|
|
|
break; |
|
|
|
|
|
case WidgetHeaderActionButtonType.miniFab: |
|
|
|
|
|
this.widgetActionFormGroup.get('buttonFillColor').enable({emitEvent: false}); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
displayShowWidgetActionForm(): boolean { |
|
|
displayShowWidgetActionForm(): boolean { |
|
|
|