feature/6371: bug-fix and refactoring

This commit is contained in:
Dmitriymush 2022-09-20 18:09:25 +03:00
parent 7c917c8e73
commit d0c2e9e1cb
6 changed files with 102 additions and 57 deletions

View File

@ -140,7 +140,7 @@ import { MatButton } from '@angular/material/button';
import { VersionControlComponent } from '@home/components/vc/version-control.component'; import { VersionControlComponent } from '@home/components/vc/version-control.component';
import { TbPopoverService } from '@shared/components/popover.service'; import { TbPopoverService } from '@shared/components/popover.service';
import { tap } from 'rxjs/operators'; import { tap } from 'rxjs/operators';
import { LayoutWidthType } from '@home/components/dashboard-page/layout/layout.models'; import { LayoutFixedSize, LayoutWidthType } from '@home/components/dashboard-page/layout/layout.models';
// @dynamic // @dynamic
@Component({ @Component({
@ -703,11 +703,20 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
return layoutDimension.leftWidthPercentage + '%'; return layoutDimension.leftWidthPercentage + '%';
} }
} else { } else {
const dashboardWidth = this.dashboardContainer.nativeElement.getBoundingClientRect().width;
const minAvailableWidth = dashboardWidth - LayoutFixedSize.MIN;
if (layoutDimension.fixedLayout === layout) { if (layoutDimension.fixedLayout === layout) {
return layoutDimension.fixedWidth + 'px'; if (minAvailableWidth <= layoutDimension.fixedWidth) {
return minAvailableWidth + 'px';
} else {
return layoutDimension.fixedWidth + 'px';
}
} else { } else {
const layoutWidth = this.dashboardContainer.nativeElement.getBoundingClientRect().width - layoutDimension.fixedWidth; if (minAvailableWidth <= layoutDimension.fixedWidth) {
return layoutWidth + 'px'; return LayoutFixedSize.MIN + 'px';
} else {
return (dashboardWidth - layoutDimension.fixedWidth) + 'px';
}
} }
} }
} else { } else {

View File

@ -28,7 +28,7 @@
<section *ngIf="layoutCtx.widgets.isEmpty()" fxLayoutAlign="center center" <section *ngIf="layoutCtx.widgets.isEmpty()" fxLayoutAlign="center center"
style="display: flex; z-index: 1; pointer-events: none;" style="display: flex; z-index: 1; pointer-events: none;"
class="mat-headline tb-absolute-fill"> class="mat-headline tb-absolute-fill">
<span *ngIf="!isEdit"> <span *ngIf="!isEdit" style="text-align: center;">
{{'dashboard.no-widgets' | translate}} {{'dashboard.no-widgets' | translate}}
</span> </span>
<button mat-button *ngIf="isEdit && !widgetEditMode" class="tb-add-new-widget" <button mat-button *ngIf="isEdit && !widgetEditMode" class="tb-add-new-widget"

View File

@ -28,3 +28,13 @@ export enum LayoutWidthType {
FIXED = 'fixed' FIXED = 'fixed'
} }
export enum LayoutPercentageSize {
MIN = 10,
MAX = 90
}
export enum LayoutFixedSize {
MIN = 150,
MAX = 4000
}

View File

