Remove category types
This commit is contained in:
parent
2b8580f8e8
commit
b4d7c831e9
6 changed files with 11 additions and 23 deletions
|
@ -21,10 +21,6 @@
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<input matInput type="number" [(ngModel)]="currentCategory.amount" placeholder="Amount" required>
|
<input matInput type="number" [(ngModel)]="currentCategory.amount" placeholder="Amount" required>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-radio-group [(ngModel)]="currentCategory.type">
|
|
||||||
<mat-radio-button [value]="categoryType.LIMIT">Limit</mat-radio-button>
|
|
||||||
<mat-radio-button [value]="categoryType.GOAL">Goal</mat-radio-button>
|
|
||||||
</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">
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input } from '@angular/core';
|
||||||
import { CategoryService } from '../category.service'
|
import { CategoryService } from '../category.service'
|
||||||
import { Category } from '../category'
|
import { Category } from '../category'
|
||||||
import { CategoryType } from '../category.type'
|
|
||||||
import { Location } from '@angular/common';
|
import { Location } from '@angular/common';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -13,7 +12,6 @@ export class AddEditCategoryComponent implements OnInit {
|
||||||
|
|
||||||
@Input() title: string;
|
@Input() title: string;
|
||||||
@Input() currentCategory: Category;
|
@Input() currentCategory: Category;
|
||||||
public categoryType = CategoryType;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private categoryService: CategoryService,
|
private categoryService: CategoryService,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import Dexie from 'dexie';
|
import Dexie from 'dexie';
|
||||||
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';
|
import { TransactionType } from './transaction.type';
|
||||||
|
|
||||||
|
@ -22,6 +21,10 @@ export class BudgetDatabase extends Dexie {
|
||||||
transactions: `++id, title, description, amount, date, category_id, 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.version(3).stores({
|
||||||
|
transactions: `++id, title, description, amount, date, category_id, type`,
|
||||||
|
categories: `++id, name, amount, repeat, color`
|
||||||
|
})
|
||||||
this.transactions.mapToClass(Transaction)
|
this.transactions.mapToClass(Transaction)
|
||||||
this.categories.mapToClass(Category)
|
this.categories.mapToClass(Category)
|
||||||
}
|
}
|
||||||
|
@ -43,5 +46,4 @@ export interface ICategory{
|
||||||
amount: number;
|
amount: number;
|
||||||
repeat: string;
|
repeat: string;
|
||||||
color: string;
|
color: string;
|
||||||
type: CategoryType;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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',
|
||||||
|
@ -53,14 +52,13 @@ export class CategoryListComponent implements OnInit {
|
||||||
categoryBalance = 0
|
categoryBalance = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category.type === CategoryType.LIMIT) {
|
// Invert the negative/positive values for calculating progress
|
||||||
// If the category is a limit, then a negative balance needs to be turned into positive
|
// since the limit for a category is saved as a positive but the
|
||||||
// and vice-versa for the completion to be properly calculated
|
// balance is used in the calculation.
|
||||||
if (categoryBalance < 0) {
|
if (categoryBalance < 0) {
|
||||||
categoryBalance = Math.abs(categoryBalance)
|
categoryBalance = Math.abs(categoryBalance)
|
||||||
} else {
|
} else {
|
||||||
categoryBalance -= (categoryBalance * 2)
|
categoryBalance -= (categoryBalance * 2)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return categoryBalance / category.amount * 100;
|
return categoryBalance / category.amount * 100;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { ICategory } from './budget-database'
|
import { ICategory } from './budget-database'
|
||||||
import { CategoryType } from './category.type'
|
|
||||||
|
|
||||||
export class Category implements ICategory {
|
export class Category implements ICategory {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -7,5 +6,4 @@ export class Category implements ICategory {
|
||||||
amount: number;
|
amount: number;
|
||||||
repeat: string;
|
repeat: string;
|
||||||
color: string;
|
color: string;
|
||||||
type: CategoryType = CategoryType.LIMIT;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
export enum CategoryType {
|
|
||||||
LIMIT,
|
|
||||||
GOAL
|
|
||||||
}
|
|
Loading…
Reference in a new issue