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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.