Ignore:
Timestamp:
11/11/21 12:59:26 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
59329aa
Parents:
6c1585f
Message:

add location to planner

File:
1 edited

Legend:

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

    r6c1585f rceaed42  
    1 import { Component, OnInit } from '@angular/core';
    2 import { Category } from '../_models/category';
    3 import { City } from '../_models/city';
    4 import { Companion } from '../_models/companion';
    5 import { Country } from '../_models/country';
    6 import { CategoryService } from '../_services/cateogry.service';
    7 import { CityService } from '../_services/city.service';
    8 import { CompanionService } from '../_services/companion.service';
    9 import { CountryService } from '../_services/country.service';
     1import { Route } from '@angular/compiler/src/core';
     2import { Component, Input, OnInit, Output } from '@angular/core';
     3import { FormBuilder, FormGroup, Validators } from '@angular/forms';
     4import { MatDialog } from '@angular/material/dialog';
     5import { ActivatedRoute, Router } from '@angular/router';
     6import { Location } from '../_models/location';
     7import { LocationService } from '../_services/location.service';
     8import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
    109
    1110@Component({
     
    1615export class LocationComponent implements OnInit {
    1716
    18   constructor() {
    19    
    20    }
    21    
     17  form: FormGroup;
     18  categoryIds: string;
     19  cityId: number;
     20  companionId: number;
     21  lengthOfStay: number;
     22  listLocations: any[];
     23  cityOption: boolean = false;
     24  regionOption: boolean = false;
     25  regionId: number;
     26
     27  constructor(private fb: FormBuilder, private route: ActivatedRoute, private locationService: LocationService,
     28    private router: Router, private dialog: MatDialog) {
     29    this.form = fb.group({
     30      title: fb.control('initial value', Validators.required)
     31    });
     32    this.cityId = 1;
     33    this.companionId = 1;
     34    this.lengthOfStay = 1;
     35    this.categoryIds = '';
     36    this.listLocations = [];
     37    this.regionId = 1;
     38  }
     39
    2240  ngOnInit(): void {
    23    
     41
     42    this.route.queryParams
     43      .subscribe(params => {
     44        console.log(params);
     45        this.cityId = params.cityId;
     46        this.regionId = params.regionId;
     47        this.companionId = params.companionId;
     48        this.lengthOfStay = params.lengthOfStay;
     49        this.categoryIds = params.categoryIds;
     50      }
     51      );
     52
     53    if (this.route.snapshot.queryParams['cityId']) {
     54      this.locationService.getLocationsFromCity(this.cityId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     55        result => {
     56          console.log(result);
     57          this.listLocations = result;
     58        }
     59      );
     60    } else
     61      if (this.route.snapshot.queryParams['regionId']) {
     62        console.log("I am in region console");
     63        this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     64          result => {
     65            console.log(result);
     66            this.listLocations = result;
     67          }
     68        );
     69      }
     70
    2471  }
     72
     73  openDialogSave(locationId: number){
     74    console.log(locationId);
     75      const dialogRef = this.dialog.open(AddLocationToPlannerPanelComponent, {
     76        width: '250px',
     77        data: {}
     78      });
     79      this.router.navigate(['locations'], {queryParams: {locationId: locationId}});
     80  }
     81
    2582}
Note: See TracChangeset for help on using the changeset viewer.