Skip to content

Commit

Permalink
Merge pull request #39 from personalmoney/develop
Browse files Browse the repository at this point in the history
Performance updates
  • Loading branch information
bhagavan44 authored Jun 10, 2021
2 parents 8450a06 + 06a8fd6 commit b57b445
Show file tree
Hide file tree
Showing 35 changed files with 107 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/app/accounts/save/save.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
size-lg="6">
<ion-item lines="full">
<ion-label position="floating">Account Type</ion-label>
<ion-select *ngIf="!isWeb"
<ion-select *ngIf="!shared.isWeb"
interface="popover"
formControlName="accountType"
placeholder="Select Account Type"
Expand All @@ -49,7 +49,7 @@
*ngFor="let type of accountTypes">
{{type.name}}</ion-select-option>
</ion-select>
<ion-select *ngIf="isWeb"
<ion-select *ngIf="shared.isWeb"
interface="popover"
formControlName="accountType"
placeholder="Select Account Type"
Expand Down
14 changes: 4 additions & 10 deletions src/app/accounts/save/save.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ export class SaveComponent extends BaseForm implements OnInit {
@Input()
account: Account;
accountTypes: AccountType[] = [];
isWeb = false;
@Select(AccountTypeState.getSortedData) accountTypes$: Observable<AccountType[]>;

constructor(
private formBuilder: FormBuilder,
private store: Store,
private storeService: StoreService,
shared: SharedService,
public shared: SharedService,
private modal: ModalController
) {
super();
shared.isWeb
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(c => {
this.isWeb = c;
});
this.storeService.getAccountTypes();
}

Expand All @@ -54,7 +48,7 @@ export class SaveComponent extends BaseForm implements OnInit {

this.form = this.formBuilder.group({
name: [this.account.name, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
accountType: [this.isWeb ? this.account.account_type_id : this.account.account_type_local_id,
accountType: [this.shared.isWeb ? this.account.account_type_id : this.account.account_type_local_id,
[Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
creditLimit: [this.account.credit_limit, [Validators.min(0)]],
includeInBalance: [this.account.include_in_balance, [Validators.required]],
Expand All @@ -76,7 +70,7 @@ export class SaveComponent extends BaseForm implements OnInit {
const model = { ...this.account };

model.name = this.form.controls.name.value;
if (this.isWeb) {
if (this.shared.isWeb) {
model.account_type_id = this.form.controls.accountType.value;
} else {
model.account_type_local_id = this.form.controls.accountType.value;
Expand Down Expand Up @@ -134,7 +128,7 @@ export class SaveComponent extends BaseForm implements OnInit {
return;
}
const value = this.form.controls.accountType.value;
const type = this.accountTypes.find(c => this.isWeb ? c.id === value : c.local_id === value);
const type = this.accountTypes.find(c => this.shared.isWeb ? c.id === value : c.local_id === value);
return type ? type.name : '';
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/accounts/service/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AccountService extends SyncService<Account> {
}

getAll(): Observable<Account[]> {
if (this.isweb) {
if (this.shared.isWeb) {
return from(this.authService.supabase.from('accounts_view').select('*'))
.pipe(map(response => response.data));
}
Expand Down
8 changes: 5 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { MenuItem } from './models/menu-item';
import { environment } from 'src/environments/environment';
import { SharedService } from './core/services/shared.service';
import { filter, takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { Meta } from '@angular/platform-browser';
import { SqLiteService } from './core/services/sq-lite.service';
import { SchemaService } from './core/services/schema.service';
import { AuthService } from './services/auth.service';
import { NavigationEnd, Router } from '@angular/router';
import { Device } from '@capacitor/device';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -91,13 +90,16 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
});
}

ngOnInit() {
async ngOnInit() {
this.sharedService.showMenu$
.pipe(takeUntil(this.destroy$))
.subscribe((result) => {
this.showMenu = result;
});
this.getUserName();

const info = await Device.getInfo();
this.sharedService.isWeb = info.platform === 'web';
}

async getUserName() {
Expand Down
12 changes: 4 additions & 8 deletions src/app/core/services/crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AuthService } from 'src/app/services/auth.service';
export abstract class CrudService<T extends TimeModel> {
abstract endpoint = '';
abstract tableName = '';
isweb;
currentUserId = '';

constructor(
Expand All @@ -19,9 +18,6 @@ export abstract class CrudService<T extends TimeModel> {
protected authService: AuthService,
protected sqlite: SqLiteService
) {
shared.isWeb.subscribe(data => {
this.isweb = data;
});
authService.currentUser.subscribe(d => {
if (d) {
this.currentUserId = d.id;
Expand All @@ -37,7 +33,7 @@ export abstract class CrudService<T extends TimeModel> {
}

getAll(forceRefresh = false, queryString: string = '*'): Observable<T[]> {
if (this.isweb || forceRefresh) {
if (this.shared.isWeb || forceRefresh) {
return from(this.authService.supabase.from(this.endpoint).select(queryString))
.pipe(map(response => response.data));
}
Expand All @@ -59,7 +55,7 @@ export abstract class CrudService<T extends TimeModel> {
}

create(record: T): Observable<T> {
if (this.isweb) {
if (this.shared.isWeb) {
return this.createRequest(record);
}
else if (this.shared.isOnline) {
Expand Down Expand Up @@ -93,7 +89,7 @@ export abstract class CrudService<T extends TimeModel> {
}

update(record: T): Observable<T> {
if (this.isweb) {
if (this.shared.isWeb) {
return this.updateRequest(record);
}
else if (this.shared.isOnline && record.id) {
Expand Down Expand Up @@ -130,7 +126,7 @@ export abstract class CrudService<T extends TimeModel> {
}

delete(record: T) {
if (this.isweb) {
if (this.shared.isWeb) {
return this.deleteRequest(record);
}
else if (this.shared.isOnline && record.id) {
Expand Down
9 changes: 3 additions & 6 deletions src/app/core/services/shared.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { ToastController } from '@ionic/angular';
import { Device } from '@capacitor/device';
import { Network } from '@capacitor/network';

@Injectable({
Expand All @@ -11,16 +10,14 @@ export class SharedService {
public loadingMap: Map<string, boolean> = new Map<string, boolean>();
public showMenu$: Subject<boolean> = new Subject<boolean>();
isOnline = false;
isWeb = new BehaviorSubject(false);
isWeb = true;
isElectron = new BehaviorSubject(false);
falseValue: string | number = 'false';
trueValue: string | number = 'true';

constructor(public toastController: ToastController) {
Device.getInfo().then(data => {
this.isWeb.next(data.platform === 'web');
this.isElectron.next(false); //TODO Need to find whether it is running in electron
});
this.isElectron.next(false); //TODO Need to find whether it is running in electron

Network.getStatus().then(data => {
this.isOnline = data.connected;
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@
</ion-item>
</ion-toolbar>
</ion-footer>
<app-sync [isWeb]="isWeb"></app-sync>
<app-sync [isWeb]="shared.isWeb"></app-sync>
11 changes: 2 additions & 9 deletions src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BaseComponent } from '../core/helpers/base.component';
import { Account } from '../accounts/models/account';
import { SharedService } from '../core/services/shared.service';
import { combineLatest } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { ModalController, NavController } from '@ionic/angular';
import { StoreService } from '../store/store.service';
import { Store } from '@ngxs/store';
Expand All @@ -24,22 +23,16 @@ export class DashboardComponent extends BaseComponent implements OnInit {
accountTypes: AccountType[] = [];
totalBalance = 0;
dashboardData: any[] = [];
isWeb = false;

constructor(
private router: NavController,
private storeService: StoreService,
private store: Store,
private modal: ModalController,
private spinner: SpinnerVisibilityService,
private shared: SharedService
public shared: SharedService
) {
super();
shared.isWeb
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(c => {
this.isWeb = c;
});
}

ngOnInit() {
Expand All @@ -65,7 +58,7 @@ export class DashboardComponent extends BaseComponent implements OnInit {

this.accountTypes.map(c => {
let currentAccounts;
if (this.isWeb) {
if (this.shared.isWeb) {
currentAccounts = this.accounts.filter(d => d.account_type_id === c.id
&& d.exclude_from_dashboard === false
&& d.is_active === true);
Expand Down
12 changes: 6 additions & 6 deletions src/app/entities/categories/index/index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export class IndexComponent extends BaseComponent implements OnInit {
private alertController: AlertController,
public popoverController: PopoverController,
private storeService: StoreService,
platform: Platform,
private platform: Platform,
private modal: ModalController
) {
super();
platform.ready().then(() => {
this.height = platform.height();
this.width = platform.width();
});
}

ngOnInit() {
async ngOnInit() {
await this.platform.ready();
this.height = this.platform.height();
this.width = this.platform.width();

this.storeService.getCategories();
this.categories$.pipe(
takeUntil(this.ngUnsubscribe),
Expand Down
2 changes: 1 addition & 1 deletion src/app/entities/categories/service/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class CategoryService extends SyncService<Category> {
}

getAll() {
if (this.isweb) {
if (this.shared.isWeb) {
return super.getAll(false, `*,sub_categories(id,name,category_id)`);
}
return super.getAll()
Expand Down
12 changes: 6 additions & 6 deletions src/app/entities/payees/index/index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export class IndexComponent extends BaseComponent implements OnInit {
private store: Store,
private alertController: AlertController,
private storeService: StoreService,
platform: Platform,
private platform: Platform,
private modal: ModalController
) {
super();
platform.ready().then(() => {
this.height = platform.height();
this.width = platform.width();
});
}

ngOnInit() {
async ngOnInit() {
await this.platform.ready();
this.height = this.platform.height();
this.width = this.platform.width();

this.storeService.getPayees();

this.payees$.pipe(
Expand Down
12 changes: 6 additions & 6 deletions src/app/entities/tags/index/index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ export class IndexComponent extends BaseComponent implements OnInit {
private store: Store,
private alertController: AlertController,
private storeService: StoreService,
platform: Platform,
private platform: Platform,
private modal: ModalController
) {
super();
platform.ready().then(() => {
this.height = platform.height();
this.width = platform.width();
});
}

ngOnInit() {
async ngOnInit() {
await this.platform.ready();
this.height = this.platform.height();
this.width = this.platform.width();

this.storeService.getTags();
this.tags$.pipe(
takeUntil(this.ngUnsubscribe),
Expand Down
4 changes: 2 additions & 2 deletions src/app/transaction/index/index.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(change)="accountChange($event)">
<option [value]="account.id"
[selected]="account.id === selectedAccountId"
*ngFor="let account of (accounts | async)">{{account.name}}</option>
*ngFor="let account of accounts">{{account.name}}</option>
</select>
</ion-buttons>
</ion-toolbar>
Expand Down Expand Up @@ -93,4 +93,4 @@
</ion-item>
</ion-toolbar>
</ion-footer>
<app-sync [isWeb]="isWeb"></app-sync>
<app-sync [isWeb]="shared.isWeb"></app-sync>
Loading

0 comments on commit b57b445

Please sign in to comment.