31 changed files with 890 additions and 65 deletions
@ -0,0 +1,37 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div [formGroup]="keyRowFormGroup" class="tb-form-table-row tb-comparison-key-row"> |
|||
<mat-checkbox class="tb-show-field" formControlName="showValuesForComparison"></mat-checkbox> |
|||
<tb-data-key-input |
|||
[editable]="false" |
|||
[removable]="false" |
|||
[datasourceType]="datasourceType" |
|||
[formControl]="keyFormControl"> |
|||
</tb-data-key-input> |
|||
<div class="tb-label-field"> |
|||
<mat-form-field class="tb-inline-field" appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="comparisonValuesLabel" placeholder="{{ 'widgets.time-series-chart.comparison.comparison-values-label-auto' | translate }}"> |
|||
</mat-form-field> |
|||
</div> |
|||
<div class="tb-color-field"> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="color"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,54 @@ |
|||
/** |
|||
* 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 '../../../../../../../../scss/constants'; |
|||
|
|||
.tb-comparison-key-row { |
|||
.tb-show-field { |
|||
width: 40px; |
|||
min-width: 40px; |
|||
} |
|||
|
|||
.tb-data-key-input { |
|||
flex: 1; |
|||
@media #{$mat-gt-xs} { |
|||
min-width: 100px; |
|||
flex: 1 1 40%; |
|||
} |
|||
} |
|||
|
|||
.tb-label-field, .tb-color-field { |
|||
display: flex; |
|||
flex-direction: row; |
|||
place-content: center; |
|||
align-items: center; |
|||
.tb-inline-field { |
|||
flex: 1; |
|||
} |
|||
} |
|||
|
|||
.tb-label-field { |
|||
flex: 1; |
|||
@media #{$mat-gt-xs} { |
|||
min-width: 150px; |
|||
flex: 1 1 60%; |
|||
} |
|||
} |
|||
|
|||
.tb-color-field { |
|||
width: 40px; |
|||
min-width: 40px; |
|||
} |
|||
} |
|||
@ -0,0 +1,131 @@ |
|||
///
|
|||
/// 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, forwardRef, Input, OnInit, ViewEncapsulation } from '@angular/core'; |
|||
import { |
|||
ControlValueAccessor, |
|||
NG_VALUE_ACCESSOR, |
|||
UntypedFormBuilder, |
|||
UntypedFormControl, |
|||
UntypedFormGroup |
|||
} from '@angular/forms'; |
|||
import { |
|||
DataKey, |
|||
DataKeyComparisonSettings, |
|||
DataKeySettingsWithComparison, |
|||
DatasourceType |
|||
} from '@shared/models/widget.models'; |
|||
import { deepClone } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-comparison-key-row', |
|||
templateUrl: './comparison-key-row.component.html', |
|||
styleUrls: ['./comparison-key-row.component.scss', '../../data-keys.component.scss'], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => ComparisonKeyRowComponent), |
|||
multi: true |
|||
} |
|||
], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class ComparisonKeyRowComponent implements ControlValueAccessor, OnInit { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
@Input() |
|||
datasourceType: DatasourceType; |
|||
|
|||
keyFormControl: UntypedFormControl; |
|||
|
|||
keyRowFormGroup: UntypedFormGroup; |
|||
|
|||
modelValue: DataKey; |
|||
|
|||
private propagateChange = (_val: any) => {}; |
|||
|
|||
constructor(private fb: UntypedFormBuilder, |
|||
private cd: ChangeDetectorRef) { |
|||
} |
|||
|
|||
ngOnInit() { |
|||
this.keyFormControl = this.fb.control(null, []); |
|||
this.keyRowFormGroup = this.fb.group({ |
|||
showValuesForComparison: [null, []], |
|||
comparisonValuesLabel: [null, []], |
|||
color: [null, []] |
|||
}); |
|||
this.keyRowFormGroup.valueChanges.subscribe( |
|||
() => this.updateModel() |
|||
); |
|||
this.keyRowFormGroup.get('showValuesForComparison').valueChanges.subscribe(() => this.updateValidators()); |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(_fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (isDisabled) { |
|||
this.keyFormControl.disable({emitEvent: false}); |
|||
this.keyRowFormGroup.disable({emitEvent: false}); |
|||
} else { |
|||
this.keyFormControl.enable({emitEvent: false}); |
|||
this.keyRowFormGroup.enable({emitEvent: false}); |
|||
this.updateValidators(); |
|||
} |
|||
} |
|||
|
|||
writeValue(value: DataKey): void { |
|||
this.modelValue = value; |
|||
const comparisonSettings = (value?.settings as DataKeySettingsWithComparison)?.comparisonSettings; |
|||
this.keyRowFormGroup.patchValue( |
|||
comparisonSettings, {emitEvent: false} |
|||
); |
|||
this.keyFormControl.patchValue(deepClone(this.modelValue), {emitEvent: false}); |
|||
this.updateValidators(); |
|||
this.cd.markForCheck(); |
|||
} |
|||
|
|||
private updateValidators() { |
|||
const showValuesForComparison: boolean = this.keyRowFormGroup.get('showValuesForComparison').value; |
|||
if (showValuesForComparison) { |
|||
this.keyFormControl.enable({emitEvent: false}); |
|||
this.keyRowFormGroup.get('comparisonValuesLabel').enable({emitEvent: false}); |
|||
this.keyRowFormGroup.get('color').enable({emitEvent: false}); |
|||
} else { |
|||
this.keyFormControl.disable({emitEvent: false}); |
|||
this.keyRowFormGroup.get('comparisonValuesLabel').disable({emitEvent: false}); |
|||
this.keyRowFormGroup.get('color').disable({emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
private updateModel() { |
|||
const comparisonSettings: DataKeyComparisonSettings = this.keyRowFormGroup.value; |
|||
if (!this.modelValue.settings) { |
|||
this.modelValue.settings = {}; |
|||
} |
|||
this.modelValue.settings.comparisonSettings = comparisonSettings; |
|||
this.propagateChange(this.modelValue); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-comparison-keys-table tb-form-table"> |
|||
<div class="tb-form-table-header"> |
|||
<div class="tb-form-table-header-cell tb-show-header" translate>widgets.time-series-chart.comparison.show</div> |
|||
<div class="tb-form-table-header-cell tb-key-header" translate>datakey.key</div> |
|||
<div class="tb-form-table-header-cell tb-label-header" translate>datakey.label</div> |
|||
<div class="tb-form-table-header-cell tb-color-header" translate>datakey.color</div> |
|||
</div> |
|||
<div *ngIf="keysFormArray().controls.length; else noKeys" class="tb-form-table-body"> |
|||
<div *ngFor="let keyControl of keysFormArray().controls; trackBy: trackByKey; let $index = index;"> |
|||
<tb-comparison-key-row |
|||
fxFlex |
|||
[datasourceType]="datasourceType" |
|||
[formControl]="keyControl"> |
|||
</tb-comparison-key-row> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<ng-template #noKeys> |
|||
<span fxLayoutAlign="center center" |
|||
class="tb-prompt">{{ 'widgets.chart.no-series' | translate }}</span> |
|||
</ng-template> |
|||
@ -0,0 +1,53 @@ |
|||
/** |
|||
* 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 '../../../../../../../../scss/constants'; |
|||
|
|||
.tb-comparison-keys-table { |
|||
.tb-form-table-header-cell { |
|||
|
|||
&.tb-show-header { |
|||
width: 40px; |
|||
min-width: 40px; |
|||
} |
|||
|
|||
&.tb-key-header { |
|||
flex: 1; |
|||
@media #{$mat-gt-xs} { |
|||
min-width: 100px; |
|||
flex: 1 1 40%; |
|||
} |
|||
} |
|||
|
|||
&.tb-label-header { |
|||
flex: 1; |
|||
@media #{$mat-gt-xs} { |
|||
min-width: 150px; |
|||
flex: 1 1 60%; |
|||
} |
|||
} |
|||
|
|||
&.tb-color-header { |
|||
width: 40px; |
|||
min-width: 40px; |
|||
} |
|||
} |
|||
|
|||
.tb-form-table-body { |
|||
tb-comparison-key-row { |
|||
overflow: hidden; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,110 @@ |
|||
///
|
|||
/// 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 { Component, forwardRef, Input, OnInit, ViewEncapsulation } from '@angular/core'; |
|||
import { |
|||
AbstractControl, |
|||
ControlValueAccessor, |
|||
NG_VALUE_ACCESSOR, |
|||
UntypedFormArray, |
|||
UntypedFormBuilder, |
|||
UntypedFormGroup |
|||
} from '@angular/forms'; |
|||
import { DataKey, DatasourceType } from '@shared/models/widget.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-comparison-keys-table', |
|||
templateUrl: './comparison-keys-table.component.html', |
|||
styleUrls: ['./comparison-keys-table.component.scss'], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => ComparisonKeysTableComponent), |
|||
multi: true |
|||
} |
|||
], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class ComparisonKeysTableComponent implements ControlValueAccessor, OnInit { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
@Input() |
|||
datasourceType: DatasourceType; |
|||
|
|||
keysListFormGroup: UntypedFormGroup; |
|||
|
|||
get noKeys(): boolean { |
|||
const keys: DataKey[] = this.keysListFormGroup.get('keys').value; |
|||
return keys.length === 0; |
|||
} |
|||
|
|||
private propagateChange = (_val: any) => {}; |
|||
|
|||
constructor(private fb: UntypedFormBuilder) { |
|||
} |
|||
|
|||
ngOnInit() { |
|||
this.keysListFormGroup = this.fb.group({ |
|||
keys: [this.fb.array([]), []] |
|||
}); |
|||
this.keysListFormGroup.valueChanges.subscribe( |
|||
() => { |
|||
const keys: DataKey[] = this.keysListFormGroup.get('keys').value; |
|||
this.propagateChange(keys); |
|||
} |
|||
); |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(_fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
if (isDisabled) { |
|||
this.keysListFormGroup.disable({emitEvent: false}); |
|||
} else { |
|||
this.keysListFormGroup.enable({emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
writeValue(value: DataKey[] | undefined): void { |
|||
this.keysListFormGroup.setControl('keys', this.prepareKeysFormArray(value), {emitEvent: false}); |
|||
} |
|||
|
|||
keysFormArray(): UntypedFormArray { |
|||
return this.keysListFormGroup.get('keys') as UntypedFormArray; |
|||
} |
|||
|
|||
trackByKey(_index: number, keyControl: AbstractControl): any { |
|||
return keyControl; |
|||
} |
|||
|
|||
private prepareKeysFormArray(keys: DataKey[] | undefined): UntypedFormArray { |
|||
const keysControls: Array<AbstractControl> = []; |
|||
if (keys) { |
|||
keys.forEach((key) => { |
|||
keysControls.push(this.fb.control(key, [])); |
|||
}); |
|||
} |
|||
return this.fb.array(keysControls); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<button type="button" |
|||
mat-stroked-button |
|||
color="primary" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
(click)="openAxisSettingsPopup($event, matButton)" |
|||
matTooltip="{{ panelTitle }}" |
|||
matTooltipPosition="above"> |
|||
{{ (axisType === 'xAxis' ? 'widgets.time-series-chart.axis.x-axis' : 'widgets.time-series-chart.axis.y-axis') | translate }} |
|||
<tb-icon matButtonIcon>settings</tb-icon> |
|||
</button> |
|||
@ -0,0 +1,108 @@ |
|||
///
|
|||
/// 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 { Component, forwardRef, Input, OnInit, Renderer2, ViewContainerRef } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { coerceBoolean } from '@shared/decorators/coercion'; |
|||
import { TimeSeriesChartAxisSettings } from '@home/components/widget/lib/chart/time-series-chart.models'; |
|||
import { |
|||
TimeSeriesChartAxisSettingsPanelComponent |
|||
} from '@home/components/widget/lib/settings/common/chart/time-series-chart-axis-settings-panel.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-time-series-chart-axis-settings-button', |
|||
templateUrl: './time-series-chart-axis-settings-button.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => TimeSeriesChartAxisSettingsButtonComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class TimeSeriesChartAxisSettingsButtonComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
@Input() |
|||
axisType: 'xAxis' | 'yAxis' = 'xAxis'; |
|||
|
|||
@Input() |
|||
panelTitle: string; |
|||
|
|||
@Input() |
|||
@coerceBoolean() |
|||
advanced = false; |
|||
|
|||
private modelValue: TimeSeriesChartAxisSettings; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
constructor(private popoverService: TbPopoverService, |
|||
private renderer: Renderer2, |
|||
private viewContainerRef: ViewContainerRef) {} |
|||
|
|||
ngOnInit(): void { |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(_fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
} |
|||
|
|||
writeValue(value: TimeSeriesChartAxisSettings): void { |
|||
this.modelValue = value; |
|||
} |
|||
|
|||
openAxisSettingsPopup($event: Event, matButton: MatButton) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = matButton._elementRef.nativeElement; |
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const ctx: any = { |
|||
axisSettings: this.modelValue, |
|||
axisType: this.axisType, |
|||
panelTitle: this.panelTitle, |
|||
advanced: this.advanced |
|||
}; |
|||
const axisSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, TimeSeriesChartAxisSettingsPanelComponent, ['leftOnly', 'leftTopOnly', 'leftBottomOnly'], true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
axisSettingsPanelPopover.tbComponentRef.instance.popover = axisSettingsPanelPopover; |
|||
axisSettingsPanelPopover.tbComponentRef.instance.axisSettingsApplied.subscribe((axisSettings) => { |
|||
axisSettingsPanelPopover.hide(); |
|||
this.modelValue = axisSettings; |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue