diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 06e62ec..82dd7d5 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -3,6 +3,9 @@ import { NgModule } from '@angular/core'; import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; +import {DragDropModule} from '@angular/cdk/drag-drop'; + + // Angular Material Components import {MatToolbarModule} from '@angular/material/toolbar'; import {MatButtonModule} from '@angular/material/button'; @@ -16,6 +19,7 @@ import {MatListModule} from '@angular/material/list'; import {MatFormFieldModule} from '@angular/material/form-field'; import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; import {MatProgressBarModule} from '@angular/material/progress-bar'; +import {MatCheckboxModule} from '@angular/material/checkbox'; import { AppRoutingModule } from './app-routing.module'; @@ -58,7 +62,9 @@ import { TableOverviewComponent } from './pages/table-overview/table-overview.co MatFormFieldModule, MatProgressSpinnerModule, MatProgressBarModule, - GraphQLModule + MatCheckboxModule, + GraphQLModule, + DragDropModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/pages/tables/bikes/bikes.component.html b/src/app/pages/tables/bikes/bikes.component.html index 13bd53f..5c2fc6c 100644 --- a/src/app/pages/tables/bikes/bikes.component.html +++ b/src/app/pages/tables/bikes/bikes.component.html @@ -2,46 +2,84 @@ - - - - - - - + + + + + - - - - - + + + + + - - - - + + + + + + + - + {{ element.security.frameNumber }} + + + + + + + + - - - - - + + + + + - - -
ID{{ element.id }} + + + + + + Name - {{ element.name }} - Name + {{ element.name }} + Fahrgestellnummer - + + ID{{ element.id }}Fahrgestellnummer + - {{ element.security.frameNumber }} - Anzahl Kinder{{ element.numberOfChildren }}Anzahl Kinder{{ element.numberOfChildren }} + more_vert +
+ + + + + diff --git a/src/app/pages/tables/bikes/bikes.component.scss b/src/app/pages/tables/bikes/bikes.component.scss index c53b27c..0c8228e 100644 --- a/src/app/pages/tables/bikes/bikes.component.scss +++ b/src/app/pages/tables/bikes/bikes.component.scss @@ -1,6 +1,24 @@ .table-control { - margin: 0.5em; + margin: 0.5em; } -table { +#table-container { + width: 100%; + max-width: 100%; + overflow: auto; + table { width: 100%; -} \ No newline at end of file + th.mat-column-name, + td.mat-column-name { + padding-left: 8px; + } + + .mat-table-sticky:first-child { + border-right: 1px solid #ffffff1f; + padding-right: 1em; + } + + .mat-table-sticky:last-child { + border-left: 1px solid #ffffff1f; + } + } +} diff --git a/src/app/pages/tables/bikes/bikes.component.ts b/src/app/pages/tables/bikes/bikes.component.ts index cbf0e03..019a1d3 100644 --- a/src/app/pages/tables/bikes/bikes.component.ts +++ b/src/app/pages/tables/bikes/bikes.component.ts @@ -1,4 +1,6 @@ +import { SelectionModel } from '@angular/cdk/collections'; import { Component, OnInit } from '@angular/core'; +import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop'; import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service'; @Component({ @@ -7,13 +9,34 @@ import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service'; styleUrls: ['./bikes.component.scss'], }) export class BikesComponent { - displayedColumns: string[] = ['id', 'name', 'frameNumber', 'numberOfChildren']; + displayedColumns: string[] = ['select', 'name', 'id', 'frameNumber', 'numberOfChildren', 'buttons']; bikes: CargoBikeResult[]; + selection = new SelectionModel(true, []); + constructor(private bikesService: BikesService) { bikesService.bikes.subscribe(bikes => this.bikes = bikes); bikesService.loadBikes(); } + + drop(event: CdkDragDrop) { + console.log(event); + moveItemInArray(this.displayedColumns, event.previousIndex + 1, event.currentIndex + 1); // + 1 because the first (selection) column is not dragable + } + + /** Whether the number of selected elements matches the total number of rows. */ + isAllSelected() { + const numSelected = this.selection.selected.length; + const numRows = this.bikes.length; + return numSelected === numRows; + } + + /** Selects all rows if they are not all selected; otherwise clear selection. */ + masterToggle() { + this.isAllSelected() ? + this.selection.clear() : + this.bikes.forEach(row => this.selection.select(row)); + } }