Add descriptions to categories

This commit is contained in:
William Brawner 2020-10-08 02:48:10 +00:00
parent 2c48722dec
commit 69ecb9334e
8 changed files with 16 additions and 3 deletions

View file

@ -0,0 +1,4 @@
.category-description {
padding: 0 1em;
white-space: pre-wrap;
}

View file

@ -1,3 +1,4 @@
<p class="category-description" *ngIf="category && category.description">{{ category.description }}</p>
<app-transaction-list *ngIf="budgetId && category" [budgetId]="budgetId" [categoryId]="category.id"></app-transaction-list>
<a mat-fab routerLink="/budgets/{{ budgetId }}/transactions/new">
<mat-icon aria-label="Add">add</mat-icon>

View file

@ -5,6 +5,9 @@
<mat-form-field (keyup.enter)="doAction()">
<input matInput [(ngModel)]="currentCategory.title" placeholder="Name" required>
</mat-form-field>
<mat-form-field (keyup.enter)="doAction()">
<textarea matInput [(ngModel)]="currentCategory.description" placeholder="Description"></textarea>
</mat-form-field>
<mat-form-field (keyup.enter)="doAction()">
<input matInput type="text" [(ngModel)]="currentCategory.amount" placeholder="Amount" required currencyMask>
</mat-form-field>

View file

@ -33,6 +33,7 @@ export class CategoryFormComponent implements OnInit {
this.currentCategory.id,
{
name: this.currentCategory.title,
description: this.currentCategory.description,
amount: this.currentCategory.amount * 100,
expense: this.currentCategory.expense,
archived: this.currentCategory.archived
@ -43,6 +44,7 @@ export class CategoryFormComponent implements OnInit {
observable = this.twigsService.createCategory(
this.budgetId,
this.currentCategory.title,
this.currentCategory.description,
this.currentCategory.amount * 100,
this.currentCategory.expense
);

View file

@ -1,6 +1,7 @@
export class Category {
id: number;
title: string;
description: string;
amount: number;
expense: boolean;
archived: boolean;

View file

@ -116,9 +116,10 @@ export class TwigsHttpService implements TwigsService {
return this.http.get<Category>(`${this.apiUrl}/categories/${id}`, this.options);
}
createCategory(budgetId: number, name: string, amount: number, isExpense: boolean): Observable<Category> {
createCategory(budgetId: number, name: string, description: string, amount: number, isExpense: boolean): Observable<Category> {
const params = {
'title': name,
'description': description,
'amount': amount,
'expense': isExpense,
'budgetId': budgetId

View file

@ -153,10 +153,11 @@ export class TwigsLocalService implements TwigsService {
});
}
createCategory(budgetId: number, name: string, amount: number, isExpense: boolean): Observable<Category> {
createCategory(budgetId: number, name: string, description: string, amount: number, isExpense: boolean): Observable<Category> {
return Observable.create(subscriber => {
const category = new Category();
category.title = name;
category.description = description;
category.amount = amount;
category.expense = isExpense;
category.budgetId = budgetId;

View file

@ -25,7 +25,7 @@ export interface TwigsService {
// Categories
getCategories(budgetId?: number, count?: number): Observable<Category[]>;
getCategory(id: number): Observable<Category>;
createCategory(budgetId: number, name: string, amount: number, isExpense: boolean): Observable<Category>;
createCategory(budgetId: number, name: string, description: string, amount: number, isExpense: boolean): Observable<Category>;
updateCategory(budgetId: number, id: number, changes: object): Observable<Category>;
deleteCategory(budgetId: number, id: number): Observable<void>;