38 changed files with 905 additions and 168 deletions
@ -0,0 +1,62 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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. |
|||
|
|||
--> |
|||
<form [formGroup]="filterUserInfoFormGroup" (ngSubmit)="save()" style="width: 500px;"> |
|||
<mat-toolbar color="primary"> |
|||
<h2 translate>filter.edit-filter-user-params</h2> |
|||
<span fxFlex></span> |
|||
<button mat-icon-button |
|||
(click)="cancel()" |
|||
type="button"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
</mat-toolbar> |
|||
<div mat-dialog-content> |
|||
<fieldset [disabled]="isLoading$ | async" fxLayout="column"> |
|||
<mat-checkbox fxFlex formControlName="editable" style="margin-bottom: 16px;"> |
|||
{{ 'filter.editable' | translate }} |
|||
</mat-checkbox> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field fxFlex class="mat-block"> |
|||
<mat-label translate>filter.display-label</mat-label> |
|||
<input matInput formControlName="label"> |
|||
</mat-form-field> |
|||
<mat-checkbox formControlName="autogeneratedLabel"> |
|||
{{ 'filter.autogenerated-label' | translate }} |
|||
</mat-checkbox> |
|||
</div> |
|||
<mat-form-field fxFlex class="mat-block"> |
|||
<mat-label translate>filter.order-priority</mat-label> |
|||
<input matInput type="number" formControlName="order"> |
|||
</mat-form-field> |
|||
</fieldset> |
|||
</div> |
|||
<div mat-dialog-actions fxLayoutAlign="end center"> |
|||
<button mat-raised-button color="primary" |
|||
type="submit" |
|||
[disabled]="(isLoading$ | async) || filterUserInfoFormGroup.invalid || !filterUserInfoFormGroup.dirty"> |
|||
{{ 'action.update' | translate }} |
|||
</button> |
|||
<button mat-button color="primary" |
|||
type="button" |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="cancel()" |
|||
cdkFocusInitial> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
</div> |
|||
</form> |
|||
@ -0,0 +1,108 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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, Inject, OnInit, SkipSelf } from '@angular/core'; |
|||
import { ErrorStateMatcher } from '@angular/material/core'; |
|||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms'; |
|||
import { Router } from '@angular/router'; |
|||
import { DialogComponent } from '@app/shared/components/dialog.component'; |
|||
import { |
|||
BooleanOperation, |
|||
EntityKeyValueType, generateUserFilterValueLabel, |
|||
KeyFilterPredicateUserInfo, NumericOperation, |
|||
StringOperation |
|||
} from '@shared/models/query/query.models'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
|
|||
export interface FilterUserInfoDialogData { |
|||
key: string; |
|||
valueType: EntityKeyValueType; |
|||
operation: StringOperation | BooleanOperation | NumericOperation; |
|||
keyFilterPredicateUserInfo: KeyFilterPredicateUserInfo; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'tb-filter-user-info-dialog', |
|||
templateUrl: './filter-user-info-dialog.component.html', |
|||
providers: [{provide: ErrorStateMatcher, useExisting: FilterUserInfoDialogComponent}], |
|||
styleUrls: [] |
|||
}) |
|||
export class FilterUserInfoDialogComponent extends |
|||
DialogComponent<FilterUserInfoDialogComponent, KeyFilterPredicateUserInfo> |
|||
implements OnInit, ErrorStateMatcher { |
|||
|
|||
filterUserInfoFormGroup: FormGroup; |
|||
|
|||
submitted = false; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected router: Router, |
|||
@Inject(MAT_DIALOG_DATA) public data: FilterUserInfoDialogData, |
|||
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
|||
public dialogRef: MatDialogRef<FilterUserInfoDialogComponent, KeyFilterPredicateUserInfo>, |
|||
private fb: FormBuilder, |
|||
private translate: TranslateService) { |
|||
super(store, router, dialogRef); |
|||
|
|||
this.filterUserInfoFormGroup = this.fb.group( |
|||
{ |
|||
editable: [this.data.keyFilterPredicateUserInfo.editable], |
|||
label: [this.data.keyFilterPredicateUserInfo.label], |
|||
autogeneratedLabel: [this.data.keyFilterPredicateUserInfo.autogeneratedLabel], |
|||
order: [this.data.keyFilterPredicateUserInfo.order] |
|||
} |
|||
); |
|||
this.onAutogeneratedLabelChange(); |
|||
this.filterUserInfoFormGroup.get('autogeneratedLabel').valueChanges.subscribe(() => { |
|||
this.onAutogeneratedLabelChange(); |
|||
}); |
|||
} |
|||
|
|||
private onAutogeneratedLabelChange() { |
|||
const autogeneratedLabel: boolean = this.filterUserInfoFormGroup.get('autogeneratedLabel').value; |
|||
if (autogeneratedLabel) { |
|||
const generatedLabel = generateUserFilterValueLabel(this.data.key, this.data.valueType, this.data.operation, this.translate); |
|||
this.filterUserInfoFormGroup.get('label').patchValue(generatedLabel, {emitEvent: false}); |
|||
this.filterUserInfoFormGroup.get('label').disable({emitEvent: false}); |
|||
} else { |
|||
this.filterUserInfoFormGroup.get('label').enable({emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
} |
|||
|
|||
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
|||
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
|||
const customErrorState = !!(control && control.invalid && this.submitted); |
|||
return originalErrorState || customErrorState; |
|||
} |
|||
|
|||
cancel(): void { |
|||
this.dialogRef.close(null); |
|||
} |
|||
|
|||
save(): void { |
|||
this.submitted = true; |
|||
if (this.filterUserInfoFormGroup.valid) { |
|||
const keyFilterPredicateUserInfo: KeyFilterPredicateUserInfo = this.filterUserInfoFormGroup.getRawValue(); |
|||
this.dialogRef.close(keyFilterPredicateUserInfo); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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 mat-icon-button color="primary" |
|||
class="tb-mat-32" |
|||
[fxShow]="!disabled" |
|||
type="button" |
|||
(click)="openFilterUserInfoDialog()" |
|||
matTooltip="{{ 'filter.edit-filter-user-params' | translate }}" |
|||
matTooltipPosition="above"> |
|||
<mat-icon>settings</mat-icon> |
|||
</button> |
|||
@ -0,0 +1,104 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 } from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
import { |
|||
BooleanOperation, |
|||
EntityKeyValueType, |
|||
KeyFilterPredicateUserInfo, NumericOperation, |
|||
StringOperation |
|||
} from '@shared/models/query/query.models'; |
|||
import { MatDialog } from '@angular/material/dialog'; |
|||
import { |
|||
FilterUserInfoDialogComponent, |
|||
FilterUserInfoDialogData |
|||
} from '@home/components/filter/filter-user-info-dialog.component'; |
|||
import { deepClone } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-filter-user-info', |
|||
templateUrl: './filter-user-info.component.html', |
|||
styleUrls: [], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => FilterUserInfoComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class FilterUserInfoComponent implements ControlValueAccessor, OnInit { |
|||
|
|||
@Input() disabled: boolean; |
|||
|
|||
@Input() key: string; |
|||
|
|||
@Input() operation: StringOperation | BooleanOperation | NumericOperation; |
|||
|
|||
@Input() valueType: EntityKeyValueType; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
private keyFilterPredicateUserInfo: KeyFilterPredicateUserInfo; |
|||
|
|||
constructor(private dialog: MatDialog) { |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState?(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
} |
|||
|
|||
writeValue(keyFilterPredicateUserInfo: KeyFilterPredicateUserInfo): void { |
|||
this.keyFilterPredicateUserInfo = keyFilterPredicateUserInfo; |
|||
} |
|||
|
|||
private openFilterUserInfoDialog() { |
|||
this.dialog.open<FilterUserInfoDialogComponent, FilterUserInfoDialogData, |
|||
KeyFilterPredicateUserInfo>(FilterUserInfoDialogComponent, { |
|||
disableClose: true, |
|||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|||
data: { |
|||
keyFilterPredicateUserInfo: deepClone(this.keyFilterPredicateUserInfo), |
|||
valueType: this.valueType, |
|||
key: this.key, |
|||
operation: this.operation |
|||
} |
|||
}).afterClosed().subscribe( |
|||
(result) => { |
|||
if (result) { |
|||
this.keyFilterPredicateUserInfo = result; |
|||
this.updateModel(); |
|||
} |
|||
} |
|||
); |
|||
} |
|||
|
|||
private updateModel() { |
|||
this.propagateChange(this.keyFilterPredicateUserInfo); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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. |
|||
|
|||
--> |
|||
<form [formGroup]="userFilterFormGroup" (ngSubmit)="save()" style="width: 400px;"> |
|||
<mat-toolbar color="primary"> |
|||
<h2>{{ filter.filter }}</h2> |
|||
<span fxFlex></span> |
|||
<button mat-icon-button |
|||
(click)="cancel()" |
|||
type="button"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
</mat-toolbar> |
|||
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
|||
</mat-progress-bar> |
|||
<div mat-dialog-content> |
|||
<fieldset [disabled]="isLoading$ | async"> |
|||
<div fxFlex fxLayout="column"> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" |
|||
formArrayName="userInputs" |
|||
*ngFor="let userInputControl of userInputsFormArray().controls; let $index = index"> |
|||
<div fxFlex fxLayout="column" |
|||
[ngSwitch]="userInputControl.get('valueType').value"> |
|||
<ng-template [ngSwitchCase]="valueTypeEnum.STRING"> |
|||
<mat-form-field fxFlex class="mat-block"> |
|||
<mat-label>{{ userInputControl.get('label').value }}</mat-label> |
|||
<input matInput [formControl]="userInputControl.get('value')"> |
|||
</mat-form-field> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="valueTypeEnum.NUMERIC"> |
|||
<mat-form-field fxFlex class="mat-block"> |
|||
<mat-label>{{ userInputControl.get('label').value }}</mat-label> |
|||
<input required type="number" matInput [formControl]="userInputControl.get('value')"> |
|||
</mat-form-field> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="valueTypeEnum.DATE_TIME"> |
|||
<label class="tb-title no-padding tb-required">{{ userInputControl.get('label').value }}</label> |
|||
<tb-datetime fxFlex [formControl]="userInputControl.get('value')" |
|||
dateText="filter.date" |
|||
timeText="filter.time" |
|||
required [showLabel]="false"></tb-datetime> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="valueTypeEnum.BOOLEAN"> |
|||
<mat-checkbox labelPosition="before" fxFlex [formControl]="userInputControl.get('value')"> |
|||
{{ userInputControl.get('label').value }} |
|||
</mat-checkbox> |
|||
</ng-template> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</fieldset> |
|||
</div> |
|||
<div mat-dialog-actions fxLayoutAlign="end center"> |
|||
<button mat-raised-button color="primary" |
|||
type="submit" |
|||
[disabled]="(isLoading$ | async) || userFilterFormGroup.invalid || !userFilterFormGroup.dirty"> |
|||
{{ 'action.update' | translate }} |
|||
</button> |
|||
<button mat-button color="primary" |
|||
type="button" |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="cancel()" cdkFocusInitial> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
</div> |
|||
</form> |
|||
@ -0,0 +1,118 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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, Inject, OnInit, SkipSelf } from '@angular/core'; |
|||
import { ErrorStateMatcher } from '@angular/material/core'; |
|||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { |
|||
AbstractControl, FormArray, |
|||
FormBuilder, |
|||
FormControl, |
|||
FormGroup, |
|||
FormGroupDirective, |
|||
NgForm, |
|||
Validators |
|||
} from '@angular/forms'; |
|||
import { Router } from '@angular/router'; |
|||
import { DialogComponent } from '@app/shared/components/dialog.component'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
import { |
|||
EntityKeyValueType, |
|||
Filter, |
|||
filterToUserFilterInfoList, |
|||
UserFilterInputInfo |
|||
} from '@shared/models/query/query.models'; |
|||
|
|||
export interface UserFilterDialogData { |
|||
filter: Filter; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'tb-user-filter-dialog', |
|||
templateUrl: './user-filter-dialog.component.html', |
|||
providers: [{provide: ErrorStateMatcher, useExisting: UserFilterDialogComponent}], |
|||
styleUrls: [] |
|||
}) |
|||
export class UserFilterDialogComponent extends DialogComponent<UserFilterDialogComponent, Filter> |
|||
implements OnInit, ErrorStateMatcher { |
|||
|
|||
filter: Filter; |
|||
|
|||
userFilterFormGroup: FormGroup; |
|||
|
|||
valueTypeEnum = EntityKeyValueType; |
|||
|
|||
submitted = false; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected router: Router, |
|||
@Inject(MAT_DIALOG_DATA) public data: UserFilterDialogData, |
|||
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
|||
public dialogRef: MatDialogRef<UserFilterDialogComponent, Filter>, |
|||
private fb: FormBuilder, |
|||
public translate: TranslateService) { |
|||
super(store, router, dialogRef); |
|||
this.filter = data.filter; |
|||
const userInputs = filterToUserFilterInfoList(this.filter, translate); |
|||
|
|||
const userInputControls: Array<AbstractControl> = []; |
|||
for (const userInput of userInputs) { |
|||
userInputControls.push(this.createUserInputFormControl(userInput)); |
|||
} |
|||
|
|||
this.userFilterFormGroup = this.fb.group({ |
|||
userInputs: this.fb.array(userInputControls) |
|||
}); |
|||
} |
|||
|
|||
private createUserInputFormControl(userInput: UserFilterInputInfo): AbstractControl { |
|||
const userInputControl = this.fb.group({ |
|||
label: [userInput.label], |
|||
valueType: [userInput.valueType], |
|||
value: [(userInput.info.keyFilterPredicate as any).value, |
|||
userInput.valueType === EntityKeyValueType.NUMERIC || |
|||
userInput.valueType === EntityKeyValueType.DATE_TIME ? [Validators.required] : []] |
|||
}); |
|||
userInputControl.get('value').valueChanges.subscribe(value => { |
|||
(userInput.info.keyFilterPredicate as any).value = value; |
|||
}); |
|||
return userInputControl; |
|||
} |
|||
|
|||
userInputsFormArray(): FormArray { |
|||
return this.userFilterFormGroup.get('userInputs') as FormArray; |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
} |
|||
|
|||
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
|||
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
|||
const customErrorState = !!(control && control.invalid && this.submitted); |
|||
return originalErrorState || customErrorState; |
|||
} |
|||
|
|||
cancel(): void { |
|||
this.dialogRef.close(null); |
|||
} |
|||
|
|||
save(): void { |
|||
this.submitted = true; |
|||
this.dialogRef.close(this.filter); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue