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

Location:
trip-planner-front/src/app
Files:
7 edited

Legend:

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

    re29cc2e r8d391a1  
    5555        return this.httpClient.get<Location[]>(url + "?plannerId=" + id);
    5656    }
     57
     58    getAllLocationIdsForPlanner(id:number):Observable<number[]>{
     59        let url = "http://localhost:8080/api/planner/locationIds";
     60        return this.httpClient.get<number[]>(url + "?plannerId="+id);
     61    }
    5762   
    5863}
  • trip-planner-front/src/app/create-initial-planner/create-initial-planner.component.html

    re29cc2e r8d391a1  
    1 <form (ngSubmit)="onFormSubmitPlanner(f)" #f="ngForm">
     1<form (ngSubmit)="onFormSubmitPlanner(f)" #f="ngForm" >
    22  <div mat-dialog-content>
    33    <p>Planner name</p>
  • trip-planner-front/src/app/location/add-location-to-planner-panel/add-location-to-planner-panel.component.html

    re29cc2e r8d391a1  
    77        </tr>
    88    </ng-template>
    9     <ng-template pTemplate="body" let-planner>
     9    <ng-template pTemplate="body" let-planner let-data>
    1010        <tr>
    1111            <td>{{planner.name}}</td>
    12 
    1312            <td>
    14                 <button pButton pRipple type="button" icon="pi pi-heart"
    15                     class="p-button-rounded p-button-help p-button-text" (click)="selectPlanner(planner)"></button>
     13                <button pButton pRipple type="button" icon="pi pi-heart" class="p-button-rounded p-button-help"
     14                    (click)="selectPlanner(planner)" ></button>
    1615            </td>
    1716        </tr>
  • trip-planner-front/src/app/location/add-location-to-planner-panel/add-location-to-planner-panel.component.ts

    re29cc2e r8d391a1  
    44import { PlannerService } from 'src/app/_services/planner.service';
    55import { DynamicDialogRef } from 'primeng/dynamicdialog';
    6 
    7 
     6import { LocationService } from 'src/app/_services/location.service';
     7import { Location } from 'src/app/_models/location';
     8import { PlannerLocationDto } from 'src/app/_models/dto/plannerLocationDto';
    89
    910
     
    1617
    1718  planners: Planner[];
    18 
    19 
    20 
     19 
    2120  constructor(private plannerService: PlannerService,
    22     private route: ActivatedRoute, private ref: DynamicDialogRef) {
     21    private route: ActivatedRoute, private ref: DynamicDialogRef, private locationService : LocationService) {
    2322    this.planners = [];
    2423  }
     
    3130      }
    3231    );
     32
    3333  }
    3434
     
    3737  }
    3838
    39 
    40 
    4139}
  • trip-planner-front/src/app/location/location-details/location-details.component.html

    re29cc2e r8d391a1  
    33<p>{{locationDetails.description}}</p>
    44
    5 
    65<div class="content-section implementation">
    76    <div class="card">
    8         <h5>More photos</h5>
    97        <p-galleria [value]="images" [responsiveOptions]="responsiveOptions" [containerStyle]="{'max-width': '640px'}"
    10             [numVisible]="5" [circular]="true" [showItemNavigators]="true">
     8            [numVisible]="5" [circular]="true" [showItemNavigators]="true" [showThumbnails]="false">
    119            <ng-template pTemplate="item" let-image>
    1210                <img src="data:image/png;base64,{{image.content}}"
     
    1614                <div class="p-grid p-nogutter p-justify-center">
    1715                    <img src="data:image/png;base64,{{image.content}}"
    18                         style=" height:50px; display: block;" />
     16                        style=" display: block;" />
    1917                </div>
    2018            </ng-template>
    2119        </p-galleria>
    2220    </div>
    23 
     21</div>
  • 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}
  • trip-planner-front/src/app/locations-form/locations-form.component.ts

    re29cc2e r8d391a1  
    6868
    6969  ngOnInit(): void {
    70  
     70
    7171    this.filteredOptions = this.myControl.valueChanges
    7272      .pipe(
     
    140140          console.log(result);
    141141          this.proba = result;
    142           this.router.navigate(['locations'], {queryParams: {cityId: this.cityId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds}});
     142          this.router.navigate(['locations'], { queryParams: { cityId: this.cityId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds } });
    143143        }
    144144      );
     
    148148          result => {
    149149            console.log(result);
    150             this.router.navigate(['locations'], {queryParams: {regionId: this.regionId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds}});
     150            this.router.navigate(['locations'], { queryParams: { regionId: this.regionId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds } });
    151151          }
    152152        );
Note: See TracChangeset for help on using the changeset viewer.