TODO: Refactor the product and productgroup tables as per the comments added.

rename the product group table to either product category or menu category
move the group_type field from productgroup to products and name it sales category eg. Food, beverage, etc. also, set the tax for sales category and not individual product
Added the printers permission to end of permissions and only for owner, set them right
This commit is contained in:
Amritanshu
2019-06-20 01:59:11 +05:30
parent c51a9bd5ff
commit 16455fdcac
38 changed files with 770 additions and 128 deletions

View File

@ -1,59 +1,17 @@
import {DataSource} from '@angular/cdk/collections';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {map} from 'rxjs/operators';
import {merge, Observable, of as observableOf} from 'rxjs';
import {Tax} from '../../core/tax';
import { DataSource} from '@angular/cdk/collections';
import { Observable, of as observableOf} from 'rxjs';
import { Tax} from '../../core/tax';
export class TaxListDataSource extends DataSource<Tax> {
constructor(private paginator: MatPaginator, private sort: MatSort, public data: Tax[]) {
constructor(public data: Tax[]) {
super();
}
connect(): Observable<Tax[]> {
const dataMutations = [
observableOf(this.data),
this.paginator.page,
this.sort.sortChange
];
// Set the paginators length
this.paginator.length = this.data.length;
return merge(...dataMutations).pipe(map(() => {
return this.getPagedData(this.getSortedData([...this.data]));
}));
return observableOf(this.data);
}
disconnect() {
}
private getPagedData(data: Tax[]) {
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
return data.splice(startIndex, this.paginator.pageSize);
}
private getSortedData(data: Tax[]) {
if (!this.sort.active || this.sort.direction === '') {
return data;
}
return data.sort((a, b) => {
const isAsc = this.sort.direction === 'asc';
switch (this.sort.active) {
case 'name':
return compare(a.name, b.name, isAsc);
case 'id':
return compare(+a.id, +b.id, isAsc);
default:
return 0;
}
});
}
}
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
function compare(a, b, isAsc) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}

View File

@ -7,35 +7,28 @@
</a>
</mat-card-title-group>
<mat-card-content>
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let row"><a [routerLink]="['/taxes', row.id]">{{row.name}}</a></mat-cell>
</ng-container>
</ng-container>
<!-- Rate Column -->
<ng-container matColumnDef="rate">
<mat-header-cell *matHeaderCellDef mat-sort-header>Rate</mat-header-cell>
<mat-header-cell *matHeaderCellDef>Rate</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.rate | percent:'1.2-2'}}</mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="isFixture">
<mat-header-cell *matHeaderCellDef mat-sort-header>Is Fixture?</mat-header-cell>
<mat-header-cell *matHeaderCellDef>Is Fixture?</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.isFixture}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
<mat-paginator #paginator
[length]="dataSource.data.length"
[pageIndex]="0"
[pageSize]="50"
[pageSizeOptions]="[25, 50, 100, 250]">
</mat-paginator>
</mat-card-content>
</mat-card>

View File

@ -1,9 +1,7 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {TaxListDataSource} from './tax-list-datasource';
import {Tax} from '../../core/tax';
import {ActivatedRoute} from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { TaxListDataSource } from './tax-list-datasource';
import { Tax } from '../../core/tax';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-tax-list',
@ -11,8 +9,6 @@ import {ActivatedRoute} from '@angular/router';
styleUrls: ['./tax-list.component.css']
})
export class TaxListComponent implements OnInit {
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
dataSource: TaxListDataSource;
list: Tax[];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
@ -26,6 +22,6 @@ export class TaxListComponent implements OnInit {
.subscribe((data: { list: Tax[] }) => {
this.list = data.list;
});
this.dataSource = new TaxListDataSource(this.paginator, this.sort, this.list);
this.dataSource = new TaxListDataSource(this.list);
}
}

View File

@ -8,9 +8,7 @@ import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule } from '@angular/material/table';
import {CdkTableModule} from '@angular/cdk/table';
import {ReactiveFormsModule} from '@angular/forms';
@ -25,9 +23,7 @@ import {FlexLayoutModule} from '@angular/flex-layout';
MatCardModule,
MatIconModule,
MatInputModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule,
ReactiveFormsModule,
TaxesRoutingModule