Browse Source

UI: Added select layout and clear dashboard json

pull/11355/head
Vladyslav_Prykhodko 2 years ago
parent
commit
4c353534cc
  1. 24
      ui-ngx/src/app/core/services/dashboard-utils.service.ts
  2. 8
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html
  3. 3
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.scss
  4. 35
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts
  5. 14
      ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.ts

24
ui-ngx/src/app/core/services/dashboard-utils.service.ts

@ -29,7 +29,7 @@ import {
GridSettings, GridSettings,
WidgetLayout WidgetLayout
} from '@shared/models/dashboard.models'; } from '@shared/models/dashboard.models';
import { deepClone, isDefined, isDefinedAndNotNull, isNotEmptyStr, isString, isUndefined } from '@core/utils'; import { deepClone, isDefined, isDefinedAndNotNull, isNotEmptyStr, isString, isUndefined, isEqual } from '@core/utils';
import { import {
Datasource, Datasource,
datasourcesHasOnlyComparisonAggregation, datasourcesHasOnlyComparisonAggregation,
@ -742,6 +742,28 @@ export class DashboardUtilsService {
} }
} }
public removeBreakpointsDuplicateInLayouts(dashboard: Dashboard) {
const dashboardConfiguration = dashboard.configuration;
const states = dashboardConfiguration.states;
for (const s of Object.keys(states)) {
const state = states[s];
for (const l of Object.keys(state.layouts)) {
const layout: DashboardLayout = state.layouts[l];
if (layout.breakpoints) {
for (const breakpoint of Object.keys(layout.breakpoints)) {
const breakpointLayout = layout.breakpoints[breakpoint];
if (isEqual(breakpointLayout.widgets, layout.widgets) && isEqual(breakpointLayout.gridSettings, layout.gridSettings)) {
delete layout.breakpoints[breakpoint];
if (isEqual(layout.breakpoints, {})) {
delete layout.breakpoints;
}
}
}
}
}
}
}
private validateAndUpdateEntityAliases(configuration: DashboardConfiguration, private validateAndUpdateEntityAliases(configuration: DashboardConfiguration,
datasourcesByAliasId: {[aliasId: string]: Array<Datasource>}, datasourcesByAliasId: {[aliasId: string]: Array<Datasource>},
targetDevicesByAliasId: {[aliasId: string]: Array<TargetDevice>}): DashboardConfiguration { targetDevicesByAliasId: {[aliasId: string]: Array<TargetDevice>}): DashboardConfiguration {

8
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html

@ -285,7 +285,8 @@
</mat-form-field> </mat-form-field>
</section> </section>
<mat-drawer-container class="tb-dashboard-layouts" fxFlex <mat-drawer-container class="tb-dashboard-layouts" fxFlex
[ngClass]="{ 'tb-shrinked' : isEditingWidget }"> [class]="{'tb-shrinked' : isEditingWidget,
'diagonal-stripes': !layouts.right.show && layouts.main.layoutCtx.breakpoint !== 'default'}">
<mat-drawer *ngIf="layouts.right.show" <mat-drawer *ngIf="layouts.right.show"
id="tb-right-layout" id="tb-right-layout"
[ngStyle]="{minWidth: rightLayoutSize.width, [ngStyle]="{minWidth: rightLayoutSize.width,
@ -311,8 +312,9 @@
</mat-drawer> </mat-drawer>
<mat-drawer-content [fxShow]="layouts.main.show" <mat-drawer-content [fxShow]="layouts.main.show"
id="tb-main-layout" id="tb-main-layout"
[ngStyle]="{width: mainLayoutSize.width, [style]="{width: mainLayoutSize.width,
height: mainLayoutSize.height}"> height: mainLayoutSize.height,
maxWidth: mainLayoutSize.maxWidth}">
<tb-dashboard-layout <tb-dashboard-layout
[dashboardCheatSheet]="cheatSheetComponent" [dashboardCheatSheet]="cheatSheetComponent"
[layoutCtx]="mobileDisplayRightLayoutFirst ? layouts.right.layoutCtx : layouts.main.layoutCtx" [layoutCtx]="mobileDisplayRightLayoutFirst ? layouts.right.layoutCtx : layouts.main.layoutCtx"

3
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.scss

@ -131,6 +131,9 @@ div.tb-dashboard-page {
width: max(40%, calc(100% - 1192px)); width: max(40%, calc(100% - 1192px));
} }
} }
&.diagonal-stripes {
background: repeating-linear-gradient(45deg, #ccc, #ccc 10px, #fff0 10px, #fff0 20px);
}
} }
mat-drawer.tb-details-drawer { mat-drawer.tb-details-drawer {

35
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

@ -254,7 +254,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
addingLayoutCtx: DashboardPageLayoutContext; addingLayoutCtx: DashboardPageLayoutContext;
mainLayoutSize: {width: string; height: string} = {width: '100%', height: '100%'}; mainLayoutSize: {width: string; height: string; maxWidth: string} = {width: '100%', height: '100%', maxWidth: '100%'};
rightLayoutSize: {width: string; height: string} = {width: '100%', height: '100%'}; rightLayoutSize: {width: string; height: string} = {width: '100%', height: '100%'};
private dashboardLogoCache: SafeUrl; private dashboardLogoCache: SafeUrl;
@ -756,6 +756,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
private updateMainLayoutSize(): boolean { private updateMainLayoutSize(): boolean {
const prevMainLayoutWidth = this.mainLayoutSize.width; const prevMainLayoutWidth = this.mainLayoutSize.width;
const prevMainLayoutHeight = this.mainLayoutSize.height; const prevMainLayoutHeight = this.mainLayoutSize.height;
const prevMainLayoutMaxWidth = this.mainLayoutSize.maxWidth;
if (this.isEditingWidget && this.editingLayoutCtx.id === 'main') { if (this.isEditingWidget && this.editingLayoutCtx.id === 'main') {
this.mainLayoutSize.width = '100%'; this.mainLayoutSize.width = '100%';
} else { } else {
@ -766,7 +767,36 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
} else { } else {
this.mainLayoutSize.height = '0px'; this.mainLayoutSize.height = '0px';
} }
return prevMainLayoutWidth !== this.mainLayoutSize.width || prevMainLayoutHeight !== this.mainLayoutSize.height; if (this.isEdit) {
const xOffset = this.dashboardContainer.nativeElement.getBoundingClientRect().x;
let width;
switch (this.layouts.main.layoutCtx.breakpoint) {
case 'xl':
width = `${5000 - xOffset}px`;
break;
case 'lg':
width = `${1919 - xOffset}px`;
break;
case 'md':
width = `${1279 - xOffset}px`;
break;
case 'sm':
width = '959px';
break;
case 'xs':
width = '599px';
break;
default:
width = '100%';
}
this.mainLayoutSize.maxWidth = width;
} else {
this.mainLayoutSize.maxWidth = '100%';
}
return prevMainLayoutWidth !== this.mainLayoutSize.width || prevMainLayoutHeight !== this.mainLayoutSize.height ||
prevMainLayoutMaxWidth !== this.mainLayoutSize.maxWidth;
} }
private updateRightLayoutSize(): boolean { private updateRightLayoutSize(): boolean {
@ -1155,6 +1185,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
}; };
this.window.parent.postMessage(JSON.stringify(message), '*'); this.window.parent.postMessage(JSON.stringify(message), '*');
} else { } else {
this.dashboardUtils.removeBreakpointsDuplicateInLayouts(this.dashboard);
this.dashboardService.saveDashboard(this.dashboard).subscribe(); this.dashboardService.saveDashboard(this.dashboard).subscribe();
} }
} }

14
ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.ts

@ -93,12 +93,14 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo
private rxSubscriptions = new Array<Subscription>(); private rxSubscriptions = new Array<Subscription>();
constructor(protected store: Store<AppState>, constructor(
private translate: TranslateService, protected store: Store<AppState>,
private itembuffer: ItemBufferService, private translate: TranslateService,
private imagePipe: ImagePipe, private itembuffer: ItemBufferService,
private sanitizer: DomSanitizer, private imagePipe: ImagePipe,
private dashboardUtils: DashboardUtilsService,) { private sanitizer: DomSanitizer,
private dashboardUtils: DashboardUtilsService,
) {
super(store); super(store);
this.initHotKeys(); this.initHotKeys();
} }

Loading…
Cancel
Save