Fix compilation issues
This commit is contained in:
parent
7fe7b67c29
commit
fb5e2549a1
10 changed files with 74 additions and 15 deletions
|
@ -25,8 +25,10 @@
|
||||||
<mat-radio-button [value]="categoryType.LIMIT">Limit</mat-radio-button>
|
<mat-radio-button [value]="categoryType.LIMIT">Limit</mat-radio-button>
|
||||||
<mat-radio-button [value]="categoryType.GOAL">Goal</mat-radio-button>
|
<mat-radio-button [value]="categoryType.GOAL">Goal</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
|
<!--
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<input type="color" matInput [(ngModel)]="currentCategory.color" placeholder="Color">
|
<input type="color" matInput [(ngModel)]="currentCategory.color" placeholder="Color">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
-->
|
||||||
<button class="button-delete" mat-button color="warn" *ngIf="currentCategory.id" (click)="delete()">Delete</button>
|
<button class="button-delete" mat-button color="warn" *ngIf="currentCategory.id" (click)="delete()">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,6 +17,7 @@ export class AddEditTransactionComponent implements OnInit {
|
||||||
@Input() currentTransaction: Transaction;
|
@Input() currentTransaction: Transaction;
|
||||||
public transactionType = TransactionType;
|
public transactionType = TransactionType;
|
||||||
public selectedCategory: Category;
|
public selectedCategory: Category;
|
||||||
|
public categories: Category[]
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private categoryService: CategoryService,
|
private categoryService: CategoryService,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import Dexie from 'dexie';
|
import Dexie from 'dexie';
|
||||||
import { TransactionType } from './transaction.type';
|
|
||||||
import { Category } from './category'
|
import { Category } from './category'
|
||||||
|
import { CategoryType } from './category.type';
|
||||||
import { Transaction } from './transaction'
|
import { Transaction } from './transaction'
|
||||||
|
import { TransactionType } from './transaction.type';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -14,7 +15,7 @@ export class BudgetDatabase extends Dexie {
|
||||||
constructor () {
|
constructor () {
|
||||||
super('BudgetDatabase')
|
super('BudgetDatabase')
|
||||||
this.version(1).stores({
|
this.version(1).stores({
|
||||||
transactions: `++id, title, description, amount, date, category, type`,
|
transactions: `++id, title, description, amount, date, category_id, type`,
|
||||||
categories: `++id, name, amount, repeat, color, type-`
|
categories: `++id, name, amount, repeat, color, type-`
|
||||||
})
|
})
|
||||||
this.transactions.mapToClass(Transaction)
|
this.transactions.mapToClass(Transaction)
|
||||||
|
@ -28,7 +29,7 @@ export interface ITransaction {
|
||||||
description: string;
|
description: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
date: Date;
|
date: Date;
|
||||||
category: ICategory;
|
categoryId: number;
|
||||||
type: TransactionType;
|
type: TransactionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { Location } from '@angular/common';
|
||||||
export class CategoriesComponent implements OnInit {
|
export class CategoriesComponent implements OnInit {
|
||||||
|
|
||||||
public categories: Category[];
|
public categories: Category[];
|
||||||
private categoryBalances: Map<number, number>;
|
public categoryBalances: Map<number, number>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private categoryService: CategoryService,
|
private categoryService: CategoryService,
|
||||||
|
|
|
@ -24,5 +24,6 @@ export class CategoryDetailsComponent implements OnInit {
|
||||||
getCategory(): void {
|
getCategory(): void {
|
||||||
const id = +this.route.snapshot.paramMap.get('id')
|
const id = +this.route.snapshot.paramMap.get('id')
|
||||||
this.categoryService.getCategory(id)
|
this.categoryService.getCategory(id)
|
||||||
.subscribe(category => this.category = category)
|
.subscribe(category => this.category = category)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,3 +6,13 @@
|
||||||
::ng-deep .mat-progress-bar-buffer {
|
::ng-deep .mat-progress-bar-buffer {
|
||||||
background-color: #BDBDBD;
|
background-color: #BDBDBD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.mat-line.category-list-title {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.mat-line.category-list-title .remaining {
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
</style>
|
</style>
|
||||||
<mat-nav-list class="categories">
|
<mat-nav-list class="categories">
|
||||||
<a mat-list-item *ngFor="let category of categories" routerLink="/categories/{{ category.id }}">
|
<a mat-list-item *ngFor="let category of categories" routerLink="/categories/{{ category.id }}">
|
||||||
<p matLine>{{category.name}}</p>
|
<p matLine class="category-list-title">
|
||||||
<style>
|
<span>
|
||||||
::ng-deep .mat-progress-bar-fill::after {
|
{{ category.name }}
|
||||||
background-color: "{{ category.color }}";
|
</span>
|
||||||
}
|
<span class="remaining">
|
||||||
</style>
|
{{ getCategoryRemainingBalance(category) | currency }} remaining
|
||||||
<mat-progress-bar matLine mode="determinate" value="{{ getCategoryCompletion(category) }}"></mat-progress-bar>
|
</span>
|
||||||
|
</p>
|
||||||
|
<mat-progress-bar matLine mode="determinate" #categoryProgress [attr.id]="'cat-' + category.id" value="{{ getCategoryCompletion(category) }}"></mat-progress-bar>
|
||||||
</a>
|
</a>
|
||||||
</mat-nav-list>
|
</mat-nav-list>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input } from '@angular/core';
|
||||||
import { Category } from '../category'
|
import { Category } from '../category'
|
||||||
|
import { CategoryType } from '../category.type'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-category-list',
|
selector: 'app-category-list',
|
||||||
|
@ -16,6 +17,32 @@ export class CategoryListComponent implements OnInit {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
ngAfterViewInit() {
|
||||||
|
this.categoryProgressBars.changes.subscribe( list =>
|
||||||
|
list.forEach(progressBar =>
|
||||||
|
progressBar._elementRef.nativeElement.innerHTML += `
|
||||||
|
<style>
|
||||||
|
.mat-progress-bar-fill::after {
|
||||||
|
background-color: ${this.categories[0].color};
|
||||||
|
color: purple;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
getCategoryRemainingBalance(category: Category): number {
|
||||||
|
let categoryBalance = this.categoryBalances.get(category.id)
|
||||||
|
if (!categoryBalance) {
|
||||||
|
categoryBalance = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return category.amount + categoryBalance;
|
||||||
|
}
|
||||||
|
|
||||||
getCategoryCompletion(category: Category): number {
|
getCategoryCompletion(category: Category): number {
|
||||||
if (category.amount <= 0) {
|
if (category.amount <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -26,6 +53,16 @@ export class CategoryListComponent implements OnInit {
|
||||||
categoryBalance = 0
|
categoryBalance = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return categoryBalance / category.amount;
|
if (category.type === CategoryType.LIMIT) {
|
||||||
|
// If the category is a limit, then a negative balance needs to be turned into positive
|
||||||
|
// and vice-versa for the completion to be properly calculated
|
||||||
|
if (categoryBalance < 0) {
|
||||||
|
categoryBalance = Math.abs(categoryBalance)
|
||||||
|
} else {
|
||||||
|
categoryBalance -= (categoryBalance * 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return categoryBalance / category.amount * 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ export class CategoryService {
|
||||||
getBalance(category: Category): Observable<number> {
|
getBalance(category: Category): Observable<number> {
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
return from(
|
return from(
|
||||||
this.db.transactions.filter(transaction => transaction.category === category).each(function(transaction) {
|
this.db.transactions.filter(transaction => transaction.categoryId === category.id).each(function(transaction) {
|
||||||
if (transaction.type === TransactionType.INCOME) {
|
if (transaction.type === TransactionType.INCOME) {
|
||||||
sum += transaction.amount
|
sum += transaction.amount
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,6 +37,11 @@ export class DashboardComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
getCategories(): void {
|
getCategories(): void {
|
||||||
this.categoryService.getCategories(5).subscribe(categories => this.categories = categories)
|
this.categoryService.getCategories(5).subscribe(categories => {
|
||||||
|
this.categories = categories
|
||||||
|
for (let category of this.categories) {
|
||||||
|
this.categoryService.getBalance(category).subscribe(balance => this.categoryBalances.set(category.id, balance))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue