Feature: Download Products

Fix: Add user
Fix: Added 5000 page size in products
Fix: Local Time Pipe was showing the wrong time
This commit is contained in:
Amritanshu
2018-07-29 23:43:26 +05:30
parent f8162f364d
commit cd20982753
8 changed files with 89 additions and 53 deletions

View File

@ -1,6 +1,9 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Products</mat-card-title>
<button mat-button mat-icon-button *ngIf="dataSource.data.length" (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
<a mat-button [routerLink]="['/Product']">
<mat-icon>add_box</mat-icon>
Add
@ -77,7 +80,7 @@
[length]="dataSource.data.length"
[pageIndex]="0"
[pageSize]="50"
[pageSizeOptions]="[25, 50, 100, 250]">
[pageSizeOptions]="[25, 50, 100, 250, 5000]">
</mat-paginator>
</mat-card-content>
</mat-card>

View File

@ -6,6 +6,7 @@ import {ActivatedRoute} from '@angular/router';
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
import {FormBuilder, FormGroup} from '@angular/forms';
import {Observable} from 'rxjs';
import {ToCsvService} from "../../shared/to-csv.service";
@Component({
selector: 'app-product-list',
@ -23,7 +24,7 @@ export class ProductListComponent implements OnInit, AfterViewInit {
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns: string[];
constructor(private route: ActivatedRoute, private fb: FormBuilder) {
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
this.showExtended = false;
this.createForm();
this.filter = this.listenToFilterChange();
@ -73,4 +74,24 @@ export class ProductListComponent implements OnInit, AfterViewInit {
}
}
exportCsv() {
const headers = {
Code: 'code',
Name: 'name',
Units: 'units',
Fraction: 'fraction',
FractionUnits: 'fractionUnits',
CostPrice: 'costPrice',
Yield: 'yield',
ProductGroup: 'productGroup'
};
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
const link = document.createElement('a');
link.href = window.URL.createObjectURL(csvData);
link.setAttribute('download', 'products.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}