@ -49,7 +49,7 @@
#tooltip="matTooltip" #tooltip="matTooltip"
matTooltip="" matTooltip=""
matTooltipPosition="below"> matTooltipPosition="below">
<div fxLayout="column" fxLayoutAlign="start center" [fxFlex]="buttonFlexValue()" class="tb-layout-preview-container-main"> <div fxLayout="column" fxLayoutAlign="start center" fxFlex="{{ buttonFlexValue() }}" class="tb-layout-preview-container-main">
<button mat-icon-button <button mat-icon-button
type="button" type="button"
matTooltip="{{ 'dashboard.layout-settings' | translate }}" matTooltip="{{ 'dashboard.layout-settings' | translate }}"
@ -57,7 +57,7 @@
(click)="openLayoutSettings('main')" (click)="openLayoutSettings('main')"
class="tb-layout-preview-element" class="tb-layout-preview-element"
aria-label="Layout settings" aria-label="Layout settings"
[ngClass]="layoutButtonTextAndClass('main', false)"> [ngClass]="layoutButtonClass('main')">
<mat-icon>settings</mat-icon> <mat-icon>settings</mat-icon>
</button> </button>
<button fxFlex <button fxFlex
@ -65,35 +65,32 @@
mat-raised-button mat-raised-button
color="primary" color="primary"
class="tb-layout-button" class="tb-layout-button"
[matTooltip]="layoutButtonTextAndClass('main', true)" [matTooltip]="layoutButtonText('main')"
matTooltipPosition="above" matTooltipPosition="above"
matTooltipClass="tb-layout-button-tooltip" matTooltipClass="tb-layout-button-tooltip"
(click)="setFixedLayout('main')" (click)="setFixedLayout('main')"
[ngClass]="layoutButtonTextAndClass('main', false)" [ngClass]="layoutButtonClass('main', true)">
[ngStyle]="layoutsFormGroup.get('right').value ?
{'border-radius': '5px 0 0 5px;'} :
{'border-radius': '5px 5px 5px 5px;'}">
<span>{{ (layoutsFormGroup.value.right ? 'layout.left' : 'layout.main') | translate }}</span> <span>{{ (layoutsFormGroup.value.right ? 'layout.left' : 'layout.main') | translate }}</span>
</button> </button>
<div fxFlex class="tb-layout-preview-element tb-layout-preview-input" [fxShow]="showPreviewInputs('main')"> <div fxFlex class="tb-layout-preview-element tb-layout-preview-input" *ngIf="showPreviewInputs('main')">
<input [fxShow]="layoutsFormGroup.get('type').value !== LayoutWidthType.FIXED" <input *ngIf="layoutsFormGroup.get('type').value !== layoutWidthType.FIXED"
formControlName="leftWidthPercentage" formControlName="leftWidthPercentage"
type="number" type="number"
step="1" step="1"
min="10" min="{{ layoutPercentageSize.MIN }}"
max="90" max="{{ layoutPercentageSize.MAX }}"
required> required>
<input [fxShow]="layoutsFormGroup.get('type').value === LayoutWidthType.FIXED" <input *ngIf="layoutsFormGroup.get('type').value === layoutWidthType.FIXED &&
*ngIf="layoutsFormGroup.get('fixedLayout').value === 'main'" layoutsFormGroup.get('fixedLayout').value === 'main'"
formControlName="fixedWidth" formControlName="fixedWidth"
type="number" type="number"
step="1" step="1"
min="150" min="{{ layoutFixedSize.MIN }}"
max="1700" max="{{ layoutFixedSize.MAX }}"
required> required>
</div> </div>
</div> </div>
<div fxLayout="column" fxLayoutAlign="start center" fxFlex [fxShow]="layoutsFormGroup.get('right').value" matTooltip=""> <div fxLayout="column" fxLayoutAlign="start center" fxFlex *ngIf="layoutsFormGroup.get('right').value" matTooltip="">
<button mat-icon-button <button mat-icon-button
type="button" type="button"
matTooltip="{{ 'dashboard.layout-settings' | translate }}" matTooltip="{{ 'dashboard.layout-settings' | translate }}"
@ -101,56 +98,55 @@
(click)="openLayoutSettings('right')" (click)="openLayoutSettings('right')"
class="tb-layout-preview-element" class="tb-layout-preview-element"
aria-label="Layout settings" aria-label="Layout settings"
[ngClass]="layoutButtonTextAndClass('right', false)"> [ngClass]="layoutButtonClass('right')">
<mat-icon>settings</mat-icon> <mat-icon>settings</mat-icon>
</button> </button>
<button fxFlex <button fxFlex
type="button" type="button"
mat-raised-button mat-raised-button
color="primary" color="primary"
class="tb-layout-button" class="tb-layout-button tb-layout-button-right"
[matTooltip]="layoutButtonTextAndClass('right', true)" [matTooltip]="layoutButtonText('right')"
matTooltipPosition="above" matTooltipPosition="above"
matTooltipClass="tb-layout-button-tooltip" matTooltipClass="tb-layout-button-tooltip"
(click)="setFixedLayout('right')" (click)="setFixedLayout('right')"
[ngClass]="layoutButtonTextAndClass('right', false)" [ngClass]="layoutButtonClass('right')">
style="border-radius: 0 5px 5px 0;">
<span>{{ 'layout.right' | translate }}</span> <span>{{ 'layout.right' | translate }}</span>
</button> </button>
<div fxFlex class="tb-layout-preview-element tb-layout-preview-input" [fxShow]="showPreviewInputs('right')"> <div fxFlex class="tb-layout-preview-element tb-layout-preview-input" *ngIf="showPreviewInputs('right')">
<input [fxShow]="layoutsFormGroup.get('type').value !== LayoutWidthType.FIXED" <input *ngIf="layoutsFormGroup.get('type').value !== layoutWidthType.FIXED"
formControlName="rightWidthPercentage" formControlName="rightWidthPercentage"
type="number" type="number"
step="1" step="1"
min="10" min="{{ layoutPercentageSize.MIN }}"
max="90" max="{{ layoutPercentageSize.MAX }}"
required> required>
<input [fxShow]="layoutsFormGroup.get('type').value === LayoutWidthType.FIXED" <input *ngIf="layoutsFormGroup.get('type').value === layoutWidthType.FIXED"
formControlName="fixedWidth" formControlName="fixedWidth"
type="number" type="number"
step="1" step="1"
min="150" min="{{ layoutFixedSize.MIN }}"
max="1700" max="{{ layoutFixedSize.MAX }}"
required> required>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div fxLayout="column" fxLayoutAlign="center center" fxLayoutGap="8px" [fxShow]="layoutsFormGroup.get('right').value" style="width: 80%"> <div fxLayout="column" fxLayoutAlign="center center" fxLayoutGap="8px" *ngIf="layoutsFormGroup.get('right').value" style="width: 80%">
<mat-slider [fxShow]="layoutsFormGroup.get('type').value === LayoutWidthType.PERCENTAGE" <mat-slider *ngIf="layoutsFormGroup.get('type').value === layoutWidthType.PERCENTAGE"
min="10"
step="1" step="1"
max="90" min="{{ layoutPercentageSize.MIN }}"
max="{{ layoutPercentageSize.MAX }}"
style="width: 100%;" style="width: 100%;"
color="accent" color="accent"
formControlName="sliderPercentage" formControlName="sliderPercentage"
thumbLabel thumbLabel
[displayWith]="formatSliderTooltipLabel.bind(this)"> [displayWith]="formatSliderTooltipLabel.bind(this)">
</mat-slider> </mat-slider>
<mat-slider [fxShow]="layoutsFormGroup.get('type').value !== LayoutWidthType.PERCENTAGE" <mat-slider *ngIf="layoutsFormGroup.get('type').value !== layoutWidthType.PERCENTAGE"
min="150"
step="1" step="1"
max="1700" min="{{ layoutFixedSize.MIN }}"
max="{{ layoutFixedSize.MAX }}"
style="width: 100%;" style="width: 100%;"
color="accent" color="accent"
formControlName="sliderFixed" formControlName="sliderFixed"
@ -158,8 +154,12 @@
[displayWith]="formatSliderTooltipLabel.bind(this)"> [displayWith]="formatSliderTooltipLabel.bind(this)">
</mat-slider> </mat-slider>
<div fxLayout="row" fxLayoutAlign="space-between center" class="tb-hint tb-hint-group" style="width: 100%;"> <div fxLayout="row" fxLayoutAlign="space-between center" class="tb-hint tb-hint-group" style="width: 100%;">
<label>{{layoutsFormGroup.get('type').value === LayoutWidthType.PERCENTAGE ? '10 %' : '150px'}}</label> <label>
<label>{{layoutsFormGroup.get('type').value === LayoutWidthType.PERCENTAGE ? '90 %' : '1700px'}}</label> {{layoutsFormGroup.get('type').value === layoutWidthType.PERCENTAGE ? layoutPercentageSize.MIN + '%' : layoutFixedSize.MIN + 'px'}}
</label>
<label>
{{layoutsFormGroup.get('type').value === layoutWidthType.PERCENTAGE ? layoutPercentageSize.MAX + '%' : layoutFixedSize.MAX + 'px'}}
</label>
</div> </div>
</div> </div>
</div> </div>

