Changeset eed0bf8


Ignore:
Timestamp:
10/18/21 00:19:16 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
188ee53
Parents:
fa375fe
Message:

editing location-form on frontend and backend

Files:
151 added
7 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/locations-form/locations-form.component.html

    rfa375fe reed0bf8  
    11<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
    22
    3 <form class="example-form">
    4   <label><h5>Please select a place</h5></label>
     3<div class="example-form">
     4
     5  <div class="d-block">
     6    <button class="btn" (click)="chooseCityOption()" >
     7      City
     8    </button>
     9    <button class="btn" (click)="chooseRegionOption()">
     10      Region
     11    </button>
     12  </div>
     13  <br>
     14  <br>
     15  <!--
    516  <mat-form-field class="example-full-width" appearance="fill">
    617    <mat-label>Please select a place</mat-label>
     
    1728    </mat-autocomplete>
    1829  </mat-form-field>
     30  -->
     31
     32
     33  <div *ngIf="cityOption">
     34    <label><h5>Please select a city</h5></label>
     35    <mat-form-field appearance="fill" class="example-full-width">
     36      <mat-label>Please select a city</mat-label>
     37      <mat-select [(ngModel)]="locationId" placeholder="Select city">
     38        <mat-option [value]="city.id" *ngFor="let city of cities" [value]="city.id"> {{city.name}}</mat-option>
     39      </mat-select>
     40    </mat-form-field>
     41  </div>
     42
     43  <div *ngIf="regionOption">
     44    <label><h5>Please select a region</h5></label>
     45    <mat-form-field appearance="fill" class="example-full-width">
     46      <mat-label>Please select a region</mat-label>
     47      <mat-select [(ngModel)]="regionId" placeholder="Select region">
     48        <mat-option [value]="region.id" *ngFor="let region of regions" [value]="region.id"> {{region.name}}</mat-option>
     49      </mat-select>
     50    </mat-form-field>
     51  </div>
    1952
    2053  <h5>Who are you travelling with?  </h5>
    2154  <mat-form-field appearance="fill" class="example-full-width">
    2255    <mat-label>Please select a companion</mat-label>
    23     <mat-select [disabled]="disableSelect.value">
    24       <mat-option value="option1" *ngFor="let companion of companions">{{companion.type}}</mat-option>
     56    <mat-select [(ngModel)]="companionId" placeholder="Please select a companion">
     57      <mat-option [value]="companion.id" *ngFor="let companion of companions">{{companion.type}}</mat-option>
    2558    </mat-select>
    2659  </mat-form-field>
     
    2962  <mat-form-field class="example-full-width" appearance="fill">
    3063    <mat-label>Please select a number of days</mat-label>
    31     <input matInput placeholder="No. Dys"  type="number">
     64    <input matInput placeholder="No. Days"  type="number" [(ngModel)]="lengthOfStay">
    3265  </mat-form-field>
    3366
    3467   <h5>What are your priorities to visit?</h5>
    3568  <mat-chip-list  selectable multiple>
    36     <mat-chip #c="matChip" color="accent" selected *ngFor="let category of categories"
    37     (click)="toggleSelection(c)">
    38   <mat-icon *ngIf="c.selected">check</mat-icon>
     69    <mat-chip #c="matChip" selected *ngFor="let category of categories"
     70    (click)="toggleSelection(c, category)" >
     71  <mat-icon *ngIf="!c.selected" >check</mat-icon>
    3972  {{category.name}}
    4073  </mat-chip>
    4174  </mat-chip-list>
    42   <button mat-raised-button color="primary">Create my planner</button>
    43 </form>
     75  <button mat-raised-button color="primary" (click)="createMyPlanner()">Create my planner</button>
     76
     77
     78</div>
     79 
  • trip-planner-front/src/app/locations-form/locations-form.component.ts

    rfa375fe reed0bf8  
    1313import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
    1414import { MatChip } from '@angular/material/chips';
     15import { LocationService } from '../_services/location.service';
     16import { Region } from '../_models/region';
     17import { RegionService } from '../_services/region.service';
    1518
    1619@Component({
     
    2326  myControl = new FormControl();
    2427  cities: City[];
    25   countries: Country[];
     28  regions: Region[];
    2629  companions: Companion[];
    2730  categories: Category[];
    2831  filteredOptions: Observable<City[]>;
    2932  disableSelect = new FormControl(false);
     33  chipsSeletion: number[];
     34  categoryIds: string;
     35  locationId: number;
     36  regionId: number;
     37  companionId: number;
     38  lengthOfStay: number;
     39  cityOption: boolean = false;
     40  regionOption: boolean = false;
    3041
    31   constructor(private cityService : CityService, private countryService : CountryService,
    32               private companionService : CompanionService, private categoryService : CategoryService){
     42  constructor(private cityService : CityService, private regionService: RegionService,
     43              private companionService : CompanionService, private categoryService : CategoryService,
     44              private locationService: LocationService){
    3345    this.filteredOptions = new Observable<City[]>();
    3446    this.cities = [];
    35     this.countries = [];
     47    this.regions = [];
    3648    this.companions = [];
    3749    this.categories = [];
     50    this.chipsSeletion = [];
     51    this.locationId = 0;
     52    this.companionId = 0;
     53    this.lengthOfStay = 1;
     54    this.categoryIds = '';
     55    this.regionId = 0;
    3856  }
    3957 
     
    4563        return this.filter(val || '')
    4664      })       
     65    );
     66
     67    this.cityService.getAllCities().subscribe(
     68      data => {
     69        this.cities = data;
     70      }
     71    );
     72
     73    this.regionService.getAllRegions().subscribe(
     74      data => {
     75        this.regions = data;
     76      }
    4777    );
    4878
     
    71101 } 
    72102
    73  toggleSelection(chip: MatChip){
    74    chip.toggleSelected();
     103 toggleSelection(chip: MatChip, category: Category){
     104  chip.toggleSelected();
     105  if(this.chipsSeletion.length > 0){
     106    if(this.chipsSeletion.indexOf(category.id) <= -1){
     107      this.chipsSeletion.push(category.id);
     108    }else{
     109      const index = this.chipsSeletion.indexOf(category.id);
     110      this.chipsSeletion.splice(index, 1);
     111    }
     112  }else{
     113    this.chipsSeletion.push(category.id);
     114  }
     115  console.log(this.chipsSeletion);
    75116 }
    76117
     118
     119 createMyPlanner(){
     120   this.categoryIds = this.chipsSeletion.join(',');
     121   console.log(this.companionId);
     122   this.locationService.getAllPlaces(this.locationId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     123     result => {
     124       console.log(result);
     125     }
     126   );
     127 }
     128 chooseCityOption(){
     129   this.cityOption = true;
     130   this.regionOption = false;
     131 }
     132  chooseRegionOption() {
     133    this.regionOption = true;
     134    this.cityOption = false;
     135  }
    77136}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java

    rfa375fe reed0bf8  
    4444            "GROUP BY l.id_location ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
    4545    List<Location> findLocationsFromCountry(@Param("locName") String ime, @Param("companion") String companion, @Param("region") String region, @Param("categories") List<String> categories);
     46
     47    @Query(value = "SELECT  * FROM locations AS l  " +
     48            "LEFT JOIN recommended_companion AS rc ON l.id_location = rc.id_location " +
     49            "LEFT JOIN companions AS com ON rc.id_companion = com.id_companion " +
     50            "LEFT JOIN locations_belong lb ON l.id_location = lb.id_location " +
     51            "LEFT JOIN categories AS cate ON lb.id_category = cate.id_category " +
     52            "LEFT JOIN regions AS r" +
     53            " ON l.id_region = r.id_region" +
     54            " LEFT JOIN cities AS cit" +
     55            " ON r.id_region = cit.id_region AND cit.id_city = l.id_city " +
     56            "WHERE cit.id_city = :locationId and com.id_companion = :companionId and cate.id_category in (:categories) " +
     57            "GROUP BY l.id_location " +
     58            "ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
     59    List<Location> findLocationsFromForm(@Param("locationId") Long locationId, @Param("companionId") Long companionId, @Param("categories") List<Long> categories);
    4660}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java

    rfa375fe reed0bf8  
    1515    List<Location> scheduleLocations(String locName, String companion,String region, List<String> categories, int numberOfDays);
    1616    Optional<Location> findById(Long id);
     17
     18    List<Location> findLocations(Long locationId, Long companionId, Long lengthOfStay, String categoryIds);
    1719}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    rfa375fe reed0bf8  
    88
    99import java.util.*;
     10import java.util.stream.Collectors;
    1011
    1112
     
    4647    public Optional<Location> findById(Long id) {
    4748        return this.locationRepository.findById(id);
     49    }
     50
     51    @Override
     52    public List<Location> findLocations(Long locationId, Long companionId, Long lengthOfStay, String categoryIds) {
     53        List<Long> categories = null;
     54        if(categoryIds != null && !categoryIds.isEmpty()){
     55            List<String> ids = Arrays.asList(categoryIds.split(","));
     56            categories = ids.stream().map(Long::valueOf).collect(Collectors.toList());
     57        }
     58        List<Location> foundLocations = locationRepository.findLocationsFromForm(locationId, companionId, categories);
     59        return foundLocations;
    4860    }
    4961
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    rfa375fe reed0bf8  
    3434    }
    3535
    36     @PostMapping(value = "/trip/locations")
    37     public List<Location> allLocationsAfterSubmittedForm(@RequestParam(required = false) String locName,
    38                                                          @RequestParam(required = false)  String companion,
    39                                                          @RequestParam(required = false) String region,
    40                                                          @RequestParam(required = false) List<String> categories,
    41                                                          @RequestParam(required = false)  int numberOfDays)  {
    42         List<Location> generatedLocations = this.locationService.scheduleLocations(locName, companion, region, categories, numberOfDays);
     36    @GetMapping(value = "/trip/locations")
     37    public List<Location> allLocationsAfterSubmittedForm(@RequestParam(required = false) Long locationId,
     38                                                         @RequestParam(required = false)  Long companionId,
     39                                                         @RequestParam(required = false) Long lengthOfStay,
     40                                                         @RequestParam(required = false) String categoryIds)  {
     41        return this.locationService.findLocations(locationId, companionId, lengthOfStay, categoryIds);
     42        /* List<Location> generatedLocations = this.locationService.scheduleLocations(locName, companion, region, categories, numberOfDays);
    4343        if(locName.equals("Macedonia")){
    4444            return generatedLocations;
    4545        }else{
    4646            return generatedLocations;
    47         }
     47        }*/
    4848    }
    4949}
  • trip-planner/src/test/api.http

    rfa375fe reed0bf8  
    3030
    3131###
    32 POST http://localhost:8080/api/trip/locations
     32GET http://localhost:8080/api/trip/locations
    3333Content-Type: application/x-www-form-urlencoded
    3434
Note: See TracChangeset for help on using the changeset viewer.