34 changed files with 797 additions and 103 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,49 @@ |
|||
<!-- |
|||
|
|||
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-auto-date-format-settings-panel" [formGroup]="autoDateFormatFormGroup"> |
|||
<div class="tb-auto-date-format-settings-title" translate>date.time-granularity-formats</div> |
|||
<div class="tb-auto-date-format-settings-panel-content"> |
|||
<div class="tb-form-row" *ngFor="let unit of formatTimeUnits"> |
|||
<div class="fixed-title-width">{{ formatTimeUnitTranslations.get(unit) | translate }}</div> |
|||
<div fxFlex fxLayout="column" fxLayoutGap="8px" |
|||
fxLayout.gt-xs="row" fxLayoutAlign.gt-xs="start center" fxLayoutGap.gt-xs="16px"> |
|||
<mat-form-field class="tb-date-format-input flex" appearance="outline" subscriptSizing="dynamic"> |
|||
<input required matInput [formControlName]="unit" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matIconSuffix tb-help-popup="date/date-format" [tb-help-popup-style]="{width: '800px'}"></div> |
|||
</mat-form-field> |
|||
<mat-divider fxHide fxShow.gt-xs vertical></mat-divider> |
|||
<div class="preview-text" fxFlex>{{ previewText[unit] }}</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-auto-date-format-settings-panel-buttons"> |
|||
<button mat-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="applyAutoDateFormatSettings()" |
|||
[disabled]="autoDateFormatFormGroup.invalid || !autoDateFormatFormGroup.dirty"> |
|||
{{ 'action.apply' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,73 @@ |
|||
/** |
|||
* 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-auto-date-format-settings-panel { |
|||
width: 620px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
@media #{$mat-lt-md} { |
|||
width: 90vw; |
|||
} |
|||
.tb-auto-date-format-settings-title { |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
letter-spacing: 0.25px; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
.tb-auto-date-format-settings-panel-content { |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
overflow: auto; |
|||
margin: -10px; |
|||
padding: 10px; |
|||
} |
|||
.tb-form-row { |
|||
.fixed-title-width { |
|||
min-width: 120px; |
|||
} |
|||
.mat-mdc-form-field.tb-date-format-input { |
|||
.mat-mdc-text-field-wrapper.mdc-text-field--outlined { |
|||
.mat-mdc-form-field-flex { |
|||
.mat-mdc-form-field-icon-suffix { |
|||
display: flex; |
|||
align-items: center; |
|||
line-height: normal; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
.preview-text { |
|||
font-size: 14px; |
|||
font-style: normal; |
|||
font-weight: 400; |
|||
line-height: 20px; |
|||
letter-spacing: 0.2px; |
|||
color: rgba(0, 0, 0, 0.38); |
|||
} |
|||
} |
|||
.tb-auto-date-format-settings-panel-buttons { |
|||
height: 40px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
///
|
|||
/// 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, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { |
|||
AutoDateFormatSettings, defaultAutoDateFormatSettings, |
|||
FormatTimeUnit, |
|||
formatTimeUnits, |
|||
formatTimeUnitTranslations |
|||
} from '@shared/models/widget-settings.models'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { DatePipe } from '@angular/common'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-auto-date-format-settings-panel', |
|||
templateUrl: './auto-date-format-settings-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./auto-date-format-settings-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class AutoDateFormatSettingsPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
formatTimeUnits = formatTimeUnits; |
|||
|
|||
formatTimeUnitTranslations = formatTimeUnitTranslations; |
|||
|
|||
@Input() |
|||
autoDateFormatSettings: AutoDateFormatSettings; |
|||
|
|||
@Input() |
|||
defaultValues = defaultAutoDateFormatSettings; |
|||
|
|||
@Input() |
|||
popover: TbPopoverComponent<AutoDateFormatSettingsPanelComponent>; |
|||
|
|||
@Output() |
|||
autoDateFormatSettingsApplied = new EventEmitter<AutoDateFormatSettings>(); |
|||
|
|||
autoDateFormatFormGroup: UntypedFormGroup; |
|||
|
|||
previewText: {[unit in FormatTimeUnit]: string} = {} as any; |
|||
|
|||
constructor(private date: DatePipe, |
|||
private fb: UntypedFormBuilder, |
|||
protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.autoDateFormatFormGroup = this.fb.group({}); |
|||
for (const unit of formatTimeUnits) { |
|||
this.autoDateFormatFormGroup.addControl(unit, |
|||
this.fb.control(this.autoDateFormatSettings[unit] || this.defaultValues[unit], [Validators.required])); |
|||
this.autoDateFormatFormGroup.get(unit).valueChanges.subscribe((value: string) => { |
|||
this.previewText[unit] = this.date.transform(Date.now(), value); |
|||
}); |
|||
this.previewText[unit] = this.date.transform(Date.now(), this.autoDateFormatSettings[unit] || this.defaultValues[unit]); |
|||
} |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
applyAutoDateFormatSettings() { |
|||
const autoDateFormatSettings: AutoDateFormatSettings = this.autoDateFormatFormGroup.value; |
|||
for (const unit of formatTimeUnits) { |
|||
if (autoDateFormatSettings[unit] === this.defaultValues[unit]) { |
|||
delete autoDateFormatSettings[unit]; |
|||
} |
|||
} |
|||
this.autoDateFormatSettingsApplied.emit(autoDateFormatSettings); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<!-- |
|||
|
|||
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 |
|||
class="tb-box-button" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
(click)="openAutoFormatSettingsPopup($event, matButton)"> |
|||
<tb-icon matButtonIcon>mdi:clock-edit-outline</tb-icon> |
|||
</button> |
|||
@ -0,0 +1,99 @@ |
|||
///
|
|||
/// 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 { AutoDateFormatSettings, defaultAutoDateFormatSettings } from '@shared/models/widget-settings.models'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { deepClone, mergeDeep } from '@core/utils'; |
|||
import { |
|||
AutoDateFormatSettingsPanelComponent |
|||
} from '@home/components/widget/lib/settings/common/auto-date-format-settings-panel.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-auto-date-format-settings', |
|||
templateUrl: './auto-date-format-settings.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => AutoDateFormatSettingsComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class AutoDateFormatSettingsComponent implements OnInit, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
@Input() |
|||
defaultValues = defaultAutoDateFormatSettings; |
|||
|
|||
private modelValue: AutoDateFormatSettings; |
|||
|
|||
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: AutoDateFormatSettings): void { |
|||
this.modelValue = value; |
|||
} |
|||
|
|||
openAutoFormatSettingsPopup($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 = { |
|||
autoDateFormatSettings: deepClone(this.modelValue), |
|||
defaultValues: this.defaultValues |
|||
}; |
|||
const autoDateFormatSettingsPanelPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, AutoDateFormatSettingsPanelComponent, ['leftOnly', 'leftTopOnly', 'leftBottomOnly'], true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
autoDateFormatSettingsPanelPopover.tbComponentRef.instance.popover = autoDateFormatSettingsPanelPopover; |
|||
autoDateFormatSettingsPanelPopover.tbComponentRef.instance.autoDateFormatSettingsApplied.subscribe((autoDateFormatSettings) => { |
|||
autoDateFormatSettingsPanelPopover.hide(); |
|||
this.modelValue = autoDateFormatSettings; |
|||
this.propagateChange(this.modelValue); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue