diff options
Diffstat (limited to 'ufund-ui/src/app/components/cupboard')
3 files changed, 125 insertions, 191 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index fe4971a..e45d929 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -1,21 +1,54 @@  :host { -    display: block; -    border: 2px solid #000; -    border-radius: 5px; -    padding: 10px 20px; +    display: flex; +    justify-content: center;  } -#menu, #create-form, #delete-form, #update-form { -   background-color: #d9d9d9; +#box { +    width: 800px; +    display: flex; +    flex-direction: column; +} + +#menu { +      display: flex; + +      margin: 10px; + +} + +.tab, .selected-tab { +   background-color: lightgray; +   border: 3px solid #000; +   border-top-left-radius: 5px; +   border-top-right-radius: 5px; +   margin-right: 5px; +   border-bottom: 0; +} + +.selected-tab { +   background-color: white; +} + +#create-form, #delete-form, #update-form { +   background-color: #3a3a3a;     padding: 10px 20px 20px 20px;     border: 2px solid #000; -   border-radius: 5px;   -   width: 20%; +   border-radius: 5px;     visibility: visible; - +    /*position: absolute;*/  } -#create-button { -   padding: 10px 20px; -    -}
\ No newline at end of file +#header { +    display: flex; +    gap: 20px; +    align-items: center; + +    h1 { +        display: inline; +        width: min-content; +    } + +    button { +        margin-top: 3px; +    } +} diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 0d64475..37954bb 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,50 +1,38 @@ -<h1> Cupboard </h1> -<h2 *ngIf="isManager()" > Admin View </h2> -<div id="menu" *ngIf="isManager()"> -    <button (click)="opencreate()">Create new Need</button> -    <button (click)="openupdate()">Update existing Need</button> +<div id="box"> +    <div id="header"> +        <h1> Cupboard </h1> +        <button *ngIf="isManager()" class="button2" (click)="this.selectForm('create')"><span class="icon">add</span>Create Need</button> +    </div> +    <app-need-list (currentNeed) = populateForm($event) #needList></app-need-list>  </div> -<div id="create-form"> -    <h1> Create a new need </h1> -    <form #cupboardForm="ngForm" (ngSubmit)="submit(cupboardForm.value)"> -        <label>Name:</label><br> -        <input type="text" name="name" ngModel><br> -        <label>Max Goal:</label><br> -        <input type="number" name="maxGoal" ngModel><br> -        <label>Type</label><br> -        <input type="radio" name="type" value="MONETARY" ngModel> -        <label>Monetary</label><br> -        <input type="radio" name="type" value="PHYSICAL" ngModel> -        <label>Physical</label><br> -        <input type="submit" value="Submit"> -    </form> -    <button (click)="back()">Close</button> -    <span *ngIf="statusText">‼️{{statusText | async}}</span> +<ng-template [ngIf]="isManager()" > +<div> +    <app-need-edit *ngIf="selectedForm === 'update'" [selectedNeed]="selectedNeed" (refreshNeedList)="needList.refresh()"></app-need-edit> +    <div> +    <div id="create-form" *ngIf="selectedForm === 'create'"> +        <h1> Create Need </h1> +        <form #cupboardForm="ngForm" (ngSubmit)="submit(cupboardForm.value)"> +            <label>Name:</label><br> +            <input type="text" name="name" ngModel><br> +            <label>Image:</label><br> +            <input type="text" name="image" ngModel><br> +            <label>Location:</label><br> +            <input type="text" name="location" ngModel><br> +            <label>Max Goal:</label><br> +            <input type="number" name="maxGoal" ngModel><br> +            <label>Type</label><br> +            <input type="radio" name="type" value="MONETARY" ngModel> +            <label>Monetary</label><br> +            <input type="radio" name="type" value="PHYSICAL" ngModel> +            <label>Physical</label><br> +            <input type="checkbox" name="urgent" value="false" ngModel> +            <label>Urgent</label><br> +            <label>Description</label><br> +            <textarea name="description"></textarea><br> +            <input type="submit" value="Submit"> +        </form> +    </div> +    </div>  </div> -<div id="update-form"> -    <h1> Update a need </h1> -    <label>Needs:</label><br> -    <form #updateForm="ngForm" (ngSubmit)="update(updateForm.value)"> -        <div *ngFor="let need of needs"> - -            <input type="radio" name="id" [value]=need.id [(ngModel)]="selectedNeedId" (change)="populateForm(need)"> -            <label name="template">{{need.name}}</label><br> -        </div> -        <label>Name:</label><br> -        <input type="text" name="name" [(ngModel)]="selectedNeed.name"><br> -        <label>Max Goal:</label><br> -        <input type="number" name="maxGoal" [(ngModel)]="selectedNeed.maxGoal"><br> -        <label>Type</label><br> -        <input type="radio" name="type" value="MONETARY" [(ngModel)]="selectedNeed.type"> -        <label>Monetary</label><br> -        <input type="radio" name="type" value="PHYSICAL" [(ngModel)]="selectedNeed.type"> -        <label>Physical</label><br> -        <input type="submit" value="Submit"> -    </form> -    <button (click)="back()">Close</button> -    <span *ngIf="statusText">{{statusText | async}}</span> - -</div> -<hr> -<app-need-list #needList></app-need-list> +</ng-template> diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 24b3e2d..2230cd3 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,10 +1,11 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import {Component, OnInit, ViewChild} from '@angular/core';  import { CupboardService } from '../../services/cupboard.service'; -import { UsersService } from '../../services/users.service';  import { Need, GoalType } from '../../models/Need';  import { userType } from '../../models/User'; -import { BehaviorSubject, catchError, of } from 'rxjs'; +import { catchError, of } from 'rxjs';  import { NeedListComponent } from '../need-list/need-list.component'; +import {AuthService} from '../../services/auth.service'; +import {ToastsService, ToastType} from '../../services/toasts.service';  @Component({      selector: 'app-cupboard', @@ -15,18 +16,18 @@ import { NeedListComponent } from '../need-list/need-list.component';  export class CupboardComponent implements OnInit { -    protected statusText = new BehaviorSubject("") - +    selectedForm?: string = undefined;      needs: any;      @ViewChild("needList") needList?: NeedListComponent -    constructor(private cupboardService: CupboardService, private usersService: UsersService) { } +    constructor( +        private cupboardService: CupboardService, +        private authService: AuthService, +        private toastService: ToastsService +    ) {}      ngOnInit(): void {          this.cupboardService.getNeeds().subscribe(n => this.needs = n); -        this.close(); -        this.openmenu(); -          if (this.isManager()) {              console.log("Admin view of Cupboard");          } else { @@ -36,117 +37,74 @@ export class CupboardComponent implements OnInit {      selectedNeed: any = {          name: '', +        location:'',          id: null,          maxGoal: null, -        type: '' +        type: '', +        urgent: false      };      selectedNeedId: number | null = null; +    searchResults: any[] = []; -    private hideElement(element: any) { -        if (element) { -            element.style.visibility = 'hidden'; -            element.style.position = 'absolute'; +    selectForm(name: string) { +        //get search results from the need list +        if (this.needList) { +            this.searchResults = this.needList.searchResults;          } -    } +        console.log(this.searchResults) +        this.selectedForm = name; +        if (name == 'update') { +            if (this.searchResults) { +                this.searchResults.forEach((element: any) => { +                    console.log(element) +                }); +            } -    private showElement(element: any) { -        if (element) { -            element.style.visibility = 'visible'; -            element.style.position = 'relative';          }      } -    openmenu() { -        const menuElement = document.getElementById('menu'); -        this.showElement(menuElement); -    } - -    opencreate() { -        this.close(); -        this.showElement(document.getElementById('create-form')); -    } - -    openupdate() { -        this.close(); -        this.showElement(document.getElementById('update-form')); -    } - -    back() { -        this.close(); -        this.openmenu(); -    } - -    close() { -        this.hideElement(document.getElementById('create-form')); -        this.hideElement(document.getElementById('destroy-form')); -        this.hideElement(document.getElementById('menu')); -        this.hideElement(document.getElementById('update-form')); +    async updateSearchResults() { +        if (this.needList) { +            while (this.selectedForm == 'update') { +                this.searchResults = this.needList.searchResults +                await new Promise(resolve => setTimeout(resolve, 100)); +            } +        }      }      populateForm(need: any): void { +        this.selectForm('update');          this.selectedNeed = { ...need };      }      isManager() { -        const type = this.usersService.getCurrentUser()?.type; +        const type = this.authService.getCurrentUser()?.type;          return type === ("MANAGER" as unknown as userType);      } -    update(form: any) { -        console.log(form); -        const need: Need = { -            name: form.name, -            id: form.id, //system will control this -            maxGoal: form.maxGoal, -            type: GoalType[form.type as keyof typeof GoalType], -            filterAttributes: [], -            current: 0 -        }; -        console.log("need:", need); -        console.log(need.id, need, "need updated"); -        this.cupboardService.updateNeed(need.id, need) -            .pipe(catchError((ex, r) => { -                if (ex.status == 500) { -                    this.statusText.next("Fields cannot be blank"); -                } else if (ex.status == 400) { -                    this.statusText.next("Goal must be greater than 0"); -                } else { -                    this.statusText.next("Error on creating need"); -                } -                return of() -            })) -            .subscribe( -                (result) => { -                    if (result) { -                        console.log("need updated successfully"); -                        this.needList?.refresh() -                    } else { -                        console.log("need update failed"); -                    } -                } - -            ); -    } -      submit(form: any) {          const need: Need = {              name: form.name, +            image: form.image, +            location: form.location,              id: 0,              maxGoal: form.maxGoal,              type: form.type, +            urgent: form.urgent ? true : false,              filterAttributes: [], -            current: 0 +            current: 0, +            description: form.description          };          console.log("need:", need);          console.log("form submitted. creating need: ", need);          this.cupboardService.createNeed(need) -            .pipe(catchError((ex, r) => { +            .pipe(catchError((ex, _) => {                  if (ex.status == 500) { -                    this.statusText.next("Fields cannot be blank"); +                    this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank");                  } else if (ex.status == 400) { -                    this.statusText.next("Goal must be greater than 0"); +                    this.toastService.sendToast(ToastType.ERROR, ex.error);                  } else { -                    this.statusText.next("Error on creating need"); +                    this.toastService.sendToast(ToastType.ERROR, "Error on creating need");                  }                  return of()              })) @@ -167,48 +125,3 @@ export class CupboardComponent implements OnInit {      }  } - -let friendlyHttpStatus: { [key: number]: string } = { -    200: 'OK', -    201: 'Created', -    202: 'Accepted', -    203: 'Non-Authoritative Information', -    204: 'No Content', -    205: 'Reset Content', -    206: 'Partial Content', -    300: 'Multiple Choices', -    301: 'Moved Permanently', -    302: 'Found', -    303: 'See Other', -    304: 'Not Modified', -    305: 'Use Proxy', -    306: 'Unused', -    307: 'Temporary Redirect', -    400: 'Bad Request', -    401: 'Unauthorized', -    402: 'Payment Required', -    403: 'Forbidden', -    404: 'Not Found', -    405: 'Method Not Allowed', -    406: 'Not Acceptable', -    407: 'Proxy Authentication Required', -    408: 'Request Timeout', -    409: 'Conflict', -    410: 'Gone', -    411: 'Length Required', -    412: 'Precondition Required', -    413: 'Request Entry Too Large', -    414: 'Request-URI Too Long', -    415: 'Unsupported Media Type', -    416: 'Requested Range Not Satisfiable', -    417: 'Expectation Failed', -    418: 'I\'m a teapot', -    422: 'Unprocessable Entity', -    429: 'Too Many Requests', -    500: 'Internal Server Error', -    501: 'Not Implemented', -    502: 'Bad Gateway', -    503: 'Service Unavailable', -    504: 'Gateway Timeout', -    505: 'HTTP Version Not Supported', -};  | 
