Moved to Angular 6.0

----

Pending
* Table width for the points column in incentive
* Linting
* keyboard navigation where it was used earlier
* can remove the unused totals calculated serverside in productledger
* spinner and loading bars
* Activate Guard for Employee Function tabs
* Progress for Fingerprint uploads
* deleted reconcile and receipe features as they were not being used
* focus the right control on component load
This commit is contained in:
tanshu
2018-05-25 19:19:00 +05:30
parent b3cb01da02
commit 6be1dd5a3a
1380 changed files with 23914 additions and 18722 deletions

View File

@ -0,0 +1,63 @@
import {DataSource} from '@angular/cdk/collections';
import {MatPaginator, MatSort} from '@angular/material';
import {map} from 'rxjs/operators';
import {merge, Observable, of as observableOf} from 'rxjs';
import {ProfitLossItem} from './profit-loss';
export class ProfitLossDataSource extends DataSource<ProfitLossItem> {
constructor(private paginator: MatPaginator, private sort: MatSort, public data: ProfitLossItem[]) {
super();
}
connect(): Observable<ProfitLossItem[]> {
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]));
}));
}
disconnect() {
}
private getPagedData(data: ProfitLossItem[]) {
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
return data.splice(startIndex, this.paginator.pageSize);
}
private getSortedData(data: ProfitLossItem[]) {
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 'group':
return compare(a.group, b.group, isAsc);
case 'name':
return compare(a.name, b.name, isAsc);
case 'amount':
return compare(+a.amount, +b.amount, isAsc);
case 'total':
return compare(+a.total, +b.total, 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

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {ProfitLossResolver} from './profit-loss-resolver.service';
describe('ProfitLossResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ProfitLossResolver]
});
});
it('should be created', inject([ProfitLossResolver], (service: ProfitLossResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,20 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/internal/Observable';
import {ProfitLoss} from './profit-loss';
import {ProfitLossService} from './profit-loss.service';
@Injectable({
providedIn: 'root'
})
export class ProfitLossResolver implements Resolve<ProfitLoss> {
constructor(private ser: ProfitLossService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ProfitLoss> {
const startDate = route.queryParamMap.get('startDate') || null;
const finishDate = route.queryParamMap.get('finishDate') || null;
return this.ser.list(startDate, finishDate);
}
}

View File

@ -0,0 +1,13 @@
import {ProfitLossRoutingModule} from './profit-loss-routing.module';
describe('ProfitLossRoutingModule', () => {
let profitLossRoutingModule: ProfitLossRoutingModule;
beforeEach(() => {
profitLossRoutingModule = new ProfitLossRoutingModule();
});
it('should create an instance', () => {
expect(profitLossRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,37 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router';
import {ProfitLossResolver} from './profit-loss-resolver.service';
import {AuthGuard} from '../auth/auth-guard.service';
import {ProfitLossComponent} from './profit-loss.component';
const profitLossRoutes: Routes = [
{
path: 'ProfitLoss',
component: ProfitLossComponent,
canActivate: [AuthGuard],
data: {
permission: 'Profit & Loss'
},
resolve: {
info: ProfitLossResolver
},
runGuardsAndResolvers: 'always'
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(profitLossRoutes)
],
exports: [
RouterModule
],
providers: [
ProfitLossResolver
]
})
export class ProfitLossRoutingModule {
}

View File

@ -0,0 +1,12 @@
.right {
display: flex;
justify-content: flex-end;
}
.selected{
background: #fff3cd
}
.unposted{
background: #f8d7da
}

View File

@ -0,0 +1,70 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Profit & Loss</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
fxLayoutAlign="space-around start">
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="startDate" (focus)="startDate.open()" placeholder="Start Date"
formControlName="startDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="finishDate" (focus)="finishDate.open()" placeholder="Finish Date"
formControlName="finishDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="finishDate"></mat-datepicker-toggle>
<mat-datepicker #finishDate></mat-datepicker>
</mat-form-field>
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
</div>
</form>
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
<!-- Group Column -->
<ng-container matColumnDef="group">
<mat-header-cell *matHeaderCellDef mat-sort-header>Group</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.group}}</mat-cell>
<mat-footer-cell *matFooterCellDef>{{info.footer.group}}</mat-footer-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
<mat-footer-cell *matFooterCellDef>{{info.footer.name}}</mat-footer-cell>
</ng-container>
<!-- Amount Column -->
<ng-container matColumnDef="amount">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Amount</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.amount | currency:'INR'}}</mat-cell>
<mat-footer-cell *matFooterCellDef class="right">
{{info.footer.amount | currency:'INR'}}
</mat-footer-cell>
</ng-container>
<!-- Total Column -->
<ng-container matColumnDef="total">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Total</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.total | currency:'INR'}}</mat-cell>
<mat-footer-cell *matFooterCellDef class="right">
{{info.footer.total | currency:'INR'}}
</mat-footer-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
<mat-footer-row *matFooterRowDef="displayedColumns"></mat-footer-row>
</mat-table>
<mat-paginator #paginator
[length]="dataSource.data.length"
[pageIndex]="0"
[pageSize]="50"
[pageSizeOptions]="[25, 50, 100, 250, 300]">
</mat-paginator>
</mat-card-content>
</mat-card>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ProfitLossComponent} from './profit-loss.component';
describe('ProfitLossComponent', () => {
let component: ProfitLossComponent;
let fixture: ComponentFixture<ProfitLossComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProfitLossComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProfitLossComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,71 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {MatPaginator, MatSort} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router';
import * as moment from 'moment';
import {ProfitLossDataSource} from './profit-loss-datasource';
import {ProfitLoss} from './profit-loss';
@Component({
selector: 'app-profit-loss',
templateUrl: './profit-loss.component.html',
styleUrls: ['./profit-loss.component.css']
})
export class ProfitLossComponent implements OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
dataSource: ProfitLossDataSource;
form: FormGroup;
info: ProfitLoss;
selectedRowId: string;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['group', 'name', 'amount', 'total'];
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder
) {
this.createForm();
}
ngOnInit() {
this.route.data
.subscribe((data: { info: ProfitLoss }) => {
this.info = data.info;
this.form.setValue({
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
});
this.dataSource = new ProfitLossDataSource(this.paginator, this.sort, this.info.body);
});
}
show() {
const l = this.prepareSubmit();
this.router.navigate(['ProfitLoss'], {
queryParams: {
startDate: l.startDate,
finishDate: l.finishDate
}
});
}
createForm() {
this.form = this.fb.group({
startDate: '',
finishDate: '',
});
}
prepareSubmit(): ProfitLoss {
const formModel = this.form.value;
return {
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
body: [],
footer: {group: null, name: null, amount: null, total: null}
};
}
}

View File

@ -0,0 +1,13 @@
import {ProfitLossModule} from './profit-loss.module';
describe('ProfitLossModule', () => {
let profitLossModule: ProfitLossModule;
beforeEach(() => {
profitLossModule = new ProfitLossModule();
});
it('should create an instance', () => {
expect(profitLossModule).toBeTruthy();
});
});

View File

@ -0,0 +1,75 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {
DateAdapter,
MAT_DATE_FORMATS,
MAT_DATE_LOCALE,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDatepickerModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule
} from '@angular/material';
import {SharedModule} from '../shared/shared.module';
import {ReactiveFormsModule} from '@angular/forms';
import {CdkTableModule} from '@angular/cdk/table';
import {ProfitLossRoutingModule} from './profit-loss-routing.module';
import {ProfitLossComponent} from './profit-loss.component';
import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y';
import {FlexLayoutModule, FlexModule} from '@angular/flex-layout';
export const MY_FORMATS = {
parse: {
dateInput: 'DD-MMM-YYYY',
},
display: {
dateInput: 'DD-MMM-YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'DD-MMM-YYYY',
monthYearA11yLabel: 'MMM YYYY',
},
};
@NgModule({
imports: [
A11yModule,
CommonModule,
CdkTableModule,
FlexModule,
FlexLayoutModule,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDatepickerModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule,
ReactiveFormsModule,
SharedModule,
ProfitLossRoutingModule
],
declarations: [
ProfitLossComponent
],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
]
})
export class ProfitLossModule {
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {ProfitLossService} from './profit-loss.service';
describe('ProfitLossService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ProfitLossService]
});
});
it('should be created', inject([ProfitLossService], (service: ProfitLossService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,37 @@
import {Injectable} from '@angular/core';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {ProfitLoss} from './profit-loss';
import {ErrorLoggerService} from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/api/ProfitLoss';
const serviceName = 'ProfitLossService';
@Injectable({
providedIn: 'root'
})
export class ProfitLossService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
list(startDate: string, finishDate): Observable<ProfitLoss> {
const options = {params: new HttpParams()};
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
return <Observable<ProfitLoss>>this.http.get<ProfitLoss>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
}

View File

@ -0,0 +1,14 @@
export class ProfitLossItem {
group: string;
name: string;
amount: number;
total: number;
}
export class ProfitLoss {
startDate: string;
finishDate: string;
body: ProfitLossItem[];
footer: ProfitLossItem;
}