committed by
GitHub
46 changed files with 1130 additions and 652 deletions
@ -0,0 +1,36 @@ |
|||
/** |
|||
* 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. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.common.data.id.EdgeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
@Data |
|||
@Builder |
|||
public class DeviceInfoFilter { |
|||
|
|||
private TenantId tenantId; |
|||
private CustomerId customerId; |
|||
private EdgeId edgeId; |
|||
private String type; |
|||
private DeviceProfileId deviceProfileId; |
|||
private Boolean active; |
|||
|
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
<!-- |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<ng-container *ngIf="panelMode; else componentMode"> |
|||
<ng-container *ngTemplateOutlet="deviceFilterPanel"></ng-container> |
|||
</ng-container> |
|||
<ng-template #componentMode> |
|||
<ng-container *ngIf="buttonMode; else deviceFilter"> |
|||
<button color="primary" |
|||
matTooltip="{{buttonDisplayValue}}" |
|||
matTooltipPosition="above" |
|||
mat-stroked-button |
|||
(click)="toggleDeviceFilterPanel($event)"> |
|||
<mat-icon>filter_list</mat-icon>{{buttonDisplayValue}} |
|||
</button> |
|||
</ng-container> |
|||
</ng-template> |
|||
<ng-template #deviceFilterPanel> |
|||
<form fxLayout="column" class="mat-content mat-padding" (ngSubmit)="update()"> |
|||
<ng-container *ngTemplateOutlet="deviceFilter"></ng-container> |
|||
<div fxLayout="row" class="tb-panel-actions" fxLayoutAlign="end center"> |
|||
<button type="button" |
|||
mat-button |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button type="submit" |
|||
mat-raised-button |
|||
color="primary" |
|||
[disabled]="deviceInfoFilterForm.invalid || !deviceInfoFilterForm.dirty"> |
|||
{{ 'action.update' | translate }} |
|||
</button> |
|||
</div> |
|||
</form> |
|||
</ng-template> |
|||
<ng-template #deviceFilter> |
|||
<div fxLayout="column" fxLayoutGap="16px" style="min-width: 280px;" [formGroup]="deviceInfoFilterForm"> |
|||
<tb-device-profile-autocomplete |
|||
subscriptSizing="dynamic" |
|||
formControlName="deviceProfileId" |
|||
[displayAllOnEmpty]="true" |
|||
(deviceProfileChanged)="deviceProfileChanged($event)" |
|||
[editProfileEnabled]="false"> |
|||
</tb-device-profile-autocomplete> |
|||
<mat-form-field> |
|||
<mat-label translate>device.device-state</mat-label> |
|||
<mat-select formControlName="active"> |
|||
<mat-option value=""> |
|||
{{ 'device.any' | translate }} |
|||
</mat-option> |
|||
<mat-option [value]="true"> |
|||
{{ 'device.active' | translate }} |
|||
</mat-option> |
|||
<mat-option [value]="false"> |
|||
{{ 'device.inactive' | translate }} |
|||
</mat-option> |
|||
</mat-select> |
|||
</mat-form-field> |
|||
</div> |
|||
</ng-template> |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* 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. |
|||
*/ |
|||
:host { |
|||
display: block; |
|||
overflow: hidden; |
|||
max-width: 100%; |
|||
.mdc-button { |
|||
max-width: 100%; |
|||
} |
|||
} |
|||
|
|||
:host ::ng-deep { |
|||
.mdc-button { |
|||
.mat-icon { |
|||
min-width: 24px; |
|||
} |
|||
.mdc-button__label { |
|||
overflow: hidden; |
|||
text-overflow: ellipsis; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,254 @@ |
|||
///
|
|||
/// 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 { |
|||
ChangeDetectorRef, |
|||
Component, |
|||
ElementRef, |
|||
forwardRef, |
|||
Inject, |
|||
InjectionToken, |
|||
Input, |
|||
OnDestroy, |
|||
OnInit, |
|||
Optional, |
|||
TemplateRef, |
|||
ViewChild, |
|||
ViewContainerRef |
|||
} from '@angular/core'; |
|||
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
|||
import { coerceBoolean } from '@shared/decorators/coerce-boolean'; |
|||
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
|||
import { TemplatePortal } from '@angular/cdk/portal'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
import { DeviceInfoFilter } from '@shared/models/device.models'; |
|||
import { isDefinedAndNotNull } from '@core/utils'; |
|||
import { EntityInfoData } from '@shared/models/entity.models'; |
|||
import { DeviceProfileService } from '@core/http/device-profile.service'; |
|||
|
|||
export const DEVICE_FILTER_CONFIG_DATA = new InjectionToken<any>('DeviceFilterConfigData'); |
|||
|
|||
export interface DeviceFilterConfigData { |
|||
panelMode: boolean; |
|||
deviceInfoFilter: DeviceInfoFilter; |
|||
} |
|||
|
|||
// @dynamic
|
|||
@Component({ |
|||
selector: 'tb-device-info-filter', |
|||
templateUrl: './device-info-filter.component.html', |
|||
styleUrls: ['./device-info-filter.component.scss'], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => DeviceInfoFilterComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class DeviceInfoFilterComponent implements OnInit, OnDestroy, ControlValueAccessor { |
|||
|
|||
@ViewChild('deviceFilterPanel') |
|||
deviceFilterPanel: TemplateRef<any>; |
|||
|
|||
@Input() disabled: boolean; |
|||
|
|||
@coerceBoolean() |
|||
@Input() |
|||
buttonMode = true; |
|||
|
|||
panelMode = false; |
|||
|
|||
buttonDisplayValue = this.translate.instant('device.device-filter'); |
|||
|
|||
deviceInfoFilterForm: UntypedFormGroup; |
|||
|
|||
deviceFilterOverlayRef: OverlayRef; |
|||
|
|||
panelResult: DeviceInfoFilter = null; |
|||
|
|||
private deviceProfileInfo: EntityInfoData; |
|||
|
|||
private deviceInfoFilter: DeviceInfoFilter; |
|||
|
|||
private propagateChange = (_: any) => {}; |
|||
|
|||
constructor(@Optional() @Inject(DEVICE_FILTER_CONFIG_DATA) |
|||
private data: DeviceFilterConfigData | undefined, |
|||
@Optional() |
|||
private overlayRef: OverlayRef, |
|||
private fb: UntypedFormBuilder, |
|||
private translate: TranslateService, |
|||
private overlay: Overlay, |
|||
private nativeElement: ElementRef, |
|||
private viewContainerRef: ViewContainerRef, |
|||
private deviceProfileService: DeviceProfileService, |
|||
private cd: ChangeDetectorRef) { |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
if (this.data) { |
|||
this.panelMode = this.data.panelMode; |
|||
this.deviceInfoFilter = this.data.deviceInfoFilter; |
|||
} |
|||
this.deviceInfoFilterForm = this.fb.group({ |
|||
deviceProfileId: [null, []], |
|||
active: ['', []] |
|||
}); |
|||
this.deviceInfoFilterForm.valueChanges.subscribe( |
|||
() => { |
|||
this.updateValidators(); |
|||
if (!this.buttonMode) { |
|||
this.deviceFilterUpdated(this.deviceInfoFilterForm.value); |
|||
} |
|||
} |
|||
); |
|||
if (this.panelMode) { |
|||
this.updateDeviceInfoFilterForm(this.deviceInfoFilter); |
|||
} |
|||
} |
|||
|
|||
ngOnDestroy(): void { |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (this.disabled) { |
|||
this.deviceInfoFilterForm.disable({emitEvent: false}); |
|||
} else { |
|||
this.deviceInfoFilterForm.enable({emitEvent: false}); |
|||
this.updateValidators(); |
|||
} |
|||
} |
|||
|
|||
writeValue(deviceInfoFilter?: DeviceInfoFilter): void { |
|||
this.deviceInfoFilter = deviceInfoFilter; |
|||
this.updateButtonDisplayValue(); |
|||
this.updateDeviceInfoFilterForm(deviceInfoFilter); |
|||
} |
|||
|
|||
private updateValidators() { |
|||
} |
|||
|
|||
toggleDeviceFilterPanel($event: Event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const config = new OverlayConfig({ |
|||
panelClass: 'tb-filter-panel', |
|||
backdropClass: 'cdk-overlay-transparent-backdrop', |
|||
hasBackdrop: true, |
|||
maxHeight: '80vh', |
|||
height: 'min-content', |
|||
minWidth: '' |
|||
}); |
|||
config.hasBackdrop = true; |
|||
const connectedPosition: ConnectedPosition = { |
|||
originX: 'start', |
|||
originY: 'bottom', |
|||
overlayX: 'start', |
|||
overlayY: 'top' |
|||
}; |
|||
config.positionStrategy = this.overlay.position().flexibleConnectedTo(this.nativeElement) |
|||
.withPositions([connectedPosition]); |
|||
|
|||
this.deviceFilterOverlayRef = this.overlay.create(config); |
|||
this.deviceFilterOverlayRef.backdropClick().subscribe(() => { |
|||
this.deviceFilterOverlayRef.dispose(); |
|||
}); |
|||
this.deviceFilterOverlayRef.attach(new TemplatePortal(this.deviceFilterPanel, |
|||
this.viewContainerRef)); |
|||
} |
|||
|
|||
cancel() { |
|||
this.updateDeviceInfoFilterForm(this.deviceInfoFilter); |
|||
if (this.overlayRef) { |
|||
this.overlayRef.dispose(); |
|||
} else { |
|||
this.deviceFilterOverlayRef.dispose(); |
|||
} |
|||
} |
|||
|
|||
update() { |
|||
this.deviceFilterUpdated(this.deviceInfoFilterForm.value); |
|||
if (this.panelMode) { |
|||
this.panelResult = this.deviceInfoFilter; |
|||
} |
|||
if (this.overlayRef) { |
|||
this.overlayRef.dispose(); |
|||
} else { |
|||
this.deviceFilterOverlayRef.dispose(); |
|||
} |
|||
} |
|||
|
|||
deviceProfileChanged(deviceProfileInfo: EntityInfoData) { |
|||
this.deviceProfileInfo = deviceProfileInfo; |
|||
this.updateButtonDisplayValue(); |
|||
} |
|||
|
|||
private updateDeviceInfoFilterForm(deviceInfoFilter?: DeviceInfoFilter) { |
|||
this.deviceInfoFilterForm.patchValue({ |
|||
deviceProfileId: deviceInfoFilter?.deviceProfileId, |
|||
active: isDefinedAndNotNull(deviceInfoFilter?.active) ? deviceInfoFilter?.active : '' |
|||
}, {emitEvent: false}); |
|||
this.updateValidators(); |
|||
} |
|||
|
|||
private deviceFilterUpdated(deviceInfoFilter: DeviceInfoFilter) { |
|||
this.deviceInfoFilter = deviceInfoFilter; |
|||
if ((this.deviceInfoFilter.active as any) === '') { |
|||
this.deviceInfoFilter.active = null; |
|||
} |
|||
this.updateButtonDisplayValue(); |
|||
this.propagateChange(this.deviceInfoFilter); |
|||
} |
|||
|
|||
private updateButtonDisplayValue() { |
|||
if (this.buttonMode) { |
|||
const filterTextParts: string[] = []; |
|||
if (isDefinedAndNotNull(this.deviceInfoFilter?.deviceProfileId)) { |
|||
if (!this.deviceProfileInfo) { |
|||
this.deviceProfileService.getDeviceProfileInfo(this.deviceInfoFilter?.deviceProfileId.id, |
|||
{ignoreLoading: true, ignoreErrors: true}).subscribe( |
|||
(deviceProfileInfo) => { |
|||
this.deviceProfileChanged(deviceProfileInfo); |
|||
}); |
|||
return; |
|||
} else { |
|||
filterTextParts.push(this.deviceProfileInfo.name); |
|||
} |
|||
} |
|||
if (isDefinedAndNotNull(this.deviceInfoFilter?.active)) { |
|||
const translationKey = this.deviceInfoFilter?.active ? 'device.active' : 'device.inactive'; |
|||
filterTextParts.push(this.translate.instant(translationKey)); |
|||
} |
|||
if (!filterTextParts.length) { |
|||
this.buttonDisplayValue = this.translate.instant('device.device-filter-title'); |
|||
} else { |
|||
this.buttonDisplayValue = this.translate.instant('device.filter-title') + `: ${filterTextParts.join(', ')}`; |
|||
} |
|||
this.cd.detectChanges(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
After Width: | Height: | Size: 5.2 KiB |
Loading…
Reference in new issue