5 changed files with 298 additions and 4 deletions
@ -0,0 +1,146 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 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. |
||||
|
|
||||
|
--> |
||||
|
<section class="tb-widget-settings" [formGroup]="dateRangeNavigatorWidgetSettingsForm" fxLayout="column"> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.date-range-navigator.date-range-picker-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="!dateRangeNavigatorWidgetSettingsForm.get('hidePicker').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="hidePicker" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.date-range-navigator.hide-date-range-picker' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<section fxLayout="column" fxFlex> |
||||
|
<mat-checkbox formControlName="onePanel" style="margin-bottom: 16px;"> |
||||
|
{{ 'widgets.date-range-navigator.picker-one-panel' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<mat-checkbox formControlName="autoConfirm" style="margin-bottom: 16px;"> |
||||
|
{{ 'widgets.date-range-navigator.picker-auto-confirm' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<mat-checkbox formControlName="showTemplate" style="margin-bottom: 16px;"> |
||||
|
{{ 'widgets.date-range-navigator.picker-show-template' | translate }} |
||||
|
</mat-checkbox> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.date-range-navigator.first-day-of-week</mat-label> |
||||
|
<input matInput type="number" min="1" max="7" step="1" formControlName="firstDayOfWeek"> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.date-range-navigator.interval-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="!dateRangeNavigatorWidgetSettingsForm.get('hideInterval').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="hideInterval" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.date-range-navigator.hide-interval' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.date-range-navigator.initial-interval</mat-label> |
||||
|
<mat-select formControlName="initialInterval"> |
||||
|
<mat-option [value]="'hour'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-hour' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'day'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-day' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'week'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-week' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'twoWeeks'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-two-weeks' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'month'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-month' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'threeMonths'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-three-months' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'sixMonths'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-six-months' | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.date-range-navigator.step-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="!dateRangeNavigatorWidgetSettingsForm.get('hideStepSize').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="hideStepSize" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.date-range-navigator.hide-step-size' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.date-range-navigator.initial-step-size</mat-label> |
||||
|
<mat-select formControlName="stepSize"> |
||||
|
<mat-option [value]="'hour'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-hour' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'day'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-day' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'week'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-week' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'twoWeeks'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-two-weeks' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'month'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-month' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'threeMonths'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-three-months' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'sixMonths'"> |
||||
|
{{ 'widgets.date-range-navigator.interval-six-months' | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
<mat-slide-toggle formControlName="hideLabels" class="slide-block"> |
||||
|
{{ 'widgets.date-range-navigator.hide-labels' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<mat-slide-toggle formControlName="useSessionStorage" class="slide-block"> |
||||
|
{{ 'widgets.date-range-navigator.use-session-storage' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</section> |
||||
@ -0,0 +1,120 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 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 } from '@angular/core'; |
||||
|
import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; |
||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-date-range-navigator-widget-settings', |
||||
|
templateUrl: './date-range-navigator-widget-settings.component.html', |
||||
|
styleUrls: ['./../widget-settings.scss'] |
||||
|
}) |
||||
|
export class DateRangeNavigatorWidgetSettingsComponent extends WidgetSettingsComponent { |
||||
|
|
||||
|
dateRangeNavigatorWidgetSettingsForm: FormGroup; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
private fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
protected settingsForm(): FormGroup { |
||||
|
return this.dateRangeNavigatorWidgetSettingsForm; |
||||
|
} |
||||
|
|
||||
|
protected defaultSettings(): WidgetSettings { |
||||
|
return { |
||||
|
hidePicker: false, |
||||
|
onePanel: false, |
||||
|
autoConfirm: false, |
||||
|
showTemplate: false, |
||||
|
firstDayOfWeek: 1, |
||||
|
hideInterval: false, |
||||
|
initialInterval: 'week', |
||||
|
hideStepSize: false, |
||||
|
stepSize: 'day', |
||||
|
hideLabels: false, |
||||
|
useSessionStorage: true |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
protected onSettingsSet(settings: WidgetSettings) { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm = this.fb.group({ |
||||
|
|
||||
|
// Date range picker settings
|
||||
|
|
||||
|
hidePicker: [settings.hidePicker, []], |
||||
|
onePanel: [settings.onePanel, []], |
||||
|
autoConfirm: [settings.autoConfirm, []], |
||||
|
showTemplate: [settings.showTemplate, []], |
||||
|
firstDayOfWeek: [settings.firstDayOfWeek, [Validators.min(1), Validators.max(7)]], |
||||
|
|
||||
|
// Interval settings
|
||||
|
|
||||
|
hideInterval: [settings.hideInterval, []], |
||||
|
initialInterval: [settings.initialInterval, []], |
||||
|
|
||||
|
// Step settings
|
||||
|
|
||||
|
hideStepSize: [settings.hideStepSize, []], |
||||
|
stepSize: [settings.stepSize, []], |
||||
|
|
||||
|
hideLabels: [settings.hideLabels, []], |
||||
|
useSessionStorage: [settings.useSessionStorage, []], |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
protected validatorTriggers(): string[] { |
||||
|
return ['hidePicker', 'hideInterval', 'hideStepSize']; |
||||
|
} |
||||
|
|
||||
|
protected updateValidators(emitEvent: boolean) { |
||||
|
const hidePicker: boolean = this.dateRangeNavigatorWidgetSettingsForm.get('hidePicker').value; |
||||
|
const hideInterval: boolean = this.dateRangeNavigatorWidgetSettingsForm.get('hideInterval').value; |
||||
|
const hideStepSize: boolean = this.dateRangeNavigatorWidgetSettingsForm.get('hideStepSize').value; |
||||
|
if (hidePicker) { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('onePanel').disable(); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('autoConfirm').disable(); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('showTemplate').disable(); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('firstDayOfWeek').disable(); |
||||
|
} else { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('onePanel').enable(); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('autoConfirm').enable(); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('showTemplate').enable(); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('firstDayOfWeek').enable(); |
||||
|
} |
||||
|
if (hideInterval) { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('initialInterval').disable(); |
||||
|
} else { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('initialInterval').enable(); |
||||
|
} |
||||
|
if (hideStepSize) { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('stepSize').disable(); |
||||
|
} else { |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('stepSize').enable(); |
||||
|
} |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('onePanel').updateValueAndValidity({emitEvent}); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('autoConfirm').updateValueAndValidity({emitEvent}); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('showTemplate').updateValueAndValidity({emitEvent}); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('firstDayOfWeek').updateValueAndValidity({emitEvent}); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('initialInterval').updateValueAndValidity({emitEvent}); |
||||
|
this.dateRangeNavigatorWidgetSettingsForm.get('stepSize').updateValueAndValidity({emitEvent}); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue