Skip to content

Commit e04aa36

Browse files
author
Binod Sahu
committed
table view added
1 parent 9396b7d commit e04aa36

File tree

5 files changed

+60
-76
lines changed

5 files changed

+60
-76
lines changed
Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
<div class="mat-elevation-z8">
2-
<table mat-table [dataSource]="dataSource">
3-
4-
<!-- Position Column -->
5-
<ng-container matColumnDef="position">
6-
<th mat-header-cell *matHeaderCellDef> No. </th>
7-
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
8-
</ng-container>
9-
10-
<!-- Name Column -->
11-
<ng-container matColumnDef="name">
12-
<th mat-header-cell *matHeaderCellDef> Name </th>
13-
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
14-
</ng-container>
15-
16-
<!-- Weight Column -->
17-
<ng-container matColumnDef="weight">
18-
<th mat-header-cell *matHeaderCellDef> Weight </th>
19-
<td mat-cell *matCellDef="let element"> {{element.weight}} </td>
20-
</ng-container>
21-
22-
<!-- Symbol Column -->
23-
<ng-container matColumnDef="symbol">
24-
<th mat-header-cell *matHeaderCellDef> Symbol </th>
25-
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
26-
</ng-container>
27-
28-
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
29-
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
30-
</table>
31-
32-
<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
2+
<table mat-table [dataSource]="dataSource">
3+
4+
<!-- Position Column -->
5+
<ng-container matColumnDef="model">
6+
<th mat-header-cell *matHeaderCellDef> Model </th>
7+
<td mat-cell *matCellDef="let element"> {{element.model}} </td>
8+
</ng-container>
9+
10+
<!-- Name Column -->
11+
<ng-container matColumnDef="ram">
12+
<th mat-header-cell *matHeaderCellDef> RAM </th>
13+
<td mat-cell *matCellDef="let element"> {{element.ram.memory}} {{element.ram.unit}}</td>
14+
</ng-container>
15+
16+
<!-- Weight Column -->
17+
<ng-container matColumnDef="hdd">
18+
<th mat-header-cell *matHeaderCellDef> HDD </th>
19+
<td mat-cell *matCellDef="let element"> {{element.hdd.count}}{{element.hdd.unit}} </td>
20+
</ng-container>
21+
22+
<!-- Symbol Column -->
23+
<ng-container matColumnDef="location">
24+
<th mat-header-cell *matHeaderCellDef> Location </th>
25+
<td mat-cell *matCellDef="let element"> {{element.location | slice:0:-6}} </td>
26+
</ng-container>
27+
28+
<!-- Symbol Column -->
29+
<ng-container matColumnDef="price">
30+
<th mat-header-cell *matHeaderCellDef> price </th>
31+
<td mat-cell *matCellDef="let element"> {{element.price.currencySymbol}} {{element.price.amountCents}} </td>
32+
</ng-container>
33+
34+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
35+
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
36+
</table>
37+
38+
<mat-paginator [pageSizeOptions]="[10, 20, 30]" showFirstLastButtons></mat-paginator>
3339
</div>
Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,29 @@
1-
import { Component, OnInit, ViewChild } from '@angular/core';
1+
import { Component, OnInit, ViewChild, Input, ChangeDetectorRef, SimpleChanges, OnChanges } from '@angular/core';
22
import {MatPaginator} from '@angular/material/paginator';
33
import {MatTableDataSource} from '@angular/material/table';
44
// import { PeriodicElement } from '../customer-side-nav/customer-side-nav.component';
5-
6-
export interface PeriodicElement {
7-
name: string;
8-
position: number;
9-
weight: number;
10-
symbol: string;
11-
}
5+
import {
6+
Servers
7+
} from 'src/app/model/customer';
128

