|
|
|
@ -14,7 +14,7 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, Injector } from '@angular/core'; |
|
|
|
import { Component } from '@angular/core'; |
|
|
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
import { AppState } from '@core/core.state'; |
|
|
|
@ -35,6 +35,7 @@ import { formatValue, isUndefined } from '@core/utils'; |
|
|
|
import { cssSizeToStrSize, resolveCssSize } from '@shared/models/widget-settings.models'; |
|
|
|
import { |
|
|
|
batteryLevelDefaultSettings, |
|
|
|
BatteryLevelLayout, |
|
|
|
batteryLevelLayoutImages, |
|
|
|
batteryLevelLayouts, |
|
|
|
batteryLevelLayoutTranslations, |
|
|
|
@ -67,9 +68,13 @@ export class BatteryLevelBasicConfigComponent extends BasicWidgetConfigComponent |
|
|
|
|
|
|
|
valuePreviewFn = this._valuePreviewFn.bind(this); |
|
|
|
|
|
|
|
get sectionsCountEnabled(): boolean { |
|
|
|
const layout: BatteryLevelLayout = this.batteryLevelWidgetConfigForm.get('layout').value; |
|
|
|
return [BatteryLevelLayout.vertical_divided, BatteryLevelLayout.horizontal_divided].includes(layout); |
|
|
|
} |
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>, |
|
|
|
protected widgetConfigComponent: WidgetConfigComponent, |
|
|
|
private $injector: Injector, |
|
|
|
private fb: UntypedFormBuilder) { |
|
|
|
super(store, widgetConfigComponent); |
|
|
|
} |
|
|
|
@ -90,6 +95,7 @@ export class BatteryLevelBasicConfigComponent extends BasicWidgetConfigComponent |
|
|
|
datasources: [configData.config.datasources, []], |
|
|
|
|
|
|
|
layout: [settings.layout, []], |
|
|
|
sectionsCount: [settings.sectionsCount, [Validators.min(2), Validators.max(20)]], |
|
|
|
|
|
|
|
showTitle: [configData.config.showTitle, []], |
|
|
|
title: [configData.config.title, []], |
|
|
|
@ -136,6 +142,7 @@ export class BatteryLevelBasicConfigComponent extends BasicWidgetConfigComponent |
|
|
|
this.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
|
|
|
|
|
|
|
this.widgetConfig.config.settings.layout = config.layout; |
|
|
|
this.widgetConfig.config.settings.sectionsCount = config.sectionsCount; |
|
|
|
|
|
|
|
this.widgetConfig.config.settings.showValue = config.showValue; |
|
|
|
this.widgetConfig.config.settings.autoScaleValueSize = config.autoScaleValueSize === true; |
|
|
|
@ -155,13 +162,15 @@ export class BatteryLevelBasicConfigComponent extends BasicWidgetConfigComponent |
|
|
|
} |
|
|
|
|
|
|
|
protected validatorTriggers(): string[] { |
|
|
|
return ['showTitle', 'showIcon', 'showValue']; |
|
|
|
return ['showTitle', 'showIcon', 'showValue', 'layout']; |
|
|
|
} |
|
|
|
|
|
|
|
protected updateValidators(emitEvent: boolean, trigger?: string) { |
|
|
|
const showTitle: boolean = this.batteryLevelWidgetConfigForm.get('showTitle').value; |
|
|
|
const showIcon: boolean = this.batteryLevelWidgetConfigForm.get('showIcon').value; |
|
|
|
const showValue: boolean = this.batteryLevelWidgetConfigForm.get('showValue').value; |
|
|
|
const layout: BatteryLevelLayout = this.batteryLevelWidgetConfigForm.get('layout').value; |
|
|
|
const divided = [BatteryLevelLayout.vertical_divided, BatteryLevelLayout.horizontal_divided].includes(layout); |
|
|
|
|
|
|
|
if (showTitle) { |
|
|
|
this.batteryLevelWidgetConfigForm.get('title').enable(); |
|
|
|
@ -199,6 +208,11 @@ export class BatteryLevelBasicConfigComponent extends BasicWidgetConfigComponent |
|
|
|
this.batteryLevelWidgetConfigForm.get('valueFont').disable(); |
|
|
|
this.batteryLevelWidgetConfigForm.get('valueColor').disable(); |
|
|
|
} |
|
|
|
if (divided) { |
|
|
|
this.batteryLevelWidgetConfigForm.get('sectionsCount').enable(); |
|
|
|
} else { |
|
|
|
this.batteryLevelWidgetConfigForm.get('sectionsCount').disable(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private getCardButtons(config: WidgetConfig): string[] { |
|
|
|
|