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 committed 2018-06-09 17:05:11 +05:30
1 parent b3cb01da02
commit 6be1dd5a3a
1380 files changed
+23914 -18722

No files matched your search

@@ -0,0 +1,3 @@
.example-card {
max-width: 400px;
}
@@ -0,0 +1,21 @@
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
<mat-card fxFlex>
<mat-card-title-group>
<mat-card-title>Cost Center</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex>
<mat-label>Name</mat-label>
<input matInput #nameElement placeholder="Name" formControlName="name" (keyup.enter)="save()">
</mat-form-field>
</div>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button (click)="save()" color="primary">Save</button>
</mat-card-actions>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {CostCentreDetailComponent} from './cost-centre-detail.component';
describe('CostCentreDetailComponent', () => {
let component: CostCentreDetailComponent;
let fixture: ComponentFixture<CostCentreDetailComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CostCentreDetailComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CostCentreDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,73 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {CostCentreService} from '../cost-centre.service';
import {CostCentre} from '../cost-centre';
import {ActivatedRoute, Router} from '@angular/router';
import {ToasterService} from '../../core/toaster.service';
import {FormBuilder, FormGroup} from '@angular/forms';
@Component({
selector: 'app-cost-centre-detail',
templateUrl: './cost-centre-detail.component.html',
styleUrls: ['./cost-centre-detail.component.css']
})
export class CostCentreDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement') nameElement: ElementRef;
form: FormGroup;
item: CostCentre;
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private toaster: ToasterService,
private ser: CostCentreService
) {
this.createForm();
}
createForm() {
this.form = this.fb.group({
name: ''
});
}
ngOnInit() {
this.route.data
.subscribe((data: { item: CostCentre }) => {
this.showItem(data.item);
});
}
showItem(item: CostCentre) {
this.item = item;
this.form.setValue({
name: this.item.name,
});
}
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
}, 0);
}
save() {
this.ser.saveOrUpdate(this.getItem())
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/CostCentres');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
getItem(): CostCentre {
const formModel = this.form.value;
this.item.name = formModel.name;
return this.item;
}
}
@@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {CostCentreListResolverService} from './cost-centre-list-resolver.service';
describe('CostCentreListResolverService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [CostCentreListResolverService]
});
});
it('should be created', inject([CostCentreListResolverService], (service: CostCentreListResolverService) => {
expect(service).toBeTruthy();
}));
});
@@ -0,0 +1,18 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {CostCentre} from './cost-centre';
import {Observable} from 'rxjs/internal/Observable';
import {CostCentreService} from './cost-centre.service';
@Injectable({
providedIn: 'root'
})
export class CostCentreListResolver implements Resolve<CostCentre[]> {
constructor(private ser: CostCentreService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<CostCentre[]> {
return this.ser.list();
}
}
@@ -0,0 +1,58 @@
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 {CostCentre} from '../cost-centre';
export class CostCentreListDataSource extends DataSource<CostCentre> {
constructor(private paginator: MatPaginator, private sort: MatSort, public data: CostCentre[]) {
super();
}
connect(): Observable<CostCentre[]> {
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: CostCentre[]) {
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
return data.splice(startIndex, this.paginator.pageSize);
}
private getSortedData(data: CostCentre[]) {
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);
}
@@ -0,0 +1,35 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Cost Centers</mat-card-title>
<a mat-button [routerLink]="['/CostCentre']">
<mat-icon>add_box</mat-icon>
Add
</a>
</mat-card-title-group>
<mat-card-content>
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
<mat-cell *matCellDef="let row"><a [routerLink]="['/CostCentre', row.id]">{{row.name}}</a></mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="isFixture">
<mat-header-cell *matHeaderCellDef mat-sort-header>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>
@@ -0,0 +1,23 @@
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import {CostCentreListComponent} from './cost-centre-list.component';
describe('CostCentreListComponent', () => {
let component: CostCentreListComponent;
let fixture: ComponentFixture<CostCentreListComponent>;
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [CostCentreListComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CostCentreListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should compile', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,30 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {MatPaginator, MatSort} from '@angular/material';
import {CostCentreListDataSource} from './cost-centre-list-datasource';
import {CostCentre} from '../cost-centre';
import {ActivatedRoute} from '@angular/router';
@Component({
selector: 'app-cost-centre-list',
templateUrl: './cost-centre-list.component.html',
styleUrls: ['./cost-centre-list.component.css']
})
export class CostCentreListComponent implements OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
dataSource: CostCentreListDataSource;
list: CostCentre[];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'isFixture'];
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.data
.subscribe((data: { list: CostCentre[] }) => {
this.list = data.list;
});
this.dataSource = new CostCentreListDataSource(this.paginator, this.sort, this.list);
}
}
@@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {CostCentreResolverService} from './cost-centre-resolver.service';
describe('CostCentreResolverService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [CostCentreDetailResolverService]
});
});
it('should be created', inject([CostCentreDetailResolverService], (service: CostCentreDetailResolverService) => {
expect(service).toBeTruthy();
}));
});
@@ -0,0 +1,19 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {CostCentreService} from './cost-centre.service';
import {CostCentre} from './cost-centre';
import {Observable} from 'rxjs/internal/Observable';
@Injectable({
providedIn: 'root'
})
export class CostCentreResolver implements Resolve<CostCentre> {
constructor(private ser: CostCentreService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<CostCentre> {
const id = route.paramMap.get('id');
return this.ser.get(id);
}
}
@@ -0,0 +1,13 @@
import {CostCentreRoutingModule} from './cost-centre-routing.module';
describe('CostCentreRoutingModule', () => {
let costCentreRoutingModule: CostCentreRoutingModule;
beforeEach(() => {
costCentreRoutingModule = new CostCentreRoutingModule();
});
it('should create an instance', () => {
expect(costCentreRoutingModule).toBeTruthy();
});
});
@@ -0,0 +1,61 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router';
import {CostCentreListResolver} from './cost-centre-list-resolver.service';
import {CostCentreResolver} from './cost-centre-resolver.service';
import {CostCentreListComponent} from './cost-centre-list/cost-centre-list.component';
import {CostCentreDetailComponent} from './cost-centre-detail/cost-centre-detail.component';
import {AuthGuard} from '../auth/auth-guard.service';
const costCentreRoutes: Routes = [
{
path: 'CostCentres',
component: CostCentreListComponent,
canActivate: [AuthGuard],
data: {
permission: 'Cost Centres'
},
resolve: {
list: CostCentreListResolver
}
},
{
path: 'CostCentre',
component: CostCentreDetailComponent,
canActivate: [AuthGuard],
data: {
permission: 'Cost Centres'
},
resolve: {
item: CostCentreResolver
}
},
{
path: 'CostCentre/:id',
component: CostCentreDetailComponent,
canActivate: [AuthGuard],
data: {
permission: 'Cost Centres'
},
resolve: {
item: CostCentreResolver
}
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(costCentreRoutes)
],
exports: [
RouterModule
],
providers: [
CostCentreListResolver,
CostCentreResolver
]
})
export class CostCentreRoutingModule {
}
@@ -0,0 +1,13 @@
import {CostCentreModule} from './cost-centre.module';
describe('CostCentreModule', () => {
let costCentreModule: CostCentreModule;
beforeEach(() => {
costCentreModule = new CostCentreModule();
});
it('should create an instance', () => {
expect(costCentreModule).toBeTruthy();
});
});
@@ -0,0 +1,44 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {CostCentreListComponent} from './cost-centre-list/cost-centre-list.component';
import {CostCentreDetailComponent} from './cost-centre-detail/cost-centre-detail.component';
import {CostCentreRoutingModule} from './cost-centre-routing.module';
import {
MatButtonModule,
MatCardModule,
MatIconModule,
MatInputModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule
} from '@angular/material';
import {CdkTableModule} from '@angular/cdk/table';
import {ReactiveFormsModule} from '@angular/forms';
import {FlexLayoutModule, FlexModule} from '@angular/flex-layout';
@NgModule({
imports: [
CommonModule,
CdkTableModule,
FlexModule,
FlexLayoutModule,
MatButtonModule,
MatCardModule,
MatIconModule,
MatInputModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSortModule,
MatTableModule,
ReactiveFormsModule,
CostCentreRoutingModule
],
declarations: [
CostCentreListComponent,
CostCentreDetailComponent
]
})
export class CostCentreModule {
}
@@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {CostCentreService} from './cost-centre.service';
describe('CostCentreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [CostCentreService]
});
});
it('should be created', inject([CostCentreService], (service: CostCentreService) => {
expect(service).toBeTruthy();
}));
});
@@ -0,0 +1,65 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {ErrorLoggerService} from '../core/error-logger.service';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {CostCentre} from './cost-centre';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/api/CostCentre';
const serviceName = 'CostCentreService';
@Injectable({
providedIn: 'root'
})
export class CostCentreService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(id: string): Observable<CostCentre> {
const getUrl: string = (id === null) ? url : `${url}/${id}`;
return <Observable<CostCentre>>this.http.get<CostCentre>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
}
list(): Observable<CostCentre[]> {
const options = {params: new HttpParams().set('l', '')};
return <Observable<CostCentre[]>>this.http.get<CostCentre[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
save(costCentre: CostCentre): Observable<CostCentre> {
return <Observable<CostCentre>>this.http.post<CostCentre>(url, costCentre, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(costCentre: CostCentre): Observable<CostCentre> {
return <Observable<CostCentre>>this.http.put<CostCentre>(`${url}/${costCentre.id}`, costCentre, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}
saveOrUpdate(costCentre: CostCentre): Observable<CostCentre> {
if (!costCentre.id) {
return this.save(costCentre);
} else {
return this.update(costCentre);
}
}
delete(id: string): Observable<CostCentre> {
return <Observable<CostCentre>>this.http.delete<CostCentre>(`${url}/${id}`, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'delete'))
);
}
}
@@ -0,0 +1,5 @@
export class CostCentre {
id: string;
name: string;
isFixture: boolean;
}