139
@Component({
1410
selector: 'app-customer-right-side-table',
1511
templateUrl: './customer-right-side-table.component.html',
1612
styleUrls: ['./customer-right-side-table.component.scss']
1713
})
18-
export class CustomerRightSideTableComponent implements OnInit {
19-
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
20-
dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
14+
export class CustomerRightSideTableComponent implements OnInit, OnChanges {
15+
@Input() serverTabledata: Servers[] = null;
16+
displayedColumns: string[] = ['model', 'ram', 'hdd', 'location', 'price'];
17+
dataSource: MatTableDataSource<Servers> = null;
2118
@ViewChild(MatPaginator) paginator: MatPaginator;
2219

23-
constructor() { }
20+
constructor(private cd: ChangeDetectorRef) { }
2421

25-
ngOnInit() {
22+
ngOnInit() { }
23+
24+
ngOnChanges(changes: SimpleChanges): void {
25+
this.dataSource = new MatTableDataSource(this.serverTabledata);
2626
this.dataSource.paginator = this.paginator;
27+
this.cd.markForCheck();
2728
}
28-
2929
}
30-
31-
const ELEMENT_DATA: PeriodicElement[] = [
32-
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
33-
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
34-
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
35-
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
36-
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
37-
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
38-
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
39-
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
40-
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
41-
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
42-
{position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'},
43-
{position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'},
44-
{position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'},
45-
{position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'},
46-
{position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'},
47-
{position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'},
48-
{position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'},
49-
{position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'},
50-
{position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'},
51-
{position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'},
52-
];

src/app/components/customer-side-nav/customer-side-nav.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@
5454
</div>
5555
</div>
5656
<div class="customer-table-container">
57-
<app-customer-right-side-table></app-customer-right-side-table>
57+
<app-customer-right-side-table [serverTabledata]="serverTabledata"></app-customer-right-side-table>
5858
</div>
5959
</div>

src/app/components/customer-side-nav/customer-side-nav.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Component, OnInit, ViewEncapsulation, ViewChild } from '@angular/core';
1+
import { Component, OnInit, ViewEncapsulation, ViewChild, ChangeDetectorRef } from '@angular/core';
22
import { CustomerService } from 'src/app/services/customer-service';
33
import {
44
Customer,
55
HDDs,
66
Hddtype,
77
checkboxContentType,
8-
checkboxContent
8+
checkboxContent, Servers
99
} from 'src/app/model/customer';
1010
import { removeDuplicates } from '../../util/util';
1111

@@ -22,12 +22,14 @@ export class CustomerSideNavComponent implements OnInit {
2222
step = 250;
2323
stepRange = [0, 72000];
2424
serverData: Customer;
25+
serverTabledata: Servers[];
2526
HDDs: Hddtype[] = HDDs;
2627
ramCheckboxContent: checkboxContentType[] = checkboxContent;
2728
locationDropdown: string | string[];
2829

2930
constructor(
30-
public restApi: CustomerService
31+
public restApi: CustomerService,
32+
private cd: ChangeDetectorRef
3133
) { }
3234

3335
ngOnInit() {
@@ -37,17 +39,17 @@ export class CustomerSideNavComponent implements OnInit {
3739
loadCustomer() {
3840
this.restApi.getCustomer().subscribe((data: Customer) => {
3941
this.serverData = data;
40-
console.log(this.serverData.servers);
42+
this.serverTabledata = data.servers;
43+
this.cd.markForCheck();
4144
this.locationDropdown = removeDuplicates(this.serverData.servers.map(location => { return location.location }));
42-
console.log(this.locationDropdown);
4345
});
4446
}
4547
rangeChanged(event) {
4648
console.log(event[0]);
4749
console.log(event[1]);
4850
}
4951
valueChange() {
50-
console.log(this.ramCheckboxContent.filter(x => x.checked === true).map(x => x.name).join(','));
52+
console.log(this.ramCheckboxContent.filter(x => x.checked === true).map(x => x.value).join(','));
5153
}
5254
locationSelection(event){
5355
console.error(event.value);

src/app/services/customer-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class CustomerService {
1212

1313
endpointURL:string = 'http://assignment.ut3.nl:4300/api/servers';
1414
constructor(private httpClient: HttpClient) { }
15-
1615
getFilteredCustomerList(searchParams){
1716
const httpOptions = {
1817
params: new HttpParams().set("storageMin", searchParams.storageMin)

0 commit comments

Comments
 (0)