Browse Source

UI: On tables hide page size option on mobile view

pull/5655/head
ArtemDzhereleiko 5 years ago
parent
commit
76dccab3f7
  1. 2
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html
  2. 33
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.html
  4. 32
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.ts
  5. 2
      ui-ngx/src/app/modules/home/components/relation/relation-table.component.html
  6. 33
      ui-ngx/src/app/modules/home/components/relation/relation-table.component.ts
  7. 2
      ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.html
  8. 31
      ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts
  9. 3
      ui-ngx/src/app/modules/home/components/widget/lib/alarms-table-widget.component.ts
  10. 3
      ui-ngx/src/app/modules/home/components/widget/lib/entities-table-widget.component.ts
  11. 3
      ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts
  12. 1
      ui-ngx/src/app/shared/models/constants.ts

2
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html

@ -15,7 +15,7 @@
limitations under the License.
-->
<div class="mat-padding tb-entity-table tb-absolute-fill">
<div #attributeTableContainer class="mat-padding tb-entity-table tb-absolute-fill">
<div fxFlex fxLayout="column" class="mat-elevation-z1 tb-entity-table-content">
<mat-toolbar class="mat-table-toolbar" [fxShow]="mode === 'default' && !textSearchMode && dataSource.selection.isEmpty()">
<div class="mat-toolbar-tools">

33
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts

