From 3ab5413c431818a311e4ddea468d09014fb120e5 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Mon, 24 Feb 2020 19:34:35 -0600 Subject: [PATCH] Move actionable buttons from app component to specific components Signed-off-by: William Brawner --- src/app/actionable.ts | 4 ---- src/app/app.component.html | 8 ++++---- src/app/app.component.ts | 3 +-- src/app/app.module.ts | 2 ++ .../add-edit-budget.component.html | 1 + .../add-edit-budget.component.ts | 17 ++--------------- src/app/budgets/budget.component.html | 9 +++++---- src/app/budgets/budget.component.ts | 13 ++++++++++--- .../add-edit-category.component.html | 1 + .../add-edit-category.component.ts | 14 ++------------ .../add-edit-transaction.component.html | 1 + .../add-edit-transaction.component.ts | 14 ++------------ src/app/users/login/login.component.html | 1 + src/app/users/login/login.component.ts | 14 ++------------ src/app/users/register/register.component.html | 6 ++++-- src/app/users/register/register.component.ts | 17 +++++------------ src/styles.css | 5 +++++ 17 files changed, 48 insertions(+), 82 deletions(-) delete mode 100644 src/app/actionable.ts diff --git a/src/app/actionable.ts b/src/app/actionable.ts deleted file mode 100644 index de2a9f8..0000000 --- a/src/app/actionable.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface Actionable { - doAction(): void; - getActionLabel(): string; -} diff --git a/src/app/app.component.html b/src/app/app.component.html index ae937d7..7799979 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,4 +1,7 @@ - +

+ You appear to be offline. Twigs unfortunately doesn't currently support offline use at the moment though it may be implemented in a future release! +

