Ignore:
Timestamp:
11/16/20 03:55:10 (2 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
db484c9
Parents:
8b13eb2
Message:

Fix bugs, add some more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts

    r8b13eb2 r8e74e2f  
    99import { ActivatedRoute, Router } from '@angular/router';
    1010import { AuthService } from '../shared/services/auth.service';
     11import { AddMedicineDialogComponent } from '../dialogs/add-medicine-dialog/add-medicine-dialog.component';
     12import { ListMedicinesDialogComponent } from '../dialogs/list-medicines-dialog/list-medicines-dialog.component';
    1113
    1214@Component({
     
    2123  public filteredMedicines: IMedicine[] = [];
    2224  public request: IPharmacyHeadRequest;
     25  editedMedicine: boolean = false;
     26  medicinesEditMode: boolean = false;
    2327
    2428  constructor(private dataService: DataService, private authService: AuthService, private dialog: MatDialog, private snackBar: MatSnackBar, private router: Router, private route: ActivatedRoute) {
     
    3741        .subscribe((pharmacy: IPharmacy[]) => {
    3842          this.pharmacies = pharmacy;
     43          this.head.Pharmacy.forEach((pharma) => {
     44            this.filteredPharmacies = this.pharmacies = this.pharmacies.filter(x => x == pharma);
     45          });
    3946        },
    4047        (err: any) => console.log(err),
    4148        () => console.log('Pharmacy data retrieved'));
     49    this.filteredMedicines = this.head.PharmacyMedicines;
    4250  }
    4351 
     
    8391  deleteMedicine(medicine: IMedicine){
    8492    this.head.PharmacyMedicines = this.head.PharmacyMedicines.filter(x => x !== medicine);
     93    this.filteredMedicines = this.head.PharmacyMedicines;
     94    this.editedMedicine = true;
     95  }
     96 
     97  saveDeletedMedicines() {
    8598    this.dataService.updatePharmacyHead(this.head)
    86         .subscribe((hd: IPharmacyHead) => {
    87           if(hd) {
    88             this.openSnackBar("Success! Medicine deleted", "OK");
    89           }
    90           else {
    91             this.openSnackBar("Unable to delete Medicine", "Try again");
    92           }
    93         },
    94         (err: any) => console.log(err),
    95         () => console.log('Update sent!'));
     99      .subscribe((hd: IPharmacyHead) => {
     100        if(hd) {
     101          this.openSnackBar("Success! Medicine deleted", "OK");
     102          this.editedMedicine = false;
     103        }
     104        else {
     105          this.openSnackBar("Unable to delete Medicine", "Try again");
     106        }
     107      },
     108      (err: any) => console.log(err),
     109      () => console.log('Update sent!'));
    96110  }
    97111
     
    99113    console.log("applyFilterMedicines works!")
    100114    if(filterValue) {
    101       this.dataService.searchMedicines(filterValue)
    102           .subscribe((medicine: IMedicine[]) => {
    103             this.filteredMedicines = medicine;
    104           },
    105           (err: any) => console.log(err),
    106           () => console.log('Medicine data retrieved'));
     115      this.filteredMedicines = this.filteredMedicines.filter(x => x.name.toLocaleLowerCase().includes(filterValue.toLocaleLowerCase()));
    107116    }
    108117    else {
    109118      this.filteredMedicines = this.head.PharmacyMedicines;
     119    }
     120  }
     121
     122  addMedicine() {
     123    let dialogRef = this.dialog.open(AddMedicineDialogComponent, {
     124      width: 'auto'
     125    });
     126    dialogRef.afterClosed().subscribe((newMedicine: IMedicine) => {
     127      if(newMedicine){
     128        this.head.PharmacyMedicines.push(newMedicine);
     129        this.filteredMedicines = this.head.PharmacyMedicines;
     130        if(this.editedMedicine == false) {
     131          this.editedMedicine = true;
     132        }
     133        this.openSnackBar("Success! Medicine added, please save changes now", "OK");
     134      }
     135      else {
     136        this.openSnackBar("Failed! Please try again", "OK");
     137      }
     138    }, () => this.openSnackBar("Failed! Please try again", "OK"));
     139  }
     140
     141  addMedicinesFromList() {
     142    let dialogRef = this.dialog.open(ListMedicinesDialogComponent, {
     143      width: 'auto',
     144      height: 'auto'
     145    });
     146    dialogRef.afterClosed().subscribe((listMedicines: IMedicine[]) => {
     147      if(listMedicines){
     148        listMedicines.forEach((medicine) => {
     149          this.head.PharmacyMedicines = this.head.PharmacyMedicines.filter(x => x != medicine);
     150          this.head.PharmacyMedicines.push(medicine);
     151          this.filteredMedicines = this.head.PharmacyMedicines;
     152        });
     153        if(this.editedMedicine == false) {
     154          this.editedMedicine = true;
     155        }
     156        this.openSnackBar("Success! Medicines added, please save changes now", "OK");
     157      }
     158      else {
     159        this.openSnackBar("Failed! Please try again", "OK");
     160      }
     161    }, () => this.openSnackBar("Failed! Please try again", "OK"));
     162  }
     163
     164  switchEditMedicineMode() {
     165    this.medicinesEditMode = !this.medicinesEditMode;
     166    if(this.editedMedicine == false) {
     167      this.editedMedicine = true;
    110168    }
    111169  }
     
    117175          .subscribe((pharmacy: IPharmacy[]) => {
    118176            this.filteredPharmacies = pharmacy;
     177            this.head.Pharmacy.forEach((pharma) => {
     178              this.filteredPharmacies = this.filteredPharmacies.filter(x => x == pharma);
     179            });
    119180          },
    120181          (err: any) => console.log(err),
     
    123184    else {
    124185      this.filteredPharmacies = this.pharmacies;
    125     }   
     186    }
    126187  }
    127188
     
    138199
    139200  openEditPharmacyDialog(pharmacy: IPharmacy): void {
     201    console.log(pharmacy);
    140202    let dialogRef = this.dialog.open(EditPharmacyDialogComponent, {
    141203      width: '450px',
Note: See TracChangeset for help on using the changeset viewer.