Ignore:
Timestamp:
11/26/21 20:07:18 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
1ad8e64
Parents:
e29cc2e
Message:

disabling to add location if it already exists in the planner

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/location/location.component.ts

    re29cc2e r8d391a1  
    11import { Component, OnInit } from '@angular/core';
    2 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
    32import { ActivatedRoute, Router } from '@angular/router';
    4 import { MessageService, PrimeNGConfig } from 'primeng/api';
     3import { MessageService } from 'primeng/api';
    54import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
    65import { Planner } from '../_models/planner';
     
    3029  plannerLocationDto: PlannerLocationDto;
    3130  ref: DynamicDialogRef;
    32 
     31  locationIdsPlanner: number[];
    3332
    3433
     
    4241    this.regionId = 1;
    4342    this.locationId = 1;
    44     this.ref = new DynamicDialogRef;
     43    this.ref = new DynamicDialogRef();
    4544    this.plannerLocationDto = new PlannerLocationDto();
    46 
     45    this.locationIdsPlanner = [];
    4746  }
    4847
     
    8584
    8685  show(location: Location) {
     86    console.log(location.id);
    8787    this.ref = this.dialogService.open(AddLocationToPlannerPanelComponent, {
    8888      header: 'Choose a Planner',
     
    9393
    9494    this.ref.onClose.subscribe((planner: Planner) => {
    95 
    9695      this.plannerLocationDto.locationId = location.id;
    9796      this.plannerLocationDto.plannerId = planner.id;
    9897      console.log("LOC ID: " + this.plannerLocationDto.locationId);
    9998      console.log("PLANNER ID: " + this.plannerLocationDto.plannerId);
    100       this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
    101         data => {
    102           console.log(data);
     99
     100      this.locationService.getAllLocationIdsForPlanner(planner.id).subscribe(
     101        lid => {
     102          if (lid.length == 0) {
     103            this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
     104              data => {
     105                console.log(data);
     106              }
     107            );
     108            this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ', detail: planner.name });
     109
     110          } else if (lid.length > 0) {
     111            if (lid.indexOf(this.plannerLocationDto.locationId) !== -1) {
     112              console.log("LOKACIJATA VEKE JA IMA VO PLANEROT");
     113              this.messageService.add({ severity: 'error', summary: 'Location ' + location.name + ' already exists in the planner.' });
     114            } else {
     115              this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
     116                data => {
     117                  console.log(data);
     118                }
     119              );
     120              this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ', detail: planner.name });
     121            }
     122
     123          }
    103124        }
    104125      );
    105       if (planner) {
    106         this.messageService.add({ severity: 'success', summary: 'Location ' + location.name +  ' has been added to planner: ' , detail: planner.name });
    107       }
     126
     127
    108128    });
    109129  }
     
    115135  }
    116136
    117   onClickBackToMyPlanners(){
     137  onClickBackToMyPlanners() {
    118138    this.router.navigate(['planners']);
    119139  }
     140
     141
    120142}
Note: See TracChangeset for help on using the changeset viewer.