@ -38,7 +38,7 @@ import { TranslateService } from '@ngx-translate/core';
import { MatDialog } from '@angular/material/dialog';
import { DialogService } from '@core/services/dialog.service';
import { Direction, SortOrder } from '@shared/models/page/sort-order';
import { fromEvent, merge, Subscription } from 'rxjs';
import { fromEvent, merge } from 'rxjs';
import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
import { EntityId } from '@shared/models/id/entity-id';
import {
@ -84,8 +84,8 @@ import {
} from '@home/components/attribute/add-widget-to-dashboard-dialog.component';
import { deepClone } from '@core/utils';
import { Filters } from '@shared/models/query/query.models';
import { MediaBreakpoints } from '@shared/models/constants';
import { BreakpointObserver } from '@angular/cdk/layout';
import { hidePageSizePixelValue } from '@shared/models/constants';
import { ResizeObserver } from '@juggle/resize-observer';
@Component({
@ -168,13 +168,14 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
@Input()
entityName: string;
@ViewChild('attributeTableContainer', {static: true}) attributeTableContainerRef: ElementRef;
@ViewChild('searchInput') searchInputField: ElementRef;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
private breakpointObserverSubscription$: Subscription;
public hidePageSize = true;
public hidePageSize = false;
private widgetResize$: ResizeObserver;
constructor(protected store: Store<AppState>,
private attributeService: AttributeService,
@ -189,8 +190,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
private dashboardUtils: DashboardUtilsService,
private widgetService: WidgetService,
private zone: NgZone,
private cd: ChangeDetectorRef,
private breakpointObserver: BreakpointObserver) {
private cd: ChangeDetectorRef) {
super(store);
this.dirtyValue = !this.activeValue;
const sortOrder: SortOrder = { property: 'key', direction: Direction.ASC };
@ -199,18 +199,19 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
}
ngOnInit() {
this.breakpointObserverSubscription$ = this.breakpointObserver
.observe(MediaBreakpoints['gt-xs']).subscribe(
() => {
this.hidePageSize = !this.breakpointObserver.isMatched(MediaBreakpoints['gt-xs']);
this.cd.detectChanges();
}
);
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.attributeTableContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.cd.detectChanges();
}
});
this.widgetResize$.observe(this.attributeTableContainerRef.nativeElement);
}
ngOnDestroy() {
if (this.breakpointObserverSubscription$) {
this.breakpointObserverSubscription$.unsubscribe();
if (this.widgetResize$) {
this.widgetResize$.disconnect();
}
}

2
ui-ngx/src/app/modules/home/components/entity/entities-table.component.html

@ -32,7 +32,7 @@
</tb-entity-details-panel>
</mat-drawer>
<mat-drawer-content>
<div class="mat-padding tb-entity-table tb-absolute-fill">
<div #entitiesTableContainer class="mat-padding tb-entity-table tb-absolute-fill">
<div fxLayout="column" class="mat-elevation-z1 tb-entity-table-content">
<mat-toolbar class="mat-table-toolbar" [fxShow]="!textSearchMode && dataSource.selection.isEmpty()">
<div class="mat-toolbar-tools">

32
ui-ngx/src/app/modules/home/components/entity/entities-table.component.ts

@ -64,8 +64,8 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
import { isDefined, isUndefined } from '@core/utils';
import { HasUUID } from '@shared/models/id/has-uuid';
import { MediaBreakpoints } from '@shared/models/constants';
import { BreakpointObserver } from '@angular/cdk/layout';
import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants';
@Component({
selector: 'tb-entities-table',
@ -111,6 +111,8 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
isDetailsOpen = false;
detailsPanelOpened = new EventEmitter<boolean>();
@ViewChild('entitiesTableContainer', {static: true}) entitiesTableContainerRef: ElementRef;
@ViewChild('entityTableHeader', {static: true}) entityTableHeaderAnchor: TbAnchorComponent;
@ViewChild('searchInput') searchInputField: ElementRef;
@ -122,8 +124,8 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
private updateDataSubscription: Subscription;
private viewInited = false;
private breakpointObserverSubscription$: Subscription;
public hidePageSize = true;
private widgetResize$: ResizeObserver;
public hidePageSize = false;
constructor(protected store: Store<AppState>,
public route: ActivatedRoute,
@ -132,8 +134,7 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
private dialogService: DialogService,
private domSanitizer: DomSanitizer,
private cd: ChangeDetectorRef,
private componentFactoryResolver: ComponentFactoryResolver,
private breakpointObserver: BreakpointObserver) {
private componentFactoryResolver: ComponentFactoryResolver) {
super(store);
}
@ -143,18 +144,19 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
} else {
this.init(this.route.snapshot.data.entitiesTableConfig);
}
this.breakpointObserverSubscription$ = this.breakpointObserver
.observe(MediaBreakpoints['gt-xs']).subscribe(
() => {
this.hidePageSize = !this.breakpointObserver.isMatched(MediaBreakpoints['gt-xs']);
this.cd.detectChanges();
}
);
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.entitiesTableContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.cd.detectChanges();
}
});
this.widgetResize$.observe(this.entitiesTableContainerRef.nativeElement);
}
ngOnDestroy() {
if (this.breakpointObserverSubscription$) {
this.breakpointObserverSubscription$.unsubscribe();
if (this.widgetResize$) {
this.widgetResize$.disconnect();
}
}

2
ui-ngx/src/app/modules/home/components/relation/relation-table.component.html

@ -15,7 +15,7 @@
limitations under the License.
-->
<div class="mat-padding tb-entity-table tb-absolute-fill">
<div #relationTableContainer class="mat-padding tb-entity-table tb-absolute-fill">
<div fxFlex fxLayout="column" class="mat-elevation-z1 tb-entity-table-content">
<mat-toolbar class="mat-table-toolbar" [fxShow]="!textSearchMode && dataSource.selection.isEmpty()">
<div class="mat-toolbar-tools">

33
ui-ngx/src/app/modules/home/components/relation/relation-table.component.ts

@ -35,7 +35,7 @@ import { MatDialog } from '@angular/material/dialog';
import { DialogService } from '@core/services/dialog.service';
import { EntityRelationService } from '@core/http/entity-relation.service';
import { Direction, SortOrder } from '@shared/models/page/sort-order';
import { forkJoin, fromEvent, merge, Observable, Subscription } from 'rxjs';
import { forkJoin, fromEvent, merge, Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
import {
EntityRelation,
@ -47,8 +47,8 @@ import {
import { EntityId } from '@shared/models/id/entity-id';
import { RelationsDatasource } from '../../models/datasource/relation-datasource';
import { RelationDialogComponent, RelationDialogData } from '@home/components/relation/relation-dialog.component';
import { MediaBreakpoints } from '@shared/models/constants';
import { BreakpointObserver } from '@angular/cdk/layout';
import { hidePageSizePixelValue } from '@shared/models/constants';
import { ResizeObserver } from '@juggle/resize-observer';
@Component({
selector: 'tb-relation-table',
@ -76,8 +76,8 @@ export class RelationTableComponent extends PageComponent implements AfterViewIn
viewsInited = false;
private breakpointObserverSubscription$: Subscription;
public hidePageSize = true;
private widgetResize$: ResizeObserver;
public hidePageSize = false;
@Input()
set active(active: boolean) {
@ -105,6 +105,7 @@ export class RelationTableComponent extends PageComponent implements AfterViewIn
}
}
@ViewChild('relationTableContainer', {static: true}) relationTableContainerRef: ElementRef;
@ViewChild('searchInput') searchInputField: ElementRef;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ -115,8 +116,7 @@ export class RelationTableComponent extends PageComponent implements AfterViewIn
public translate: TranslateService,
public dialog: MatDialog,
private dialogService: DialogService,
private cd: ChangeDetectorRef,
private breakpointObserver: BreakpointObserver) {
private cd: ChangeDetectorRef) {
super(store);
this.dirtyValue = !this.activeValue;
const sortOrder: SortOrder = { property: 'type', direction: Direction.ASC };
@ -127,18 +127,19 @@ export class RelationTableComponent extends PageComponent implements AfterViewIn
}
ngOnInit() {
this.breakpointObserverSubscription$ = this.breakpointObserver
.observe(MediaBreakpoints['gt-xs']).subscribe(
() => {
this.hidePageSize = !this.breakpointObserver.isMatched(MediaBreakpoints['gt-xs']);
this.cd.detectChanges();
}
);
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.relationTableContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.cd.detectChanges();
}
});
this.widgetResize$.observe(this.relationTableContainerRef.nativeElement);
}
ngOnDestroy() {
if (this.breakpointObserverSubscription$) {
this.breakpointObserverSubscription$.unsubscribe();
if (this.widgetResize$) {
this.widgetResize$.disconnect();
}
}

2
ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.html

@ -15,7 +15,7 @@
limitations under the License.
-->
<div class="mat-padding tb-entity-table tb-absolute-fill">
<div #manageActionWidgetContainer class="mat-padding tb-entity-table tb-absolute-fill">
<div fxFlex fxLayout="column" class="mat-elevation-z1 tb-entity-table-content">
<mat-toolbar class="mat-table-toolbar" [fxShow]="!textSearchMode">
<div class="mat-toolbar-tools">

31
ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts

@ -14,7 +14,17 @@
/// limitations under the License.
///
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import {
AfterViewInit,
ChangeDetectorRef,
Component,
ElementRef,
forwardRef,
Input,
OnDestroy,
OnInit,
ViewChild
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { PageComponent } from '@shared/components/page.component';
@ -43,6 +53,8 @@ import {
} from '@home/components/widget/action/widget-action-dialog.component';
import { deepClone } from '@core/utils';
import { widgetType } from '@shared/models/widget.models';
import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants';
@Component({
selector: 'tb-manage-widget-actions',
@ -73,7 +85,10 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
viewsInited = false;
dirtyValue = false;
public hidePageSize = false;
private widgetResize$: ResizeObserver;
@ViewChild('manageActionWidgetContainer', {static: true}) manageActionWidgetContainerRef: ElementRef;
@ViewChild('searchInput') searchInputField: ElementRef;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ -85,7 +100,8 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
private translate: TranslateService,
private utils: UtilsService,
private dialog: MatDialog,
private dialogs: DialogService) {
private dialogs: DialogService,
private cd: ChangeDetectorRef) {
super(store);
const sortOrder: SortOrder = { property: 'actionSourceName', direction: Direction.ASC };
this.pageLink = new PageLink(10, 0, null, sortOrder);
@ -94,9 +110,20 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
}
ngOnInit(): void {
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.manageActionWidgetContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.cd.detectChanges();
}
});
this.widgetResize$.observe(this.manageActionWidgetContainerRef.nativeElement);
}
ngOnDestroy(): void {
if (this.widgetResize$) {
this.widgetResize$.disconnect();
}
}
ngAfterViewInit() {

3
ui-ngx/src/app/modules/home/components/widget/lib/alarms-table-widget.component.ts

@ -124,6 +124,7 @@ import {
import { entityFields } from '@shared/models/entity.models';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants';
interface AlarmsTableWidgetSettings extends TableWidgetSettings {
alarmsTitle: string;
@ -262,7 +263,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
() => this.pageLink.page = 0
);
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.ctx.$container[0].offsetWidth < 500;
const showHidePageSize = this.alarmWidgetContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.ctx.detectChanges();

3
ui-ngx/src/app/modules/home/components/widget/lib/entities-table-widget.component.ts

@ -108,6 +108,7 @@ import { entityFields } from '@shared/models/entity.models';
import { DatePipe } from '@angular/common';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants';
interface EntitiesTableWidgetSettings extends TableWidgetSettings {
entitiesTitle: string;
@ -217,7 +218,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
this.ctx.updateWidgetParams();
if (this.displayPagination) {
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.ctx.$container[0].offsetWidth < 500;
const showHidePageSize = this.entitiesWidgetContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.ctx.detectChanges();

3
ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts

@ -72,6 +72,7 @@ import { DatePipe } from '@angular/common';
import { parseData } from '@home/components/widget/lib/maps/common-maps-utils';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants';
export interface TimeseriesTableWidgetSettings extends TableWidgetSettings {
showTimestamp: boolean;
@ -195,7 +196,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
}
);
this.widgetResize$ = new ResizeObserver(() => {
const showHidePageSize = this.ctx.$container[0].offsetWidth < 500;
const showHidePageSize = this.timeseriesWidgetContainerRef.nativeElement.offsetWidth < hidePageSizePixelValue;
if (showHidePageSize !== this.hidePageSize) {
this.hidePageSize = showHidePageSize;
this.ctx.detectChanges();

1
ui-ngx/src/app/shared/models/constants.ts

@ -241,6 +241,7 @@ export const contentTypesMap = new Map<ContentType, ContentTypeData>(
]
);
export const hidePageSizePixelValue = 550;
export const customTranslationsPrefix = 'custom.';
export const i18nPrefix = 'i18n';

Loading…
Cancel
Save