Remove category types

This commit is contained in:
William Brawner 2018-09-01 10:38:56 -05:00
parent 2b8580f8e8
commit b4d7c831e9
6 changed files with 11 additions and 23 deletions

View file

@ -21,10 +21,6 @@
<mat-form-field>
<input matInput type="number" [(ngModel)]="currentCategory.amount" placeholder="Amount" required>
</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>
<input type="color" matInput [(ngModel)]="currentCategory.color" placeholder="Color">

View file

@ -1,7 +1,6 @@
import { Component, OnInit, Input } from '@angular/core';
import { CategoryService } from '../category.service'
import { Category } from '../category'
import { CategoryType } from '../category.type'
import { Location } from '@angular/common';
@Component({
@ -13,7 +12,6 @@ export class AddEditCategoryComponent implements OnInit {
@Input() title: string;
@Input() currentCategory: Category;
public categoryType = CategoryType;
constructor(
private categoryService: CategoryService,

View file

@ -1,7 +1,6 @@
import { Injectable } from '@angular/core';
import Dexie from 'dexie';
import { Category } from './category'
import { CategoryType } from './category.type';
import { Transaction } from './transaction'
import { TransactionType } from './transaction.type';
@ -22,6 +21,10 @@ export class BudgetDatabase extends Dexie {
transactions: `++id, title, description, amount, date, category_id, 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.categories.mapToClass(Category)
}
@ -43,5 +46,4 @@ export interface ICategory{
amount: number;
repeat: string;
color: string;
type: CategoryType;
}

View file

@ -1,6 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { Category } from '../category'
import { CategoryType } from '../category.type'
@Component({
selector: 'app-category-list',
@ -53,14 +52,13 @@ export class CategoryListComponent implements OnInit {
categoryBalance = 0
}
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)
}
// Invert the negative/positive values for calculating progress
// since the limit for a category is saved as a positive but the
// balance is used in the calculation.
if (categoryBalance < 0) {
categoryBalance = Math.abs(categoryBalance)
} else {
categoryBalance -= (categoryBalance * 2)
}
return categoryBalance / category.amount * 100;

View file

@ -1,5 +1,4 @@
import { ICategory } from './budget-database'
import { CategoryType } from './category.type'
export class Category implements ICategory {
id: number;
@ -7,5 +6,4 @@ export class Category implements ICategory {
amount: number;
repeat: string;
color: string;
type: CategoryType = CategoryType.LIMIT;
}

View file

@ -1,4 +0,0 @@
export enum CategoryType {
LIMIT,
GOAL
}