Skip to content

Commit 57feafb

Browse files
author
ALEXANDRU BEZDADEA
committed
dataSorce functionala
1 parent af6539f commit 57feafb

File tree

5 files changed

+86
-32
lines changed

5 files changed

+86
-32
lines changed

src/app/app.component.html

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,32 @@
11
<div class="error-message" *ngIf="errorMessage">
22
{{ errorMessage }}
33
</div>
4-
54
<div id="scanner-container">
65
<!-- QuaggaJS will populate this element -->
76
</div>
8-
97
<div class="instructions">
108
<!-- This is a companion app for the blog post located <a target="_blank" href="https://blog.classycode.com/">here</a>.
119
The source code is available on <a target="_blank" href="https://github.com/classycodeoss/mobile-scanning-demo">Github</a>. -->
12-
1310
<ul>
1411
<li *ngFor="let item of catalogue2">{{item.name}}, preț: {{item.price}}</li>
1512
</ul>
1613
<!-- <p>{{catalogue2.price}}</p> -->
17-
18-
1914
</div>
20-
2115
<div class="controls">
2216
<form>
2317
<input id="acceptAnyCode" type="checkbox" [(ngModel)]="acceptAnyCode" name="acceptAnyCode" required />
2418
<label for="acceptAnyCode">Acceptă și coduri neînregistrate în sistem</label>
2519
&nbsp;
26-
2720
<button (click)="clearCart()">Șterge selecții</button>
2821
</form>
29-
3022
</div>
31-
3223
<div class="shopping-cart">
33-
34-
35-
36-
<ul>
24+
<!-- <ul>
3725
<small>
3826
<li *ngFor="let item of catalogue2"> {{item.name}}, Cod bare: {{item.ean}}</li>
3927
</small>
40-
</ul>
41-
42-
43-
28+
</ul> -->
4429
<span *ngIf="items.length === 0 else shoppingCartItems">Lista e goală</span>
45-
4630
<mat-tab-group>
4731
<mat-tab>
4832
<ng-template mat-tab-label>
@@ -51,30 +35,40 @@
5135
</ng-template>
5236
Content 1
5337
</mat-tab>
54-
5538
<mat-tab>
5639
<ng-template mat-tab-label>
5740
<!-- <mat-icon class="example-tab-icon">thumb_up</mat-icon> -->
5841
Second
5942
</ng-template>
60-
Content 2
43+
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
44+
<!--- Note that these columns can be defined in any order.
45+
The actual rendered columns are set as a property on the row definition" -->
46+
<!-- Name Column -->
47+
<ng-container matColumnDef="name">
48+
<th mat-header-cell *matHeaderCellDef> Name </th>
49+
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
50+
</ng-container>
51+
<!-- Ean Column -->
52+
<ng-container matColumnDef="ean">
53+
<th mat-header-cell *matHeaderCellDef> Ean </th>
54+
<td mat-cell *matCellDef="let element"> {{element.ean}} </td>
55+
</ng-container>
56+
<!-- Price Column -->
57+
<ng-container matColumnDef="price">
58+
<th mat-header-cell *matHeaderCellDef> Price </th>
59+
<td mat-cell *matCellDef="let element"> {{element.price}} </td>
60+
</ng-container>
61+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
62+
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
63+
</table>
6164
</mat-tab>
62-
63-
6465
</mat-tab-group>
65-
6666
<ng-template #shoppingCartItems>
67-
6867
<app-shopping-cart-item *ngFor="let articleAndCount of items" [article]="articleAndCount[0]"
6968
[count]="articleAndCount[1]">
7069
</app-shopping-cart-item>
71-
7270
<div class="shopping-cart-total">
7371
Total: {{ totalPrice }} Lei
7472
</div>
75-
76-
77-
78-
7973
</ng-template>
8074
</div>

src/app/app.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@
4747
font-weight: bold;
4848
text-align: right;
4949
}
50+
51+
table {
52+
width: 100%;
53+
}

src/app/app.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { DocumentData } from '@angular/fire/firestore';
1313
import { enableDebugTools } from '@angular/platform-browser';
1414
import {MatTabsModule} from '@angular/material/tabs';
1515
// import { MatIconModule } from '@angular/material/icon'
16-
16+
import {MatTableDataSource, MatTableModule} from '@angular/material/table'
1717

1818
@Component({
1919
selector: 'app-root',
@@ -34,7 +34,14 @@ export class AppComponent implements AfterViewInit {
3434
{ name: 'Classy Crab (gold, ltd. ed.)', ean: '7601234564561', image: 'assets/classy_crab_gold.png', price: 50 },
3535
{ name: 'Cafea', ean: '8000070038028', image: 'https://www.lavazza.ro/ro/cafea/macinata/qualita-rossa.html', price: 50 }
3636
];
37-
public catalogue2: any = [];
37+
public catalogue2: Article[] = [];
38+
39+
40+
41+
42+
displayedColumns: string[] = ['name', 'ean', 'price'];
43+
dataSource: any;
44+
3845

3946
pokemon$: Observable<DocumentData>;
4047

@@ -71,6 +78,7 @@ export class AppComponent implements AfterViewInit {
7178
}
7279
this.logheaza();
7380
this.getDocs();
81+
this.getDocsForTable();
7482
this.pokemon$ = this.pokedexService.getAll();
7583
}
7684

@@ -83,6 +91,14 @@ export class AppComponent implements AfterViewInit {
8391
console.log('mongo Crabs=>', this.catalogue2);
8492
});
8593
}
94+
public getDocsForTable() {
95+
this.beepService
96+
.getDocs()
97+
.subscribe((data) => {
98+
this.dataSource = data;
99+
console.log('table docs=>', this.dataSource);
100+
});
101+
}
86102

87103
logheaza(){
88104
console.log("WORKS")

src/app/app.module.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ import { provideFunctions,getFunctions } from '@angular/fire/functions';
1717
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1818
import {MatTabsModule} from '@angular/material/tabs';
1919

20+
import {MatTableModule} from '@angular/material/table'
21+
22+
import { MaterialComponentsModule } from './material-components/material-components.module';
23+
24+
2025
@NgModule({
2126
declarations: [
2227
AppComponent,
2328
ShoppingCartItemComponent,
24-
AfisareProduseComponent
29+
AfisareProduseComponent,
30+
2531
],
2632
imports: [
2733
BrowserModule,
2834
FormsModule,
2935
HttpClientModule,
3036
RouterModule,
3137
MatTabsModule,
38+
MatTableModule,
39+
MaterialComponentsModule,
40+
BrowserAnimationsModule,
3241

3342

3443

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
import {MatTableModule} from '@angular/material/table';
5+
import {MatInputModule} from '@angular/material/input';
6+
import {MatSelectModule} from '@angular/material/select';
7+
import {MatCardModule} from '@angular/material/card';
8+
import {MatSortModule} from '@angular/material/sort';
9+
10+
11+
12+
13+
@NgModule({
14+
declarations: [],
15+
imports: [
16+
MatTableModule,
17+
CommonModule,
18+
MatInputModule,
19+
MatSelectModule,
20+
MatCardModule,
21+
MatSortModule
22+
],
23+
exports:[
24+
MatTableModule,
25+
MatInputModule,
26+
MatSelectModule,
27+
MatCardModule,
28+
MatSortModule
29+
]
30+
})
31+
export class MaterialComponentsModule { }

0 commit comments

Comments
 (0)