WIP: Implement accounts

This commit is contained in:
William Brawner 2019-05-04 11:32:26 -07:00
parent e7067744d9
commit 7c2e58cb11
6 changed files with 93 additions and 70 deletions

8
package-lock.json generated
View file

@ -4186,11 +4186,13 @@
}, },
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true "bundled": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -4207,7 +4209,8 @@
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true "bundled": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
@ -4336,6 +4339,7 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }

View file

@ -7,69 +7,70 @@ import { UserService, USER_SERVICE } from 'src/app/users/user.service';
import { User } from 'src/app/users/user'; import { User } from 'src/app/users/user';
@Component({ @Component({
selector: 'app-add-edit-account', selector: 'app-add-edit-account',
templateUrl: './add-edit-account.component.html', templateUrl: './add-edit-account.component.html',
styleUrls: ['./add-edit-account.component.css'] styleUrls: ['./add-edit-account.component.css']
}) })
export class AddEditAccountComponent implements OnInit, OnDestroy, Actionable { export class AddEditAccountComponent implements OnInit, OnDestroy, Actionable {
@Input() title: string; @Input() title: string;
@Input() account: Account; @Input() account: Account;
public users: User[]; public users: User[];
public searchedUsers: User[]; public searchedUsers: User[];
constructor( constructor(
private app: AppComponent, private app: AppComponent,
@Inject(ACCOUNT_SERVICE) private accountService: AccountService, @Inject(ACCOUNT_SERVICE) private accountService: AccountService,
@Inject(USER_SERVICE) private userService: UserService, @Inject(USER_SERVICE) private userService: UserService,
) { ) {
this.app.title = this.title; this.app.title = this.title;
this.app.backEnabled = true; this.app.backEnabled = true;
this.app.actionable = this; this.app.actionable = this;
}
ngOnInit() {
}
ngOnDestroy(): void {
this.app.actionable = null;
}
doAction(): void {
let observable;
if (this.account.id) {
// This is an existing transaction, update it
observable = this.accountService.updateAccount(this.account.id, this.account);
} else {
// This is a new transaction, save it
observable = this.accountService.createAccount(
this.account.name,
this.account.description,
this.account.currency,
this.users
);
} }
// TODO: Check if it was actually successful or not
observable.subscribe(val => {
this.app.goBack();
});
}
getActionLabel(): string { ngOnInit() {
return 'Save'; }
}
delete(): void { ngOnDestroy(): void {
this.accountService.deleteAccount(this.account.id); this.app.actionable = null;
this.app.goBack(); }
}
searchUsers(username: string) { doAction(): void {
this.userService.getUsersByUsername(username).subscribe(users => { let observable;
this.searchedUsers = users; if (this.account.id) {
}); // This is an existing transaction, update it
} observable = this.accountService.updateAccount(this.account.id, this.account);
} else {
// This is a new transaction, save it
observable = this.accountService.createAccount(
this.account.name,
this.account.description,
this.account.currency,
this.users
);
}
// TODO: Check if it was actually successful or not
observable.subscribe(val => {
this.app.goBack();
});
}
clearUserSearch() { getActionLabel(): string {
this.searchedUsers = []; return 'Save';
} }
delete(): void {
this.accountService.deleteAccount(this.account.id);
this.app.goBack();
}
// TODO: Implement a search box with suggestions to add users
searchUsers(username: string) {
this.userService.getUsersByUsername(username).subscribe(users => {
this.searchedUsers = users;
});
}
clearUserSearch() {
this.searchedUsers = [];
}
} }

View file

@ -1,3 +1 @@
<p> <app-add-edit-account [title]="'Add Account'" [account]="account"></app-add-edit-account>
new-account works!
</p>

View file

@ -1,15 +1,20 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Account } from '../account';
@Component({ @Component({
selector: 'app-new-account', selector: 'app-new-account',
templateUrl: './new-account.component.html', templateUrl: './new-account.component.html',
styleUrls: ['./new-account.component.css'] styleUrls: ['./new-account.component.css']
}) })
export class NewAccountComponent implements OnInit { export class NewAccountComponent implements OnInit {
constructor() { } public account: Account;
ngOnInit() { constructor() {
} this.account = new Account();
}
ngOnInit() {
}
} }

View file

@ -1,15 +1,16 @@
import { TestBed, inject } from '@angular/core/testing'; import { TestBed, inject } from '@angular/core/testing';
import { UserService } from './user.service'; import { UserService } from './user.service';
import { FirestoreUserService } from './user.service.firestore';
describe('UserService', () => { describe('UserService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [UserService] providers: [FirestoreUserService]
}); });
}); });
it('should be created', inject([UserService], (service: UserService) => { it('should be created', inject([FirestoreUserService], (service: UserService) => {
expect(service).toBeTruthy(); expect(service).toBeTruthy();
})); }));
}); });

View file

@ -0,0 +1,14 @@
import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from './user';
import { UserService } from './user.service';
import * as firebase from 'firebase/app';
import 'firebase/firestore';
export class FirestoreUserService implements UserService {
getUsersByUsername(username: string): Observable<User[]> {
return Observable.create(subscriber => {
})
}
}