View File

@ -39,7 +39,11 @@ import {
DashboardSettingsDialogComponent, DashboardSettingsDialogComponent,
DashboardSettingsDialogData DashboardSettingsDialogData
} from '@home/components/dashboard-page/dashboard-settings-dialog.component'; } from '@home/components/dashboard-page/dashboard-settings-dialog.component';
import { LayoutWidthType } from '@home/components/dashboard-page/layout/layout.models'; import {
LayoutFixedSize,
LayoutPercentageSize,
LayoutWidthType
} from '@home/components/dashboard-page/layout/layout.models';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { MatTooltip } from '@angular/material/tooltip'; import { MatTooltip } from '@angular/material/tooltip';
@ -60,7 +64,11 @@ export class ManageDashboardLayoutsDialogComponent extends DialogComponent<Manag
layoutsFormGroup: FormGroup; layoutsFormGroup: FormGroup;
LayoutWidthType = LayoutWidthType; layoutWidthType = LayoutWidthType;
layoutPercentageSize = LayoutPercentageSize;
layoutFixedSize = LayoutFixedSize;
private readonly layouts: DashboardStateLayouts; private readonly layouts: DashboardStateLayouts;
@ -87,11 +95,11 @@ export class ManageDashboardLayoutsDialogComponent extends DialogComponent<Manag
main: [{value: isDefined(this.layouts.main), disabled: true}], main: [{value: isDefined(this.layouts.main), disabled: true}],
right: [isDefined(this.layouts.right)], right: [isDefined(this.layouts.right)],
sliderPercentage: [50], sliderPercentage: [50],
sliderFixed: [150], sliderFixed: [this.layoutFixedSize.MIN],
leftWidthPercentage: [50, [Validators.min(10), Validators.max(90), Validators.required]], leftWidthPercentage: [50, [Validators.min(this.layoutPercentageSize.MIN), Validators.max(this.layoutPercentageSize.MAX), Validators.required]],
rightWidthPercentage: [50, [Validators.min(10), Validators.max(90), Validators.required]], rightWidthPercentage: [50, [Validators.min(this.layoutPercentageSize.MIN), Validators.max(this.layoutPercentageSize.MAX), Validators.required]],
type: [LayoutWidthType.PERCENTAGE], type: [LayoutWidthType.PERCENTAGE],
fixedWidth: [150, [Validators.min(150), Validators.max(1700), Validators.required]], fixedWidth: [this.layoutFixedSize.MIN, [Validators.min(this.layoutFixedSize.MIN), Validators.max(this.layoutFixedSize.MAX), Validators.required]],
fixedLayout: ['main', []] fixedLayout: ['main', []]
} }
); );
@ -233,7 +241,9 @@ export class ManageDashboardLayoutsDialogComponent extends DialogComponent<Manag
} }
} }
delete this.layouts.main.gridSettings.layoutDimension; delete this.layouts.main.gridSettings.layoutDimension;
delete this.layouts.right.gridSettings.layoutDimension; if (this.layouts.right?.gridSettings) {
delete this.layouts.right.gridSettings.layoutDimension;
}
if (this.layoutsFormGroup.value.right) { if (this.layoutsFormGroup.value.right) {
const formValues = this.layoutsFormGroup.value; const formValues = this.layoutsFormGroup.value;
const widthType = formValues.type; const widthType = formValues.type;
@ -338,17 +348,24 @@ export class ManageDashboardLayoutsDialogComponent extends DialogComponent<Manag
} }
} }
layoutButtonTextAndClass(side: string, isText: boolean): string { layoutButtonClass(side: DashboardLayoutId, border: boolean = false): string {
const formValues = this.layoutsFormGroup.value;
if (formValues.right) {
let classString = border ? 'tb-layout-button-main ' : '';
if (!(formValues.fixedLayout === side || formValues.type === LayoutWidthType.PERCENTAGE)) {
classString += 'tb-fixed-layout-button';
}
return classString;
}
}
layoutButtonText(side: DashboardLayoutId): string {
const formValues = this.layoutsFormGroup.value; const formValues = this.layoutsFormGroup.value;
if (!(formValues.fixedLayout === side || !formValues.right || formValues.type === LayoutWidthType.PERCENTAGE)) { if (!(formValues.fixedLayout === side || !formValues.right || formValues.type === LayoutWidthType.PERCENTAGE)) {
if (isText) { if (side === 'main') {
if (side === 'main') { return this.translate.instant('layout.left-side');
return this.translate.instant('layout.left-side');
} else {
return this.translate.instant('layout.right-side');
}
} else { } else {
return 'tb-fixed-layout-button'; return this.translate.instant('layout.right-side');
} }
} }
} }

View File

@ -19,6 +19,15 @@
height: 100%; height: 100%;
padding: 40px 10px; padding: 40px 10px;
cursor: default; cursor: default;
border-radius: 5px;
&-right {
border-radius: 0 5px 5px 0;
}
&-main {
border-radius: 5px 0 0 5px;
}
} }
&::ng-deep { &::ng-deep {