Implement dashboard view
This commit is contained in:
parent
b1fa5c021d
commit
3aa4b0cfe2
13 changed files with 178 additions and 21 deletions
|
@ -10,3 +10,7 @@
|
||||||
mat-radio-button {
|
mat-radio-button {
|
||||||
padding-bottom: 15px;
|
padding-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.button-delete {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
|
@ -35,5 +35,5 @@
|
||||||
<mat-radio-button [value]="transactionType.EXPENSE">Expense</mat-radio-button>
|
<mat-radio-button [value]="transactionType.EXPENSE">Expense</mat-radio-button>
|
||||||
<mat-radio-button [value]="transactionType.INCOME">Income</mat-radio-button>
|
<mat-radio-button [value]="transactionType.INCOME">Income</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
<button mat-button *ngIf="currentTransaction.id" (click)="delete()">Delete</button>
|
<button class="button-delete" mat-button color="warn" *ngIf="currentTransaction.id" (click)="delete()">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||||
import { TransactionsComponent } from './transactions/transactions.component';
|
import { TransactionsComponent } from './transactions/transactions.component';
|
||||||
import { TransactionDetailsComponent } from './transaction-details/transaction-details.component';
|
import { TransactionDetailsComponent } from './transaction-details/transaction-details.component';
|
||||||
import { NewTransactionComponent } from './new-transaction/new-transaction.component';
|
import { NewTransactionComponent } from './new-transaction/new-transaction.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', redirectTo: '/transactions', pathMatch: 'full' },
|
{ path: '', component: DashboardComponent },
|
||||||
{ path: 'transactions', component: TransactionsComponent },
|
{ path: 'transactions', component: TransactionsComponent },
|
||||||
{ path: 'transactions/new', component: NewTransactionComponent },
|
{ path: 'transactions/new', component: NewTransactionComponent },
|
||||||
{ path: 'transactions/:id', component: TransactionDetailsComponent },
|
{ path: 'transactions/:id', component: TransactionDetailsComponent },
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { AppRoutingModule } from './app-routing.module';
|
||||||
import { TransactionDetailsComponent } from './transaction-details/transaction-details.component';
|
import { TransactionDetailsComponent } from './transaction-details/transaction-details.component';
|
||||||
import { NewTransactionComponent } from './new-transaction/new-transaction.component';
|
import { NewTransactionComponent } from './new-transaction/new-transaction.component';
|
||||||
import { AddEditTransactionComponent } from './add-edit-transaction/add-edit-transaction.component';
|
import { AddEditTransactionComponent } from './add-edit-transaction/add-edit-transaction.component';
|
||||||
|
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -26,7 +27,8 @@ import { AddEditTransactionComponent } from './add-edit-transaction/add-edit-tra
|
||||||
TransactionsComponent,
|
TransactionsComponent,
|
||||||
TransactionDetailsComponent,
|
TransactionDetailsComponent,
|
||||||
NewTransactionComponent,
|
NewTransactionComponent,
|
||||||
AddEditTransactionComponent
|
AddEditTransactionComponent,
|
||||||
|
DashboardComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
|
32
src/app/dashboard/dashboard.component.css
Normal file
32
src/app/dashboard/dashboard.component.css
Normal file
|
@ -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;
|
||||||
|
}
|
15
src/app/dashboard/dashboard.component.html
Normal file
15
src/app/dashboard/dashboard.component.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<mat-toolbar>
|
||||||
|
<!-- empty span object for spacing -->
|
||||||
|
<span></span>
|
||||||
|
<span>My Finances</span>
|
||||||
|
<!-- empty span object for spacing -->
|
||||||
|
<span></span>
|
||||||
|
</mat-toolbar>
|
||||||
|
<div class="dashboard">
|
||||||
|
<div class="dashboard-primary">
|
||||||
|
<h2 class="balance">
|
||||||
|
Current Balance: <span [ngClass]="{'income': balance > 0, 'expense': balance < 0}" >{{ balance | currency }}</span>
|
||||||
|
</h2>
|
||||||
|
<a routerLink="/transactions">View Transactions >></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
25
src/app/dashboard/dashboard.component.spec.ts
Normal file
25
src/app/dashboard/dashboard.component.spec.ts
Normal file
|
@ -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<DashboardComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ DashboardComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DashboardComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
30
src/app/dashboard/dashboard.component.ts
Normal file
30
src/app/dashboard/dashboard.component.ts
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,8 +15,12 @@ export class TransactionService {
|
||||||
this.db = new BudgetDatabase();
|
this.db = new BudgetDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransactions(): Observable<Transaction[]> {
|
getTransactions(count: number?): Observable<Transaction[]> {
|
||||||
return from(this.db.transactions.toCollection().toArray())
|
if (count) {
|
||||||
|
return from(this.db.transactions.toCollection().limit(count).toArray())
|
||||||
|
} else {
|
||||||
|
return from(this.db.transactions.toCollection().toArray())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransaction(id: number): Observable<Transaction> {
|
getTransaction(id: number): Observable<Transaction> {
|
||||||
|
@ -36,4 +40,20 @@ export class TransactionService {
|
||||||
deleteTransaction(transaction: Transaction): Observable<any> {
|
deleteTransaction(transaction: Transaction): Observable<any> {
|
||||||
return from(this.db.transactions.delete(transaction.id))
|
return from(this.db.transactions.delete(transaction.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBalance(): Observable<number {
|
||||||
|
console.log("Getting balance")
|
||||||
|
let sum = 0;
|
||||||
|
return from(
|
||||||
|
this.db.transactions.each(function(transaction) {
|
||||||
|
if (transaction.type === TransactionType.INCOME) {
|
||||||
|
sum += transaction.amount
|
||||||
|
} else {
|
||||||
|
sum -= transaction.amount
|
||||||
|
}
|
||||||
|
}).then(function() {
|
||||||
|
return sum;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,6 @@
|
||||||
mat-toolbar {
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount.income {
|
|
||||||
color: #81C784;
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount.expense {
|
|
||||||
color: #E57373;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transactions .list-row-one {
|
.transactions .list-row-one {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
padding-bottom: 0.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
<mat-toolbar>Transactions</mat-toolbar>
|
<mat-toolbar>
|
||||||
|
<span>
|
||||||
|
<a (click)="goBack()">
|
||||||
|
<mat-icon>arrow_back</mat-icon>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<span>Transactions</span>
|
||||||
|
<!-- empty span object for spacing -->
|
||||||
|
<span></span>
|
||||||
|
</mat-toolbar>
|
||||||
<mat-nav-list *ngIf="transactions" class="transactions">
|
<mat-nav-list *ngIf="transactions" class="transactions">
|
||||||
<a mat-list-item *ngFor="let transaction of transactions" routerLink="/transactions/{{ transaction.id }}">
|
<a mat-list-item *ngFor="let transaction of transactions" routerLink="/transactions/{{ transaction.id }}">
|
||||||
<div matLine class="list-row-one">
|
<div matLine class="list-row-one">
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||||
import { Transaction } from '../transaction';
|
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';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-transactions',
|
selector: 'app-transactions',
|
||||||
|
@ -14,14 +15,21 @@ export class TransactionsComponent implements OnInit {
|
||||||
|
|
||||||
public transactions: Transaction[]
|
public transactions: Transaction[]
|
||||||
|
|
||||||
constructor(private transactionService: TransactionService) { }
|
constructor(
|
||||||
|
private transactionService: TransactionService,
|
||||||
|
private location: Location
|
||||||
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.getTransactions()
|
this.getTransactions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goBack(): void {
|
||||||
|
this.location.back()
|
||||||
|
}
|
||||||
|
|
||||||
getTransactions(): void {
|
getTransactions(): void {
|
||||||
this.transactionService.getTransactions().subscribe(transactions => {
|
this.transactionService.getTransactions(5).subscribe(transactions => {
|
||||||
this.transactions = transactions;
|
this.transactions = transactions;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ html, body {
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
|
color: #F1F1F1;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +22,24 @@ a.mat-fab {
|
||||||
color: #BDBDBD
|
color: #BDBDBD
|
||||||
}
|
}
|
||||||
|
|
||||||
.mat-toolbar {
|
mat-toolbar {
|
||||||
box-shadow: 0px 3px 3px 1px #212121;
|
box-shadow: 0px 3px 3px 1px #212121;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
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 {
|
mat-toolbar mat-icon {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -41,3 +54,12 @@ mat-toolbar .action-item {
|
||||||
mat-toolbar .action-item a {
|
mat-toolbar .action-item a {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.income {
|
||||||
|
color: #81C784;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expense {
|
||||||
|
color: #E57373;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue