diff --git a/src/app/budgets/add-edit-budget/add-edit-budget.component.html b/src/app/budgets/add-edit-budget/add-edit-budget.component.html index 54cf0fb..c6e6073 100644 --- a/src/app/budgets/add-edit-budget/add-edit-budget.component.html +++ b/src/app/budgets/add-edit-budget/add-edit-budget.component.html @@ -1,7 +1,8 @@ -
+ +

Select a budget from the list to view details about it or edit it.

-
+
diff --git a/src/app/budgets/add-edit-budget/add-edit-budget.component.ts b/src/app/budgets/add-edit-budget/add-edit-budget.component.ts index 7ff64df..2bcb582 100644 --- a/src/app/budgets/add-edit-budget/add-edit-budget.component.ts +++ b/src/app/budgets/add-edit-budget/add-edit-budget.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, Input, Inject, OnDestroy } from '@angular/core'; import { Budget } from '../budget'; import { AppComponent } from 'src/app/app.component'; -import { User } from 'src/app/users/user'; +import { User, UserPermission, Permission } from 'src/app/users/user'; import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; @Component({ @@ -12,8 +12,9 @@ import { TWIGS_SERVICE, TwigsService } from 'src/app/shared/twigs.service'; export class AddEditBudgetComponent { @Input() title: string; @Input() budget: Budget; - public userIds: number[]; + public users: UserPermission[]; public searchedUsers: User[] = []; + public isLoading = false; constructor( private app: AppComponent, @@ -21,11 +22,12 @@ export class AddEditBudgetComponent { ) { this.app.title = this.title; this.app.backEnabled = true; - this.userIds = [this.app.user.id]; + this.users = [new UserPermission(this.app.user.id, Permission.OWNER)]; } save(): void { let observable; + this.isLoading = true; if (this.budget.id) { // This is an existing transaction, update it observable = this.twigsService.updateBudget(this.budget.id, this.budget); @@ -34,7 +36,7 @@ export class AddEditBudgetComponent { observable = this.twigsService.createBudget( this.budget.name, this.budget.description, - this.userIds + this.users ); } // TODO: Check if it was actually successful or not @@ -44,6 +46,7 @@ export class AddEditBudgetComponent { } delete(): void { + this.isLoading = true; this.twigsService.deleteBudget(this.budget.id); this.app.goBack(); } diff --git a/src/app/shared/twigs.http.service.ts b/src/app/shared/twigs.http.service.ts index bc2f19e..4312bb4 100644 --- a/src/app/shared/twigs.http.service.ts +++ b/src/app/shared/twigs.http.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'; import { Observable, Subscriber } from 'rxjs'; -import { User } from '../users/user'; +import { User, UserPermission, Permission } from '../users/user'; import { TwigsService } from './twigs.service'; import { Budget } from '../budgets/budget'; import { Category } from '../categories/category'; @@ -43,7 +43,7 @@ export class TwigsHttpService implements TwigsService { } logout(): Observable { - return this.http.post(this.apiUrl + '/logout', this.options); + return this.http.post(this.apiUrl + '/login?logout', this.options); } // Budgets @@ -58,12 +58,17 @@ export class TwigsHttpService implements TwigsService { createBudget( name: string, description: string, - userIds: number[], + users: UserPermission[], ): Observable { const params = { 'name': name, 'description': description, - 'userIds': userIds + 'users': users.map(user => { + return { + user: user.user, + permission: Permission[user.permission] + }; + }) }; return this.http.post(this.apiUrl + '/budgets/new', params, this.options); } diff --git a/src/app/shared/twigs.local.service.ts b/src/app/shared/twigs.local.service.ts index adccd88..46da74a 100644 --- a/src/app/shared/twigs.local.service.ts +++ b/src/app/shared/twigs.local.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'; import { Observable, Subscriber } from 'rxjs'; -import { User } from '../users/user'; +import { User, UserPermission } from '../users/user'; import { TwigsService } from './twigs.service'; import { Budget } from '../budgets/budget'; import { Category } from '../categories/category'; @@ -82,14 +82,14 @@ export class TwigsLocalService implements TwigsService { createBudget( name: string, description: string, - userIds: number[], + users: UserPermission[], ): Observable { return Observable.create(subscriber => { const budget = new Budget(); budget.name = name; budget.description = description; budget.users = this.users.filter(user => { - return userIds.indexOf(user.id) > -1; + return users.map(userPerm => userPerm.user).indexOf(user.id) > -1; }); budget.id = this.budgets.length + 1; this.budgets.push(budget); diff --git a/src/app/shared/twigs.service.ts b/src/app/shared/twigs.service.ts index c37a09d..db0c726 100644 --- a/src/app/shared/twigs.service.ts +++ b/src/app/shared/twigs.service.ts @@ -1,6 +1,6 @@ import { InjectionToken } from '@angular/core'; import { Observable } from 'rxjs'; -import { User } from '../users/user'; +import { User, UserPermission } from '../users/user'; import { Budget } from '../budgets/budget'; import { Category } from '../categories/category'; import { Transaction } from '../transactions/transaction'; @@ -17,7 +17,7 @@ export interface TwigsService { createBudget( name: string, description: string, - userIds: number[], + users: UserPermission[], ): Observable; updateBudget(id: number, changes: object): Observable; deleteBudget(id: number): Observable; diff --git a/src/app/users/login/login.component.html b/src/app/users/login/login.component.html index 5e1dc93..508272d 100644 --- a/src/app/users/login/login.component.html +++ b/src/app/users/login/login.component.html @@ -1,9 +1,10 @@ -