Browse Source
* Event filter implementation * Removed redundant imports * convert createdTime to column name * UI: Added ui to filter events parameters * Case sensitivity fixed, boolean Is Error added * UI: Added support event filter for error * Improvement for implementation of Event Filter * UI: Refactoring event filter * UI: Add trim * Filter added for all event types * UI: Updated filter events for new API * Refactoring * Code cleaning. Debug Rule Chain added * Removed redundant casts in JpaBaseEventDao, correct created_time check * Removed redundant abstract method in DebugEvent * refactoring of the filter queries * Filters for debug events * UI: Refactoring event table panel Co-authored-by: AndrewVolosytnykhThingsboard <avolostnykh@thingsboard.io> Co-authored-by: Vladyslav_Prykhodko <vprykhodko@thingsboard.io> Co-authored-by: AndrewVolosytnykhThingsboard <77969531+AndrewVolosytnykhThingsboard@users.noreply.github.com>pull/4416/head
committed by
GitHub
43 changed files with 1018 additions and 59 deletions
@ -0,0 +1,45 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
import lombok.Data; |
|||
import org.eclipse.leshan.core.util.StringUtils; |
|||
|
|||
@Data |
|||
public abstract class DebugEvent implements EventFilter { |
|||
|
|||
private String msgDirectionType; |
|||
private String server; |
|||
private String dataSearch; |
|||
private String metadataSearch; |
|||
private String entityName; |
|||
private String relationType; |
|||
private String entityId; |
|||
private String msgType; |
|||
private boolean isError; |
|||
private String error; |
|||
|
|||
public void setIsError(boolean isError) { |
|||
this.isError = isError; |
|||
} |
|||
|
|||
@Override |
|||
public boolean hasFilterForJsonBody() { |
|||
return !StringUtils.isEmpty(msgDirectionType) || !StringUtils.isEmpty(server) || !StringUtils.isEmpty(dataSearch) || !StringUtils.isEmpty(metadataSearch) |
|||
|| !StringUtils.isEmpty(entityName) || !StringUtils.isEmpty(relationType) || !StringUtils.isEmpty(entityId) || !StringUtils.isEmpty(msgType) || !StringUtils.isEmpty(error) || isError; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
public class DebugRuleChainEventFilter extends DebugEvent { |
|||
@Override |
|||
public EventType getEventType() { |
|||
return EventType.DEBUG_RULE_CHAIN; |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
public class DebugRuleNodeEventFilter extends DebugEvent { |
|||
@Override |
|||
public EventType getEventType() { |
|||
return EventType.DEBUG_RULE_NODE; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
import lombok.Data; |
|||
import org.eclipse.leshan.core.util.StringUtils; |
|||
|
|||
@Data |
|||
public class ErrorEventFilter implements EventFilter { |
|||
private String server; |
|||
private String method; |
|||
private String error; |
|||
|
|||
@Override |
|||
public EventType getEventType() { |
|||
return EventType.ERROR; |
|||
} |
|||
|
|||
@Override |
|||
public boolean hasFilterForJsonBody() { |
|||
return !StringUtils.isEmpty(server) || !StringUtils.isEmpty(method) || !StringUtils.isEmpty(error); |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
|
|||
@JsonTypeInfo( |
|||
use = JsonTypeInfo.Id.NAME, |
|||
include = JsonTypeInfo.As.PROPERTY, |
|||
property = "eventType") |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value = DebugRuleNodeEventFilter.class, name = "DEBUG_RULE_NODE"), |
|||
@JsonSubTypes.Type(value = DebugRuleChainEventFilter.class, name = "DEBUG_RULE_CHAIN"), |
|||
@JsonSubTypes.Type(value = ErrorEventFilter.class, name = "ERROR"), |
|||
@JsonSubTypes.Type(value = LifeCycleEventFilter.class, name = "LC_EVENT"), |
|||
@JsonSubTypes.Type(value = StatisticsEventFilter.class, name = "STATS") |
|||
}) |
|||
public interface EventFilter { |
|||
@JsonIgnore |
|||
EventType getEventType(); |
|||
|
|||
boolean hasFilterForJsonBody(); |
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
public enum EventType { |
|||
ERROR, LC_EVENT, STATS, DEBUG_RULE_NODE, DEBUG_RULE_CHAIN |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
import lombok.Data; |
|||
import org.eclipse.leshan.core.util.StringUtils; |
|||
|
|||
@Data |
|||
public class LifeCycleEventFilter implements EventFilter { |
|||
private String server; |
|||
private String event; |
|||
private String status; |
|||
private String error; |
|||
|
|||
@Override |
|||
public EventType getEventType() { |
|||
return EventType.LC_EVENT; |
|||
} |
|||
|
|||
@Override |
|||
public boolean hasFilterForJsonBody() { |
|||
return !StringUtils.isEmpty(server) || !StringUtils.isEmpty(event) || !StringUtils.isEmpty(status) || !StringUtils.isEmpty(error); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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.event; |
|||
|
|||
import lombok.Data; |
|||
import org.eclipse.leshan.core.util.StringUtils; |
|||
|
|||
@Data |
|||
public class StatisticsEventFilter implements EventFilter { |
|||
private String server; |
|||
private Integer messagesProcessed; |
|||
private Integer errorsOccurred; |
|||
|
|||
@Override |
|||
public EventType getEventType() { |
|||
return EventType.STATS; |
|||
} |
|||
|
|||
@Override |
|||
public boolean hasFilterForJsonBody() { |
|||
return !StringUtils.isEmpty(server) || (messagesProcessed != null && messagesProcessed > 0) || (errorsOccurred != null && errorsOccurred > 0); |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2021 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 fxLayout="column" class="mat-content mat-padding" [formGroup]="eventFilterFormGroup" (ngSubmit)="update()"> |
|||
<ng-container *ngFor="let column of showColumns"> |
|||
<ng-container [ngSwitch]="column.key"> |
|||
<ng-template [ngSwitchCase]="isSelector(column.key)"> |
|||
<mat-form-field> |
|||
<mat-label>{{ column.title | translate}}</mat-label> |
|||
<mat-select [formControlName]="column.key"> |
|||
<mat-option [value]="">{{ 'event.all-events' | translate}}</mat-option> |
|||
<mat-option *ngFor="let value of selectorValues(column.key)" [value]="value"> |
|||
{{ value }} |
|||
</mat-option> |
|||
</mat-select> |
|||
</mat-form-field> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="'isError'"> |
|||
<tb-checkbox formControlName="isError" [falseValue]="''"> |
|||
{{ 'event.has-error' | translate }} |
|||
</tb-checkbox> |
|||
</ng-template> |
|||
<ng-template [ngSwitchCase]="'error'"> |
|||
<mat-form-field fxHide [fxShow]="showErrorMsgFields()"> |
|||
<mat-label>{{ column.title | translate}}</mat-label> |
|||
<input matInput type="text" name="errorSearchText" formControlName="error"> |
|||
</mat-form-field> |
|||
</ng-template> |
|||
<ng-container *ngSwitchDefault> |
|||
<mat-form-field> |
|||
<mat-label>{{ column.title | translate}}</mat-label> |
|||
<input matInput type="text" [name]="column.key" [formControlName]="column.key"> |
|||
</mat-form-field> |
|||
</ng-container> |
|||
</ng-container> |
|||
</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]="eventFilterFormGroup.invalid || !eventFilterFormGroup.dirty"> |
|||
{{ 'action.update' | translate }} |
|||
</button> |
|||
</div> |
|||
</form> |
|||
@ -0,0 +1,35 @@ |
|||
/** |
|||
* Copyright © 2016-2021 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 { |
|||
width: 100%; |
|||
min-width: 300px; |
|||
overflow: auto; |
|||
background: #fff; |
|||
border-radius: 4px; |
|||
box-shadow: |
|||
0 7px 8px -4px rgba(0, 0, 0, .2), |
|||
0 13px 19px 2px rgba(0, 0, 0, .14), |
|||
0 5px 24px 4px rgba(0, 0, 0, .12); |
|||
|
|||
.mat-content { |
|||
overflow: hidden; |
|||
background-color: #fff; |
|||
} |
|||
|
|||
.mat-padding { |
|||
padding: 16px; |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
///
|
|||
/// Copyright © 2016-2021 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, InjectionToken } from '@angular/core'; |
|||
import { FormBuilder, FormGroup } from '@angular/forms'; |
|||
import { OverlayRef } from '@angular/cdk/overlay'; |
|||
import { EntityType } from '@shared/models/entity-type.models'; |
|||
import { FilterEventBody } from '@shared/models/event.models'; |
|||
import { deepTrim } from '@core/utils'; |
|||
|
|||
export const EVENT_FILTER_PANEL_DATA = new InjectionToken<any>('AlarmFilterPanelData'); |
|||
|
|||
export interface EventFilterPanelData { |
|||
filterParams: FilterEventBody; |
|||
columns: Array<FilterEntityColumn>; |
|||
} |
|||
|
|||
export interface FilterEntityColumn { |
|||
key: string; |
|||
title: string; |
|||
} |
|||
|
|||
|
|||
@Component({ |
|||
selector: 'tb-event-filter-panel', |
|||
templateUrl: './event-filter-panel.component.html', |
|||
styleUrls: ['./event-filter-panel.component.scss'] |
|||
}) |
|||
export class EventFilterPanelComponent { |
|||
|
|||
eventFilterFormGroup: FormGroup; |
|||
result: EventFilterPanelData; |
|||
|
|||
private conditionError = false; |
|||
|
|||
private msgDirectionTypes = ['IN', 'OUT']; |
|||
private statusTypes = ['Success', 'Failure']; |
|||
private entityTypes = Object.keys(EntityType); |
|||
|
|||
showColumns: FilterEntityColumn[] = []; |
|||
|
|||
constructor(@Inject(EVENT_FILTER_PANEL_DATA) |
|||
public data: EventFilterPanelData, |
|||
public overlayRef: OverlayRef, |
|||
private fb: FormBuilder) { |
|||
this.eventFilterFormGroup = this.fb.group({}); |
|||
this.data.columns.forEach((column) => { |
|||
this.showColumns.push(column); |
|||
this.eventFilterFormGroup.addControl(column.key, this.fb.control(this.data.filterParams[column.key] || '')); |
|||
if (column.key === 'isError') { |
|||
this.conditionError = true; |
|||
} |
|||
}); |
|||
} |
|||
|
|||
isSelector(key: string): string { |
|||
return ['msgDirectionType', 'status', 'entityName'].includes(key) ? key : ''; |
|||
} |
|||
|
|||
selectorValues(key: string): string[] { |
|||
switch (key) { |
|||
case 'msgDirectionType': |
|||
return this.msgDirectionTypes; |
|||
case 'status': |
|||
return this.statusTypes; |
|||
case 'entityName': |
|||
return this.entityTypes; |
|||
} |
|||
} |
|||
|
|||
update() { |
|||
const filter = deepTrim(Object.fromEntries(Object.entries(this.eventFilterFormGroup.value).filter(([_, v]) => v !== ''))); |
|||
this.result = { |
|||
filterParams: filter, |
|||
columns: this.data.columns |
|||
}; |
|||
this.overlayRef.dispose(); |
|||
} |
|||
|
|||
showErrorMsgFields() { |
|||
return !this.conditionError || this.eventFilterFormGroup.get('isError').value !== ''; |
|||
} |
|||
|
|||
cancel() { |
|||
this.overlayRef.dispose(); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue