13 changed files with 554 additions and 160 deletions
@ -0,0 +1,118 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2024 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<ng-container *ngIf="mobileAppQrCodeWidgetConfigForm" [formGroup]="mobileAppQrCodeWidgetConfigForm"> |
||||
|
<div class="tb-form-panel no-border no-padding"> |
||||
|
<div class="tb-form-row no-border no-padding-bottom"> |
||||
|
<mat-slide-toggle class="mat-slide" formControlName="useSystemSettings" (click)="$event.stopPropagation()"> |
||||
|
{{ 'admin.mobile-app.use-system-settings' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-form-panel no-border no-padding" *ngIf="!mobileAppQrCodeWidgetConfigForm.get('useSystemSettings').value"> |
||||
|
<div class="tb-form-panel"> |
||||
|
<div class="tb-form-panel-title" translate>widget-config.appearance</div> |
||||
|
<div class="tb-form-hint tb-primary-fill">{{ 'widgets.mobile-app-qr-code.configuration-hint' | translate }}</div> |
||||
|
<div class="tb-form-row space-between no-padding-bottom column-xs"> |
||||
|
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="badgeEnabled" |
||||
|
(click)="$event.stopPropagation()"> |
||||
|
{{ 'admin.mobile-app.badges' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<mat-select formControlName="badgePosition" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<mat-option *ngFor="let badgePosition of badgePositionTranslationsMap | keyvalue" [value]="badgePosition.key"> |
||||
|
{{ badgePosition.value | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between no-padding-bottom column-xs"> |
||||
|
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="qrCodeLabelEnabled" (click)="$event.stopPropagation()"> |
||||
|
{{ 'admin.mobile-app.label' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="qrCodeLabel" maxlength="50" placeholder="{{'admin.mobile-app.set' | translate}}"> |
||||
|
<mat-icon matSuffix |
||||
|
matTooltipPosition="above" |
||||
|
matTooltipClass="tb-error-tooltip" |
||||
|
[matTooltip]="'admin.mobile-app.label-required' | translate" |
||||
|
*ngIf="mobileAppQrCodeWidgetConfigForm.get('qrCodeLabel').hasError('required') |
||||
|
&& mobileAppQrCodeWidgetConfigForm.get('qrCodeLabel').touched" |
||||
|
class="tb-error"> |
||||
|
warning |
||||
|
</mat-icon> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row column-xs"> |
||||
|
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitle"> |
||||
|
{{ 'widgets.liquid-level-card.title' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<div class="tb-flex row flex-start align-center"> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="title" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
<tb-font-settings formControlName="titleFont" |
||||
|
[previewText]="mobileAppQrCodeWidgetConfigForm.get('title').value"> |
||||
|
</tb-font-settings> |
||||
|
<tb-color-input asBoxInput colorClearButton formControlName="titleColor"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-form-row column-xs"> |
||||
|
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitleIcon"> |
||||
|
{{ 'widgets.liquid-level-card.icon' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<div class="tb-flex row flex-end align-center"> |
||||
|
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
||||
|
<input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
<tb-css-unit-select fxFlex formControlName="iconSizeUnit"></tb-css-unit-select> |
||||
|
<tb-material-icon-select asBoxInput |
||||
|
iconClearButton |
||||
|
[color]="mobileAppQrCodeWidgetConfigForm.get('iconColor').value" |
||||
|
formControlName="titleIcon"> |
||||
|
</tb-material-icon-select> |
||||
|
<tb-color-input asBoxInput colorClearButton formControlName="iconColor"> |
||||
|
</tb-color-input> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="tb-form-panel"> |
||||
|
<div class="tb-form-panel-title" translate>widget-config.card-appearance</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div>{{ 'widgets.background.background' | translate }}</div> |
||||
|
<tb-background-settings formControlName="background"> |
||||
|
</tb-background-settings> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div translate>widget-config.show-card-buttons</div> |
||||
|
<mat-chip-listbox multiple formControlName="cardButtons"> |
||||
|
<mat-chip-option value="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option> |
||||
|
</mat-chip-listbox> |
||||
|
</div> |
||||
|
<div class="tb-form-row space-between"> |
||||
|
<div>{{ 'widget-config.card-border-radius' | translate }}</div> |
||||
|
<mat-form-field appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="borderRadius" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</div> |
||||
|
<tb-widget-actions-panel |
||||
|
formControlName="actions"> |
||||
|
</tb-widget-actions-panel> |
||||
|
</div> |
||||
|
</ng-container> |
||||
@ -0,0 +1,182 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { ChangeDetectorRef, Component, Injector } from '@angular/core'; |
||||
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { BasicWidgetConfigComponent } from '@home/components/widget/config/widget-config.component.models'; |
||||
|
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
||||
|
import { WidgetConfig } from '@shared/models/widget.models'; |
||||
|
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; |
||||
|
import { isUndefined } from '@core/utils'; |
||||
|
import { cssSizeToStrSize, resolveCssSize } from '@shared/models/widget-settings.models'; |
||||
|
import { |
||||
|
mobileAppQrCodeWidgetDefaultSettings, |
||||
|
MobileAppQrCodeWidgetSettings |
||||
|
} from '@home/components/widget/lib/cards/mobile-app-qr-code-widget.models'; |
||||
|
import { badgePositionTranslationsMap } from '@app/shared/models/mobile-app.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-mobile-app-qr-code-basic-config', |
||||
|
templateUrl: './mobile-app-qr-code-basic-config.component.html', |
||||
|
styleUrls: ['../basic-config.scss'] |
||||
|
}) |
||||
|
export class MobileAppQrCodeBasicConfigComponent extends BasicWidgetConfigComponent { |
||||
|
|
||||
|
mobileAppQrCodeWidgetConfigForm: UntypedFormGroup; |
||||
|
badgePositionTranslationsMap = badgePositionTranslationsMap; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected widgetConfigComponent: WidgetConfigComponent, |
||||
|
private cd: ChangeDetectorRef, |
||||
|
private $injector: Injector, |
||||
|
private fb: UntypedFormBuilder) { |
||||
|
super(store, widgetConfigComponent); |
||||
|
} |
||||
|
|
||||
|
protected configForm(): UntypedFormGroup { |
||||
|
return this.mobileAppQrCodeWidgetConfigForm; |
||||
|
} |
||||
|
|
||||
|
protected setupConfig(widgetConfig: WidgetConfigComponentData) { |
||||
|
super.setupConfig(widgetConfig); |
||||
|
} |
||||
|
|
||||
|
protected onConfigSet(configData: WidgetConfigComponentData) { |
||||
|
const settings: MobileAppQrCodeWidgetSettings = {...mobileAppQrCodeWidgetDefaultSettings, ...(configData.config.settings || {})}; |
||||
|
const iconSize = resolveCssSize(configData.config.iconSize); |
||||
|
|
||||
|
this.mobileAppQrCodeWidgetConfigForm = this.fb.group({ |
||||
|
useSystemSettings: [settings.useSystemSettings], |
||||
|
|
||||
|
badgeEnabled: [settings.qrCodeConfig.badgeEnabled], |
||||
|
badgePosition: [settings.qrCodeConfig.badgePosition], |
||||
|
qrCodeLabelEnabled: [settings.qrCodeConfig.qrCodeLabelEnabled], |
||||
|
qrCodeLabel: [settings.qrCodeConfig.qrCodeLabel], |
||||
|
|
||||
|
showTitle: [configData.config.showTitle, []], |
||||
|
title: [configData.config.title, []], |
||||
|
titleFont: [configData.config.titleFont, []], |
||||
|
titleColor: [configData.config.titleColor, []], |
||||
|
showTitleIcon: [configData.config.showTitleIcon, []], |
||||
|
iconSize: [iconSize[0], [Validators.min(0)]], |
||||
|
iconSizeUnit: [iconSize[1], []], |
||||
|
titleIcon: [configData.config.titleIcon, []], |
||||
|
iconColor: [configData.config.iconColor, []], |
||||
|
|
||||
|
background: [settings.background, []], |
||||
|
|
||||
|
cardButtons: [this.getCardButtons(configData.config), []], |
||||
|
borderRadius: [configData.config.borderRadius, []], |
||||
|
|
||||
|
actions: [configData.config.actions || {}, []] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
protected prepareOutputConfig(config: any): WidgetConfigComponentData { |
||||
|
this.widgetConfig.config.showTitle = config.showTitle; |
||||
|
this.widgetConfig.config.title = config.title; |
||||
|
this.widgetConfig.config.titleFont = config.titleFont; |
||||
|
this.widgetConfig.config.titleColor = config.titleColor; |
||||
|
|
||||
|
this.widgetConfig.config.showTitleIcon = config.showTitleIcon; |
||||
|
this.widgetConfig.config.iconSize = cssSizeToStrSize(config.iconSize, config.iconSizeUnit); |
||||
|
this.widgetConfig.config.titleIcon = config.titleIcon; |
||||
|
this.widgetConfig.config.iconColor = config.iconColor; |
||||
|
|
||||
|
this.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
||||
|
this.widgetConfig.config.settings.useSystemSettings = config.useSystemSettings; |
||||
|
this.widgetConfig.config.settings.qrCodeConfig = { |
||||
|
badgeEnabled: config.badgeEnabled, |
||||
|
badgePosition: config.badgePosition, |
||||
|
qrCodeLabelEnabled: config.qrCodeLabelEnabled, |
||||
|
qrCodeLabel: config.qrCodeLabel |
||||
|
}; |
||||
|
|
||||
|
this.widgetConfig.config.settings.background = config.background; |
||||
|
this.setCardButtons(config.cardButtons, this.widgetConfig.config); |
||||
|
this.widgetConfig.config.borderRadius = config.borderRadius; |
||||
|
|
||||
|
this.widgetConfig.config.actions = config.actions; |
||||
|
return this.widgetConfig; |
||||
|
} |
||||
|
|
||||
|
protected validatorTriggers(): string[] { |
||||
|
return ['showTitleIcon', 'badgeEnabled', 'qrCodeLabelEnabled', 'showTitleIcon', 'showTitle']; |
||||
|
} |
||||
|
|
||||
|
protected updateValidators(emitEvent: boolean, trigger?: string) { |
||||
|
const useSystemSettings = this.mobileAppQrCodeWidgetConfigForm.get('useSystemSettings').value; |
||||
|
|
||||
|
if (!useSystemSettings) { |
||||
|
const badgeEnabled = this.mobileAppQrCodeWidgetConfigForm.get('badgeEnabled').value; |
||||
|
const qrCodeLabelEnabled = this.mobileAppQrCodeWidgetConfigForm.get('qrCodeLabelEnabled').value; |
||||
|
const showTitleIcon: boolean = this.mobileAppQrCodeWidgetConfigForm.get('showTitleIcon').value; |
||||
|
const showTitle: boolean = this.mobileAppQrCodeWidgetConfigForm.get('showTitle').value; |
||||
|
|
||||
|
if (badgeEnabled) { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('badgePosition').enable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('badgePosition').disable({emitEvent: false}); |
||||
|
} |
||||
|
if (qrCodeLabelEnabled) { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('qrCodeLabel').enable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('qrCodeLabel').disable({emitEvent: false}); |
||||
|
} |
||||
|
if (showTitle) { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('title').enable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleFont').enable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleColor').enable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('showTitleIcon').enable({emitEvent: false}); |
||||
|
if (showTitleIcon) { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleIcon').enable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconColor').enable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconSize').enable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconSizeUnit').enable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleIcon').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconColor').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconSize').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconSizeUnit').disable({emitEvent: false}); |
||||
|
} |
||||
|
} else { |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('title').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleFont').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleColor').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('showTitleIcon').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('titleIcon').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconColor').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconSize').disable({emitEvent: false}); |
||||
|
this.mobileAppQrCodeWidgetConfigForm.get('iconSizeUnit').disable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private getCardButtons(config: WidgetConfig): string[] { |
||||
|
const buttons: string[] = []; |
||||
|
if (isUndefined(config.enableFullscreen) || config.enableFullscreen) { |
||||
|
buttons.push('fullscreen'); |
||||
|
} |
||||
|
return buttons; |
||||
|
} |
||||
|
|
||||
|
private setCardButtons(buttons: string[], config: WidgetConfig) { |
||||
|
config.enableFullscreen = buttons.includes('fullscreen'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue