76 changed files with 1001 additions and 363 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,97 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2023 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-timewindow-style-panel" [formGroup]="timewindowStyleFormGroup"> |
|||
<div class="tb-timewindow-style-title" translate>timewindow.style</div> |
|||
<div class="tb-form-row space-between"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showIcon"> |
|||
{{ 'timewindow.icon' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="iconSize"> |
|||
</mat-form-field> |
|||
<tb-material-icon-select asBoxInput |
|||
iconClearButton |
|||
formControlName="icon"> |
|||
</tb-material-icon-select> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" translate>timewindow.icon-position</div> |
|||
<mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic"> |
|||
<mat-select formControlName="iconPosition" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<mat-option [value]="'left'"> |
|||
{{ 'timewindow.icon-position-left' | translate }} |
|||
</mat-option> |
|||
<mat-option [value]="'right'"> |
|||
{{ 'timewindow.icon-position-right' | translate }} |
|||
</mat-option> |
|||
</mat-select> |
|||
</mat-form-field> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div translate>timewindow.font</div> |
|||
<tb-font-settings |
|||
clearButton |
|||
[previewText]="timewindowComponent.displayValue()" |
|||
[initialPreviewStyle]="{fontSize: '14px', |
|||
color: 'rgba(0, 0, 0, 0.87)', |
|||
opacity: '0.85', |
|||
lineHeight: 'normal', |
|||
letterSpacing: 'normal'}" |
|||
formControlName="font"> |
|||
</tb-font-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div translate>timewindow.color</div> |
|||
<tb-color-input |
|||
formControlName="color" |
|||
colorClearButton |
|||
asBoxInput> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider></mat-divider> |
|||
<div class="tb-form-row no-border no-padding timewindow-preview"> |
|||
<div class="fixed-title-width" translate>timewindow.preview</div> |
|||
<tb-timewindow #timewindowComponent |
|||
disablePanel |
|||
alwaysDisplayTypePrefix |
|||
timezone="true" |
|||
noMargin |
|||
noPadding |
|||
[timewindowStyle]="previewTimewindowStyle" |
|||
[ngModel]="previewValue" |
|||
[ngModelOptions]="{standalone: true}"> |
|||
</tb-timewindow> |
|||
</div> |
|||
<div class="tb-timewindow-style-panel-buttons"> |
|||
<button mat-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="applyTimewindowStyle()" |
|||
[disabled]="timewindowStyleFormGroup.invalid || !timewindowStyleFormGroup.dirty"> |
|||
{{ 'action.apply' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,54 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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-timewindow-style-panel { |
|||
width: 100%; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
@media #{$mat-gt-xs} { |
|||
min-width: 320px; |
|||
} |
|||
.tb-timewindow-style-title { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.tb-form-row { |
|||
.fixed-title-width { |
|||
min-width: 120px; |
|||
} |
|||
&.timewindow-preview { |
|||
align-items: flex-start; |
|||
tb-timewindow { |
|||
font-size: 14px; |
|||
opacity: .85; |
|||
} |
|||
} |
|||
} |
|||
.tb-timewindow-style-panel-buttons { |
|||
height: 60px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
///
|
|||
/// Copyright © 2016-2023 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, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { defaultTimewindowStyle, TimewindowStyle } from '@shared/models/widget-settings.models'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Timewindow } from '@shared/models/time/time.models'; |
|||
import { deepClone } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-timewindow-style-panel', |
|||
templateUrl: './timewindow-style-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./timewindow-style-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class TimewindowStylePanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() |
|||
timewindowStyle: TimewindowStyle; |
|||
|
|||
@Input() |
|||
previewValue: Timewindow; |
|||
|
|||
@Input() |
|||
popover: TbPopoverComponent<TimewindowStylePanelComponent>; |
|||
|
|||
@Output() |
|||
timewindowStyleApplied = new EventEmitter<TimewindowStyle>(); |
|||
|
|||
timewindowStyleFormGroup: UntypedFormGroup; |
|||
|
|||
previewTimewindowStyle: TimewindowStyle; |
|||
|
|||
constructor(private fb: UntypedFormBuilder, |
|||
protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
const computedTimewindowStyle = {...defaultTimewindowStyle, ...(this.timewindowStyle || {})}; |
|||
this.timewindowStyleFormGroup = this.fb.group( |
|||
{ |
|||
showIcon: [computedTimewindowStyle.showIcon, []], |
|||
iconSize: [computedTimewindowStyle.iconSize, []], |
|||
icon: [computedTimewindowStyle.icon, []], |
|||
iconPosition: [computedTimewindowStyle.iconPosition, []], |
|||
font: [computedTimewindowStyle.font, []], |
|||
color: [computedTimewindowStyle.color, []] |
|||
} |
|||
); |
|||
this.updatePreviewStyle(this.timewindowStyle); |
|||
this.updateTimewindowStyleEnabledState(); |
|||
this.timewindowStyleFormGroup.valueChanges.subscribe((timewindowStyle: TimewindowStyle) => { |
|||
if (this.timewindowStyleFormGroup.valid) { |
|||
this.updatePreviewStyle(timewindowStyle); |
|||
setTimeout(() => {this.popover?.updatePosition();}, 0); |
|||
} |
|||
}); |
|||
this.timewindowStyleFormGroup.get('showIcon').valueChanges.subscribe(() => { |
|||
this.updateTimewindowStyleEnabledState(); |
|||
}); |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
applyTimewindowStyle() { |
|||
const timewindowStyle = this.timewindowStyleFormGroup.getRawValue(); |
|||
this.timewindowStyleApplied.emit(timewindowStyle); |
|||
} |
|||
|
|||
private updateTimewindowStyleEnabledState() { |
|||
const showIcon: boolean = this.timewindowStyleFormGroup.get('showIcon').value; |
|||
if (showIcon) { |
|||
this.timewindowStyleFormGroup.get('iconSize').enable({emitEvent: false}); |
|||
this.timewindowStyleFormGroup.get('icon').enable({emitEvent: false}); |
|||
this.timewindowStyleFormGroup.get('iconPosition').enable({emitEvent: false}); |
|||
} else { |
|||
this.timewindowStyleFormGroup.get('iconSize').disable({emitEvent: false}); |
|||
this.timewindowStyleFormGroup.get('icon').disable({emitEvent: false}); |
|||
this.timewindowStyleFormGroup.get('iconPosition').disable({emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
private updatePreviewStyle(timewindowStyle: TimewindowStyle) { |
|||
this.previewTimewindowStyle = deepClone(timewindowStyle); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2023 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 |
|||
class="tb-box-button" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
(click)="openTimewindowStylePopup($event, matButton)"> |
|||
<tb-icon matButtonIcon>format_paint</tb-icon> |
|||
</button> |
|||
@ -0,0 +1,97 @@ |
|||
///
|
|||
/// Copyright © 2016-2023 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 { TimewindowStyle } from '@shared/models/widget-settings.models'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { Timewindow } from '@shared/models/time/time.models'; |
|||
import { TimewindowStylePanelComponent } from '@home/components/widget/config/timewindow-style-panel.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-timewindow-style', |
|||
templateUrl: './timewindow-style.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => TimewindowStyleComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class TimewindowStyleComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
@Input() |
|||
previewValue: Timewindow; |
|||
|
|||
private modelValue: TimewindowStyle; |
|||
|
|||
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: TimewindowStyle): void { |
|||
this.modelValue = value; |
|||
} |
|||
|
|||
openTimewindowStylePopup($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 = { |
|||
timewindowStyle: this.modelValue, |
|||
previewValue: this.previewValue |
|||
}; |
|||
const timewindowStylePanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, TimewindowStylePanelComponent, 'left', true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
timewindowStylePanelPopover.tbComponentRef.instance.popover = timewindowStylePanelPopover; |
|||
timewindowStylePanelPopover.tbComponentRef.instance.timewindowStyleApplied.subscribe((timewindowStyle) => { |
|||
timewindowStylePanelPopover.hide(); |
|||
this.modelValue = timewindowStyle; |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue