source: trip-planner-front/src/app/location/location.component.ts@ ceaed42

Last change on this file since ceaed42 was ceaed42, checked in by Ema <ema_spirova@…>, 3 years ago

add location to planner

  • Property mode set to 100644
File size: 2.6 KB
Line 
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';
9
10@Component({
11 selector: 'app-location',
12 templateUrl: './location.component.html',
13 styleUrls: ['./location.component.css']
14})
15export class LocationComponent implements OnInit {
16
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
40 ngOnInit(): void {
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
71 }
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
82}
Note: See TracBrowser for help on using the repository browser.