Browse Source

fixes

pull/8337/head
Maksym Dudnik 3 years ago
parent
commit
b9f9cf494d
  1. 3
      ui-ngx/src/app/shared/components/device/gateway-logs.component.html
  2. 6
      ui-ngx/src/app/shared/components/device/gateway-logs.component.ts
  3. 37
      ui-ngx/src/app/shared/components/device/gateway-statistics.component.html
  4. 4
      ui-ngx/src/app/shared/components/device/gateway-statistics.component.scss
  5. 60
      ui-ngx/src/app/shared/components/device/gateway-statistics.component.ts

3
ui-ngx/src/app/shared/components/device/gateway-logs.component.html

@ -53,5 +53,8 @@
<!-- </mat-cell>-->
<!-- </ng-container>-->
</table>
<span [fxShow]="dataSource.data.length === 0"
fxLayoutAlign="center center"
class="no-data-found">{{'attribute.no-telemetry-text' | translate}}</span>
<mat-divider></mat-divider>

6
ui-ngx/src/app/shared/components/device/gateway-logs.component.ts

@ -122,11 +122,10 @@ export class GatewayLogsComponent extends PageComponent implements AfterViewInit
protected attributeService: AttributeService,
protected deviceService: DeviceService,
protected dialogService: DialogService,
private cd: ChangeDetectorRef,
public dialog: MatDialog) {
super(store);
const sortOrder: SortOrder = {property: 'ts', direction: Direction.DESC};
this.pageLink = new PageLink(1000, 0, null, sortOrder);
this.pageLink = new PageLink(Number.POSITIVE_INFINITY, 0, null, sortOrder);
this.dataSource = new MatTableDataSource<AttributeData>([]);
}
@ -210,8 +209,7 @@ export class GatewayLogsComponent extends PageComponent implements AfterViewInit
return "status status-error";
case GatewayLogLevel.info:
default:
return "status status-info"
return "status status-info"
return "status status-info";
}
}

37
ui-ngx/src/app/shared/components/device/gateway-statistics.component.html

@ -29,20 +29,43 @@
</mat-option>
</mat-select>
</mat-form-field>
<!-- <mat-form-field class="mat-block" *ngIf="commandObj">-->
<!-- <mat-label>Timeout</mat-label>-->
<!-- <input matInput [value]="commandObj.timeout" disabled>-->
<!-- </mat-form-field>-->
<!-- <mat-form-field class="mat-block" *ngIf="commandObj">-->
<!-- <mat-label>Timeout</mat-label>-->
<!-- <input matInput [value]="commandObj.timeout" disabled>-->
<!-- </mat-form-field>-->
<mat-form-field class="mat-block" *ngIf="commandObj">
<mat-label>{{'gateway.statistics.command' | translate}}</mat-label>
<input matInput [value]="commandObj.command" disabled>
</mat-form-field>
</mat-card>
<div class="chart-box" fxLayout="column">
<div class="chart-container" #statisticChart>
<div class="chart-container" #statisticChart [fxShow]="isNumericData">
</div>
<div fxFlex class="legend" fxLayout="row" fxLayoutAlign="center center">
</div>
<table [fxShow]="!isNumericData" mat-table [dataSource]="dataSource"
matSort [matSortActive]="pageLink.sortOrder.property" [matSortDirection]="pageLink.sortDirection()"
matSortDisableClear>
<ng-container matColumnDef="ts">
<mat-header-cell *matHeaderCellDef mat-sort-header>Timestamp</mat-header-cell>
<mat-cell *matCellDef="let row; let rowIndex = index">
{{row[0]| date:'yyyy-MM-dd HH:mm:ss' }}
</mat-cell>
</ng-container>
<ng-container matColumnDef="message">
<mat-header-cell *matHeaderCellDef mat-sort-header style="width: 70%">Message</mat-header-cell>
<mat-cell *matCellDef="let row">
{{ row[1] }}
</mat-cell>
</ng-container>
<mat-header-row [ngClass]="{'mat-row-select': true}"
*matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
<mat-row [ngClass]="{'mat-row-select': true}"
*matRowDef="let row; columns: displayedColumns;"></mat-row>
</table>
<span [fxShow]="dataSource.data.length === 0 && !isNumericData"
fxLayoutAlign="center center"
class="no-data-found">{{'attribute.no-telemetry-text' | translate}}</span>
<div fxFlex class="legend" fxLayout="row" fxLayoutAlign="center center" [fxShow]="isNumericData">
<div class="legend-keys" *ngFor="let legendKey of legendData?.keys" fxLayout="row"
fxLayoutAlign="center center">
<span class="legend-line" [ngStyle]="{backgroundColor: legendKey.dataKey.color}"></span>

4
ui-ngx/src/app/shared/components/device/gateway-statistics.component.scss

@ -33,6 +33,10 @@
flex-grow: 1;
}
.chart-box {
overflow: auto;
}
& > * {
height: 100%;
}

60
ui-ngx/src/app/shared/components/device/gateway-statistics.component.ts

