diff --git a/src/app/add-edit-transaction/add-edit-transaction.component.css b/src/app/add-edit-transaction/add-edit-transaction.component.css index 27c5310..7d44de1 100644 --- a/src/app/add-edit-transaction/add-edit-transaction.component.css +++ b/src/app/add-edit-transaction/add-edit-transaction.component.css @@ -10,3 +10,7 @@ mat-radio-button { padding-bottom: 15px; } + +.button-delete { + float: right; +} diff --git a/src/app/add-edit-transaction/add-edit-transaction.component.html b/src/app/add-edit-transaction/add-edit-transaction.component.html index bf59689..0f95f91 100644 --- a/src/app/add-edit-transaction/add-edit-transaction.component.html +++ b/src/app/add-edit-transaction/add-edit-transaction.component.html @@ -35,5 +35,5 @@ Expense Income - + diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 013b1dc..3e360df 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,11 +1,12 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { DashboardComponent } from './dashboard/dashboard.component'; import { TransactionsComponent } from './transactions/transactions.component'; import { TransactionDetailsComponent } from './transaction-details/transaction-details.component'; import { NewTransactionComponent } from './new-transaction/new-transaction.component'; const routes: Routes = [ - { path: '', redirectTo: '/transactions', pathMatch: 'full' }, + { path: '', component: DashboardComponent }, { path: 'transactions', component: TransactionsComponent }, { path: 'transactions/new', component: NewTransactionComponent }, { path: 'transactions/:id', component: TransactionDetailsComponent }, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index a371fd0..3059888 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -19,6 +19,7 @@ import { AppRoutingModule } from './app-routing.module'; import { TransactionDetailsComponent } from './transaction-details/transaction-details.component'; import { NewTransactionComponent } from './new-transaction/new-transaction.component'; import { AddEditTransactionComponent } from './add-edit-transaction/add-edit-transaction.component'; +import { DashboardComponent } from './dashboard/dashboard.component'; @NgModule({ declarations: [ @@ -26,7 +27,8 @@ import { AddEditTransactionComponent } from './add-edit-transaction/add-edit-tra TransactionsComponent, TransactionDetailsComponent, NewTransactionComponent, - AddEditTransactionComponent + AddEditTransactionComponent, + DashboardComponent ], imports: [ BrowserModule, diff --git a/src/app/dashboard/dashboard.component.css b/src/app/dashboard/dashboard.component.css new file mode 100644 index 0000000..fc4775e --- /dev/null +++ b/src/app/dashboard/dashboard.component.css @@ -0,0 +1,32 @@ +.dashboard { + display: flex; + justify-content: center; + padding: 1em; +} + +.dashboard-primary { + background: #212121; + color: #F1F1F1; + display: inline-block; + max-width: 500px; + padding: 5em 1em; + position: relative; + text-align: center; + width: 100%; +} + +.dashboard-primary > * { + display: block; +} + +.dashboard-primary h2 { + margin: 0; +} + +.dashboard-primary a { + bottom: 1em; + color: #F1F1F1; + right: 1em; + position: absolute; + text-align: right; +} diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html new file mode 100644 index 0000000..d38be98 --- /dev/null +++ b/src/app/dashboard/dashboard.component.html @@ -0,0 +1,15 @@ + + + + My Finances + + + +
+
+

+ Current Balance: {{ balance | currency }} +

+ View Transactions >> +
+
diff --git a/src/app/dashboard/dashboard.component.spec.ts b/src/app/dashboard/dashboard.component.spec.ts new file mode 100644 index 0000000..9c996c3 --- /dev/null +++ b/src/app/dashboard/dashboard.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DashboardComponent } from './dashboard.component'; + +describe('DashboardComponent', () => { + let component: DashboardComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DashboardComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DashboardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts new file mode 100644 index 0000000..4264d0e --- /dev/null +++ b/src/app/dashboard/dashboard.component.ts @@ -0,0 +1,30 @@ +import { Component, OnInit } from '@angular/core'; +import { TransactionService } from '../transaction.service' + +@Component({ + selector: 'app-dashboard', + templateUrl: './dashboard.component.html', + styleUrls: ['./dashboard.component.css'] +}) +export class DashboardComponent implements OnInit { + + public balance: number; + public transactions: Transaction[]; + + constructor( + private transactionService: TransactionService + ) { } + + ngOnInit() { + this.getBalance(); + this.getTransactions(); + } + + getBalance(): void { + this.transactionService.getBalance().subscribe(balance => this.balance = balance) + } + + getTransactions(): void { + this.transactionService.getTransactions().subscribe(transactions => this.balance = balance) + } +} diff --git a/src/app/transaction.service.ts b/src/app/transaction.service.ts index 017c24d..71108d7 100644 --- a/src/app/transaction.service.ts +++ b/src/app/transaction.service.ts @@ -15,8 +15,12 @@ export class TransactionService { this.db = new BudgetDatabase(); } - getTransactions(): Observable { - return from(this.db.transactions.toCollection().toArray()) + getTransactions(count: number?): Observable { + if (count) { + return from(this.db.transactions.toCollection().limit(count).toArray()) + } else { + return from(this.db.transactions.toCollection().toArray()) + } } getTransaction(id: number): Observable { @@ -36,4 +40,20 @@ export class TransactionService { deleteTransaction(transaction: Transaction): Observable { return from(this.db.transactions.delete(transaction.id)) } + + getBalance(): ObservableTransactions + + + + arrow_back + + + Transactions + + +
diff --git a/src/app/transactions/transactions.component.ts b/src/app/transactions/transactions.component.ts index c1ed6dc..622baed 100644 --- a/src/app/transactions/transactions.component.ts +++ b/src/app/transactions/transactions.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Transaction } from '../transaction'; import { TransactionType } from '../transaction.type'; import { TransactionService } from '../transaction.service'; +import { Location } from '@angular/common'; @Component({ selector: 'app-transactions', @@ -14,14 +15,21 @@ export class TransactionsComponent implements OnInit { public transactions: Transaction[] - constructor(private transactionService: TransactionService) { } + constructor( + private transactionService: TransactionService, + private location: Location + ) { } ngOnInit() { this.getTransactions() } + goBack(): void { + this.location.back() + } + getTransactions(): void { - this.transactionService.getTransactions().subscribe(transactions => { + this.transactionService.getTransactions(5).subscribe(transactions => { this.transactions = transactions; }) } diff --git a/src/styles.css b/src/styles.css index 83a4907..229c87f 100644 --- a/src/styles.css +++ b/src/styles.css @@ -7,6 +7,7 @@ html, body { } p { + color: #F1F1F1; margin: 0; } @@ -21,12 +22,24 @@ a.mat-fab { color: #BDBDBD } -.mat-toolbar { +mat-toolbar { box-shadow: 0px 3px 3px 1px #212121; display: flex; justify-content: space-between; } +mat-toolbar a { + padding: 1em; +} + +mat-toolbar span:nth-child(1) > a { + padding-left: 0; +} + +mat-toolbar span:nth-child(3) > a { + padding-right: 0; +} + mat-toolbar mat-icon { vertical-align: middle; cursor: pointer; @@ -41,3 +54,12 @@ mat-toolbar .action-item { mat-toolbar .action-item a { vertical-align: middle; } + +.income { + color: #81C784; +} + +.expense { + color: #E57373; +} +