Implement category assigning for transactions
This commit is contained in:
parent
b79f754808
commit
2c8801fa53
4 changed files with 20 additions and 6 deletions
|
@ -26,10 +26,13 @@
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<input matInput type="date" [(ngModel)]="currentTransaction.date" placeholder="Date" required>
|
<input matInput type="date" [(ngModel)]="currentTransaction.date" placeholder="Date" required>
|
||||||
<!--
|
</mat-form-field>
|
||||||
<input matInput [matDatePicker]="transactionDatePicker" [(ngModel)]="currentTransaction.date" placeholder="Date" required>
|
<mat-form-field>
|
||||||
<mat-datepicker #transactionDatePicker></mat-datepicker>
|
<mat-select placeholder="Category" [(ngModel)]="currentTransaction.categoryId">
|
||||||
-->
|
<mat-option *ngFor="let category of categories" [value]="category.id">
|
||||||
|
{{ category.name }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-radio-group [(ngModel)]="currentTransaction.type">
|
<mat-radio-group [(ngModel)]="currentTransaction.type">
|
||||||
<mat-radio-button [value]="transactionType.EXPENSE">Expense</mat-radio-button>
|
<mat-radio-button [value]="transactionType.EXPENSE">Expense</mat-radio-button>
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { Transaction } from '../transaction'
|
||||||
import { TransactionType } from '../transaction.type'
|
import { TransactionType } from '../transaction.type'
|
||||||
import { TransactionService } from '../transaction.service'
|
import { TransactionService } from '../transaction.service'
|
||||||
import { Location } from '@angular/common';
|
import { Location } from '@angular/common';
|
||||||
|
import { Category } from '../category'
|
||||||
|
import { CategoryService } from '../category.service'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-add-edit-transaction',
|
selector: 'app-add-edit-transaction',
|
||||||
|
@ -14,13 +16,16 @@ export class AddEditTransactionComponent implements OnInit {
|
||||||
@Input() title: string;
|
@Input() title: string;
|
||||||
@Input() currentTransaction: Transaction;
|
@Input() currentTransaction: Transaction;
|
||||||
public transactionType = TransactionType;
|
public transactionType = TransactionType;
|
||||||
|
public selectedCategory: Category;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private categoryService: CategoryService,
|
||||||
private transactionService: TransactionService,
|
private transactionService: TransactionService,
|
||||||
private location: Location
|
private location: Location
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.getCategories()
|
||||||
}
|
}
|
||||||
|
|
||||||
goBack(): void {
|
goBack(): void {
|
||||||
|
@ -42,4 +47,8 @@ export class AddEditTransactionComponent implements OnInit {
|
||||||
this.transactionService.deleteTransaction(this.currentTransaction);
|
this.transactionService.deleteTransaction(this.currentTransaction);
|
||||||
this.goBack()
|
this.goBack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCategories() {
|
||||||
|
this.categoryService.getCategories().subscribe(categories => this.categories = categories)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
MatListModule,
|
MatListModule,
|
||||||
MatRadioModule,
|
MatRadioModule,
|
||||||
MatProgressBarModule,
|
MatProgressBarModule,
|
||||||
|
MatSelectModule,
|
||||||
MatToolbarModule,
|
MatToolbarModule,
|
||||||
} from '@angular/material';
|
} from '@angular/material';
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ import { CategoryListComponent } from './category-list/category-list.component';
|
||||||
MatListModule,
|
MatListModule,
|
||||||
MatRadioModule,
|
MatRadioModule,
|
||||||
MatProgressBarModule,
|
MatProgressBarModule,
|
||||||
|
MatSelectModule,
|
||||||
MatToolbarModule,
|
MatToolbarModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
FormsModule
|
FormsModule
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ITransaction } from './budget-database'
|
import { ITransaction } from './budget-database'
|
||||||
import { ICategory } from './budget-database'
|
import { Category } from './category'
|
||||||
import { TransactionType } from './transaction.type';
|
import { TransactionType } from './transaction.type';
|
||||||
|
|
||||||
export class Transaction implements ITransaction {
|
export class Transaction implements ITransaction {
|
||||||
|
@ -8,6 +8,6 @@ export class Transaction implements ITransaction {
|
||||||
description: string;
|
description: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
date: Date = new Date();
|
date: Date = new Date();
|
||||||
category: ICategory;
|
categoryId: number;
|
||||||
type: TransactionType = TransactionType.EXPENSE;
|
type: TransactionType = TransactionType.EXPENSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue