WIP: Implement accounts
This commit is contained in:
parent
e7067744d9
commit
7c2e58cb11
6 changed files with 93 additions and 70 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -4186,11 +4186,13 @@
|
|||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
|
@ -4207,7 +4209,8 @@
|
|||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
|
@ -4336,6 +4339,7 @@
|
|||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
|
|
|
@ -7,69 +7,70 @@ import { UserService, USER_SERVICE } from 'src/app/users/user.service';
|
|||
import { User } from 'src/app/users/user';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-edit-account',
|
||||
templateUrl: './add-edit-account.component.html',
|
||||
styleUrls: ['./add-edit-account.component.css']
|
||||
selector: 'app-add-edit-account',
|
||||
templateUrl: './add-edit-account.component.html',
|
||||
styleUrls: ['./add-edit-account.component.css']
|
||||
})
|
||||
export class AddEditAccountComponent implements OnInit, OnDestroy, Actionable {
|
||||
@Input() title: string;
|
||||
@Input() account: Account;
|
||||
public users: User[];
|
||||
public searchedUsers: User[];
|
||||
@Input() title: string;
|
||||
@Input() account: Account;
|
||||
public users: User[];
|
||||
public searchedUsers: User[];
|
||||
|
||||
constructor(
|
||||
private app: AppComponent,
|
||||
@Inject(ACCOUNT_SERVICE) private accountService: AccountService,
|
||||
@Inject(USER_SERVICE) private userService: UserService,
|
||||
) {
|
||||
this.app.title = this.title;
|
||||
this.app.backEnabled = true;
|
||||
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
|
||||
);
|
||||
constructor(
|
||||
private app: AppComponent,
|
||||
@Inject(ACCOUNT_SERVICE) private accountService: AccountService,
|
||||
@Inject(USER_SERVICE) private userService: UserService,
|
||||
) {
|
||||
this.app.title = this.title;
|
||||
this.app.backEnabled = true;
|
||||
this.app.actionable = this;
|
||||
}
|
||||
// TODO: Check if it was actually successful or not
|
||||
observable.subscribe(val => {
|
||||
this.app.goBack();
|
||||
});
|
||||
}
|
||||
|
||||
getActionLabel(): string {
|
||||
return 'Save';
|
||||
}
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
delete(): void {
|
||||
this.accountService.deleteAccount(this.account.id);
|
||||
this.app.goBack();
|
||||
}
|
||||
ngOnDestroy(): void {
|
||||
this.app.actionable = null;
|
||||
}
|
||||
|
||||
searchUsers(username: string) {
|
||||
this.userService.getUsersByUsername(username).subscribe(users => {
|
||||
this.searchedUsers = users;
|
||||
});
|
||||
}
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
clearUserSearch() {
|
||||
this.searchedUsers = [];
|
||||
}
|
||||
getActionLabel(): string {
|
||||
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 = [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
<p>
|
||||
new-account works!
|
||||
</p>
|
||||
<app-add-edit-account [title]="'Add Account'" [account]="account"></app-add-edit-account>
|
|
@ -1,15 +1,20 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { Account } from '../account';
|
||||
|
||||
@Component({
|
||||
selector: 'app-new-account',
|
||||
templateUrl: './new-account.component.html',
|
||||
styleUrls: ['./new-account.component.css']
|
||||
selector: 'app-new-account',
|
||||
templateUrl: './new-account.component.html',
|
||||
styleUrls: ['./new-account.component.css']
|
||||
})
|
||||
export class NewAccountComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
public account: Account;
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
constructor() {
|
||||
this.account = new Account();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { UserService } from './user.service';
|
||||
import { FirestoreUserService } from './user.service.firestore';
|
||||
|
||||
describe('UserService', () => {
|
||||
beforeEach(() => {
|
||||
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();
|
||||
}));
|
||||
});
|
14
src/app/users/user.service.firestore.ts
Normal file
14
src/app/users/user.service.firestore.ts
Normal 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 => {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue