UI: Clear code and change style

This commit is contained in:
Vladyslav_Prykhodko 2022-11-02 16:55:33 +02:00
parent 03794c1ad3
commit 8271b0534b
5 changed files with 43 additions and 19 deletions

View File

@ -173,7 +173,6 @@ import { RateLimitsDetailsDialogComponent } from '@home/components/profile/tenan
import { AssetProfileComponent } from '@home/components/profile/asset-profile.component'; import { AssetProfileComponent } from '@home/components/profile/asset-profile.component';
import { AssetProfileDialogComponent } from '@home/components/profile/asset-profile-dialog.component'; import { AssetProfileDialogComponent } from '@home/components/profile/asset-profile-dialog.component';
import { AssetProfileAutocompleteComponent } from '@home/components/profile/asset-profile-autocomplete.component'; import { AssetProfileAutocompleteComponent } from '@home/components/profile/asset-profile-autocomplete.component';
import { DragDropModule } from '@angular/cdk/drag-drop';
@NgModule({ @NgModule({
declarations: declarations:
@ -322,7 +321,6 @@ import { DragDropModule } from '@angular/cdk/drag-drop';
imports: [ imports: [
CommonModule, CommonModule,
SharedModule, SharedModule,
DragDropModule,
SharedHomeComponentsModule, SharedHomeComponentsModule,
WidgetSettingsModule, WidgetSettingsModule,
Lwm2mProfileComponentsModule, Lwm2mProfileComponentsModule,
@ -455,8 +453,7 @@ import { DragDropModule } from '@angular/cdk/drag-drop';
RateLimitsListComponent, RateLimitsListComponent,
RateLimitsComponent, RateLimitsComponent,
RateLimitsTextComponent, RateLimitsTextComponent,
RateLimitsDetailsDialogComponent, RateLimitsDetailsDialogComponent
DragDropModule
], ],
providers: [ providers: [
WidgetComponentService, WidgetComponentService,

View File

@ -59,36 +59,49 @@
</div> </div>
</mat-toolbar> </mat-toolbar>
<div fxFlex class="table-container"> <div fxFlex class="table-container">
<table mat-table [dataSource]="dataSource" <table mat-table
[dataSource]="dataSource"
matSort [matSortActive]="pageLink.sortOrder.property" [matSortDirection]="pageLink.sortDirection()" matSortDisableClear matSort [matSortActive]="pageLink.sortOrder.property" [matSortDirection]="pageLink.sortDirection()" matSortDisableClear
cdkDropList [cdkDropListData]="dataSource" (cdkDropListDropped)="dropAction($event)"> cdkDropList cdkDropListOrientation="vertical"
[cdkDropListData]="dataSource"
(cdkDropListDropped)="dropAction($event)"
[cdkDropListDisabled]="dragDisabled"
class="tb-drop-list">
<ng-container matColumnDef="actionSourceId"> <ng-container matColumnDef="actionSourceId">
<mat-header-cell *matHeaderCellDef mat-sort-header style="width: 40px"> {{ 'widget-config.action-source-order' | translate }} </mat-header-cell> <mat-header-cell *matHeaderCellDef style="width: 36px"></mat-header-cell>
<mat-cell *matCellDef="let action"> <mat-cell *matCellDef="let action">
<mat-icon cdkDragHandle>reorder</mat-icon> <div cdkDragHandle
class="tb-drag-handle"
style="min-width: 36px"
(mousedown)="dragDisabled = false"
(mouseup)="dragDisabled = true"
matTooltip="{{ 'action.drag' | translate }}"
matTooltipPosition="above">
<mat-icon>drag_handle</mat-icon>
</div>
</mat-cell> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="actionSourceName"> <ng-container matColumnDef="actionSourceName">
<mat-header-cell *matHeaderCellDef mat-sort-header style="width: 20%"> {{ 'widget-config.action-source' | translate }} </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header style="width: 20%"> {{ 'widget-config.action-source' | translate }} </mat-header-cell>
<mat-cell *matCellDef="let action"> <mat-cell *matCellDef="let action" style="width: 20%">
{{ action.actionSourceName }} {{ action.actionSourceName }}
</mat-cell> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="name"> <ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header style="width: 30%"> {{ 'widget-config.action-name' | translate }} </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header style="width: 30%"> {{ 'widget-config.action-name' | translate }} </mat-header-cell>
<mat-cell *matCellDef="let action"> <mat-cell *matCellDef="let action" style="width: 30%">
{{ action.name }} {{ action.name }}
</mat-cell> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="icon"> <ng-container matColumnDef="icon">
<mat-header-cell *matHeaderCellDef mat-sort-header style="width: 40px"> {{ 'widget-config.action-icon' | translate }} </mat-header-cell> <mat-header-cell *matHeaderCellDef style="width: 40px"> {{ 'widget-config.action-icon' | translate }} </mat-header-cell>
<mat-cell *matCellDef="let action"> <mat-cell *matCellDef="let action" style="width: 40px">
<mat-icon>{{ action.icon }}</mat-icon> <mat-icon>{{ action.icon }}</mat-icon>
</mat-cell> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="typeName"> <ng-container matColumnDef="typeName">
<mat-header-cell *matHeaderCellDef mat-sort-header style="width: 50%"> {{ 'widget-config.action-type' | translate }} </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header style="width: 50%"> {{ 'widget-config.action-type' | translate }} </mat-header-cell>
<mat-cell *matCellDef="let action"> <mat-cell *matCellDef="let action" style="width: 50%">
{{ action.typeName }} {{ action.typeName }}
</mat-cell> </mat-cell>
</ng-container> </ng-container>
@ -114,8 +127,8 @@
</div> </div>
</mat-cell> </mat-cell>
</ng-container> </ng-container>
<mat-header-row [ngClass]="{'mat-row-select': true}" *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row> <mat-header-row class="mat-row-select" *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
<mat-row [ngClass]="{'mat-row-select': true}" <mat-row class="mat-row-select tb-draggable"
*matRowDef="let action; columns: displayedColumns;" *matRowDef="let action; columns: displayedColumns;"
cdkDrag [cdkDragData]="action"></mat-row> cdkDrag [cdkDragData]="action"></mat-row>
</table> </table>

View File

@ -41,4 +41,17 @@
.mat-sort-header-sorted .mat-sort-header-arrow { .mat-sort-header-sorted .mat-sort-header-arrow {
opacity: 1 !important; opacity: 1 !important;
} }
.tb-draggable {
&.cdk-drag-placeholder {
opacity: 0;
}
&.cdk-drag-preview {
box-sizing: border-box;
border-radius: 4px;
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
0 8px 10px 1px rgba(0, 0, 0, 0.14),
0 3px 14px 2px rgba(0, 0, 0, 0.12);
}
}
} }

View File

@ -54,7 +54,7 @@ import {
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { ResizeObserver } from '@juggle/resize-observer'; import { ResizeObserver } from '@juggle/resize-observer';
import { hidePageSizePixelValue } from '@shared/models/constants'; import { hidePageSizePixelValue } from '@shared/models/constants';
import {CdkDragDrop, moveItemInArray, CdkDragHandle} from '@angular/cdk/drag-drop'; import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
@Component({ @Component({
selector: 'tb-manage-widget-actions', selector: 'tb-manage-widget-actions',
@ -86,6 +86,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
viewsInited = false; viewsInited = false;
dirtyValue = false; dirtyValue = false;
dragDisabled = true;
private widgetResize$: ResizeObserver; private widgetResize$: ResizeObserver;
@ -164,7 +165,8 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
this.dataSource.loadActions(this.pageLink, reload); this.dataSource.loadActions(this.pageLink, reload);
} }
dropAction(event: CdkDragDrop<WidgetActionDescriptorInfo[]>) { dropAction(event: CdkDragDrop<WidgetActionsDatasource>) {
this.dragDisabled = true;
const droppedAction = event.item.data; const droppedAction = event.item.data;
this.dataSource.getAllActions().subscribe( this.dataSource.getAllActions().subscribe(
(actions) => { (actions) => {
@ -183,7 +185,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
} }
const targetActions = this.getOrCreateTargetActions(droppedAction.actionSourceId); const targetActions = this.getOrCreateTargetActions(droppedAction.actionSourceId);
let oldIndex: number = -1; let oldIndex = -1;
let newIndex: number = nearestNeighbourAction ? -1 : (isBackward ? targetActions.length - 1 : 0); let newIndex: number = nearestNeighbourAction ? -1 : (isBackward ? targetActions.length - 1 : 0);
for (let i: number = isBackward ? targetActions.length - 1 : 0; for (let i: number = isBackward ? targetActions.length - 1 : 0;

View File

@ -3686,7 +3686,6 @@
"add-action": "Add action", "add-action": "Add action",
"search-actions": "Search actions", "search-actions": "Search actions",
"no-actions-text": "No actions found", "no-actions-text": "No actions found",
"action-source-order": "Order",
"action-source": "Action source", "action-source": "Action source",
"action-source-required": "Action source is required.", "action-source-required": "Action source is required.",
"action-name": "Name", "action-name": "Name",