diff --git a/src/app/app.component.html b/src/app/app.component.html index 1a882f1..f1016ed 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -9,7 +9,7 @@
- +

User

{{item.label}}
- + diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index cfb2117..e0a9348 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,6 +1,6 @@ -import { TestBed, waitForAsync } from '@angular/core/testing'; +import {TestBed, waitForAsync} from '@angular/core/testing'; -import { AppComponent } from './app.component'; +import {AppComponent} from './app.component'; describe('AppComponent', () => { beforeEach(waitForAsync(() => { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 49b0c6c..c952dcf 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,16 +1,16 @@ -import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core' -import { Title } from '@angular/platform-browser' -import { ActivationEnd, Router } from '@angular/router' -import { select, Store } from '@ngrx/store' -import { environment as env } from '@env' -import { selectorSettings } from '@app/settings' -import { OverlayContainer } from '@angular/cdk/overlay' -import * as fromAuth from '@app/auth/reducers' -import * as Auth from '@app/auth/actions/auth' -import { RefreshToken } from '@app/auth/actions/auth' -import { Observable, Subject } from 'rxjs' -import { filter, map, takeUntil } from 'rxjs/operators' -import { User } from '@app/auth/models/user' +import {Component, HostBinding, OnDestroy, OnInit} from '@angular/core'; +import {Title} from '@angular/platform-browser'; +import {ActivationEnd, Router} from '@angular/router'; +import {select, Store} from '@ngrx/store'; +import {environment as env} from '@env'; +import {selectorSettings} from '@app/settings'; +import {OverlayContainer} from '@angular/cdk/overlay'; +import * as fromAuth from '@app/auth/reducers'; +import * as Auth from '@app/auth/actions/auth'; +import {RefreshToken} from '@app/auth/actions/auth'; +import {Observable, Subject} from 'rxjs'; +import {filter, map, takeUntil} from 'rxjs/operators'; +import {User} from '@app/auth/models/user'; @Component({ selector: 'ndfsm-root', @@ -18,11 +18,11 @@ import { User } from '@app/auth/models/user' styleUrls: ['./app.component.scss'], }) export class AppComponent implements OnInit, OnDestroy { - @HostBinding('class') componentCssClass + @HostBinding('class') componentCssClass; // TODO EXTRACT navigation = [ - { link: 'tools', label: 'Tools' }, - ] + {link: 'tools', label: 'Tools'}, + ]; // navigationDev = [ // { link: 'games', label: 'Games' }, // { link: 'scripts', label: 'Scripts' }, @@ -30,65 +30,65 @@ export class AppComponent implements OnInit, OnDestroy { // todo move to module navigationUser = [ - { link: 'finance', label: 'Finance', + { + link: 'finance', label: 'Finance', children: [ - { link: 'finance/dashboard', label: 'Dashboard'}, - { link: 'finance/transaction', label: 'Transactions'}, - ]}, - ] + {link: 'finance/dashboard', label: 'Dashboard'}, + {link: 'finance/transaction', label: 'Transactions'}, + ] + }, + ]; navigationSideMenu = [ ...this.navigation, - { link: 'settings', label: 'Settings' }, - ] - loggedIn$: Observable - userName$: Observable + {link: 'settings', label: 'Settings'}, + ]; + loggedIn$: Observable; + userName$: Observable; - private unsubscribe$: Subject = new Subject() + private unsubscribe$: Subject = new Subject(); - constructor ( + constructor( public overlayContainer: OverlayContainer, private store: Store, private router: Router, private titleService: Title) { - this.store.dispatch(new RefreshToken(true)) + this.store.dispatch(new RefreshToken(true)); - this.loggedIn$ = this.store.pipe(select(fromAuth.getLoggedIn)) - this.userName$ = this.store.pipe(select(fromAuth.getUser)) + this.loggedIn$ = this.store.pipe(select(fromAuth.getLoggedIn)); + this.userName$ = this.store.pipe(select(fromAuth.getUser)); } - ngOnInit () { + ngOnInit() { // TODO extract - document.getElementById('global-spinner'). - setAttribute('style', 'display: none;') + document.getElementById('global-spinner').setAttribute('style', 'display: none;'); this.store.select(selectorSettings).pipe( takeUntil(this.unsubscribe$), - map(({ theme }) => theme.toLowerCase()), + map(({theme}) => theme.toLowerCase()), ).subscribe(theme => { - this.componentCssClass = theme - this.overlayContainer.getContainerElement().classList.add(theme) - }) + this.componentCssClass = theme; + this.overlayContainer.getContainerElement().classList.add(theme); + }); - this.router.events.pipe(filter(event => event instanceof ActivationEnd)). - subscribe((event: ActivationEnd) => { - let lastChild = event.snapshot - while (lastChild.children.length) { - lastChild = lastChild.children[0] - } - const { title } = lastChild.data - this.titleService.setTitle( - title ? `${title} - ${env.appName}` : env.appName, - ) - }) + this.router.events.pipe(filter(event => event instanceof ActivationEnd)).subscribe((event: ActivationEnd) => { + let lastChild = event.snapshot; + while (lastChild.children.length) { + lastChild = lastChild.children[0]; + } + const {title} = lastChild.data; + this.titleService.setTitle( + title ? `${title} - ${env.appName}` : env.appName, + ); + }); } - ngOnDestroy (): void { - this.unsubscribe$.next() - this.unsubscribe$.complete() + ngOnDestroy(): void { + this.unsubscribe$.next(); + this.unsubscribe$.complete(); } - onLogoutClick () { - this.store.dispatch(new Auth.Logout()) + onLogoutClick() { + this.store.dispatch(new Auth.Logout()); } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fe80d17..9e5eb11 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,30 +1,30 @@ -import { BrowserModule } from '@angular/platform-browser' -import { NgModule } from '@angular/core' +import {BrowserModule} from '@angular/platform-browser'; +import {NgModule} from '@angular/core'; -import { AppComponent } from './app.component' -import { HttpClientModule } from '@angular/common/http' -import { RouterModule } from '@angular/router' +import {AppComponent} from './app.component'; +import {HttpClientModule} from '@angular/common/http'; +import {RouterModule} from '@angular/router'; -import { appRoutes } from './app.routes' -import { SharedModule } from '@app/shared' -import { CoreModule } from '@app/core' -import { BrowserAnimationsModule } from '@angular/platform-browser/animations' -import { SettingsModule } from '@app/settings' -import { AuthModule } from '@app/auth/auth.module' -import { metaReducers, reducers } from '@app/reducers' -import { StoreModule } from '@ngrx/store' +import {appRoutes} from './app.routes'; +import {SharedModule} from '@app/shared'; +import {CoreModule} from '@app/core'; +import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; +import {SettingsModule} from '@app/settings'; +import {AuthModule} from '@app/auth/auth.module'; +import {metaReducers, reducers} from '@app/reducers'; +import {StoreModule} from '@ngrx/store'; import { DefaultRouterStateSerializer, NavigationActionTiming, RouterStateSerializer, StoreRouterConfig, StoreRouterConnectingModule, -} from '@ngrx/router-store' -import { environment } from '@env' -import { EffectsModule } from '@ngrx/effects' -import { CustomRouterStateSerializer } from '@app/shared/utils' -import { StoreDevtoolsModule } from '@ngrx/store-devtools' -import { ServiceWorkerModule } from '@angular/service-worker' +} from '@ngrx/router-store'; +import {environment} from '@env'; +import {EffectsModule} from '@ngrx/effects'; +import {CustomRouterStateSerializer} from '@app/shared/utils'; +import {StoreDevtoolsModule} from '@ngrx/store-devtools'; +import {ServiceWorkerModule} from '@angular/service-worker'; export const routerStateConfig: StoreRouterConfig = { stateKey: 'router', // state-slice name for routing state @@ -37,7 +37,7 @@ export const routerStateConfig: StoreRouterConfig = { BrowserAnimationsModule, BrowserModule, HttpClientModule, - RouterModule.forRoot(appRoutes, { relativeLinkResolution: 'legacy' }), + RouterModule.forRoot(appRoutes, {relativeLinkResolution: 'legacy'}), StoreModule.forRoot(reducers, {metaReducers, runtimeChecks: {strictStateImmutability: true, strictActionImmutability: true}}), StoreRouterConnectingModule.forRoot(routerStateConfig), @@ -66,4 +66,5 @@ export const routerStateConfig: StoreRouterConfig = { ], bootstrap: [AppComponent], }) -export class AppModule {} +export class AppModule { +} diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 8e8e73e..9baaa42 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,6 +1,6 @@ -import { Routes } from '@angular/router'; -import { NotFoundPageComponent } from '@app/core'; -import { SettingsComponent } from '@app/settings'; +import {Routes} from '@angular/router'; +import {NotFoundPageComponent} from '@app/core'; +import {SettingsComponent} from '@app/settings'; export const appRoutes: Routes = [ {path: 'notes', loadChildren: () => import('./notes/notes.module').then(m => m.NotesModule)}, diff --git a/src/app/auth/actions/auth.ts b/src/app/auth/actions/auth.ts index b2944f2..8f0e771 100644 --- a/src/app/auth/actions/auth.ts +++ b/src/app/auth/actions/auth.ts @@ -1,4 +1,4 @@ -import { Action } from '@ngrx/store'; +import {Action} from '@ngrx/store'; import {User, Authenticate, UserTokenResponse} from '../models/user'; export enum AuthActionTypes { @@ -19,69 +19,85 @@ export enum AuthActionTypes { export class Login implements Action { readonly type = AuthActionTypes.Login; - constructor(public payload: Authenticate) {} + constructor(public payload: Authenticate) { + } } export class LoginSuccess implements Action { readonly type = AuthActionTypes.LoginSuccess; - constructor(public payload: UserTokenResponse ) {} + constructor(public payload: UserTokenResponse) { + } } export class LoginFailure implements Action { readonly type = AuthActionTypes.LoginFailure; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class GetUserInfo implements Action { readonly type = AuthActionTypes.GetUserInfo; - constructor (public sync: boolean = false) {} + + constructor(public sync: boolean = false) { + } } export class GetUserInfoSuccess implements Action { readonly type = AuthActionTypes.GetUserInfoSuccess; - constructor(public payload: User) {} + + constructor(public payload: User) { + } } export class GetUserInfoFailure implements Action { readonly type = AuthActionTypes.GetUserInfoFailure; - constructor(public payload: any) {} + + constructor(public payload: any) { + } } export class LoginRedirect implements Action { readonly type = AuthActionTypes.LoginRedirect; - constructor(public payload: any) {} + + constructor(public payload: any) { + } } export class Logout implements Action { readonly type = AuthActionTypes.Logout; - constructor (public sync: boolean = false) {} + constructor(public sync: boolean = false) { + } } export class LogoutSuccess implements Action { readonly type = AuthActionTypes.LogoutSuccess; - constructor (public sync: boolean = false) {} + constructor(public sync: boolean = false) { + } } export class LogoutFailure implements Action { readonly type = AuthActionTypes.LogoutFailure; - constructor (public sync: boolean = false, public error: any) {} + constructor(public sync: boolean = false, public error: any) { + } } export class RefreshToken implements Action { readonly type = AuthActionTypes.RefreshToken; - constructor (public silent: boolean = false) {} + constructor(public silent: boolean = false) { + } } export class RefreshTokenFailure implements Action { readonly type = AuthActionTypes.RefreshTokenFailure; - constructor (public payload: any) {} + constructor(public payload: any) { + } } export type AuthActions = diff --git a/src/app/auth/auth.module.ts b/src/app/auth/auth.module.ts index 58d1225..71b8533 100644 --- a/src/app/auth/auth.module.ts +++ b/src/app/auth/auth.module.ts @@ -52,4 +52,5 @@ export class AuthModule { EffectsModule.forFeature([AuthEffects]), ], }) -export class RootAuthModule {} +export class RootAuthModule { +} diff --git a/src/app/auth/components/login-form.component.spec.ts b/src/app/auth/components/login-form.component.spec.ts index 97a479d..b633ee7 100644 --- a/src/app/auth/components/login-form.component.spec.ts +++ b/src/app/auth/components/login-form.component.spec.ts @@ -1,10 +1,10 @@ -import { TestBed, ComponentFixture } from '@angular/core/testing'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { StoreModule, Store, combineReducers } from '@ngrx/store'; -import { LoginFormComponent } from './login-form.component'; +import {TestBed, ComponentFixture} from '@angular/core/testing'; +import {NO_ERRORS_SCHEMA} from '@angular/core'; +import {StoreModule, Store, combineReducers} from '@ngrx/store'; +import {LoginFormComponent} from './login-form.component'; import * as Auth from '../actions/auth'; import * as fromAuth from '../reducers'; -import { ReactiveFormsModule } from '@angular/forms'; +import {ReactiveFormsModule} from '@angular/forms'; describe('Login Page', () => { let fixture: ComponentFixture; diff --git a/src/app/auth/components/login-form.component.ts b/src/app/auth/components/login-form.component.ts index 4091580..7bc4ae8 100644 --- a/src/app/auth/components/login-form.component.ts +++ b/src/app/auth/components/login-form.component.ts @@ -1,6 +1,6 @@ -import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; -import { FormGroup, FormControl } from '@angular/forms'; -import { Authenticate } from '../models/user'; +import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'; +import {FormGroup, FormControl} from '@angular/forms'; +import {Authenticate} from '../models/user'; @Component({ selector: 'ndfsm-login-form', @@ -86,9 +86,11 @@ export class LoginFormComponent implements OnInit { password: new FormControl(''), }); - constructor() {} + constructor() { + } - ngOnInit() {} + ngOnInit() { + } submit() { if (this.form.valid) { diff --git a/src/app/auth/containers/login-page.component.spec.ts b/src/app/auth/containers/login-page.component.spec.ts index 8c022fa..6442846 100644 --- a/src/app/auth/containers/login-page.component.spec.ts +++ b/src/app/auth/containers/login-page.component.spec.ts @@ -1,11 +1,11 @@ -import { TestBed, ComponentFixture } from '@angular/core/testing'; -import { MatCardModule } from '@angular/material/card'; -import { MatInputModule } from '@angular/material/input'; -import { ReactiveFormsModule } from '@angular/forms'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { StoreModule, Store, combineReducers } from '@ngrx/store'; -import { LoginPageComponent } from './login-page.component'; -import { LoginFormComponent } from '../components/login-form.component'; +import {TestBed, ComponentFixture} from '@angular/core/testing'; +import {MatCardModule} from '@angular/material/card'; +import {MatInputModule} from '@angular/material/input'; +import {ReactiveFormsModule} from '@angular/forms'; +import {NoopAnimationsModule} from '@angular/platform-browser/animations'; +import {StoreModule, Store, combineReducers} from '@ngrx/store'; +import {LoginPageComponent} from './login-page.component'; +import {LoginFormComponent} from '../components/login-form.component'; import * as Auth from '../actions/auth'; import * as fromAuth from '../reducers'; diff --git a/src/app/auth/containers/login-page.component.ts b/src/app/auth/containers/login-page.component.ts index f77590d..1ea79c7 100644 --- a/src/app/auth/containers/login-page.component.ts +++ b/src/app/auth/containers/login-page.component.ts @@ -1,6 +1,6 @@ -import { Component, OnInit } from '@angular/core'; -import { Store, select } from '@ngrx/store'; -import { Authenticate } from '../models/user'; +import {Component, OnInit} from '@angular/core'; +import {Store, select} from '@ngrx/store'; +import {Authenticate} from '../models/user'; import * as fromAuth from '../reducers'; import * as Auth from '../actions/auth'; @@ -18,9 +18,11 @@ export class LoginPageComponent implements OnInit { pending$ = this.store.pipe(select(fromAuth.getLoginPagePending)); error$ = this.store.pipe(select(fromAuth.getLoginPageError)); - constructor(private store: Store) {} + constructor(private store: Store) { + } - ngOnInit() {} + ngOnInit() { + } onSubmit($event: Authenticate) { this.store.dispatch(new Auth.Login($event)); diff --git a/src/app/auth/effects/auth.effects.spec.ts b/src/app/auth/effects/auth.effects.spec.ts index 2e565d7..bfb406f 100644 --- a/src/app/auth/effects/auth.effects.spec.ts +++ b/src/app/auth/effects/auth.effects.spec.ts @@ -1,12 +1,12 @@ -import { TestBed } from '@angular/core/testing'; -import { Actions } from '@ngrx/effects'; -import { cold, hot } from 'jasmine-marbles'; -import { Observable } from 'rxjs/Observable'; -import { empty } from 'rxjs/observable/empty'; -import { Router } from '@angular/router'; - -import { AuthEffects } from './auth.effects'; -import { AuthService } from '../services/auth.service'; +import {TestBed} from '@angular/core/testing'; +import {Actions} from '@ngrx/effects'; +import {cold, hot} from 'jasmine-marbles'; +import {Observable} from 'rxjs/Observable'; +import {empty} from 'rxjs/observable/empty'; +import {Router} from '@angular/router'; + +import {AuthEffects} from './auth.effects'; +import {AuthService} from '../services/auth.service'; import { Login, LoginFailure, @@ -14,7 +14,7 @@ import { LoginSuccess, Logout, } from '../actions/auth'; -import { Authenticate, User } from '../models/user'; +import {Authenticate, User} from '../models/user'; export class TestActions extends Actions { constructor() { @@ -42,7 +42,7 @@ describe('AuthEffects', () => { AuthEffects, { provide: AuthService, - useValue: { login: jest.fn() }, + useValue: {login: jest.fn()}, }, { provide: Actions, @@ -50,7 +50,7 @@ describe('AuthEffects', () => { }, { provide: Router, - useValue: { navigate: jest.fn() }, + useValue: {navigate: jest.fn()}, }, ], }); @@ -65,28 +65,28 @@ describe('AuthEffects', () => { describe('login$', () => { it('should return an auth.LoginSuccess action, with user information if login succeeds', () => { - const credentials: Authenticate = { username: 'test', password: '' }; - const user = { name: 'User' } as User; + const credentials: Authenticate = {username: 'test', password: ''}; + const user = {name: 'User'} as User; const action = new Login(credentials); - const completion = new LoginSuccess({ user }); + const completion = new LoginSuccess({user}); - actions$.stream = hot('-a---', { a: action }); - const response = cold('-a|', { a: user }); - const expected = cold('--b', { b: completion }); + actions$.stream = hot('-a---', {a: action}); + const response = cold('-a|', {a: user}); + const expected = cold('--b', {b: completion}); authService.login = jest.fn(() => response); expect(effects.login$).toBeObservable(expected); }); it('should return a new auth.LoginFailure if the login service throws', () => { - const credentials: Authenticate = { username: 'someOne', password: '' }; + const credentials: Authenticate = {username: 'someOne', password: ''}; const action = new Login(credentials); const completion = new LoginFailure('Invalid username or password'); const error = 'Invalid username or password'; - actions$.stream = hot('-a---', { a: action }); + actions$.stream = hot('-a---', {a: action}); const response = cold('-#|', {}, error); - const expected = cold('--b', { b: completion }); + const expected = cold('--b', {b: completion}); authService.login = jest.fn(() => response); expect(effects.login$).toBeObservable(expected); @@ -95,10 +95,10 @@ describe('AuthEffects', () => { describe('loginSuccess$', () => { it('should dispatch a RouterNavigation action', () => { - const user = { name: 'User' } as User; - const action = new LoginSuccess({ user }); + const user = {name: 'User'} as User; + const action = new LoginSuccess({user}); - actions$.stream = hot('-a---', { a: action }); + actions$.stream = hot('-a---', {a: action}); effects.loginSuccess$.subscribe(() => { expect(routerService.navigate).toHaveBeenCalledWith(['/']); @@ -110,7 +110,7 @@ describe('AuthEffects', () => { it('should dispatch a RouterNavigation action when auth.LoginRedirect is dispatched', () => { const action = new LoginRedirect(); - actions$.stream = hot('-a---', { a: action }); + actions$.stream = hot('-a---', {a: action}); effects.loginRedirect$.subscribe(() => { expect(routerService.navigate).toHaveBeenCalledWith(['/login']); @@ -120,7 +120,7 @@ describe('AuthEffects', () => { it('should dispatch a RouterNavigation action when auth.Logout is dispatched', () => { const action = new Logout(); - actions$.stream = hot('-a---', { a: action }); + actions$.stream = hot('-a---', {a: action}); effects.loginRedirect$.subscribe(() => { expect(routerService.navigate).toHaveBeenCalledWith(['/login']); diff --git a/src/app/auth/effects/auth.effects.ts b/src/app/auth/effects/auth.effects.ts index f58847d..35c133d 100644 --- a/src/app/auth/effects/auth.effects.ts +++ b/src/app/auth/effects/auth.effects.ts @@ -1,6 +1,6 @@ -import { Injectable } from '@angular/core' -import { Router } from '@angular/router' -import { Actions, createEffect, ofType } from '@ngrx/effects' +import {Injectable} from '@angular/core'; +import {Router} from '@angular/router'; +import {Actions, createEffect, ofType} from '@ngrx/effects'; import { catchError, exhaustMap, @@ -9,9 +9,9 @@ import { switchMap, takeUntil, tap, -} from 'rxjs/operators' +} from 'rxjs/operators'; -import { AuthService } from '../services/auth.service' +import {AuthService} from '../services/auth.service'; import { AuthActionTypes, GetUserInfo, @@ -25,13 +25,13 @@ import { LogoutSuccess, RefreshToken, RefreshTokenFailure, -} from '../actions/auth' -import { Authenticate } from '../models/user' -import { fromEvent, of, timer } from 'rxjs' +} from '../actions/auth'; +import {Authenticate} from '../models/user'; +import {fromEvent, of, timer} from 'rxjs'; @Injectable() export class AuthEffects { - + login$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.Login), map((action: Login) => action.payload), @@ -41,43 +41,42 @@ export class AuthEffects { catchError(error => of(new LoginFailure(error))), ), ), - )) + )); + - loginSuccess$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.LoginSuccess), tap((login: LoginSuccess) => { - this.authService.setToken(login.payload.token) - localStorage.setItem('login', Date.now().toString()) + this.authService.setToken(login.payload.token); + localStorage.setItem('login', Date.now().toString()); // TODO redirect only from login page // this.router.navigate(['/']) }), map(() => new GetUserInfo()), - )) + )); + - autoRefreshToken$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.LoginSuccess), switchMap((login: LoginSuccess) => { // TODO vs parse token // JSON.parse(atob(decodeURIComponent(login.payload.token.split('.')[1]))) - return timer(login.payload.expiresIn * 1000). - pipe( - takeUntil(this.actions$.pipe(ofType(AuthActionTypes.Logout))), - map(() => new RefreshToken()), - ) + return timer(login.payload.expiresIn * 1000).pipe( + takeUntil(this.actions$.pipe(ofType(AuthActionTypes.Logout))), + map(() => new RefreshToken()), + ); }), - )) + )); + - loginRedirect$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.LoginRedirect), tap(() => { - this.router.navigate(['/login']) + this.router.navigate(['/login']); }), - ), { dispatch: false }) + ), {dispatch: false}); + - logout$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.Logout), exhaustMap((sync) => @@ -86,21 +85,21 @@ export class AuthEffects { catchError(error => of(new LogoutFailure(sync, error))), ), ), - )) + )); + - logoutDone$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.LogoutSuccess, AuthActionTypes.LogoutFailure), tap(sync => { - this.authService.setToken(null) + this.authService.setToken(null); if (sync) { - return + return; } - localStorage.setItem('logout', Date.now().toString()) + localStorage.setItem('logout', Date.now().toString()); }), - ), { dispatch: false }) + ), {dispatch: false}); + - loginGetStatus$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.GetUserInfo), exhaustMap(() => @@ -109,8 +108,8 @@ export class AuthEffects { catchError(error => of(new GetUserInfoFailure(error))), ), ), - )) - + )); + refreshToken$ = createEffect(() => this.actions$.pipe( ofType(AuthActionTypes.RefreshToken), exhaustMap(() => @@ -119,25 +118,26 @@ export class AuthEffects { catchError(error => of(new RefreshTokenFailure(error))), ), ), - )) + )); // Todo tbd - + logoutSync$ = createEffect(() => fromEvent(window, 'storage').pipe( filter((event: StorageEvent) => event.key === 'logout'), map(() => new Logout(true)), - )) + )); // Todo tbd - + loginSync$ = createEffect(() => fromEvent(window, 'storage').pipe( filter((event: StorageEvent) => event.key === 'login'), map(() => new GetUserInfo(true)), - )) + )); - constructor ( + constructor( private actions$: Actions, private authService: AuthService, private router: Router, - ) {} + ) { + } } diff --git a/src/app/auth/reducers/auth.spec.ts b/src/app/auth/reducers/auth.spec.ts index 15a38c3..5872c48 100644 --- a/src/app/auth/reducers/auth.spec.ts +++ b/src/app/auth/reducers/auth.spec.ts @@ -1,7 +1,7 @@ -import { reducer } from './auth'; +import {reducer} from './auth'; import * as fromAuth from './auth'; -import { Login, LoginSuccess, Logout } from '../actions/auth'; -import { Authenticate, User } from '../models/user'; +import {Login, LoginSuccess, Logout} from '../actions/auth'; +import {Authenticate, User} from '../models/user'; describe('AuthReducer', () => { describe('undefined action', () => { @@ -23,7 +23,7 @@ describe('AuthReducer', () => { describe('wrong login payload', () => { it('should NOT authenticate a user', () => { - const user = { username: 'someUserName' } as Authenticate; + const user = {username: 'someUserName'} as Authenticate; const createAction = new Login(user); const expectedResult = fromAuth.initialState; @@ -36,12 +36,12 @@ describe('AuthReducer', () => { describe('LOGIN_SUCCESS', () => { it('should add a user set loggedIn to true in auth state', () => { - const user = { name: 'test' } as User; - const createAction = new LoginSuccess({ user }); + const user = {name: 'test'} as User; + const createAction = new LoginSuccess({user}); const expectedResult = { loggedIn: true, - user: { name: 'test' }, + user: {name: 'test'}, }; const result = reducer(fromAuth.initialState, createAction); @@ -54,7 +54,7 @@ describe('AuthReducer', () => { it('should logout a user', () => { const initialState = { loggedIn: true, - user: { name: 'test' }, + user: {name: 'test'}, } as fromAuth.State; const createAction = new Logout(); diff --git a/src/app/auth/reducers/auth.ts b/src/app/auth/reducers/auth.ts index deb22a8..75de676 100644 --- a/src/app/auth/reducers/auth.ts +++ b/src/app/auth/reducers/auth.ts @@ -1,5 +1,5 @@ -import { AuthActions, AuthActionTypes } from './../actions/auth'; -import { User } from '../models/user'; +import {AuthActions, AuthActionTypes} from './../actions/auth'; +import {User} from '../models/user'; export interface State { loggedIn: boolean; @@ -18,7 +18,7 @@ export function reducer(state = initialState, action: AuthActions): State { ...state, loggedIn: true, user: action.payload - } + }; } case AuthActionTypes.LoginSuccess: { return { diff --git a/src/app/auth/reducers/index.ts b/src/app/auth/reducers/index.ts index 39d24d1..b8e13f7 100644 --- a/src/app/auth/reducers/index.ts +++ b/src/app/auth/reducers/index.ts @@ -1,4 +1,4 @@ -import { createSelector, createFeatureSelector } from '@ngrx/store'; +import {createSelector, createFeatureSelector} from '@ngrx/store'; import * as fromRoot from '@app/reducers'; import * as fromAuth from './auth'; import * as fromLoginPage from './login-page'; diff --git a/src/app/auth/reducers/login-page.spec.ts b/src/app/auth/reducers/login-page.spec.ts index c4086c6..9affb71 100644 --- a/src/app/auth/reducers/login-page.spec.ts +++ b/src/app/auth/reducers/login-page.spec.ts @@ -1,7 +1,7 @@ -import { reducer } from './login-page'; +import {reducer} from './login-page'; import * as fromLoginPage from './login-page'; -import { Login, LoginSuccess, LoginFailure, Logout } from '../actions/auth'; -import { Authenticate, User } from '../models/user'; +import {Login, LoginSuccess, LoginFailure, Logout} from '../actions/auth'; +import {Authenticate, User} from '../models/user'; describe('LoginPageReducer', () => { describe('undefined action', () => { @@ -16,7 +16,7 @@ describe('LoginPageReducer', () => { describe('LOGIN', () => { it('should make pending to true', () => { - const user = { username: 'test' } as Authenticate; + const user = {username: 'test'} as Authenticate; const createAction = new Login(user); const expectedResult = { @@ -32,8 +32,8 @@ describe('LoginPageReducer', () => { describe('LOGIN_SUCCESS', () => { it('should have no error and no pending state', () => { - const user = { name: 'test' } as User; - const createAction = new LoginSuccess({ user }); + const user = {name: 'test'} as User; + const createAction = new LoginSuccess({user}); const expectedResult = { error: null, diff --git a/src/app/auth/reducers/login-page.ts b/src/app/auth/reducers/login-page.ts index 8a4b2f7..07ba64d 100644 --- a/src/app/auth/reducers/login-page.ts +++ b/src/app/auth/reducers/login-page.ts @@ -1,4 +1,4 @@ -import { AuthActionTypes, AuthActions } from './../actions/auth'; +import {AuthActionTypes, AuthActions} from './../actions/auth'; export interface State { error: string | null; diff --git a/src/app/auth/services/auth-guard.service.spec.ts b/src/app/auth/services/auth-guard.service.spec.ts index dcc3a41..2ab0c2a 100644 --- a/src/app/auth/services/auth-guard.service.spec.ts +++ b/src/app/auth/services/auth-guard.service.spec.ts @@ -1,7 +1,7 @@ -import { TestBed, inject } from '@angular/core/testing'; -import { StoreModule, Store, combineReducers } from '@ngrx/store'; -import { cold } from 'jasmine-marbles'; -import { AuthGuard } from './auth-guard.service'; +import {TestBed, inject} from '@angular/core/testing'; +import {StoreModule, Store, combineReducers} from '@ngrx/store'; +import {cold} from 'jasmine-marbles'; +import {AuthGuard} from './auth-guard.service'; import * as Auth from '../actions/auth'; import * as fromRoot from '../../reducers'; import * as fromAuth from '../reducers'; @@ -27,17 +27,17 @@ describe('Auth Guard', () => { }); it('should return false if the user state is not logged in', () => { - const expected = cold('(a|)', { a: false }); + const expected = cold('(a|)', {a: false}); expect(guard.canActivate()).toBeObservable(expected); }); it('should return true if the user state is logged in', () => { const user: any = {}; - const action = new Auth.LoginSuccess({ user }); + const action = new Auth.LoginSuccess({user}); store.dispatch(action); - const expected = cold('(a|)', { a: true }); + const expected = cold('(a|)', {a: true}); expect(guard.canActivate()).toBeObservable(expected); }); diff --git a/src/app/auth/services/auth-guard.service.ts b/src/app/auth/services/auth-guard.service.ts index 3542262..afa4ee3 100644 --- a/src/app/auth/services/auth-guard.service.ts +++ b/src/app/auth/services/auth-guard.service.ts @@ -1,18 +1,19 @@ -import { Injectable } from '@angular/core'; +import {Injectable} from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, -} from '@angular/router' -import { Store, select } from '@ngrx/store'; -import { map, take } from 'rxjs/operators'; +} from '@angular/router'; +import {Store, select} from '@ngrx/store'; +import {map, take} from 'rxjs/operators'; import * as Auth from '../actions/auth'; import * as fromAuth from '../reducers'; import {Observable} from 'rxjs'; @Injectable() export class AuthGuard implements CanActivate { - constructor(private store: Store) {} + constructor(private store: Store) { + } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { return this.store.pipe( diff --git a/src/app/auth/services/auth.service.ts b/src/app/auth/services/auth.service.ts index d0f1a45..8fbb2ec 100644 --- a/src/app/auth/services/auth.service.ts +++ b/src/app/auth/services/auth.service.ts @@ -1,57 +1,58 @@ -import { Injectable } from '@angular/core' -import { Authenticate, User, UserTokenResponse } from '../models/user' -import { Observable } from 'rxjs' -import { HttpClient } from '@angular/common/http' -import { environment } from '@env' -import { tap } from 'rxjs/operators' -import { LoggerService } from '@app/core/logger.service' +import {Injectable} from '@angular/core'; +import {Authenticate, User, UserTokenResponse} from '../models/user'; +import {Observable} from 'rxjs'; +import {HttpClient} from '@angular/common/http'; +import {environment} from '@env'; +import {tap} from 'rxjs/operators'; +import {LoggerService} from '@app/core/logger.service'; @Injectable() export class AuthService { - private baseUrl = environment.apiServers.auth + private baseUrl = environment.apiServers.auth; - private token: string = null + private token: string = null; - constructor (private httpClient: HttpClient, private logger: LoggerService) {} + constructor(private httpClient: HttpClient, private logger: LoggerService) { + } - login ({ username, password }: Authenticate): Observable { + login({username, password}: Authenticate): Observable { return this.httpClient.post(this.baseUrl + '/token', - { username, password }, - { withCredentials: true }).pipe( + {username, password}, + {withCredentials: true}).pipe( tap((next: UserTokenResponse) => this.log(`login...`)), - ) + ); } - refreshToken () { + refreshToken() { return this.httpClient.post(this.baseUrl + '/refresh-token', {}, - { withCredentials: true }).pipe( + {withCredentials: true}).pipe( tap((next: UserTokenResponse) => this.log(`refreshToken...`)) - ) + ); } - logout () { + logout() { return this.httpClient.post(this.baseUrl + '/logout', {}, - { withCredentials: true }).pipe( + {withCredentials: true}).pipe( tap(() => this.log(`logout...`)) - ) + ); } - setToken (token) { - this.token = token + setToken(token) { + this.token = token; } - getToken (): string { - return this.token + getToken(): string { + return this.token; } - me (): Observable { + me(): Observable { return this.httpClient.get(this.baseUrl + '/info', {}).pipe( tap((next: User) => this.log(`me...`)), - ) + ); } - private log (...args) { - this.logger.log('[AUTH SERVICE]', ...args) + private log(...args) { + this.logger.log('[AUTH SERVICE]', ...args); } } diff --git a/src/app/auth/services/error.interceptor.spec.ts b/src/app/auth/services/error.interceptor.spec.ts index cb83f5c..dec9e69 100644 --- a/src/app/auth/services/error.interceptor.spec.ts +++ b/src/app/auth/services/error.interceptor.spec.ts @@ -1,6 +1,6 @@ -import { TestBed } from '@angular/core/testing'; +import {TestBed} from '@angular/core/testing'; -import { ErrorInterceptor } from './error.interceptor'; +import {ErrorInterceptor} from './error.interceptor'; describe('ErrorService', () => { beforeEach(() => TestBed.configureTestingModule({})); diff --git a/src/app/auth/services/error.interceptor.ts b/src/app/auth/services/error.interceptor.ts index ee354b7..4c64724 100644 --- a/src/app/auth/services/error.interceptor.ts +++ b/src/app/auth/services/error.interceptor.ts @@ -5,7 +5,8 @@ import {catchError} from 'rxjs/operators'; @Injectable() export class ErrorInterceptor implements HttpInterceptor { - constructor(/*private authenticationService: AuthenticationService*/) {} + constructor(/*private authenticationService: AuthenticationService*/) { + } intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe(catchError(err => { diff --git a/src/app/auth/services/token.interceptor.spec.ts b/src/app/auth/services/token.interceptor.spec.ts index 9824334..772273c 100644 --- a/src/app/auth/services/token.interceptor.spec.ts +++ b/src/app/auth/services/token.interceptor.spec.ts @@ -1,6 +1,6 @@ -import { TestBed } from '@angular/core/testing'; +import {TestBed} from '@angular/core/testing'; -import { TokenInterceptor } from './token.interceptor'; +import {TokenInterceptor} from './token.interceptor'; describe('TokenService', () => { beforeEach(() => TestBed.configureTestingModule({})); diff --git a/src/app/auth/services/token.interceptor.ts b/src/app/auth/services/token.interceptor.ts index 728c8d6..e11bf0a 100644 --- a/src/app/auth/services/token.interceptor.ts +++ b/src/app/auth/services/token.interceptor.ts @@ -8,7 +8,9 @@ import {Observable} from 'rxjs'; }) export class TokenInterceptor implements HttpInterceptor { private authService: AuthService; - constructor(private injector: Injector) {} + + constructor(private injector: Injector) { + } intercept(request: HttpRequest, next: HttpHandler): Observable> { this.authService = this.injector.get(AuthService); diff --git a/src/app/core/actions/layout.ts b/src/app/core/actions/layout.ts index aa0d2e2..b4efb7b 100644 --- a/src/app/core/actions/layout.ts +++ b/src/app/core/actions/layout.ts @@ -1,4 +1,4 @@ -import { Action } from '@ngrx/store'; +import {Action} from '@ngrx/store'; export enum LayoutActionTypes { OpenSidenav = '[Layout] Open Sidenav', diff --git a/src/app/core/api.service.ts b/src/app/core/api.service.ts index 2b3a7ff..075ff5d 100644 --- a/src/app/core/api.service.ts +++ b/src/app/core/api.service.ts @@ -1,8 +1,9 @@ -import { Injectable } from '@angular/core'; +import {Injectable} from '@angular/core'; @Injectable() export class ApiService { - constructor() { } + constructor() { + } } diff --git a/src/app/core/containers/not-found-page.ts b/src/app/core/containers/not-found-page.ts index 551c5ac..ba00428 100644 --- a/src/app/core/containers/not-found-page.ts +++ b/src/app/core/containers/not-found-page.ts @@ -1,4 +1,4 @@ -import { Component, ChangeDetectionStrategy } from '@angular/core'; +import {Component, ChangeDetectionStrategy} from '@angular/core'; @Component({ selector: 'ndfsm-not-found-page', @@ -22,4 +22,5 @@ import { Component, ChangeDetectionStrategy } from '@angular/core'; `, ], }) -export class NotFoundPageComponent {} +export class NotFoundPageComponent { +} diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index f30b2eb..49b6798 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -3,12 +3,12 @@ import { NgModule, Optional, SkipSelf, -} from '@angular/core' -import { CommonModule } from '@angular/common' -import { LocalStorageService } from './local-storage/local-storage.service' -import { NotFoundPageComponent } from './containers/not-found-page' -import { SharedModule } from '@app/shared' -import { LoggerService } from '@app/core/logger.service' +} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {LocalStorageService} from './local-storage/local-storage.service'; +import {NotFoundPageComponent} from './containers/not-found-page'; +import {SharedModule} from '@app/shared'; +import {LoggerService} from '@app/core/logger.service'; @NgModule({ imports: [ @@ -21,17 +21,17 @@ import { LoggerService } from '@app/core/logger.service' export class CoreModule { /* make sure CoreModule is imported only by one NgModule the AppModule */ - constructor ( + constructor( @Optional() @SkipSelf() parentModule: CoreModule) { if (parentModule) { - throw new Error('CoreModule is already loaded. Import only in AppModule') + throw new Error('CoreModule is already loaded. Import only in AppModule'); } } - static forRoot (): ModuleWithProviders { + static forRoot(): ModuleWithProviders { return { ngModule: CoreModule, providers: [LocalStorageService, LoggerService], - } + }; } } diff --git a/src/app/core/local-storage/local-storage.service.spec.ts b/src/app/core/local-storage/local-storage.service.spec.ts index e9dfb48..d1ab76b 100644 --- a/src/app/core/local-storage/local-storage.service.spec.ts +++ b/src/app/core/local-storage/local-storage.service.spec.ts @@ -1,6 +1,6 @@ -import { TestBed, inject } from '@angular/core/testing'; +import {TestBed, inject} from '@angular/core/testing'; -import { LocalStorageService } from './local-storage.service'; +import {LocalStorageService} from './local-storage.service'; describe('LocalStorageService', () => { beforeEach(() => { diff --git a/src/app/core/local-storage/local-storage.service.ts b/src/app/core/local-storage/local-storage.service.ts index e4fe596..cc413fb 100644 --- a/src/app/core/local-storage/local-storage.service.ts +++ b/src/app/core/local-storage/local-storage.service.ts @@ -1,8 +1,8 @@ -import { Injectable } from '@angular/core'; +import {Injectable} from '@angular/core'; const APP_PREFIX = 'NDFSM-'; -@Injectable({ providedIn: 'root'}) +@Injectable({providedIn: 'root'}) export class LocalStorageService { static loadInitialState() { @@ -24,7 +24,8 @@ export class LocalStorageService { }, undefined); } - constructor() {} + constructor() { + } setItem(key: string, value: any) { localStorage.setItem(`${APP_PREFIX}${key}`, JSON.stringify(value)); diff --git a/src/app/core/logger.service.ts b/src/app/core/logger.service.ts index 7b40f2a..3044294 100644 --- a/src/app/core/logger.service.ts +++ b/src/app/core/logger.service.ts @@ -1,14 +1,15 @@ -import { Injectable } from '@angular/core'; -import { environment } from '@env' +import {Injectable} from '@angular/core'; +import {environment} from '@env'; @Injectable({providedIn: 'root'}) export class LoggerService { - constructor() { } + constructor() { + } log(...args) { if (environment.log) { - console.log(...args) + console.log(...args); } } } diff --git a/src/app/core/reducers/layout.ts b/src/app/core/reducers/layout.ts index 1ee1929..1d50f73 100644 --- a/src/app/core/reducers/layout.ts +++ b/src/app/core/reducers/layout.ts @@ -1,4 +1,4 @@ -import { LayoutActionTypes, LayoutActions } from '../actions/layout'; +import {LayoutActionTypes, LayoutActions} from '../actions/layout'; export interface State { showSidenav: boolean; diff --git a/src/app/debug/debug.component.spec.ts b/src/app/debug/debug.component.spec.ts index 3edaf2b..ae55484 100644 --- a/src/app/debug/debug.component.spec.ts +++ b/src/app/debug/debug.component.spec.ts @@ -1,6 +1,6 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; -import { DebugComponent } from './debug.component'; +import {DebugComponent} from './debug.component'; describe('DebugComponent', () => { let component: DebugComponent; @@ -8,9 +8,9 @@ describe('DebugComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ DebugComponent ] + declarations: [DebugComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/debug/debug.component.ts b/src/app/debug/debug.component.ts index 4822b78..2b10665 100644 --- a/src/app/debug/debug.component.ts +++ b/src/app/debug/debug.component.ts @@ -1,6 +1,6 @@ import {ChangeDetectionStrategy, ChangeDetectorRef, Component, HostListener, OnInit} from '@angular/core'; import {DebugService} from './debug.service'; -import { environment } from '@env'; +import {environment} from '@env'; @Component({ selector: 'ndfsm-debug', @@ -16,7 +16,9 @@ export class DebugComponent implements OnInit { isEnabled = DebugService.isDebug() && !environment.production; open = false; - constructor(private _debugService: DebugService, private _changeDetectorRef: ChangeDetectorRef) { } + constructor(private _debugService: DebugService, private _changeDetectorRef: ChangeDetectorRef) { + } + // // @HostListener('document:keypress', ['$event']) // handleKeyboardEvent(event: KeyboardEvent) { @@ -34,7 +36,7 @@ export class DebugComponent implements OnInit { ngOnInit() { setInterval(() => { - this.open = !!(window).debugDialogOpen; + this.open = !!( window).debugDialogOpen; }, 500); setInterval(() => { @@ -65,7 +67,7 @@ export class DebugComponent implements OnInit { close() { this.open = false; - (window).debugDialogOpen = false; + ( window).debugDialogOpen = false; } } diff --git a/src/app/debug/debug.decorator.ts b/src/app/debug/debug.decorator.ts index 179460c..62df27e 100644 --- a/src/app/debug/debug.decorator.ts +++ b/src/app/debug/debug.decorator.ts @@ -16,7 +16,7 @@ export function DebugDecorator(/*options*/) { const ngOnInitOriginal = constructor.prototype['ngOnInit']; // noinspection TsLint - constructor.prototype['ngOnInit'] = function (...args) { + constructor.prototype['ngOnInit'] = function(...args) { DebugService.instance.incCountOfComponents(component); console.log(`%c ${component} - ngOnInit`, `color: #4CAF50; font-weight: bold`, ...args); ngOnInitOriginal && ngOnInitOriginal.apply(this, args); // tslint:disable-line:no-unused-expression @@ -24,7 +24,7 @@ export function DebugDecorator(/*options*/) { const ngOnChangesOriginal = constructor.prototype['ngOnChanges']; // noinspection TsLint - constructor.prototype['ngOnChanges'] = function (changes) { + constructor.prototype['ngOnChanges'] = function(changes) { // if (this.__prevChanges !== JSON.stringify(changes)) { // console.log(component, 'prev >>>', this.__prevChanges, 'new >>>', JSON.stringify(changes)); // this.__prevChanges = JSON.stringify(changes); diff --git a/src/app/debug/debug.module.ts b/src/app/debug/debug.module.ts index e58653a..1e45d02 100644 --- a/src/app/debug/debug.module.ts +++ b/src/app/debug/debug.module.ts @@ -1,6 +1,6 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { DebugComponent } from './debug.component'; +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {DebugComponent} from './debug.component'; import {DebugService} from './debug.service'; @NgModule({ @@ -11,4 +11,5 @@ import {DebugService} from './debug.service'; providers: [DebugService], exports: [DebugComponent] }) -export class DebugModule { } +export class DebugModule { +} diff --git a/src/app/debug/debug.service.ts b/src/app/debug/debug.service.ts index eba2410..898f0b2 100644 --- a/src/app/debug/debug.service.ts +++ b/src/app/debug/debug.service.ts @@ -16,7 +16,8 @@ export class DebugService { return isDebug; } - constructor() {} + constructor() { + } reset() { this._countChanges = new Map(); diff --git a/src/app/finance-stats/actions/card.actions.ts b/src/app/finance-stats/actions/card.actions.ts index e64687c..43fb790 100644 --- a/src/app/finance-stats/actions/card.actions.ts +++ b/src/app/finance-stats/actions/card.actions.ts @@ -1,6 +1,6 @@ -import { Action } from '@ngrx/store' -import { ICard } from '../models/card' -import { Update } from '@ngrx/entity' +import {Action} from '@ngrx/store'; +import {ICard} from '../models/card'; +import {Update} from '@ngrx/entity'; export enum CardActionsType { Load = '[FINANCE STATS - CARD] Load', @@ -22,68 +22,78 @@ export enum CardActionsType { } export class Load implements Action { - readonly type = CardActionsType.Load + readonly type = CardActionsType.Load; } export class LoadSuccess implements Action { - readonly type = CardActionsType.LoadSuccess + readonly type = CardActionsType.LoadSuccess; - constructor (public payload: ICard[]) {} + constructor(public payload: ICard[]) { + } } export class LoadFail implements Action { - readonly type = CardActionsType.LoadFail + readonly type = CardActionsType.LoadFail; - constructor (public error: string) {} + constructor(public error: string) { + } } export class Edit implements Action { - readonly type = CardActionsType.Edit + readonly type = CardActionsType.Edit; - constructor (public payload: ICard) {} + constructor(public payload: ICard) { + } } export class EditFail implements Action { - readonly type = CardActionsType.EditFail + readonly type = CardActionsType.EditFail; // todo error interface - constructor (public payload: any) {} + constructor(public payload: any) { + } } export class CreateSuccess implements Action { readonly type = CardActionsType.CreateSuccess; - constructor(public payload: ICard) {} + constructor(public payload: ICard) { + } } export class UpdateSuccess implements Action { readonly type = CardActionsType.UpdateSuccess; - constructor(public payload: Update) {} + constructor(public payload: Update) { + } } export class Remove implements Action { readonly type = CardActionsType.Remove; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveSuccess implements Action { readonly type = CardActionsType.RemoveSuccess; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveFail implements Action { readonly type = CardActionsType.RemoveFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class OpenEditDialog implements Action { readonly type = CardActionsType.OpenEditDialog; - constructor(public payload: ICard) {} + constructor(public payload: ICard) { + } } export class DismissEditDialog implements Action { @@ -93,7 +103,8 @@ export class DismissEditDialog implements Action { export class DetailsDialog implements Action { readonly type = CardActionsType.DetailsDialog; - constructor(public payload: ICard) {} + constructor(public payload: ICard) { + } } export type CardActions = diff --git a/src/app/finance-stats/actions/transaction-type.actions.ts b/src/app/finance-stats/actions/transaction-type.actions.ts index 82f2512..cc0d01b 100644 --- a/src/app/finance-stats/actions/transaction-type.actions.ts +++ b/src/app/finance-stats/actions/transaction-type.actions.ts @@ -1,6 +1,6 @@ -import { Action } from '@ngrx/store' -import { ITransactionType } from '../models/transaction-type' -import { Update } from '@ngrx/entity' +import {Action} from '@ngrx/store'; +import {ITransactionType} from '../models/transaction-type'; +import {Update} from '@ngrx/entity'; export enum TransactionTypeActionsType { Load = '[FINANCE STATS - TRANSACTION TYPE] Load', @@ -22,68 +22,78 @@ export enum TransactionTypeActionsType { } export class Load implements Action { - readonly type = TransactionTypeActionsType.Load + readonly type = TransactionTypeActionsType.Load; } export class LoadSuccess implements Action { - readonly type = TransactionTypeActionsType.LoadSuccess + readonly type = TransactionTypeActionsType.LoadSuccess; - constructor (public payload: ITransactionType[]) {} + constructor(public payload: ITransactionType[]) { + } } export class LoadFail implements Action { - readonly type = TransactionTypeActionsType.LoadFail + readonly type = TransactionTypeActionsType.LoadFail; - constructor (public error: string) {} + constructor(public error: string) { + } } export class Edit implements Action { - readonly type = TransactionTypeActionsType.Edit + readonly type = TransactionTypeActionsType.Edit; - constructor (public payload: ITransactionType) {} + constructor(public payload: ITransactionType) { + } } export class EditFail implements Action { - readonly type = TransactionTypeActionsType.EditFail + readonly type = TransactionTypeActionsType.EditFail; // todo error interface - constructor (public payload: any) {} + constructor(public payload: any) { + } } export class CreateSuccess implements Action { readonly type = TransactionTypeActionsType.CreateSuccess; - constructor(public payload: ITransactionType) {} + constructor(public payload: ITransactionType) { + } } export class UpdateSuccess implements Action { readonly type = TransactionTypeActionsType.UpdateSuccess; - constructor(public payload: Update) {} + constructor(public payload: Update) { + } } export class Remove implements Action { readonly type = TransactionTypeActionsType.Remove; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveSuccess implements Action { readonly type = TransactionTypeActionsType.RemoveSuccess; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveFail implements Action { readonly type = TransactionTypeActionsType.RemoveFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class OpenEditDialog implements Action { readonly type = TransactionTypeActionsType.OpenEditDialog; - constructor(public payload: ITransactionType) {} + constructor(public payload: ITransactionType) { + } } export class DismissEditDialog implements Action { @@ -93,7 +103,8 @@ export class DismissEditDialog implements Action { export class DetailsDialog implements Action { readonly type = TransactionTypeActionsType.DetailsDialog; - constructor(public payload: ITransactionType) {} + constructor(public payload: ITransactionType) { + } } export type TransactionTypeActions = diff --git a/src/app/finance-stats/actions/transactions.actions.ts b/src/app/finance-stats/actions/transactions.actions.ts index 2be5b4b..f75c687 100644 --- a/src/app/finance-stats/actions/transactions.actions.ts +++ b/src/app/finance-stats/actions/transactions.actions.ts @@ -1,6 +1,6 @@ -import { Action } from '@ngrx/store' -import { ITransaction } from '../models/transaction' -import { Update } from '@ngrx/entity' +import {Action} from '@ngrx/store'; +import {ITransaction} from '../models/transaction'; +import {Update} from '@ngrx/entity'; export enum TransactionActionsType { Load = '[FINANCE STATS - TRANSACTION] Load', @@ -22,68 +22,78 @@ export enum TransactionActionsType { } export class Load implements Action { - readonly type = TransactionActionsType.Load + readonly type = TransactionActionsType.Load; } export class LoadSuccess implements Action { - readonly type = TransactionActionsType.LoadSuccess + readonly type = TransactionActionsType.LoadSuccess; - constructor (public payload: ITransaction[]) {} + constructor(public payload: ITransaction[]) { + } } export class LoadFail implements Action { - readonly type = TransactionActionsType.LoadFail + readonly type = TransactionActionsType.LoadFail; - constructor (public error: string) {} + constructor(public error: string) { + } } export class Edit implements Action { - readonly type = TransactionActionsType.Edit + readonly type = TransactionActionsType.Edit; - constructor (public payload: ITransaction) {} + constructor(public payload: ITransaction) { + } } export class EditFail implements Action { - readonly type = TransactionActionsType.EditFail + readonly type = TransactionActionsType.EditFail; // todo error interface - constructor (public payload: any) {} + constructor(public payload: any) { + } } export class CreateSuccess implements Action { readonly type = TransactionActionsType.CreateSuccess; - constructor(public payload: ITransaction) {} + constructor(public payload: ITransaction) { + } } export class UpdateSuccess implements Action { readonly type = TransactionActionsType.UpdateSuccess; - constructor(public payload: Update) {} + constructor(public payload: Update) { + } } export class Remove implements Action { readonly type = TransactionActionsType.Remove; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveSuccess implements Action { readonly type = TransactionActionsType.RemoveSuccess; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveFail implements Action { readonly type = TransactionActionsType.RemoveFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class OpenEditDialog implements Action { readonly type = TransactionActionsType.OpenEditDialog; - constructor(public payload: ITransaction) {} + constructor(public payload: ITransaction) { + } } export class DismissEditDialog implements Action { @@ -93,7 +103,8 @@ export class DismissEditDialog implements Action { export class DetailsDialog implements Action { readonly type = TransactionActionsType.DetailsDialog; - constructor(public payload: ITransaction) {} + constructor(public payload: ITransaction) { + } } export type TransactionActions = diff --git a/src/app/finance-stats/components/edit-dialog/edit-dialog.component.html b/src/app/finance-stats/components/edit-dialog/edit-dialog.component.html index 7a760a1..21a91a0 100644 --- a/src/app/finance-stats/components/edit-dialog/edit-dialog.component.html +++ b/src/app/finance-stats/components/edit-dialog/edit-dialog.component.html @@ -28,7 +28,7 @@

{{isNew ? 'Create' : 'Edit'}}

should be datepicker - +
diff --git a/src/app/finance-stats/components/edit-dialog/edit-dialog.component.spec.ts b/src/app/finance-stats/components/edit-dialog/edit-dialog.component.spec.ts index b4b92ee..34f6ae0 100644 --- a/src/app/finance-stats/components/edit-dialog/edit-dialog.component.spec.ts +++ b/src/app/finance-stats/components/edit-dialog/edit-dialog.component.spec.ts @@ -1,6 +1,6 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; -import { EditDialogComponent } from './edit-dialog.component'; +import {EditDialogComponent} from './edit-dialog.component'; describe('EditDialogComponent', () => { let component: EditDialogComponent; @@ -8,9 +8,9 @@ describe('EditDialogComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ EditDialogComponent ] + declarations: [EditDialogComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/finance-stats/components/edit-dialog/edit-dialog.component.ts b/src/app/finance-stats/components/edit-dialog/edit-dialog.component.ts index df0f641..9eae32f 100644 --- a/src/app/finance-stats/components/edit-dialog/edit-dialog.component.ts +++ b/src/app/finance-stats/components/edit-dialog/edit-dialog.component.ts @@ -1,12 +1,12 @@ -import { Component, Inject } from '@angular/core' -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog' -import { FormControl, FormGroup, Validators } from '@angular/forms' -import { select, Store } from '@ngrx/store' -import { getAllCard } from '../../reducers/card.reducer' -import { getAllTransactionType } from '../../reducers/transaction-type.reducer' -import { ICard } from '../../models/card' -import { ITransactionType } from '../../models/transaction-type' -import { Observable } from 'rxjs' +import {Component, Inject} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; +import {FormControl, FormGroup, Validators} from '@angular/forms'; +import {select, Store} from '@ngrx/store'; +import {getAllCard} from '../../reducers/card.reducer'; +import {getAllTransactionType} from '../../reducers/transaction-type.reducer'; +import {ICard} from '../../models/card'; +import {ITransactionType} from '../../models/transaction-type'; +import {Observable} from 'rxjs'; @Component({ templateUrl: './edit-dialog.component.html', @@ -30,32 +30,32 @@ export class EditDialogComponent { // fixedAmount: new FormControl(0, []), // }), - }) + }); - isNew: boolean + isNew: boolean; - transactionTypes$: Observable - cards$: Observable + transactionTypes$: Observable; + cards$: Observable; - constructor ( + constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, private store: Store) { - this.isNew = !data.id + this.isNew = !data.id; - this.transactionTypes$ = this.store.pipe(select(getAllTransactionType)) - this.cards$ = this.store.pipe(select(getAllCard)) + this.transactionTypes$ = this.store.pipe(select(getAllTransactionType)); + this.cards$ = this.store.pipe(select(getAllCard)); } - onNoClick (): void { - this.dialogRef.close() + onNoClick(): void { + this.dialogRef.close(); } - submit () { + submit() { if (this.form.valid) { - const formValues = this.form.value + const formValues = this.form.value; // todo close after success - this.dialogRef.close({ ...this.data, ...formValues }) + this.dialogRef.close({...this.data, ...formValues}); } } } diff --git a/src/app/finance-stats/components/transaction-filter/transaction-filter.component.html b/src/app/finance-stats/components/transaction-filter/transaction-filter.component.html index e411759..a5612b4 100644 --- a/src/app/finance-stats/components/transaction-filter/transaction-filter.component.html +++ b/src/app/finance-stats/components/transaction-filter/transaction-filter.component.html @@ -1,4 +1,4 @@
Errors parsing template: Only void and foreign elements can be self closed "ndfsm-transaction-filter" (" -[ERROR ->] < ndfsm-transaction-filter \/\> + [ERROR ->] < ndfsm-transaction-filter \/\>
here some filters
diff --git a/src/app/finance-stats/components/transaction-filter/transaction-filter.component.ts b/src/app/finance-stats/components/transaction-filter/transaction-filter.component.ts index e1746fc..6a6a2d7 100644 --- a/src/app/finance-stats/components/transaction-filter/transaction-filter.component.ts +++ b/src/app/finance-stats/components/transaction-filter/transaction-filter.component.ts @@ -1,10 +1,11 @@ -import { Component } from '@angular/core' -import { trackByFn } from '@app/utils' +import {Component} from '@angular/core'; +import {trackByFn} from '@app/utils'; @Component({ selector: 'ndfsm-transaction-filter', templateUrl: './transaction-filter.component.html', }) export class TransactionFilterComponent { - constructor () {} + constructor() { + } } diff --git a/src/app/finance-stats/components/transaction-list/transaction-list.component.html b/src/app/finance-stats/components/transaction-list/transaction-list.component.html index 70be70a..9041f68 100644 --- a/src/app/finance-stats/components/transaction-list/transaction-list.component.html +++ b/src/app/finance-stats/components/transaction-list/transaction-list.component.html @@ -12,7 +12,9 @@

TODO should be table

Amount: {{transaction.amount}} {{transaction.currencyCode}}
Category: {{transaction.type.name}}
Note: {{transaction.note }}
-
Card: cash{{transaction.card.name}}
-
Info: noneBlocked: {{transaction.info.blockedAmount}}, Fixed: {{transaction.info.fixedAmount}}
+
Card: cash{{transaction.card.name}}
+
Info: noneBlocked: {{transaction.info.blockedAmount}}, Fixed: {{transaction.info.fixedAmount}} +
diff --git a/src/app/finance-stats/components/transaction-list/transaction-list.component.ts b/src/app/finance-stats/components/transaction-list/transaction-list.component.ts index 4238408..1f160cc 100644 --- a/src/app/finance-stats/components/transaction-list/transaction-list.component.ts +++ b/src/app/finance-stats/components/transaction-list/transaction-list.component.ts @@ -1,19 +1,20 @@ -import { Component, Input } from '@angular/core' -import { Store } from '@ngrx/store' -import { ITransaction } from '../../models/transaction' -import { trackByFn } from '@app/utils' +import {Component, Input} from '@angular/core'; +import {Store} from '@ngrx/store'; +import {ITransaction} from '../../models/transaction'; +import {trackByFn} from '@app/utils'; @Component({ selector: 'ndfsm-transaction-list', templateUrl: './transaction-list.component.html', }) export class TransactionListComponent { - trackByFn = trackByFn + trackByFn = trackByFn; - @Input() transactions: ITransaction[] = [] + @Input() transactions: ITransaction[] = []; - @Input() canEdit = false + @Input() canEdit = false; - constructor (public store: Store) {} + constructor(public store: Store) { + } } diff --git a/src/app/finance-stats/containers/dashboard/dashboard.component.ts b/src/app/finance-stats/containers/dashboard/dashboard.component.ts index 0137da6..1180004 100644 --- a/src/app/finance-stats/containers/dashboard/dashboard.component.ts +++ b/src/app/finance-stats/containers/dashboard/dashboard.component.ts @@ -1,5 +1,5 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' -import { TransactionService } from '@app/finance-stats/services/transaction.service' +import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; +import {TransactionService} from '@app/finance-stats/services/transaction.service'; @Component({ templateUrl: './dashboard.component.html', @@ -7,11 +7,12 @@ import { TransactionService } from '@app/finance-stats/services/transaction.serv }) export class DashboardComponent implements OnInit { - constructor(private service: TransactionService) { } + constructor(private service: TransactionService) { + } ngOnInit() { this.service.stats().subscribe(data => { - console.log('dashboard.component.ts::::13 >>>', data) - }) + console.log('dashboard.component.ts::::13 >>>', data); + }); } } diff --git a/src/app/finance-stats/containers/transaction-page/transaction-page.component.html b/src/app/finance-stats/containers/transaction-page/transaction-page.component.html index 35466e2..b3c29a2 100644 --- a/src/app/finance-stats/containers/transaction-page/transaction-page.component.html +++ b/src/app/finance-stats/containers/transaction-page/transaction-page.component.html @@ -2,7 +2,7 @@

Transactions

- +
@@ -13,7 +13,8 @@
- +
diff --git a/src/app/finance-stats/containers/transaction-page/transaction-page.component.ts b/src/app/finance-stats/containers/transaction-page/transaction-page.component.ts index 25d7052..a8306e7 100644 --- a/src/app/finance-stats/containers/transaction-page/transaction-page.component.ts +++ b/src/app/finance-stats/containers/transaction-page/transaction-page.component.ts @@ -1,33 +1,33 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' -import { select, Store } from '@ngrx/store' -import { Observable } from 'rxjs' -import { ITransaction } from '../../models/transaction' -import { getAllTransaction } from '../../reducers/transaction.reducer' -import { Load, OpenEditDialog } from '../../actions/transactions.actions' -import { getLoggedIn } from '@app/auth/reducers' -import { Load as LoadTransactionType } from '../../actions/transaction-type.actions' -import { Load as LoadCard } from '../../actions/card.actions' +import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; +import {select, Store} from '@ngrx/store'; +import {Observable} from 'rxjs'; +import {ITransaction} from '../../models/transaction'; +import {getAllTransaction} from '../../reducers/transaction.reducer'; +import {Load, OpenEditDialog} from '../../actions/transactions.actions'; +import {getLoggedIn} from '@app/auth/reducers'; +import {Load as LoadTransactionType} from '../../actions/transaction-type.actions'; +import {Load as LoadCard} from '../../actions/card.actions'; @Component({ templateUrl: './transaction-page.component.html', changeDetection: ChangeDetectionStrategy.OnPush, }) export class TransactionPageComponent implements OnInit { - transactions$: Observable - loggedIn$: Observable + transactions$: Observable; + loggedIn$: Observable; - constructor (public store: Store) { - this.transactions$ = this.store.pipe(select(getAllTransaction)) - this.loggedIn$ = this.store.pipe(select(getLoggedIn)) + constructor(public store: Store) { + this.transactions$ = this.store.pipe(select(getAllTransaction)); + this.loggedIn$ = this.store.pipe(select(getLoggedIn)); } - ngOnInit (): void { - this.store.dispatch(new Load()) - this.store.dispatch(new LoadTransactionType()) - this.store.dispatch(new LoadCard()) + ngOnInit(): void { + this.store.dispatch(new Load()); + this.store.dispatch(new LoadTransactionType()); + this.store.dispatch(new LoadCard()); } - create () { - this.store.dispatch(new OpenEditDialog({} as ITransaction)) + create() { + this.store.dispatch(new OpenEditDialog({} as ITransaction)); } } diff --git a/src/app/finance-stats/effects/card.effects.ts b/src/app/finance-stats/effects/card.effects.ts index d6cf361..469fe94 100644 --- a/src/app/finance-stats/effects/card.effects.ts +++ b/src/app/finance-stats/effects/card.effects.ts @@ -1,20 +1,20 @@ -import { Injectable } from '@angular/core' -import { Actions, createEffect, ofType } from '@ngrx/effects' -import { Action } from '@ngrx/store' -import { CardService } from '../services/card.service' +import {Injectable} from '@angular/core'; +import {Actions, createEffect, ofType} from '@ngrx/effects'; +import {Action} from '@ngrx/store'; +import {CardService} from '../services/card.service'; import { CardActionsType, LoadFail, LoadSuccess, -} from '../actions/card.actions' -import { ICard } from '../models/card' -import { catchError, map, switchMap } from 'rxjs/operators' -import { Observable, of } from 'rxjs' +} from '../actions/card.actions'; +import {ICard} from '../models/card'; +import {catchError, map, switchMap} from 'rxjs/operators'; +import {Observable, of} from 'rxjs'; @Injectable() export class CardEffects { - + load$: Observable = createEffect(() => this.actions$.pipe( ofType(CardActionsType.Load), switchMap(() => @@ -23,9 +23,10 @@ export class CardEffects { catchError(err => of(new LoadFail(err))), ), ), - )) + )); - constructor ( + constructor( private actions$: Actions, - private service: CardService) {} + private service: CardService) { + } } diff --git a/src/app/finance-stats/effects/transaction-type.effects.ts b/src/app/finance-stats/effects/transaction-type.effects.ts index 79a7022..461f814 100644 --- a/src/app/finance-stats/effects/transaction-type.effects.ts +++ b/src/app/finance-stats/effects/transaction-type.effects.ts @@ -1,20 +1,18 @@ -import { Injectable } from '@angular/core' -import { Actions, createEffect, ofType } from '@ngrx/effects' -import { Action } from '@ngrx/store' -import { TransactionTypeService } from '../services/transaction-type.service' +import {Injectable} from '@angular/core'; +import {Actions, createEffect, ofType} from '@ngrx/effects'; +import {Action} from '@ngrx/store'; +import {TransactionTypeService} from '../services/transaction-type.service'; import { LoadFail, LoadSuccess, TransactionTypeActionsType, -} from '../actions/transaction-type.actions' -import { ITransactionType } from '../models/transaction-type' -import { catchError, map, switchMap } from 'rxjs/operators' -import { Observable, of } from 'rxjs' +} from '../actions/transaction-type.actions'; +import {ITransactionType} from '../models/transaction-type'; +import {catchError, map, switchMap} from 'rxjs/operators'; +import {Observable, of} from 'rxjs'; @Injectable() export class TransactionTypeEffects { - - load$: Observable = createEffect(() => this.actions$.pipe( ofType(TransactionTypeActionsType.Load), switchMap(() => @@ -24,9 +22,10 @@ export class TransactionTypeEffects { catchError(err => of(new LoadFail(err))), ), ), - )) + )); - constructor ( + constructor( private actions$: Actions, - private service: TransactionTypeService) {} + private service: TransactionTypeService) { + } } diff --git a/src/app/finance-stats/effects/transaction.effects.ts b/src/app/finance-stats/effects/transaction.effects.ts index 26cc384..e623749 100644 --- a/src/app/finance-stats/effects/transaction.effects.ts +++ b/src/app/finance-stats/effects/transaction.effects.ts @@ -1,7 +1,7 @@ -import { Injectable } from '@angular/core' -import { Actions, createEffect, ofType } from '@ngrx/effects' -import { Action } from '@ngrx/store' -import { TransactionService } from '../services/transaction.service' +import {Injectable} from '@angular/core'; +import {Actions, createEffect, ofType} from '@ngrx/effects'; +import {Action} from '@ngrx/store'; +import {TransactionService} from '../services/transaction.service'; import { LoadFail, LoadSuccess, @@ -12,18 +12,17 @@ import { EditFail, OpenEditDialog, UpdateSuccess, -} from '../actions/transactions.actions' -import { ITransaction } from '../models/transaction' -import { catchError, map, mergeMap, switchMap } from 'rxjs/operators' -import { Observable, of } from 'rxjs' -import { MatDialog } from '@angular/material/dialog' -import { EditDialogComponent } from '../components/edit-dialog/edit-dialog.component' +} from '../actions/transactions.actions'; +import {ITransaction} from '../models/transaction'; +import {catchError, map, mergeMap, switchMap} from 'rxjs/operators'; +import {Observable, of} from 'rxjs'; +import {MatDialog} from '@angular/material/dialog'; +import {EditDialogComponent} from '../components/edit-dialog/edit-dialog.component'; @Injectable() export class TransactionEffects { - load$: Observable = createEffect(() => this.actions$.pipe( ofType(TransactionActionsType.Load), switchMap(() => @@ -32,44 +31,44 @@ export class TransactionEffects { catchError(err => of(new LoadFail(err))), ), ), - )) + )); - openEditDialog$: Observable = createEffect(() => this.actions$.pipe( ofType(TransactionActionsType.OpenEditDialog), mergeMap((action: OpenEditDialog) => { const dialogRef = this.dialog.open(EditDialogComponent, { // width: '500px', data: action.payload, - }) + }); return dialogRef.afterClosed().pipe( map(result => { if (!result) { - return new DismissEditDialog() + return new DismissEditDialog(); } - return new Edit(result as ITransaction) + return new Edit(result as ITransaction); }), - ) + ); }), - )) + )); + - edit$: Observable = createEffect(() => this.actions$.pipe( ofType(TransactionActionsType.Edit), map((action: Edit) => action.payload), switchMap((record: ITransaction) => { - const isNew = !record.id + const isNew = !record.id; return this.transactionService.save(record).pipe( map((result: ITransaction) => isNew ? new CreateSuccess(result) - : new UpdateSuccess({ id: record.id, changes: result })), + : new UpdateSuccess({id: record.id, changes: result})), catchError(err => of(new EditFail(err))), - ) + ); }), - )) + )); - constructor ( + constructor( private actions$: Actions, private transactionService: TransactionService, - public dialog: MatDialog) {} + public dialog: MatDialog) { + } } diff --git a/src/app/finance-stats/finance-stats-routing.module.ts b/src/app/finance-stats/finance-stats-routing.module.ts index 773a85d..0aa215c 100644 --- a/src/app/finance-stats/finance-stats-routing.module.ts +++ b/src/app/finance-stats/finance-stats-routing.module.ts @@ -1,8 +1,8 @@ -import { RouterModule, Routes } from '@angular/router' -import { DashboardComponent } from './containers/dashboard/dashboard.component' -import { AuthGuard } from '@app/auth/services/auth-guard.service' -import { NgModule } from '@angular/core' -import { TransactionPageComponent } from './containers/transaction-page/transaction-page.component' +import {RouterModule, Routes} from '@angular/router'; +import {DashboardComponent} from './containers/dashboard/dashboard.component'; +import {AuthGuard} from '@app/auth/services/auth-guard.service'; +import {NgModule} from '@angular/core'; +import {TransactionPageComponent} from './containers/transaction-page/transaction-page.component'; export const routes: Routes = [ { @@ -15,11 +15,12 @@ export const routes: Routes = [ component: TransactionPageComponent, canActivate: [AuthGuard], }, - { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, -] + {path: '', redirectTo: 'dashboard', pathMatch: 'full'}, +]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule], }) -export class FinanceStatsRoutingModule {} +export class FinanceStatsRoutingModule { +} diff --git a/src/app/finance-stats/finance-stats.module.ts b/src/app/finance-stats/finance-stats.module.ts index 1e6ceed..546f4bf 100644 --- a/src/app/finance-stats/finance-stats.module.ts +++ b/src/app/finance-stats/finance-stats.module.ts @@ -1,22 +1,22 @@ -import { NgModule } from '@angular/core' +import {NgModule} from '@angular/core'; -import { FinanceStatsRoutingModule } from './finance-stats-routing.module' -import { SharedModule } from '@app/shared' -import { GraphQLModule } from './graphql.module' -import { DashboardComponent } from './containers/dashboard/dashboard.component' -import { TransactionService } from './services/transaction.service' -import { TransactionTypeService } from './services/transaction-type.service' -import { CardService } from './services/card.service' -import { TransactionPageComponent } from './containers/transaction-page/transaction-page.component' -import { StoreModule } from '@ngrx/store' -import { EffectsModule } from '@ngrx/effects' -import { reducers } from './reducers' -import { TransactionEffects } from './effects/transaction.effects' -import { TransactionTypeEffects } from './effects/transaction-type.effects' -import { CardEffects } from './effects/card.effects' -import { TransactionListComponent } from './components/transaction-list/transaction-list.component' -import { EditDialogComponent } from './components/edit-dialog/edit-dialog.component' -import { TransactionFilterComponent } from './components/transaction-filter/transaction-filter.component' +import {FinanceStatsRoutingModule} from './finance-stats-routing.module'; +import {SharedModule} from '@app/shared'; +import {GraphQLModule} from './graphql.module'; +import {DashboardComponent} from './containers/dashboard/dashboard.component'; +import {TransactionService} from './services/transaction.service'; +import {TransactionTypeService} from './services/transaction-type.service'; +import {CardService} from './services/card.service'; +import {TransactionPageComponent} from './containers/transaction-page/transaction-page.component'; +import {StoreModule} from '@ngrx/store'; +import {EffectsModule} from '@ngrx/effects'; +import {reducers} from './reducers'; +import {TransactionEffects} from './effects/transaction.effects'; +import {TransactionTypeEffects} from './effects/transaction-type.effects'; +import {CardEffects} from './effects/card.effects'; +import {TransactionListComponent} from './components/transaction-list/transaction-list.component'; +import {EditDialogComponent} from './components/edit-dialog/edit-dialog.component'; +import {TransactionFilterComponent} from './components/transaction-filter/transaction-filter.component'; @NgModule({ declarations: [ @@ -39,4 +39,5 @@ import { TransactionFilterComponent } from './components/transaction-filter/tran CardService, ], }) -export class FinanceStatsModule {} +export class FinanceStatsModule { +} diff --git a/src/app/finance-stats/graphql.module.ts b/src/app/finance-stats/graphql.module.ts index 8fc5d15..81ba751 100644 --- a/src/app/finance-stats/graphql.module.ts +++ b/src/app/finance-stats/graphql.module.ts @@ -2,9 +2,10 @@ import {NgModule} from '@angular/core'; import {InMemoryCache} from '@apollo/client/core'; import {APOLLO_OPTIONS} from 'apollo-angular'; import {HttpLink} from 'apollo-angular/http'; -import { environment } from '@env'; +import {environment} from '@env'; const uri = environment.apiServers.financeStats + '/graphql'; + export function createApollo(httpLink: HttpLink) { return { link: httpLink.create({uri}), @@ -22,4 +23,5 @@ export function createApollo(httpLink: HttpLink) { }, ], }) -export class GraphQLModule {} +export class GraphQLModule { +} diff --git a/src/app/finance-stats/models/bank.ts b/src/app/finance-stats/models/bank.ts index e4817a9..4ca4f56 100644 --- a/src/app/finance-stats/models/bank.ts +++ b/src/app/finance-stats/models/bank.ts @@ -1,5 +1,5 @@ export interface IBank { - id: number - name: string - url: string + id: number; + name: string; + url: string; } diff --git a/src/app/finance-stats/models/card.ts b/src/app/finance-stats/models/card.ts index 9e5e98d..9de5770 100644 --- a/src/app/finance-stats/models/card.ts +++ b/src/app/finance-stats/models/card.ts @@ -1,11 +1,11 @@ -import { IBank } from '@app/finance-stats/models/bank' +import {IBank} from '@app/finance-stats/models/bank'; export interface ICard { bank: IBank; - currencyCode: string - description: string - id: number - name: string - validFrom: Date - validTo: Date + currencyCode: string; + description: string; + id: number; + name: string; + validFrom: Date; + validTo: Date; } diff --git a/src/app/finance-stats/models/transaction-info.ts b/src/app/finance-stats/models/transaction-info.ts index 6d7282a..cef0792 100644 --- a/src/app/finance-stats/models/transaction-info.ts +++ b/src/app/finance-stats/models/transaction-info.ts @@ -1,6 +1,6 @@ export interface ITransactionInfo { - blockedAmount: number - currencyExchange: number - fixedAmount: number - id: number + blockedAmount: number; + currencyExchange: number; + fixedAmount: number; + id: number; } diff --git a/src/app/finance-stats/models/transaction-type.ts b/src/app/finance-stats/models/transaction-type.ts index 0261f0d..1536901 100644 --- a/src/app/finance-stats/models/transaction-type.ts +++ b/src/app/finance-stats/models/transaction-type.ts @@ -1,5 +1,5 @@ export interface ITransactionType { - description: string - id: number - name: string + description: string; + id: number; + name: string; } diff --git a/src/app/finance-stats/models/transaction.ts b/src/app/finance-stats/models/transaction.ts index 21881ac..fbde2c7 100644 --- a/src/app/finance-stats/models/transaction.ts +++ b/src/app/finance-stats/models/transaction.ts @@ -1,6 +1,6 @@ -import { ICard } from '@app/finance-stats/models/card' -import { ITransactionInfo } from '@app/finance-stats/models/transaction-info' -import { ITransactionType } from '@app/finance-stats/models/transaction-type' +import {ICard} from '@app/finance-stats/models/card'; +import {ITransactionInfo} from '@app/finance-stats/models/transaction-info'; +import {ITransactionType} from '@app/finance-stats/models/transaction-type'; export interface ITransaction { amount: number; diff --git a/src/app/finance-stats/reducers/card.reducer.ts b/src/app/finance-stats/reducers/card.reducer.ts index 2bb555a..5f1d1fe 100644 --- a/src/app/finance-stats/reducers/card.reducer.ts +++ b/src/app/finance-stats/reducers/card.reducer.ts @@ -1,10 +1,10 @@ import {createEntityAdapter, EntityAdapter, EntityState} from '@ngrx/entity'; -import { ICard } from '../models/card' +import {ICard} from '../models/card'; import { CardActions, CardActionsType, -} from '../actions/card.actions' -import { createFeatureSelector, createSelector } from '@ngrx/store' +} from '../actions/card.actions'; +import {createFeatureSelector, createSelector} from '@ngrx/store'; export interface State extends EntityState { @@ -45,14 +45,14 @@ export interface CardState { } export const getCardState = createFeatureSelector( - 'finance-stats') + 'finance-stats'); export const getCardEntitiesState = createSelector(getCardState, - state => state.cards) + state => state.cards); export const { selectIds: getCardIds, selectEntities: getCardEntities, selectAll: getAllCard, -} = adapter.getSelectors(getCardEntitiesState) +} = adapter.getSelectors(getCardEntitiesState); diff --git a/src/app/finance-stats/reducers/index.ts b/src/app/finance-stats/reducers/index.ts index bfed6fd..42d050f 100644 --- a/src/app/finance-stats/reducers/index.ts +++ b/src/app/finance-stats/reducers/index.ts @@ -1,9 +1,9 @@ -import { reducer as transactionReducer } from './transaction.reducer' -import { reducer as cardReducer } from './card.reducer' -import { reducer as transactionTypeReducer } from './transaction-type.reducer' +import {reducer as transactionReducer} from './transaction.reducer'; +import {reducer as cardReducer} from './card.reducer'; +import {reducer as transactionTypeReducer} from './transaction-type.reducer'; export const reducers = { transactions: transactionReducer, cards: cardReducer, transactionTypes: transactionTypeReducer, -} +}; diff --git a/src/app/finance-stats/reducers/transaction-type.reducer.ts b/src/app/finance-stats/reducers/transaction-type.reducer.ts index 620828b..f8ead31 100644 --- a/src/app/finance-stats/reducers/transaction-type.reducer.ts +++ b/src/app/finance-stats/reducers/transaction-type.reducer.ts @@ -1,10 +1,10 @@ import {createEntityAdapter, EntityAdapter, EntityState} from '@ngrx/entity'; -import { ITransactionType } from '../models/transaction-type' +import {ITransactionType} from '../models/transaction-type'; import { TransactionTypeActions, TransactionTypeActionsType, -} from '../actions/transaction-type.actions' -import { createFeatureSelector, createSelector } from '@ngrx/store' +} from '../actions/transaction-type.actions'; +import {createFeatureSelector, createSelector} from '@ngrx/store'; export interface State extends EntityState { @@ -45,14 +45,14 @@ export interface TransactionTypeState { } export const getTransactionTypeState = createFeatureSelector( - 'finance-stats') + 'finance-stats'); export const getTransactionTypeEntitiesState = createSelector(getTransactionTypeState, - state => state.transactionTypes) + state => state.transactionTypes); export const { selectIds: getTransactionTypeIds, selectEntities: getTransactionTypeEntities, selectAll: getAllTransactionType, -} = adapter.getSelectors(getTransactionTypeEntitiesState) +} = adapter.getSelectors(getTransactionTypeEntitiesState); diff --git a/src/app/finance-stats/reducers/transaction.reducer.ts b/src/app/finance-stats/reducers/transaction.reducer.ts index 539550e..18563a7 100644 --- a/src/app/finance-stats/reducers/transaction.reducer.ts +++ b/src/app/finance-stats/reducers/transaction.reducer.ts @@ -1,10 +1,10 @@ -import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity' -import { ITransaction } from '../models/transaction' +import {createEntityAdapter, EntityAdapter, EntityState} from '@ngrx/entity'; +import {ITransaction} from '../models/transaction'; import { TransactionActions, TransactionActionsType, -} from '@app/finance-stats/actions/transactions.actions' -import { createFeatureSelector, createSelector } from '@ngrx/store' +} from '@app/finance-stats/actions/transactions.actions'; +import {createFeatureSelector, createSelector} from '@ngrx/store'; export interface State extends EntityState { @@ -14,30 +14,30 @@ export const adapter: EntityAdapter = createEntityAdapter transaction.id, sortComparer: false, - }) + }); -export const initialState: State = adapter.getInitialState({}) +export const initialState: State = adapter.getInitialState({}); -export function reducer (state = initialState, action: TransactionActions) { +export function reducer(state = initialState, action: TransactionActions) { switch (action.type) { case TransactionActionsType.LoadSuccess: return { ...adapter.addMany(action.payload, state), - } + }; case TransactionActionsType.CreateSuccess: return { ...adapter.addOne(action.payload, state), - } + }; case TransactionActionsType.UpdateSuccess: return { ...adapter.updateOne(action.payload, state), - } + }; case TransactionActionsType.RemoveSuccess: return { ...adapter.removeOne(action.payload, state), - } + }; default: - return state + return state; } } @@ -46,17 +46,16 @@ export interface TransactionState { } export const getTransactionState = createFeatureSelector( - 'finance-stats') + 'finance-stats'); export const getTransactionEntitiesState = createSelector(getTransactionState, state => { - console.log('transaction.reducer.ts::::51 >>>', state) - return state.transactions - }) + return state.transactions; + }); export const { selectIds: getTransactionIds, selectEntities: getTransactionEntities, selectAll: getAllTransaction, -} = adapter.getSelectors(getTransactionEntitiesState) +} = adapter.getSelectors(getTransactionEntitiesState); diff --git a/src/app/finance-stats/services/card.service.ts b/src/app/finance-stats/services/card.service.ts index 786c4c7..56c1bbc 100644 --- a/src/app/finance-stats/services/card.service.ts +++ b/src/app/finance-stats/services/card.service.ts @@ -1,17 +1,18 @@ import {Apollo, gql} from 'apollo-angular'; -import { Injectable } from '@angular/core' +import {Injectable} from '@angular/core'; -import { map } from 'rxjs/operators' -import { Observable } from 'rxjs' -import { ICard } from '../models/card' +import {map} from 'rxjs/operators'; +import {Observable} from 'rxjs'; +import {ICard} from '../models/card'; @Injectable() export class CardService { - constructor (private apollo: Apollo) {} + constructor(private apollo: Apollo) { + } - list (): Observable { + list(): Observable { return this.apollo.query({ query: gql`{ cards { @@ -26,8 +27,8 @@ export class CardService { } } }`, - }).pipe(map(({ data }) => { - return (data as any).cards as ICard[] - })) + }).pipe(map(({data}) => { + return (data as any).cards as ICard[]; + })); } } diff --git a/src/app/finance-stats/services/transaction-type.service.ts b/src/app/finance-stats/services/transaction-type.service.ts index 0d8d4ce..c940f4e 100644 --- a/src/app/finance-stats/services/transaction-type.service.ts +++ b/src/app/finance-stats/services/transaction-type.service.ts @@ -1,17 +1,18 @@ import {Apollo, gql} from 'apollo-angular'; -import { Injectable } from '@angular/core' +import {Injectable} from '@angular/core'; -import { map } from 'rxjs/operators' -import { Observable } from 'rxjs' -import { ITransactionType } from '../models/transaction-type' +import {map} from 'rxjs/operators'; +import {Observable} from 'rxjs'; +import {ITransactionType} from '../models/transaction-type'; @Injectable() export class TransactionTypeService { - constructor (private apollo: Apollo) {} + constructor(private apollo: Apollo) { + } - list (): Observable { + list(): Observable { return this.apollo.query({ query: gql`{ transactionTypes { @@ -20,8 +21,8 @@ export class TransactionTypeService { description } }`, - }).pipe(map(({ data }) => { - return (data as any).transactionTypes as ITransactionType[] - })) + }).pipe(map(({data}) => { + return (data as any).transactionTypes as ITransactionType[]; + })); } } diff --git a/src/app/finance-stats/services/transaction.service.ts b/src/app/finance-stats/services/transaction.service.ts index 79ce4bb..5a6935d 100644 --- a/src/app/finance-stats/services/transaction.service.ts +++ b/src/app/finance-stats/services/transaction.service.ts @@ -1,10 +1,10 @@ import {Apollo, gql} from 'apollo-angular'; -import { Injectable } from '@angular/core' +import {Injectable} from '@angular/core'; -import { map } from 'rxjs/operators' -import { Observable } from 'rxjs' -import { ITransaction } from '../models/transaction' +import {map} from 'rxjs/operators'; +import {Observable} from 'rxjs'; +import {ITransaction} from '../models/transaction'; const FULL_RESPONSE = `{ id @@ -38,31 +38,32 @@ const FULL_RESPONSE = `{ currencyExchange } } -` +`; @Injectable() export class TransactionService { - constructor (private apollo: Apollo) {} + constructor(private apollo: Apollo) { + } - listFull (): Observable { + listFull(): Observable { + console.log('transaction.service.ts::listFull::50 >>>', ''); return this.apollo.query({ query: gql`query listTransactions { transactions ${FULL_RESPONSE} }`, - }).pipe(map(({ data }) => + }).pipe(map(({data}) => (data as any).transactions as ITransaction[], - )) + )); } - stats (): Observable { + stats(): Observable { return this.apollo.query({ query: gql``, - }). - pipe(map(({ data }) => (data as any).stats as ITransaction)) + }).pipe(map(({data}) => (data as any).stats as ITransaction)); } - create (record: ITransaction): Observable { + create(record: ITransaction): Observable { return this.apollo.mutate({ mutation: gql`mutation createTransaction($transaction: TransactionCreate){ addTransaction(transaction: $transaction) ${FULL_RESPONSE} @@ -70,25 +71,25 @@ export class TransactionService { variables: { transaction: record, } - }).pipe(map(({ data }) => + }).pipe(map(({data}) => (data as any).addTransaction as ITransaction, - )) + )); } - save (record: ITransaction): Observable { + save(record: ITransaction): Observable { if (record.id === undefined) { - return this.create(record) + return this.create(record); } - return this.update(record) + return this.update(record); } - update (record: ITransaction): Observable { + update(record: ITransaction): Observable { return this.apollo.mutate({ mutation: gql`{ }`, - }).pipe(map(({ data }) => + }).pipe(map(({data}) => (data as any).updateTrunsuction as ITransaction, - )) + )); } } diff --git a/src/app/notes/actions/note.actions.ts b/src/app/notes/actions/note.actions.ts index 140f2ad..df05960 100644 --- a/src/app/notes/actions/note.actions.ts +++ b/src/app/notes/actions/note.actions.ts @@ -31,13 +31,15 @@ export class Load implements Action { export class LoadSuccess implements Action { readonly type = NoteActionsType.LoadSuccess; - constructor(public payload: INote[]) {} + constructor(public payload: INote[]) { + } } export class LoadFail implements Action { readonly type = NoteActionsType.LoadFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } // --- Load group --- END @@ -47,25 +49,29 @@ export class LoadFail implements Action { export class Edit implements Action { readonly type = NoteActionsType.Edit; - constructor(public payload: INote) {} + constructor(public payload: INote) { + } } export class CreateSuccess implements Action { readonly type = NoteActionsType.CreateSuccess; - constructor(public payload: INote) {} + constructor(public payload: INote) { + } } export class UpdateSuccess implements Action { readonly type = NoteActionsType.UpdateSuccess; - constructor(public payload: Update) {} + constructor(public payload: Update) { + } } export class EditFail implements Action { readonly type = NoteActionsType.EditFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } // --- Edit group --- END @@ -75,19 +81,22 @@ export class EditFail implements Action { export class Remove implements Action { readonly type = NoteActionsType.Remove; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveSuccess implements Action { readonly type = NoteActionsType.RemoveSuccess; - constructor(public payload: number) {} + constructor(public payload: number) { + } } export class RemoveFail implements Action { readonly type = NoteActionsType.RemoveFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } // --- Remove group --- END @@ -95,7 +104,8 @@ export class RemoveFail implements Action { export class OpenEditDialog implements Action { readonly type = NoteActionsType.OpenEditDialog; - constructor(public payload: INote) {} + constructor(public payload: INote) { + } } export class DismissEditDialog implements Action { @@ -105,7 +115,8 @@ export class DismissEditDialog implements Action { export class DetailsDialog implements Action { readonly type = NoteActionsType.DetailsDialog; - constructor(public payload: INote) {} + constructor(public payload: INote) { + } } export type NoteActions = diff --git a/src/app/notes/components/details-dialog/details-dialog.component.spec.ts b/src/app/notes/components/details-dialog/details-dialog.component.spec.ts index 240c872..e5c5aaa 100644 --- a/src/app/notes/components/details-dialog/details-dialog.component.spec.ts +++ b/src/app/notes/components/details-dialog/details-dialog.component.spec.ts @@ -1,6 +1,6 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; -import { DetailsDialogComponent } from './details-dialog.component'; +import {DetailsDialogComponent} from './details-dialog.component'; describe('DetailsDialogComponent', () => { let component: DetailsDialogComponent; @@ -8,9 +8,9 @@ describe('DetailsDialogComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ DetailsDialogComponent ] + declarations: [DetailsDialogComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/notes/components/details-dialog/details-dialog.component.ts b/src/app/notes/components/details-dialog/details-dialog.component.ts index d38ab67..fb81b0f 100644 --- a/src/app/notes/components/details-dialog/details-dialog.component.ts +++ b/src/app/notes/components/details-dialog/details-dialog.component.ts @@ -10,6 +10,7 @@ export class DetailsDialogComponent { constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public note: INote) {} + @Inject(MAT_DIALOG_DATA) public note: INote) { + } } diff --git a/src/app/notes/components/edit-dialog/edit-dialog.component.spec.ts b/src/app/notes/components/edit-dialog/edit-dialog.component.spec.ts index b4b92ee..34f6ae0 100644 --- a/src/app/notes/components/edit-dialog/edit-dialog.component.spec.ts +++ b/src/app/notes/components/edit-dialog/edit-dialog.component.spec.ts @@ -1,6 +1,6 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; -import { EditDialogComponent } from './edit-dialog.component'; +import {EditDialogComponent} from './edit-dialog.component'; describe('EditDialogComponent', () => { let component: EditDialogComponent; @@ -8,9 +8,9 @@ describe('EditDialogComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ EditDialogComponent ] + declarations: [EditDialogComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/notes/components/note-list/note-list.component.html b/src/app/notes/components/note-list/note-list.component.html index 71fc7fa..61e0b8c 100644 --- a/src/app/notes/components/note-list/note-list.component.html +++ b/src/app/notes/components/note-list/note-list.component.html @@ -8,7 +8,7 @@
{{note.keywords}}
- - + + diff --git a/src/app/notes/components/note-list/note-list.component.spec.ts b/src/app/notes/components/note-list/note-list.component.spec.ts index 54321bd..99ffa5f 100644 --- a/src/app/notes/components/note-list/note-list.component.spec.ts +++ b/src/app/notes/components/note-list/note-list.component.spec.ts @@ -1,6 +1,6 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; -import { NoteListComponent } from './note-list.component'; +import {NoteListComponent} from './note-list.component'; describe('NoteListComponent', () => { let component: NoteListComponent; @@ -8,9 +8,9 @@ describe('NoteListComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ NoteListComponent ] + declarations: [NoteListComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/notes/components/note-list/note-list.component.ts b/src/app/notes/components/note-list/note-list.component.ts index 15fad15..85ad4ca 100644 --- a/src/app/notes/components/note-list/note-list.component.ts +++ b/src/app/notes/components/note-list/note-list.component.ts @@ -18,7 +18,8 @@ export class NoteListComponent { @Input() canEdit = false; - constructor(public store: Store) {} + constructor(public store: Store) { + } edit(note: INote) { this.store.dispatch(new noteActions.OpenEditDialog(note)); diff --git a/src/app/notes/containers/note-page.component.spec.ts b/src/app/notes/containers/note-page.component.spec.ts index ab6da29..ae19378 100644 --- a/src/app/notes/containers/note-page.component.spec.ts +++ b/src/app/notes/containers/note-page.component.spec.ts @@ -1,6 +1,6 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; -import { NotePageComponent } from './note-page.component'; +import {NotePageComponent} from './note-page.component'; describe('NotesComponent', () => { let component: NotePageComponent; @@ -8,9 +8,9 @@ describe('NotesComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ NotePageComponent ] + declarations: [NotePageComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/notes/containers/note-page.component.ts b/src/app/notes/containers/note-page.component.ts index a42fd9c..f226830 100644 --- a/src/app/notes/containers/note-page.component.ts +++ b/src/app/notes/containers/note-page.component.ts @@ -1,7 +1,7 @@ import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; -import { MatDialog } from '@angular/material/dialog'; -import { INote } from '@app/notes/models/note'; -import { EditDialogComponent } from '@app/notes/components/edit-dialog/edit-dialog.component'; +import {MatDialog} from '@angular/material/dialog'; +import {INote} from '@app/notes/models/note'; +import {EditDialogComponent} from '@app/notes/components/edit-dialog/edit-dialog.component'; import {select, Store} from '@ngrx/store'; import * as fromNotes from '@app/notes/reducers'; diff --git a/src/app/notes/effects/note.effects.ts b/src/app/notes/effects/note.effects.ts index b84031a..8fd8845 100644 --- a/src/app/notes/effects/note.effects.ts +++ b/src/app/notes/effects/note.effects.ts @@ -24,7 +24,7 @@ import {Observable, of} from 'rxjs'; @Injectable() export class NoteEffects { - + loadNotes$: Observable = createEffect(() => this.actions$.pipe( ofType(NoteActionsType.Load), switchMap(() => @@ -35,7 +35,7 @@ export class NoteEffects { ), )); - + openEditDialog$: Observable = createEffect(() => this.actions$.pipe( ofType(NoteActionsType.OpenEditDialog), mergeMap((action: OpenEditDialog) => { @@ -54,7 +54,7 @@ export class NoteEffects { }), )); - + editNote$: Observable = createEffect(() => this.actions$.pipe( ofType(NoteActionsType.Edit), map((action: Edit) => action.payload), @@ -67,7 +67,7 @@ export class NoteEffects { }), )); - + detailsDialog$: Observable = createEffect(() => this.actions$.pipe( ofType(NoteActionsType.DetailsDialog), tap((action: DetailsDialog) => { @@ -80,5 +80,6 @@ export class NoteEffects { constructor( private actions$: Actions, private notesService: NotesService, - public dialog: MatDialog) {} + public dialog: MatDialog) { + } } diff --git a/src/app/notes/notes.module.ts b/src/app/notes/notes.module.ts index eea2863..3103516 100644 --- a/src/app/notes/notes.module.ts +++ b/src/app/notes/notes.module.ts @@ -9,8 +9,8 @@ import {StoreModule} from '@ngrx/store'; import {reducers} from '@app/notes/reducers'; import {EffectsModule} from '@ngrx/effects'; import {NoteEffects} from '@app/notes/effects/note.effects'; -import { NoteListComponent } from './components/note-list/note-list.component'; -import { DetailsDialogComponent } from './components/details-dialog/details-dialog.component'; +import {NoteListComponent} from './components/note-list/note-list.component'; +import {DetailsDialogComponent} from './components/details-dialog/details-dialog.component'; @NgModule({ imports: [ diff --git a/src/app/notes/notes.routes.ts b/src/app/notes/notes.routes.ts index 4aa49d2..9998d21 100644 --- a/src/app/notes/notes.routes.ts +++ b/src/app/notes/notes.routes.ts @@ -1,5 +1,5 @@ -import { Routes } from '@angular/router'; -import { NotePageComponent } from '@app/notes/containers/note-page.component'; +import {Routes} from '@angular/router'; +import {NotePageComponent} from '@app/notes/containers/note-page.component'; export const notesRoutes: Routes = [ diff --git a/src/app/notes/services/notes.service.spec.ts b/src/app/notes/services/notes.service.spec.ts index 2c29538..21b7404 100644 --- a/src/app/notes/services/notes.service.spec.ts +++ b/src/app/notes/services/notes.service.spec.ts @@ -1,6 +1,6 @@ -import { TestBed, inject } from '@angular/core/testing'; +import {TestBed, inject} from '@angular/core/testing'; -import { NotesService } from './notes.service'; +import {NotesService} from './notes.service'; describe('NotesService', () => { beforeEach(() => { diff --git a/src/app/notes/services/notes.service.ts b/src/app/notes/services/notes.service.ts index 6dfdbde..9877964 100644 --- a/src/app/notes/services/notes.service.ts +++ b/src/app/notes/services/notes.service.ts @@ -11,7 +11,8 @@ export class NotesService { private baseUrl = environment.apiServers.ndfsmFleaMarket + '/api/notes'; // URL to web api - constructor(private http: HttpClient) {} + constructor(private http: HttpClient) { + } list() { return this.http.get(this.baseUrl).pipe( diff --git a/src/app/reducers/index.ts b/src/app/reducers/index.ts index 243ce85..3575a00 100644 --- a/src/app/reducers/index.ts +++ b/src/app/reducers/index.ts @@ -5,8 +5,8 @@ import { ActionReducer, MetaReducer, } from '@ngrx/store'; -import { environment } from '@env'; -import { RouterStateUrl } from '../shared/utils'; +import {environment} from '@env'; +import {RouterStateUrl} from '../shared/utils'; import * as fromRouter from '@ngrx/router-store'; /** diff --git a/src/app/settings/settings.effects.ts b/src/app/settings/settings.effects.ts index 98c600f..73de1b7 100644 --- a/src/app/settings/settings.effects.ts +++ b/src/app/settings/settings.effects.ts @@ -12,7 +12,8 @@ export class SettingsEffects { constructor( private actions$: Actions, private localStorageService: LocalStorageService - ) {} + ) { + } persistThemeSettings(): Observable { return createEffect(() => this.actions$.pipe( @@ -22,6 +23,6 @@ export class SettingsEffects { theme: action.payload }) ) - ), { dispatch: false }); + ), {dispatch: false}); } } diff --git a/src/app/settings/settings.module.ts b/src/app/settings/settings.module.ts index cb3b007..529d14c 100644 --- a/src/app/settings/settings.module.ts +++ b/src/app/settings/settings.module.ts @@ -1,25 +1,25 @@ -import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core' -import { StoreConfig, StoreModule } from '@ngrx/store' -import { EffectsModule } from '@ngrx/effects' +import {InjectionToken, ModuleWithProviders, NgModule} from '@angular/core'; +import {StoreConfig, StoreModule} from '@ngrx/store'; +import {EffectsModule} from '@ngrx/effects'; -import { SharedModule } from '../shared' +import {SharedModule} from '../shared'; -import * as fromReducer from './settings.reducer' -import { SETTINGS_KEY } from './settings.reducer' -import { SettingsEffects } from './settings.effects' -import { SettingsComponent } from './settings/settings.component' -import { LocalStorageService } from '@app/core' +import * as fromReducer from './settings.reducer'; +import {SETTINGS_KEY} from './settings.reducer'; +import {SettingsEffects} from './settings.effects'; +import {SettingsComponent} from './settings/settings.component'; +import {LocalStorageService} from '@app/core'; // Setting configuration export const SETTINGS_CONFIG_TOKEN = new InjectionToken>( - 'Settings Config') + 'Settings Config'); -export function getConfig (localStorageService: LocalStorageService): StoreConfig { +export function getConfig(localStorageService: LocalStorageService): StoreConfig { // return the config synchronously. return { initialState: localStorageService.getItem(SETTINGS_KEY) || fromReducer.initialState, - } + }; } @NgModule({ @@ -32,7 +32,7 @@ export function getConfig (localStorageService: LocalStorageService): StoreConfi declarations: [SettingsComponent], }) export class SettingsModule { - static forRoot (): ModuleWithProviders { + static forRoot(): ModuleWithProviders { return { ngModule: SettingsModule, providers: [ @@ -42,6 +42,6 @@ export class SettingsModule { useFactory: getConfig, }, ], - } + }; } } diff --git a/src/app/settings/settings.reducer.ts b/src/app/settings/settings.reducer.ts index 317f67f..104ae2e 100644 --- a/src/app/settings/settings.reducer.ts +++ b/src/app/settings/settings.reducer.ts @@ -1,7 +1,7 @@ -import { Action } from '@app/core'; +import {Action} from '@app/core'; export interface State { - theme: string + theme: string; } export const initialState: State = { @@ -17,12 +17,12 @@ export const actionChangeTheme = (theme: string) => ({ payload: theme }); -export const selectorSettings = state => state.settings || { theme: '' }; +export const selectorSettings = state => state.settings || {theme: ''}; export function settingsReducer(state = initialState, action: Action) { switch (action.type) { case SETTINGS_CHANGE_THEME: - return { theme: action.payload }; + return {theme: action.payload}; default: return state; diff --git a/src/app/settings/settings/settings.component.html b/src/app/settings/settings/settings.component.html index ddcf2da..06a1da2 100644 --- a/src/app/settings/settings/settings.component.html +++ b/src/app/settings/settings/settings.component.html @@ -4,13 +4,13 @@

- - - - {{t.label}} - - - + + + + {{t.label}} + + +
diff --git a/src/app/settings/settings/settings.component.spec.ts b/src/app/settings/settings/settings.component.spec.ts index 103b483..62033c5 100644 --- a/src/app/settings/settings/settings.component.spec.ts +++ b/src/app/settings/settings/settings.component.spec.ts @@ -1,10 +1,10 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; +import {NoopAnimationsModule} from '@angular/platform-browser/animations'; -import { CoreModule } from '@app/core'; -import { SharedModule } from '@app/shared'; +import {CoreModule} from '@app/core'; +import {SharedModule} from '@app/shared'; -import { SettingsComponent } from './settings.component'; +import {SettingsComponent} from './settings.component'; describe('SettingsComponent', () => { let component: SettingsComponent; diff --git a/src/app/settings/settings/settings.component.ts b/src/app/settings/settings/settings.component.ts index 19730af..91ad92c 100644 --- a/src/app/settings/settings/settings.component.ts +++ b/src/app/settings/settings/settings.component.ts @@ -1,7 +1,7 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; -import { Store } from '@ngrx/store'; +import {Component, OnDestroy, OnInit} from '@angular/core'; +import {Store} from '@ngrx/store'; -import { actionChangeTheme, selectorSettings } from '../settings.reducer'; +import {actionChangeTheme, selectorSettings} from '../settings.reducer'; import {Subject} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; @@ -22,7 +22,8 @@ export class SettingsComponent implements OnInit, OnDestroy { store.select(selectorSettings).pipe(takeUntil(this.unsubscribe$)).subscribe(({theme}) => (this.theme = theme)); } - ngOnInit() {} + ngOnInit() { + } ngOnDestroy(): void { this.unsubscribe$.next(); diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 3028bfd..1f81805 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -67,4 +67,5 @@ import {MatFormFieldModule} from '@angular/material/form-field'; MatFormFieldModule, ], }) -export class SharedModule {} +export class SharedModule { +} diff --git a/src/app/shared/utils.ts b/src/app/shared/utils.ts index 73deb63..3707975 100644 --- a/src/app/shared/utils.ts +++ b/src/app/shared/utils.ts @@ -1,6 +1,6 @@ -import { RouterStateSerializer } from '@ngrx/router-store'; -import { RouterStateSnapshot, Params } from '@angular/router'; -import { Injectable } from "@angular/core"; +import {RouterStateSerializer} from '@ngrx/router-store'; +import {RouterStateSnapshot, Params} from '@angular/router'; +import {Injectable} from '@angular/core'; /** * The RouterStateSerializer takes the current RouterStateSnapshot @@ -20,9 +20,9 @@ export interface RouterStateUrl { export class CustomRouterStateSerializer implements RouterStateSerializer { serialize(routerState: RouterStateSnapshot): RouterStateUrl { - const { url } = routerState; + const {url} = routerState; const queryParams = routerState.root.queryParams; - return { url, queryParams }; + return {url, queryParams}; } } diff --git a/src/app/todos/actions/todo.ts b/src/app/todos/actions/todo.ts index cd632c0..907b0e4 100644 --- a/src/app/todos/actions/todo.ts +++ b/src/app/todos/actions/todo.ts @@ -1,5 +1,5 @@ -import { Action } from '@ngrx/store'; -import { ITodo, IUpdateTodo } from '../models/todo' +import {Action} from '@ngrx/store'; +import {ITodo, IUpdateTodo} from '../models/todo'; export enum TodoActionTypes { Add = '[TODO] Add', @@ -23,54 +23,64 @@ export type TodoFilter = 'ALL' | 'DONE' | 'ACTIVE'; export class Add implements Action { readonly type = TodoActionTypes.Add; - constructor(public payload: ITodo) {} + constructor(public payload: ITodo) { + } } export class AddSuccess implements Action { readonly type = TodoActionTypes.AddSuccess; - constructor(public payload: ITodo) {} + constructor(public payload: ITodo) { + } } export class AddFail implements Action { readonly type = TodoActionTypes.AddFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class Update implements Action { readonly type = TodoActionTypes.Update; - constructor(public payload: IUpdateTodo) {} + constructor(public payload: IUpdateTodo) { + } } export class UpdateSuccess implements Action { readonly type = TodoActionTypes.UpdateSuccess; - constructor(public payload: ITodo) {} + constructor(public payload: ITodo) { + } } export class UpdateFail implements Action { readonly type = TodoActionTypes.UpdateFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class Remove implements Action { readonly type = TodoActionTypes.Remove; - constructor(public id: string) {} + constructor(public id: string) { + } } export class RemoveSuccess implements Action { readonly type = TodoActionTypes.RemoveSuccess; - constructor(public id: string) {} + + constructor(public id: string) { + } } export class RemoveFail implements Action { readonly type = TodoActionTypes.RemoveFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } /** @@ -83,19 +93,22 @@ export class Load implements Action { export class LoadSuccess implements Action { readonly type = TodoActionTypes.LoadSuccess; - constructor(public payload: ITodo[]) {} + constructor(public payload: ITodo[]) { + } } export class LoadFail implements Action { readonly type = TodoActionTypes.LoadFail; - constructor(public payload: any) {} + constructor(public payload: any) { + } } export class Filter implements Action { - readonly type = TodoActionTypes.Filter + readonly type = TodoActionTypes.Filter; - constructor (public filter: TodoFilter) {} + constructor(public filter: TodoFilter) { + } } export type TodoActions = diff --git a/src/app/todos/containers/todo.component.html b/src/app/todos/containers/todo.component.html index fd6cd14..08b3fea 100644 --- a/src/app/todos/containers/todo.component.html +++ b/src/app/todos/containers/todo.component.html @@ -14,8 +14,10 @@ - + matTooltip="Add new todo" matTooltipPosition="before"> + add + + @@ -49,7 +51,8 @@

- + {{todo.name}}