diff --git a/src/app/shopping/list/list.component.html b/src/app/shopping/list/list.component.html index 746c22d..c568a45 100644 --- a/src/app/shopping/list/list.component.html +++ b/src/app/shopping/list/list.component.html @@ -1,4 +1,12 @@

Shopping List: {{name}}

+ + + + -
+
+ +
- + Shopping List: {{name}} {{items.qty}}x {{items.nett}}{{items.nett_unit}}   {{items.label}} @ {{currency[currencySel].symbol}}{{items.price * items.qty | number: '1.2-2'}} - + + + @@ -66,23 +81,82 @@

Shopping List: {{name}}

trending_up - +
- + + +
+ + Filter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Item {{slist.label}} Qty {{slist.qty}} Nett {{slist.nett}}{{slist.nett_unit}} Cost {{currency[currencySel].symbol}}{{slist.price}} Shop {{slist.shop}} + shopping_cart + shopping_cart +
No data matching the filter
+
+
+ +
+ +
diff --git a/src/app/shopping/list/list.component.scss b/src/app/shopping/list/list.component.scss index 38a4ca3..58a7c0d 100644 --- a/src/app/shopping/list/list.component.scss +++ b/src/app/shopping/list/list.component.scss @@ -1,3 +1,10 @@ +table { + width: 90%; + margin: auto; + table-layout: fixed; + //min-width: 500px; +} + .overall { overflow: auto; } @@ -55,4 +62,10 @@ .total-chip{ margin-left: 80%; +} + +.paginator { + margin: auto; + width: 90%; + //min-width: 500px; } \ No newline at end of file diff --git a/src/app/shopping/list/list.component.ts b/src/app/shopping/list/list.component.ts index bac2ea4..6a52b93 100644 --- a/src/app/shopping/list/list.component.ts +++ b/src/app/shopping/list/list.component.ts @@ -13,6 +13,11 @@ import {map, startWith} from 'rxjs/operators'; import { Item, Shop, SList, SlistEdge, SlistItem, SlistEdgeItem, TrendItem } from '../../interfaces'; import { DataService } from '../../data.service'; +//Table option +import { MatPaginator } from '@angular/material/paginator'; +import { MatSort } from '@angular/material/sort'; +import { MatTableDataSource } from '@angular/material/table'; + //Chart specific imports import { ViewChild } from '@angular/core'; import { Chart, ChartConfiguration, ChartEvent, ChartType } from 'chart.js'; @@ -48,6 +53,7 @@ export class ListComponent implements OnInit { name = ""; screenSize: boolean; fontSize = "normal"; + renderDefaultType = true; // true = accordion | false = table currency :curr[] = [ {abbr: "USD", symbol: "$", icon: "🇺🇸", value: 0}, @@ -58,6 +64,12 @@ export class ListComponent implements OnInit { ]; currencySel = 3; + //Table option + displayedColumns: string[] = ['label', 'qty', 'nett', 'cost', 'trolley']; + dataSource = new MatTableDataSource(); //Initiate data source class. Requires import of MatTableDataSource above. + @ViewChild(MatPaginator) paginator!: MatPaginator; + @ViewChild(MatSort) sort!: MatSort; + constructor( private route: ActivatedRoute, private dataService: DataService, @@ -73,6 +85,7 @@ export class ListComponent implements OnInit { this.getShoppingList(); this.getName(this.id.toString()); this.setFontSize(); + this.getShoppingListTable(); } setCurrency(x: number){ @@ -92,7 +105,36 @@ export class ListComponent implements OnInit { complete: () => this.setTrolleyInit(), } ); - + } + + getShoppingListTable(): void { + this.dataService.getShoppingList(this.id.toString()).subscribe({ + next: (list) => { + + var list2: SlistItem[] = []; + list.forEach(function (value){ + value.items.forEach( function (value2) { + var listx = value2; + list2.push(listx) + }) + }); + + this.dataSource.data = list2; + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + }, + error: e => console.error(e), + } + ); + } + + applyFilter(event: Event) { + const filterValue = (event.target as HTMLInputElement).value; + this.dataSource.filter = filterValue.trim().toLowerCase(); + + if (this.dataSource.paginator) { + this.dataSource.paginator.firstPage(); + } } //Update shopping list is used to dynamically update shopList when add/edit/remove/move @@ -242,6 +284,8 @@ export class ListComponent implements OnInit { ) } + + delShopListItem(key: SlistItem, shopD: string){ //warning modal var a = confirm("Do you really want to remove this item from your shopping list?"); @@ -372,7 +416,6 @@ export class ListComponent implements OnInit { } - } diff --git a/src/app/shopping/trolley/trolley.component.html b/src/app/shopping/trolley/trolley.component.html index a7fcb75..0752dbb 100644 --- a/src/app/shopping/trolley/trolley.component.html +++ b/src/app/shopping/trolley/trolley.component.html @@ -19,7 +19,7 @@ Indiv. Price - {{item.currency}} {{item.price | number:'1-2-2'}} + {{item.currency}} {{item.price | number:'1.2-2'}} Total