Feature: Lazy loading

Lazy loaded everything
TODO: The cash flow module when clicking on sub-links, it reloads the whole page, it needs to be diagnosed and fixed, this problem also exists in the other modules
TODO: Rename folders and modules such as account to accounts to match the url
This commit is contained in:
Amritanshu
2019-06-13 16:36:43 +05:30
parent fea48e1a3e
commit 72044476a8
184 changed files with 786 additions and 664 deletions
@@ -1,10 +1,10 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ToasterService} from '../../core/toaster.service';
import {ActivatedRoute, Router} from '@angular/router';
import {AccountService} from '../account.service';
import {Account} from '../account';
import {AccountType} from '../account-type';
import {CostCentre} from '../../cost-centre/cost-centre';
import {AccountService} from '../../core/account.service';
import {Account} from '../../core/account';
import {AccountType} from '../../core/account-type';
import {CostCentre} from '../../core/cost-centre';
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import {FormBuilder, FormGroup} from '@angular/forms';
@@ -75,7 +75,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/Accounts');
this.router.navigateByUrl('/accounts');
},
(error) => {
this.toaster.show('Danger', error.error);
@@ -88,7 +88,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/Accounts');
this.router.navigateByUrl('/accounts');
},
(error) => {
this.toaster.show('Danger', error.error);
@@ -1,8 +1,8 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {Account} from './account';
import {Account} from '../core/account';
import {Observable} from 'rxjs/internal/Observable';
import {AccountService} from './account.service';
import {AccountService} from '../core/account.service';
@Injectable({
providedIn: 'root'
@@ -3,7 +3,7 @@ import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {map, tap} from 'rxjs/operators';
import {merge, Observable, of as observableOf} from 'rxjs';
import {Account} from '../account';
import {Account} from '../../core/account';
export class AccountListDataSource extends DataSource<Account> {
@@ -1,7 +1,7 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Accounts</mat-card-title>
<a mat-button [routerLink]="['/Account']">
<a mat-button [routerLink]="['/accounts', 'new']">
<mat-icon>add_box</mat-icon>
Add
</a>
@@ -21,7 +21,7 @@
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
<mat-cell *matCellDef="let row">
<a [routerLink]="['/Account', row.id]">
<a [routerLink]="['/accounts', row.id]">
<mat-icon matSuffix *ngIf="row.isStarred" class="gold">star
</mat-icon>
{{row.name}}
@@ -2,7 +2,7 @@ import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {AccountListDataSource} from './account-list-datasource';
import {Account} from '../account';
import {Account} from '../../core/account';
import {ActivatedRoute} from '@angular/router';
import {Observable} from 'rxjs';
import {FormBuilder, FormGroup} from '@angular/forms';
@@ -1,7 +1,7 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {AccountService} from './account.service';
import {Account} from './account';
import {AccountService} from '../core/account.service';
import {Account} from '../core/account';
import {Observable} from 'rxjs/internal/Observable';
@Injectable({
@@ -13,7 +13,7 @@ import {CostCentreListResolver} from '../cost-centre/cost-centre-list-resolver.s
const accountRoutes: Routes = [
{
path: 'Accounts',
path: '',
component: AccountListComponent,
canActivate: [AuthGuard],
data: {
@@ -24,7 +24,7 @@ const accountRoutes: Routes = [
}
},
{
path: 'Account',
path: 'new',
component: AccountDetailComponent,
canActivate: [AuthGuard],
data: {
@@ -37,7 +37,7 @@ const accountRoutes: Routes = [
}
},
{
path: 'Account/:id',
path: ':id',
component: AccountDetailComponent,
canActivate: [AuthGuard],
data: {
@@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {AccountType} from './account-type';
import {AccountType} from '../core/account-type';
import {Observable} from 'rxjs/internal/Observable';
import {AccountTypeService} from './account-type.service';
@@ -1,11 +1,11 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/internal/Observable';
import {AccountType} from './account-type';
import {AccountType} from '../core/account-type';
import {catchError} from 'rxjs/operators';
import {HttpClient} from '@angular/common/http';
import {ErrorLoggerService} from '../core/error-logger.service';
const url = '/api/AccountTypes';
const url = '/api/account-types';
const serviceName = 'AccountTypeService';
@Injectable({
-9
View File
@@ -1,9 +0,0 @@
export class AccountType {
id: number;
name: string;
balanceSheet: boolean;
debit: boolean;
cashFlowClassification: string;
order: number;
showInList: boolean;
}
@@ -1,15 +0,0 @@
import {inject, TestBed} from '@angular/core/testing';
import {AccountService} from './account.service';
describe('AccountService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AccountService]
});
});
it('should be created', inject([AccountService], (service: AccountService) => {
expect(service).toBeTruthy();
}));
});
@@ -1,97 +0,0 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/internal/Observable';
import {catchError} from 'rxjs/operators';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {Account} from './account';
import {ErrorLoggerService} from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/api/Account';
const serviceName = 'AccountService';
@Injectable({providedIn: 'root'})
export class AccountService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(id: string): Observable<Account> {
const getUrl: string = (id === null) ? url : `${url}/${id}`;
return <Observable<Account>>this.http.get<Account>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
}
list(): Observable<Account[]> {
const options = {params: new HttpParams().set('l', '')};
return <Observable<Account[]>>this.http.get<Account[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
paymentAutocomplete(term: string): Observable<Account[]> {
const options = {params: new HttpParams().set('q', term).set('t', '1')};
return <Observable<Account[]>>this.http.get<Account[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
receiptAutocomplete(term: string): Observable<Account[]> {
const options = {params: new HttpParams().set('q', term).set('t', '1')};
return <Observable<Account[]>>this.http.get<Account[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
save(account: Account): Observable<Account> {
return <Observable<Account>>this.http.post<Account>(url, account, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(account: Account): Observable<Account> {
return <Observable<Account>>this.http.put<Account>(`${url}/${account.id}`, account, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}
saveOrUpdate(account: Account): Observable<Account> {
if (!account.id) {
return this.save(account);
} else {
return this.update(account);
}
}
delete(id: string): Observable<Account> {
return <Observable<Account>>this.http.delete<Account>(`${url}/${id}`, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'delete'))
);
}
autocomplete(term: string): Observable<Account[]> {
const options = {params: new HttpParams().set('q', term)};
return <Observable<Account[]>>this.http.get<Account[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'autocomplete'))
);
}
balance(id: string, date: string): Observable<any> {
const options = {params: new HttpParams().set('b', 'true').set('d', date)};
return <Observable<any>>this.http.get<any>(`${url}/${id}`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'balance'))
);
}
}
-19
View File
@@ -1,19 +0,0 @@
import {AccountType} from './account-type';
import {CostCentre} from '../cost-centre/cost-centre';
import {Journal} from '../journal/voucher';
export class Account {
id: string;
code: number;
name: string;
type: AccountType;
isActive: boolean;
isReconcilable: boolean;
isStarred: boolean;
isFixture: boolean;
costCentre: CostCentre;
public constructor(init?: Partial<Account>) {
Object.assign(this, init);
}
}