enable expandable rows for devices list

This commit is contained in:
Jesse Lucas 2020-04-11 22:50:42 -04:00
parent 48efea99e5
commit 7a9f317ee1
5 changed files with 80 additions and 30 deletions

View File

@ -2,27 +2,28 @@
<mat-label>Filter</mat-label> <mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event)" placeholder="Ex. Up to Date"> <input matInput (keyup)="applyFilter($event)" placeholder="Ex. Up to Date">
</mat-form-field> </mat-form-field>
<table mat-table class="full-width-table" matSort aria-label="Elements"> <table mat-table class="full-width-table" matSort aria-label="Devices" multiTemplateDataRows>
<!-- Id Column --> <ng-container matColumnDef="{{column}}" *ngFor="let column of displayedColumns">
<ng-container matColumnDef="id"> <th mat-header-cell *matHeaderCellDef> {{column}} </th>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th> <td mat-cell *matCellDef="let device"> {{device[column]}} </td>
<td mat-cell *matCellDef="let row">{{row.deviceID}}</td>
</ng-container> </ng-container>
<ng-container matColumnDef="expandedDetail">
<!-- Name Column --> <td mat-cell *matCellDef="let device" [attr.colspan]="displayedColumns.length">
<ng-container matColumnDef="name"> <div class="device-detail" [@detailExpand]="device == expandedDevice ? 'expanded' : 'collapsed'">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th> <div class="device-folders">
<td mat-cell *matCellDef="let row">{{row.name}}</td> <span>Folders: </span>
</ng-container> <span class="folder-name" *ngFor="let folder of device.folders">{{folder.label | trim}}</span>
</div>
<!-- Status Column --> </div>
<ng-container matColumnDef="state"> </td>
<th mat-header-cell *matHeaderCellDef mat-sort-header>State</th>
<td mat-cell *matCellDef="let row">{{row.state}}</td>
</ng-container> </ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr> <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> <tr mat-row *matRowDef="let device; columns: displayedColumns;" class="device-row"
[class.expanded-row]="expandedDevice === device"
(click)="expandedDevice = expandedDevice === device ? null : device">
</tr>
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="detail-row"></tr>
</table> </table>
<mat-paginator #paginator [length]="dataSource?.data.length" [pageIndex]="0" [pageSize]="25" <mat-paginator #paginator [length]="dataSource?.data.length" [pageIndex]="0" [pageSize]="25"

View File

@ -1,8 +1,44 @@
.full-width-table { .full-width-table {
width: 100%; width: 100%;
}
.mat-form-field {
font-size: 14px;
width: 100%;
} }
.mat-form-field { tr.detail-row {
font-size: 14px; height: 0;
width: 100%; }
tr.device-row:not(.expanded-row):hover {
background: whitesmoke;
}
/*
tr.device-row:not(.device-row):active {
background: #efefef;
}
*/
.device-row td {
border-bottom-width: 0;
}
.device-detail {
overflow: hidden;
display: flex;
}
.device-folders {
padding-bottom: 16px;
}
// Hide empty name
.folder-name:empty {
display: none;
}
.folder-name:not(:last-child):after {
content: ", ";
} }

View File

@ -9,11 +9,19 @@ import { FilterService } from 'src/app/services/filter.service';
import { StType } from 'src/app/type'; import { StType } from 'src/app/type';
import { MatInput } from '@angular/material/input'; import { MatInput } from '@angular/material/input';
import { DeviceService } from 'src/app/services/device.service'; import { DeviceService } from 'src/app/services/device.service';
import { trigger, state, style, transition, animate } from '@angular/animations';
@Component({ @Component({
selector: 'app-device-list', selector: 'app-device-list',
templateUrl: './device-list.component.html', templateUrl: './device-list.component.html',
styleUrls: ['./device-list.component.scss'] styleUrls: ['./device-list.component.scss'],
animations: [
trigger('detailExpand', [
state('collapsed', style({ height: '0px', minHeight: '0' })),
state('expanded', style({ height: '*' })),
transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
]),
],
}) })
export class DeviceListComponent implements AfterViewInit, OnInit, OnDestroy { export class DeviceListComponent implements AfterViewInit, OnInit, OnDestroy {
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ -23,7 +31,8 @@ export class DeviceListComponent implements AfterViewInit, OnInit, OnDestroy {
dataSource: MatTableDataSource<Device>; dataSource: MatTableDataSource<Device>;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['id', 'name', 'state']; displayedColumns = ['deviceID', 'name', 'state'];
expandedDevice: Device | null;
constructor( constructor(
private deviceService: DeviceService, private deviceService: DeviceService,

View File

@ -11,13 +11,15 @@ tr.detail-row {
height: 0; height: 0;
} }
tr.folder-row:not(.example-expanded-row):hover { tr.folder-row:not(.expanded-row):hover {
background: whitesmoke; background: whitesmoke;
} }
/*
tr.folder-row:not(.folder-row):active { tr.folder-row:not(.folder-row):active {
background: #efefef; background: #efefef;
} }
*/
.folder-row td { .folder-row td {
border-bottom-width: 0; border-bottom-width: 0;
@ -32,15 +34,11 @@ tr.folder-row:not(.folder-row):active {
padding-bottom: 16px; padding-bottom: 16px;
} }
.device-name:not(:first-child) {
margin-left: -.3em;
}
// Hide empty name // Hide empty name
.device-name:empty { .device-name:empty {
display: none; display: none;
} }
.device-name:not(:first-child):before { .device-name:not(:last-child):after {
content: ", "; content: ", ";
} }

View File

@ -31,7 +31,13 @@ export class FolderListComponent implements AfterViewInit, OnInit, OnDestroy {
dataSource: MatTableDataSource<Folder>; dataSource: MatTableDataSource<Folder>;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['id', 'label', 'path', 'state']; displayedColumns = [
"id",
"label",
"path",
"state"
];
expandedFolder: Folder | null; expandedFolder: Folder | null;
constructor( constructor(