+ {{ getUsername() }} @@ -21,9 +24,6 @@ {{ title }} - - {{ actionable.getActionLabel() }} - diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 3ad95ae..fbe1f2d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,5 @@ import { Component, Inject } from '@angular/core'; import { Location } from '@angular/common'; -import { Actionable } from './actionable'; import { User } from './users/user'; import { TWIGS_SERVICE, TwigsService } from './shared/twigs.service'; @@ -12,8 +11,8 @@ import { TWIGS_SERVICE, TwigsService } from './shared/twigs.service'; export class AppComponent { public title = 'Twigs'; public backEnabled = false; - public actionable: Actionable; public user: User; + public online = window.navigator.onLine; constructor( @Inject(TWIGS_SERVICE) private twigsService: TwigsService, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 7e222dd..c7c9eb3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -14,6 +14,7 @@ import { MatSelectModule, MatToolbarModule, MatSidenavModule, + MatProgressSpinnerModule, } from '@angular/material'; import { AppComponent } from './app.component'; @@ -92,6 +93,7 @@ export const CustomCurrencyMaskConfig: CurrencyMaskConfig = { MatSelectModule, MatToolbarModule, MatSidenavModule, + MatProgressSpinnerModule, AppRoutingModule, FormsModule, ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }), diff --git a/src/app/budgets/add-edit-budget/add-edit-budget.component.html b/src/app/budgets/add-edit-budget/add-edit-budget.component.html index 2731e05..54cf0fb 100644 --- a/src/app/budgets/add-edit-budget/add-edit-budget.component.html +++ b/src/app/budgets/add-edit-budget/add-edit-budget.component.html @@ -8,5 +8,6 @@ + diff --git a/src/app/budgets/add-edit-budget/add-edit-budget.component.ts b/src/app/budgets/add-edit-budget/add-edit-budget.component.ts index 7d9130b..7ff64df 100644 --- a/src/app/budgets/add-edit-budget/add-edit-budget.component.ts +++ b/src/app/budgets/add-edit-budget/add-edit-budget.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit, Input, Inject, OnDestroy } from '@angular/core'; import { Budget } from '../budget'; import { AppComponent } from 'src/app/app.component'; -import { Actionable } from 'src/app/actionable'; import { User } from 'src/app/users/user'; import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; @@ -10,7 +9,7 @@ import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; templateUrl: './add-edit-budget.component.html', styleUrls: ['./add-edit-budget.component.css'] }) -export class AddEditBudgetComponent implements OnInit, OnDestroy, Actionable { +export class AddEditBudgetComponent { @Input() title: string; @Input() budget: Budget; public userIds: number[]; @@ -22,18 +21,10 @@ export class AddEditBudgetComponent implements OnInit, OnDestroy, Actionable { ) { this.app.title = this.title; this.app.backEnabled = true; - this.app.actionable = this; this.userIds = [this.app.user.id]; } - ngOnInit() { - } - - ngOnDestroy(): void { - this.app.actionable = null; - } - - doAction(): void { + save(): void { let observable; if (this.budget.id) { // This is an existing transaction, update it @@ -52,10 +43,6 @@ export class AddEditBudgetComponent implements OnInit, OnDestroy, Actionable { }); } - getActionLabel(): string { - return 'Save'; - } - delete(): void { this.twigsService.deleteBudget(this.budget.id); this.app.goBack(); diff --git a/src/app/budgets/budget.component.html b/src/app/budgets/budget.component.html index 8451122..b488895 100644 --- a/src/app/budgets/budget.component.html +++ b/src/app/budgets/budget.component.html @@ -1,4 +1,5 @@ -
+ +

To begin tracking your finances, login or create an account!

@@ -6,7 +7,7 @@ Login
- +

{{ budget.name }} @@ -16,12 +17,12 @@

-
+ - + add \ No newline at end of file diff --git a/src/app/budgets/budget.component.ts b/src/app/budgets/budget.component.ts index 810a8df..b797b38 100644 --- a/src/app/budgets/budget.component.ts +++ b/src/app/budgets/budget.component.ts @@ -12,6 +12,7 @@ export class BudgetsComponent implements OnInit { @Input() budgetId: string; public budgets: Budget[]; + public loading = true; constructor( private app: AppComponent, @@ -21,9 +22,15 @@ export class BudgetsComponent implements OnInit { ngOnInit() { this.app.backEnabled = this.isLoggedIn(); this.app.title = 'Budgets'; - this.twigsService.getBudgets().subscribe(budgets => { - this.budgets = budgets; - }); + this.twigsService.getBudgets().subscribe( + budgets => { + this.budgets = budgets; + this.loading = false; + }, + error => { + this.loading = false; + } + ); } isLoggedIn(): boolean { diff --git a/src/app/categories/add-edit-category/add-edit-category.component.html b/src/app/categories/add-edit-category/add-edit-category.component.html index f284385..0207a4d 100644 --- a/src/app/categories/add-edit-category/add-edit-category.component.html +++ b/src/app/categories/add-edit-category/add-edit-category.component.html @@ -17,5 +17,6 @@ --> +
\ No newline at end of file diff --git a/src/app/categories/add-edit-category/add-edit-category.component.ts b/src/app/categories/add-edit-category/add-edit-category.component.ts index fbd1920..66e0940 100644 --- a/src/app/categories/add-edit-category/add-edit-category.component.ts +++ b/src/app/categories/add-edit-category/add-edit-category.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit, Input, OnDestroy, Inject } from '@angular/core'; import { Category } from '../category'; -import { Actionable } from 'src/app/actionable'; import { AppComponent } from 'src/app/app.component'; import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; @@ -9,7 +8,7 @@ import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; templateUrl: './add-edit-category.component.html', styleUrls: ['./add-edit-category.component.css'] }) -export class AddEditCategoryComponent implements OnInit, Actionable, OnDestroy { +export class AddEditCategoryComponent implements OnInit { @Input() budgetId: number; @Input() title: string; @@ -21,16 +20,11 @@ export class AddEditCategoryComponent implements OnInit, Actionable, OnDestroy { ) { } ngOnInit() { - this.app.actionable = this; this.app.backEnabled = true; this.app.title = this.title; } - ngOnDestroy() { - this.app.actionable = null; - } - - doAction(): void { + save(): void { let observable; if (this.currentCategory.id) { // This is an existing category, update it @@ -57,10 +51,6 @@ export class AddEditCategoryComponent implements OnInit, Actionable, OnDestroy { }); } - getActionLabel(): string { - return 'Save'; - } - delete(): void { this.twigsService.deleteCategory(this.budgetId, this.currentCategory.id).subscribe(() => { this.app.goBack(); diff --git a/src/app/transactions/add-edit-transaction/add-edit-transaction.component.html b/src/app/transactions/add-edit-transaction/add-edit-transaction.component.html index da13018..db8246d 100644 --- a/src/app/transactions/add-edit-transaction/add-edit-transaction.component.html +++ b/src/app/transactions/add-edit-transaction/add-edit-transaction.component.html @@ -28,5 +28,6 @@ Expense Income +
diff --git a/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts b/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts index 2da4013..6f2ba94 100644 --- a/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts +++ b/src/app/transactions/add-edit-transaction/add-edit-transaction.component.ts @@ -2,7 +2,6 @@ import { Component, OnInit, Input, OnChanges, OnDestroy, Inject, SimpleChanges } import { Transaction } from '../transaction'; import { TransactionType } from '../transaction.type'; import { Category } from 'src/app/categories/category'; -import { Actionable } from 'src/app/actionable'; import { AppComponent } from 'src/app/app.component'; import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; @@ -11,7 +10,7 @@ import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; templateUrl: './add-edit-transaction.component.html', styleUrls: ['./add-edit-transaction.component.css'] }) -export class AddEditTransactionComponent implements OnInit, OnChanges, OnDestroy, Actionable { +export class AddEditTransactionComponent implements OnInit, OnChanges { @Input() title: string; @Input() currentTransaction: Transaction; @Input() budgetId: number; @@ -29,7 +28,6 @@ export class AddEditTransactionComponent implements OnInit, OnChanges, OnDestroy ngOnInit() { this.app.title = this.title; this.app.backEnabled = true; - this.app.actionable = this; this.getCategories(); let d: Date; if (this.currentTransaction) { @@ -51,11 +49,7 @@ export class AddEditTransactionComponent implements OnInit, OnChanges, OnDestroy this.currentTime = `${d.getHours()}:${d.getMinutes()}`; } - ngOnDestroy() { - this.app.actionable = null; - } - - doAction(): void { + save(): void { // The amount will be input as a decimal value so we need to convert it // to an integer let observable; @@ -98,10 +92,6 @@ export class AddEditTransactionComponent implements OnInit, OnChanges, OnDestroy }); } - getActionLabel(): string { - return 'Save'; - } - delete(): void { this.twigsService.deleteTransaction(this.budgetId, this.currentTransaction.id).subscribe(() => { this.app.goBack(); diff --git a/src/app/users/login/login.component.html b/src/app/users/login/login.component.html index 011eca1..5e1dc93 100644 --- a/src/app/users/login/login.component.html +++ b/src/app/users/login/login.component.html @@ -5,4 +5,5 @@ + \ No newline at end of file diff --git a/src/app/users/login/login.component.ts b/src/app/users/login/login.component.ts index f018f81..e84ea36 100644 --- a/src/app/users/login/login.component.ts +++ b/src/app/users/login/login.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit, OnDestroy, Inject, ChangeDetectorRef } from '@angular/core'; import { TwigsService, TWIGS_SERVICE } from '../../shared/twigs.service'; import { User } from '../user'; -import { Actionable } from 'src/app/actionable'; import { AppComponent } from 'src/app/app.component'; import { Router } from '@angular/router'; @@ -10,7 +9,7 @@ import { Router } from '@angular/router'; templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) -export class LoginComponent implements OnInit, OnDestroy, Actionable { +export class LoginComponent implements OnInit { public email: string; public password: string; @@ -23,15 +22,10 @@ export class LoginComponent implements OnInit, OnDestroy, Actionable { ngOnInit() { this.app.title = 'Login'; - this.app.actionable = this; this.app.backEnabled = true; } - ngOnDestroy() { - this.app.actionable = null; - } - - doAction(): void { + login(): void { this.twigsService.login(this.email, this.password) .subscribe(user => { this.app.user = user; @@ -42,8 +36,4 @@ export class LoginComponent implements OnInit, OnDestroy, Actionable { alert("Login failed. Please verify you have the correct credentials"); }) } - - getActionLabel() { - return 'Submit'; - } } diff --git a/src/app/users/register/register.component.html b/src/app/users/register/register.component.html index 292d7d6..b0a1405 100644 --- a/src/app/users/register/register.component.html +++ b/src/app/users/register/register.component.html @@ -1,4 +1,5 @@ -
+ +
@@ -11,4 +12,5 @@ -
\ No newline at end of file + +
\ No newline at end of file diff --git a/src/app/users/register/register.component.ts b/src/app/users/register/register.component.ts index 4440334..8a09ea0 100644 --- a/src/app/users/register/register.component.ts +++ b/src/app/users/register/register.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit, OnDestroy, Inject } from '@angular/core'; import { TwigsService, TWIGS_SERVICE } from '../../shared/twigs.service'; -import { Actionable } from 'src/app/actionable'; import { AppComponent } from 'src/app/app.component'; import { Router } from '@angular/router'; @@ -9,12 +8,13 @@ import { Router } from '@angular/router'; templateUrl: './register.component.html', styleUrls: ['./register.component.css'] }) -export class RegisterComponent implements OnInit, OnDestroy, Actionable { +export class RegisterComponent implements OnInit { public username: string; public email: string; public password: string; public confirmedPassword: string; + public isLoading = false; constructor( private app: AppComponent, @@ -24,29 +24,22 @@ export class RegisterComponent implements OnInit, OnDestroy, Actionable { ngOnInit() { this.app.title = 'Register'; - this.app.actionable = this; this.app.backEnabled = true; } - ngOnDestroy() { - this.app.actionable = null; - } - - doAction(): void { + register(): void { if (this.password !== this.confirmedPassword) { alert('Passwords don\'t match'); return; } + this.isLoading = true; this.twigsService.register(this.username, this.email, this.password).subscribe(user => { console.log(user); this.router.navigate(['/']) }, error => { console.error(error); alert("Registration failed!") + this.isLoading = false; }) } - - getActionLabel() { - return 'Submit'; - } } diff --git a/src/styles.css b/src/styles.css index 00fbc05..1c2a073 100644 --- a/src/styles.css +++ b/src/styles.css @@ -94,6 +94,11 @@ mat-sidenav { min-width: 300px; } +.mat-progress-spinner { + top: 5em; + left: calc(50% - 25px); +} + .income { color: #81C784; }