@ -35,6 +35,10 @@ import { DatasourceType, LegendConfig, LegendData, LegendPosition, widgetType }
import { EntityType } from '@shared/models/entity-type.models';
import { EntityId } from '@shared/models/id/entity-id';
import { BaseData } from '@shared/models/base-data';
import { PageLink } from "@shared/models/page/page-link";
import { Direction, SortOrder } from "@shared/models/page/sort-order";
import { MatTableDataSource } from "@angular/material/table";
import { MatSort } from "@angular/material/sort";
@Component({
@ -44,29 +48,36 @@ import { BaseData } from '@shared/models/base-data';
})
export class GatewayStatisticsComponent extends PageComponent implements AfterViewInit {
@ViewChild(MatSort) sort: MatSort;
@ViewChild('statisticChart') statisticChart: ElementRef;
@Input()
ctx: WidgetContext;
@Input()
general: boolean;
public general: boolean;
public isNumericData: boolean = true;
public chartInited: boolean;
private flot: TbFlot;
private flotCtx;
public statisticForm: FormGroup;
public statisticsKeys = [];
public commands = [];
public commandObj: any;
public dataSource: MatTableDataSource<any>;
public pageLink: PageLink;
private resize$: ResizeObserver;
private subscription: IWidgetSubscription;
private subscriptionInfo: SubscriptionInfo [];
public legendData: LegendData;
public displayedColumns: Array<string>;
private subscriptionOptions: WidgetSubscriptionOptions = {
callbacks: {
onDataUpdated: (subscription, detectChanges) => this.ctx.ngZone.run(() => {
onDataUpdated: () => this.ctx.ngZone.run(() => {
this.onDataUpdated();
}),
onDataUpdateError: (subscription, e) => this.ctx.ngZone.run(() => {
this.onDataUpdateError(subscription, e);
this.onDataUpdateError(e);
})
},
useDashboardTimewindow: false,
@ -74,8 +85,6 @@ export class GatewayStatisticsComponent extends PageComponent implements AfterVi
position: LegendPosition.bottom
} as LegendConfig
};
private subscriptionInfo: SubscriptionInfo [];
public legendData: LegendData;
constructor(protected router: Router,
@ -89,6 +98,10 @@ export class GatewayStatisticsComponent extends PageComponent implements AfterVi
private utils: UtilsService,
public dialog: MatDialog) {
super(store);
const sortOrder: SortOrder = {property: 'ts', direction: Direction.DESC};
this.pageLink = new PageLink(Number.POSITIVE_INFINITY, 0, null, sortOrder);
this.displayedColumns = ['ts', 'message'];
this.dataSource = new MatTableDataSource<any>([]);
this.statisticForm = this.fb.group({
statisticKey: [null, []]
})
@ -104,6 +117,7 @@ export class GatewayStatisticsComponent extends PageComponent implements AfterVi
ngAfterViewInit() {
this.dataSource.sort = this.sort;
this.init();
if (this.ctx.defaultSubscription.datasources.length) {
@ -211,7 +225,7 @@ export class GatewayStatisticsComponent extends PageComponent implements AfterVi
}
}
private onDataUpdateError(subscription: IWidgetSubscription, e: any) {
private onDataUpdateError( e: any) {
const exceptionData = this.utils.parseException(e);
let errorText = exceptionData.name;
if (exceptionData.message) {
@ -221,11 +235,31 @@ export class GatewayStatisticsComponent extends PageComponent implements AfterVi
}
private onDataUpdated() {
if (this.flot) {
this.flot.update();
this.checkDataToBeNumeric();
if (this.isNumericData) {
if (this.chartInited) {
if (this.flot) {
this.flot.update();
}
} else {
this.initChart();
}
}
}
private initChart() {
this.chartInited = true;
this.flotCtx.$container = $(this.statisticChart.nativeElement);
this.resize$.observe(this.statisticChart.nativeElement);
this.flot = new TbFlot(this.flotCtx as WidgetContext, "line");
this.flot.update();
}
private checkDataToBeNumeric() {
this.dataSource.data = this.subscription.data.length ? this.subscription.data[0].data : [];
this.isNumericData = this.dataSource.data.every(data => isNaN(data[1]) === false);
}
changeSubscription(subscriptionInfo: SubscriptionInfo[]) {
if (this.subscription) {
@ -234,16 +268,16 @@ export class GatewayStatisticsComponent extends PageComponent implements AfterVi
if (this.ctx.datasources[0].entity) {
this.ctx.subscriptionApi.createSubscriptionFromInfo(widgetType.timeseries, subscriptionInfo, this.subscriptionOptions, false, true).subscribe(subscription => {
this.subscription = subscription;
this.checkDataToBeNumeric();
this.legendData = this.subscription.legendData;
this.flotCtx.defaultSubscription = subscription;
this.flotCtx.$container = $(this.statisticChart.nativeElement);
this.resize$ = new ResizeObserver(() => {
this.resize();
});
this.resize$.observe(this.statisticChart.nativeElement);
this.ctx.detectChanges();
this.flot = new TbFlot(this.flotCtx as WidgetContext, "line");
this.flot.update();
if (this.isNumericData) {
this.initChart();
}
})
}

Loading…
Cancel
Save