diff options
Diffstat (limited to 'ufund-ui/src/app/components/dashboard')
3 files changed, 37 insertions, 8 deletions
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.css b/ufund-ui/src/app/components/dashboard/dashboard.component.css index e69de29..9db015e 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.css +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.css @@ -0,0 +1,7 @@ +:host { +    display: flex; +    flex-direction: column; +    width: 1200px; +    align-self: center; +    gap: 20px +} diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index a1151b7..330d1f3 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -1,4 +1,5 @@ -<h1>Dashboard</h1> -<app-cupboard></app-cupboard> -<app-funding-basket *ngIf="!isManager()"></app-funding-basket>
\ No newline at end of file +<h1>Your Dashboard</h1> +<app-mini-need-list [needList]="topNeeds" jtitle="Top needs" url="/cupboard"/> +<app-mini-need-list [needList]="almostThere" jtitle="Almost there" url="/cupboard"/> +<app-mini-need-list [needList]="inBasket" jtitle="In your basket" url="/cupboard"/> diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index a0ad566..165c7ba 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -1,6 +1,11 @@ -import {Component} from '@angular/core'; +import {Component, OnInit} from '@angular/core';  import {userType} from '../../models/User';  import {AuthService} from '../../services/auth.service'; +import {Router} from '@angular/router'; +import {Need} from '../../models/Need'; +import {CupboardService} from '../../services/cupboard.service'; +import {UsersService} from '../../services/users.service'; +import {firstValueFrom} from 'rxjs';  @Component({      selector: 'app-dashboard', @@ -8,14 +13,30 @@ import {AuthService} from '../../services/auth.service';      templateUrl: './dashboard.component.html',      styleUrl: './dashboard.component.css'  }) -export class DashboardComponent { +export class DashboardComponent implements OnInit{ + +    topNeeds?: Need[] +    almostThere?: Need[] +    inBasket?: Need[] +      constructor(          protected authService: AuthService, +        protected router: Router, +        protected cupboardService: CupboardService      ) {} -    isManager() { -        const type = this.authService.getCurrentUser()?.type; -        return type === ("MANAGER" as unknown as userType); +    ngOnInit() { +        let user = this.authService.getCurrentUser() +        if(!user) { +            this.router.navigate(['/login']) +            return +        } + +        firstValueFrom(this.cupboardService.getNeeds()).then(r => { +            this.topNeeds = r.sort((a, b) => b.current - a.current) +            this.almostThere = r.sort((a, b) => a.current/a.maxGoal - b.current/b.maxGoal) +            this.inBasket = r.filter(n => n.id in user?.basket) +        })      }  }  | 
