- Timestamp:
- 11/11/21 12:59:26 (3 years ago)
- Branches:
- master
- Children:
- 59329aa
- Parents:
- 6c1585f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/src/app/locations-form/locations-form.component.ts
r6c1585f rceaed42 1 import { Component, Injectable, OnInit } from '@angular/core';2 import { Form Control, NgForm} from '@angular/forms';3 import { map, startWith, switchMap} from 'rxjs/operators';4 import { forkJoin, Observable} from 'rxjs';1 import { Component, EventEmitter, OnInit, Output } from '@angular/core'; 2 import { FormBuilder, FormControl } from '@angular/forms'; 3 import { map, startWith, switchMap } from 'rxjs/operators'; 4 import { Observable } from 'rxjs'; 5 5 import { CityService } from '../_services/city.service'; 6 6 import { City } from '../_models/city'; 7 import { Country } from '../_models/country';8 import { CountryService } from '../_services/country.service';9 7 import { Companion } from '../_models/companion'; 10 8 import { CompanionService } from '../_services/companion.service'; 11 9 import { Category } from '../_models/category'; 12 10 import { CategoryService } from '../_services/cateogry.service'; 13 import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';14 11 import { MatChip } from '@angular/material/chips'; 15 12 import { LocationService } from '../_services/location.service'; 16 13 import { Region } from '../_models/region'; 17 14 import { RegionService } from '../_services/region.service'; 18 import { Router } from '@angular/router'; 15 import { ActivatedRoute, Params, Router } from '@angular/router'; 16 import { Location } from '../_models/location'; 17 18 19 19 20 20 @Component({ … … 41 41 cityOption: boolean = false; 42 42 regionOption: boolean = false; 43 value: number;43 value: number; 44 44 max: number; 45 45 toggle = true; 46 46 status = 'Enable'; 47 proba: any[]; 47 48 48 constructor(private cityService : CityService, private regionService: RegionService, 49 private companionService : CompanionService, private categoryService : CategoryService, 50 private locationService: LocationService, private router : Router){ 49 50 constructor(private cityService: CityService, private regionService: RegionService, 51 private companionService: CompanionService, private categoryService: CategoryService, 52 private locationService: LocationService, private router: Router, private fb: FormBuilder, private route: ActivatedRoute) { 51 53 this.filteredOptions = new Observable<City[]>(); 52 54 this.cities = []; … … 63 65 this.value = 0; 64 66 this.max = 30; 67 this.proba = []; 65 68 } 69 70 ngOnInit(): void { 66 71 67 ngOnInit() :void {68 72 this.filteredOptions = this.myControl.valueChanges 69 .pipe(70 startWith(''),71 switchMap(val => {72 return this.filter(val || '')73 })74 );73 .pipe( 74 startWith(''), 75 switchMap(val => { 76 return this.filter(val || '') 77 }) 78 ); 75 79 76 80 this.cityService.getAllCities().subscribe( … … 96 100 this.companions = data; 97 101 } 98 ) 102 ); 103 99 104 } 100 105 101 106 filter(val: string): Observable<City[]> { 102 107 // call the service which makes the http-request … … 107 112 })) 108 113 ) 109 110 114 } 111 115 112 toggleSelection(chip: MatChip, category: Category){ 113 chip.toggleSelected(); 114 115 if (this.chipsSeletion.length > 0) { 116 if (this.chipsSeletion.indexOf(category.id) <= -1) { 117 this.chipsSeletion.push(category.id); 118 } else { 119 const index = this.chipsSeletion.indexOf(category.id); 120 this.chipsSeletion.splice(index, 1); 121 } 122 } else { 123 this.chipsSeletion.push(category.id); 124 } 125 console.log(this.chipsSeletion); 126 } 116 toggleSelection(chip: MatChip, category: Category) { 117 chip.toggleSelected(); 118 119 if (this.chipsSeletion.length > 0) { 120 if (this.chipsSeletion.indexOf(category.id) <= -1) { 121 this.chipsSeletion.push(category.id); 122 } else { 123 const index = this.chipsSeletion.indexOf(category.id); 124 this.chipsSeletion.splice(index, 1); 125 } 126 } else { 127 this.chipsSeletion.push(category.id); 128 } 129 console.log(this.chipsSeletion); 130 } 131 127 132 128 133 … … 135 140 result => { 136 141 console.log(result); 137 this.router.navigate(['locations']); 142 this.proba = result; 143 this.router.navigate(['locations'], {queryParams: {cityId: this.cityId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds}}); 138 144 } 139 145 ); 140 } else if (this.regionOption) { 141 this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe( 142 result => { 143 console.log(result); 144 this.router.navigate(['locations']); 145 } 146 ); 147 } 148 149 150 146 } else 147 if (this.regionOption) { 148 this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe( 149 result => { 150 console.log(result); 151 this.router.navigate(['locations'], {queryParams: {regionId: this.regionId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds}}); 152 } 153 ); 154 } 151 155 } 152 156 … … 166 170 } 167 171 172 168 173 }
Note:
See TracChangeset
for help on using the changeset viewer.