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

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

adding photos

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import { Component, Input, OnInit, Output } from '@angular/core';
2import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3import { MatDialog } from '@angular/material/dialog';
4import { ActivatedRoute, Router } from '@angular/router';
5import { LocationService } from '../_services/location.service';
6import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
7
8@Component({
9 selector: 'app-location',
10 templateUrl: './location.component.html',
11 styleUrls: ['./location.component.css']
12})
13export class LocationComponent implements OnInit {
14
15 form: FormGroup;
16 categoryIds: string;
17 cityId: number;
18 companionId: number;
19 lengthOfStay: number;
20 listLocations: any[];
21 cityOption: boolean = false;
22 regionOption: boolean = false;
23 regionId: number;
24 locationId: number;
25
26 constructor(private fb: FormBuilder, private route: ActivatedRoute, private locationService: LocationService,
27 private router: Router, private dialog: MatDialog) {
28 this.form = fb.group({
29 title: fb.control('initial value', Validators.required)
30 });
31 this.cityId = 1;
32 this.companionId = 1;
33 this.lengthOfStay = 1;
34 this.categoryIds = '';
35 this.listLocations = [];
36 this.regionId = 1;
37 this.locationId = 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){
74 // console.log(locationId);
75 const dialogRef = this.dialog.open(AddLocationToPlannerPanelComponent, {
76 width: '250px',
77 data: {}
78 });
79 this.router.navigate(['locations'], {queryParams: {regionId: this.regionId, companionId: this.companionId, lengthOfStay: this.lengthOfStay, categoryIds: this.categoryIds, locationId: locationId}});
80
81 }
82
83 onClickSeeDetails(id: number){
84 this.router.navigate(['location'], {queryParams: {id: id}});
85 }
86}
Note: See TracBrowser for help on using the repository browser.