diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 11d7e67..641595f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -30,7 +30,6 @@ export class AppComponent implements OnInit , OnDestroy { this.listenToMenuEvent(); // must be the last, as it may emit events this.authService.AutoLogin(); - } listenToMenuEvent(): void { diff --git a/src/app/app.config.model.ts b/src/app/app.config.model.ts new file mode 100644 index 0000000..ba38fca --- /dev/null +++ b/src/app/app.config.model.ts @@ -0,0 +1,5 @@ + +export class AppConfigModel { + Server = 'https://c5016.biukop.com.au:8080/api/v1/'; + Socket = 'ws://c5016.biukop.com.au:8080/api/v1/'; +} diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 8b13789..810c36e 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1 +1,58 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import {AppConfigModel} from './app.config.model'; + + +@Injectable() +export class AppConfig { + static config: AppConfigModel; + static debugConfig: AppConfigModel = { + Server: 'https://svr2021.lawipac.com:8080/api/v1/', + Socket: 'wss://svr2021.lawipac.com:8080/api/v1/ws' + }; + + static productionConfig: AppConfigModel = { + Server: 'https://c5016.biukop.com.au:8080/api/v1/', + Socket: 'wss://c5016.biukop.com.au:8080/api/v1/ws' + }; + + constructor(private http: HttpClient) {} + + load(): Promise { + return new Promise((resolve, reject) => { + const el: HTMLElement = document.getElementById('config'); + try { + if ( location.href.includes('//localhost:4200/') ) { + AppConfig.config = AppConfig.debugConfig; + console.log('Using Debug Config:', AppConfig.config); + }else{ + const json = this.decode(el.innerText); + AppConfig.config = JSON.parse(json); + console.log('Using Production Config:', AppConfig.config); + } + resolve(); + }catch (e){ + console.log('cannot load config'); + alert('Failed to load configuration, please contact administrator'); + AppConfig.config = AppConfig.productionConfig; // fallback to hardcoded config + console.log('fall back to built-in config', AppConfig.config); + resolve(); + // reject(); + } + }); + } + + decode(strIn: string): string { + return atob(strIn); + } + + public get apiUrl(): string { + return AppConfig.config.Server; + } + + public get apiWsUrl(): string { + return AppConfig.config.Socket; + } + +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5434387..033499e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,6 @@ //Angular -import { NgModule } from '@angular/core'; +import {APP_INITIALIZER, NgModule} from '@angular/core'; import { CommonModule } from '@angular/common'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; @@ -94,10 +94,14 @@ import { UploadDetailComponent } from './upload-detail/upload-detail.component'; import {SafeUrlPipe} from './pipe/safe.url.pipe'; import { ImagePopupDialogComponent } from './image-popup-dialog/image-popup-dialog.component'; import { PopupIncomeFilterComponent } from './popup-income-filter/popup-income-filter.component'; +import { LoanCardComponent } from './loan-card/loan-card.component'; +import {AppConfig} from './app.config'; - +export function initializeApp(appConfig: AppConfig): () => Promise { + return () => appConfig.load(); +} @@ -157,7 +161,8 @@ import { PopupIncomeFilterComponent } from './popup-income-filter/popup-income-f UploadDetailComponent, SafeUrlPipe, ImagePopupDialogComponent, - PopupIncomeFilterComponent + PopupIncomeFilterComponent, + LoanCardComponent ], imports: [ BrowserModule, @@ -210,7 +215,11 @@ import { PopupIncomeFilterComponent } from './popup-income-filter/popup-income-f provide: HTTP_INTERCEPTORS, useClass: UploadInterceptor, multi: true - } + }, + AppConfig, + { provide: APP_INITIALIZER, + useFactory: initializeApp, + deps: [AppConfig], multi: true } ], bootstrap: [AppComponent] }) diff --git a/src/app/client-loan-list/client-loan-list.component.ts b/src/app/client-loan-list/client-loan-list.component.ts index 37325ae..7e1cfff 100644 --- a/src/app/client-loan-list/client-loan-list.component.ts +++ b/src/app/client-loan-list/client-loan-list.component.ts @@ -19,7 +19,7 @@ export class ClientLoanListComponent implements OnInit { resp => { this.Loans = []; resp.forEach( v => { - const l = new LoanModel(v.Id); + const l = new LoanModel(v); l.Response = v; this.Loans.push(l); }); diff --git a/src/app/loan-card/loan-card.component.html b/src/app/loan-card/loan-card.component.html new file mode 100644 index 0000000..a8d2f65 --- /dev/null +++ b/src/app/loan-card/loan-card.component.html @@ -0,0 +1,6 @@ +
+ {{Loan.Item}} + Amount: {{Loan.Amount | currency }} + Settlement: {{Loan.Settlement | date:'yyyy-mm-dd' }} +
+ diff --git a/src/app/loan-card/loan-card.component.scss b/src/app/loan-card/loan-card.component.scss new file mode 100644 index 0000000..98b51c3 --- /dev/null +++ b/src/app/loan-card/loan-card.component.scss @@ -0,0 +1,17 @@ +div.loan.card { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -ms-flex-direction: column; + flex-direction: column; + position: relative; + -webkit-transition: all 0.4s cubic-bezier(0.645, 0.045, 0.355, 1); + -o-transition: all 0.4s cubic-bezier(0.645, 0.045, 0.355, 1); + transition: all 0.4s cubic-bezier(0.645, 0.045, 0.355, 1); + border-radius: 10px; + overflow: hidden; + -webkit-box-shadow: 15px 15px 27px #e1e1e3, -15px -15px 27px #ffffff; + box-shadow: 15px 15px 27px #e1e1e3, -15px -15px 27px #ffffff; +} diff --git a/src/app/loan-card/loan-card.component.spec.ts b/src/app/loan-card/loan-card.component.spec.ts new file mode 100644 index 0000000..69ccf68 --- /dev/null +++ b/src/app/loan-card/loan-card.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoanCardComponent } from './loan-card.component'; + +describe('LoanCardComponent', () => { + let component: LoanCardComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ LoanCardComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(LoanCardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loan-card/loan-card.component.ts b/src/app/loan-card/loan-card.component.ts new file mode 100644 index 0000000..fb32b2d --- /dev/null +++ b/src/app/loan-card/loan-card.component.ts @@ -0,0 +1,26 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {LoanModel} from '../models/loan.model'; +import {LoanSingleService} from '../service/loan.single.service'; +import {Router} from '@angular/router'; + +@Component({ + selector: 'app-loan-card', + templateUrl: './loan-card.component.html', + styleUrls: ['./loan-card.component.scss'] +}) +export class LoanCardComponent implements OnInit { + @Input() LoanId = ''; + public Loan: LoanModel = new LoanModel({}); + constructor(private lss: LoanSingleService, private router: Router) { } + + ngOnInit(): void { + this.lss.getLoan(this.LoanId).subscribe( resp => { + this.Loan.Response = resp; + }); + } + + public gotoLoan(id: string): void { + this.router.navigate(['/edit-loan', id]); + } + +} diff --git a/src/app/loan-edit/loan-edit.component.ts b/src/app/loan-edit/loan-edit.component.ts index 59b36fd..1d3e7c6 100644 --- a/src/app/loan-edit/loan-edit.component.ts +++ b/src/app/loan-edit/loan-edit.component.ts @@ -21,7 +21,7 @@ export class LoanEditComponent implements OnInit { @Output() LoanUpdated = new EventEmitter(); - public Loan: LoanModel = new LoanModel(''); + public Loan: LoanModel = new LoanModel({}); public curStepSuccess = false; public showDelete = false; diff --git a/src/app/models/loan.model.ts b/src/app/models/loan.model.ts index c92d126..3949522 100644 --- a/src/app/models/loan.model.ts +++ b/src/app/models/loan.model.ts @@ -14,35 +14,102 @@ export interface LoanModelCallBacks { export class LoanModel { - constructor( - public Id: string, - public Amount?: number, - public Status?: string, - public Item?: string, - public Rating?: number, - public Settlement?: Date, - public Description?: string, - - public Lender?: string, - public LenderLoanNumber?: string, - public Client?: PeopleModel[], - public Broker?: BrokerModel[], - public OtherRewarder?: PeopleModel[], - public Reward?: RewardModel[], - public RewardPeople?: PeopleModel[], - public PayIn?: PayInModel[], - public PeopleMap?: PeopleMapModel[], - - public auth?: AuthService, - public lss?: LoanSingleService - ){} + public Id: string; + public Amount?: number; + public Status?: string; + public Item?: string; + public Rating?: number; + public Settlement?: Date; + public Description?: string; + public Lender?: string; + public LenderLoanNumber?: string; + public Client?: PeopleModel[]; + public Broker?: BrokerModel[]; + public OtherRewarder?: PeopleModel[]; + public Reward?: RewardModel[]; + public RewardPeople?: PeopleModel[]; + public PayIn?: PayInModel[]; + public PeopleMap?: PeopleMapModel[]; + public auth?: AuthService; + public lss?: LoanSingleService; + + constructor(payload: Partial) { + this.Id = payload.Id || ''; + this.Amount = payload.Amount || 0; + this.Status = payload.Status || ''; + this.Item = payload.Item || ''; + this.Rating = payload.Rating || 0; + this.Settlement = payload.Settlement ? new Date(payload.Settlement) : new Date('1900-01-01') ; + this.Description = payload.Description || ''; + this.Lender = payload.Lender || ''; + this.LenderLoanNumber = payload.LenderLoanNumber || ''; + + if ( payload.Client && payload.Client.length > 0 ){ + this.setClient(payload.Client); + } else{ + this.Client = []; + } + + if (payload.Broker && payload.Broker.length > 0 ) { + this.setBroker(payload.Broker); + }else{ + this.Broker = []; + } + + if (payload.OtherRewarder && payload.OtherRewarder.length > 0 ) { + this.setOtherRewarder(payload.OtherRewarder); + }else{ + this.OtherRewarder = []; + } + + if (payload.Reward && payload.Reward.length > 0 ) { + this.setReward(payload.Reward); + }else{ + this.Reward = []; + } + + if (payload.RewardPeople && payload.RewardPeople.length > 0 ) { + this.setRewardPeople(payload.RewardPeople); + }else{ + this.RewardPeople = []; + } + + if (payload.PayIn && payload.PayIn.length > 0 ) { + this.setPayIn(payload.PayIn); + }else{ + this.PayIn = []; + } + + if (payload.PeopleMap && payload.PeopleMap.length > 0) { + this.PeopleMap = payload.PeopleMap; + }else{ + this.PeopleMap = []; + } + + this.auth = payload.auth || null; + this.lss = payload.lss || null; + } public static EmptyNew(lss: LoanSingleService, auth: AuthService): LoanModel { - const nLoan = new LoanModel( - '', 0 , '', '', 0, new Date(), '', - '', '', [], [], [], [], [], [], [], + const nLoan = new LoanModel({ + Id: '', + Amount: 0, + Status: '', + Item: '', + Rating: 0, + Settlement: new Date(), + Description: '', + Lender: '', + LenderLoanNumber: '', + Client: [], + Broker: [], + OtherRewarder: [], + Reward: [], + RewardPeople: [], + PayIn: [], + PeopleMap: [], auth, lss - ); + }); return nLoan; } @@ -287,25 +354,25 @@ export class LoanModel { // remove auth serivce and lss service for Json.stringify public cloneForJson(): LoanModel { - return new LoanModel( - this.Id, - this.Amount, - this.Status, - this.Item, - this.Rating, - this.Settlement, - this.Description, - this.Lender, - this.LenderLoanNumber, - this.Client, - this.Broker, - this.OtherRewarder, - this.Reward, - this.RewardPeople, - this.PayIn, - this.PeopleMap, - undefined, - undefined - ); + return new LoanModel({ + Id: this.Id, + Amount: this.Amount, + Status: this.Status, + Item: this.Item, + Rating: this.Rating, + Settlement: this.Settlement, + Description: this.Description, + Lender: this.Lender, + LenderLoanNumber: this.LenderLoanNumber, + Client: this.Client, + Broker: this.Broker, + OtherRewarder: this.OtherRewarder, + Reward: this.Reward, + RewardPeople: this.RewardPeople, + PayIn: this.PayIn, + PeopleMap: this.PeopleMap, + auth: undefined, + lss: undefined + }); } } diff --git a/src/app/pay-in/pay-in.component.html b/src/app/pay-in/pay-in.component.html index 64b977a..e1d2dfc 100644 --- a/src/app/pay-in/pay-in.component.html +++ b/src/app/pay-in/pay-in.component.html @@ -119,9 +119,10 @@ - + - + + diff --git a/src/app/pay-in/pay-in.component.ts b/src/app/pay-in/pay-in.component.ts index 5a85dee..26df171 100644 --- a/src/app/pay-in/pay-in.component.ts +++ b/src/app/pay-in/pay-in.component.ts @@ -155,9 +155,7 @@ export class PayInComponent implements OnInit { public showUpload(id: number): void { this.router.navigate(['/upload-details', id]); } - public gotoLoan(id: string): void { - this.router.navigate(['/edit-loan', id]); - } + public setBalance(): void{ if ( this.showBalance ){ diff --git a/src/app/service/auth.service.ts b/src/app/service/auth.service.ts index 3233503..d106912 100644 --- a/src/app/service/auth.service.ts +++ b/src/app/service/auth.service.ts @@ -5,6 +5,7 @@ import {Router} from '@angular/router'; import {PeopleModel} from '../models/people.model'; import {UserExtraModel} from '../models/user-extra.model'; import {Observable} from 'rxjs'; +import {AppConfig} from '../app.config'; @Injectable() export class AuthService { @@ -17,10 +18,12 @@ export class AuthService { loginSuccess = new EventEmitter (); constructor( private http: HttpClient , - private router: Router) { + private router: Router, + private config: AppConfig) { + this.apiUrl = config.apiUrl; + this.apiWsUrl = config.apiWsUrl; } - public AutoLogin(): void { const sfm: ApiV1LoginResponse = JSON.parse(localStorage.getItem('sfm')); if (!sfm) { diff --git a/src/index.html b/src/index.html index 980e616..58feb1b 100644 --- a/src/index.html +++ b/src/index.html @@ -8,10 +8,15 @@ - + - \ No newline at end of file +