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

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

primeNG components

  • Property mode set to 100644
File size: 3.8 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3import { ActivatedRoute, Router } from '@angular/router';
4import { MessageService, PrimeNGConfig } from 'primeng/api';
5import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
6import { Planner } from '../_models/planner';
7import { LocationService } from '../_services/location.service';
8import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
9import { Location } from '../_models/location';
10import { PlannerLocationDto } from '../_models/dto/plannerLocationDto';
11
12
13@Component({
14 selector: 'app-location',
15 templateUrl: './location.component.html',
16 styleUrls: ['./location.component.css'],
17 providers: [DialogService, MessageService]
18})
19export class LocationComponent implements OnInit {
20
21 categoryIds: string;
22 cityId: number;
23 companionId: number;
24 lengthOfStay: number;
25 listLocations: any[];
26 cityOption: boolean = false;
27 regionOption: boolean = false;
28 regionId: number;
29 locationId: number;
30 plannerLocationDto: PlannerLocationDto;
31 ref: DynamicDialogRef;
32
33
34
35 constructor(private route: ActivatedRoute, private locationService: LocationService,
36 private router: Router, private dialogService: DialogService, private messageService: MessageService) {
37 this.cityId = 1;
38 this.companionId = 1;
39 this.lengthOfStay = 1;
40 this.categoryIds = '';
41 this.listLocations = [];
42 this.regionId = 1;
43 this.locationId = 1;
44 this.ref = new DynamicDialogRef;
45 this.plannerLocationDto = new PlannerLocationDto();
46
47 }
48
49 ngOnInit(): void {
50
51 this.route.queryParams
52 .subscribe(params => {
53 console.log(params);
54 this.cityId = params.cityId;
55 this.regionId = params.regionId;
56 this.companionId = params.companionId;
57 this.lengthOfStay = params.lengthOfStay;
58 this.categoryIds = params.categoryIds;
59 }
60 );
61
62 if (this.route.snapshot.queryParams['cityId']) {
63 this.locationService.getLocationsFromCity(this.cityId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
64 result => {
65 console.log(result);
66 this.listLocations = result;
67 }
68 );
69 } else
70 if (this.route.snapshot.queryParams['regionId']) {
71 console.log("I am in region console");
72 this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
73 result => {
74 console.log(result);
75 this.listLocations = result;
76 }
77 );
78 }
79
80 }
81
82 onClickSeeDetails(id: number) {
83 this.router.navigate(['location'], { queryParams: { id: id } });
84 }
85
86 show(location: Location) {
87 this.ref = this.dialogService.open(AddLocationToPlannerPanelComponent, {
88 header: 'Choose a Planner',
89 width: '70%',
90 contentStyle: { "max-height": "500px", "overflow": "auto" },
91 baseZIndex: 10000
92 });
93
94 this.ref.onClose.subscribe((planner: Planner) => {
95
96 this.plannerLocationDto.locationId = location.id;
97 this.plannerLocationDto.plannerId = planner.id;
98 console.log("LOC ID: " + this.plannerLocationDto.locationId);
99 console.log("PLANNER ID: " + this.plannerLocationDto.plannerId);
100 this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
101 data => {
102 console.log(data);
103 }
104 );
105 if (planner) {
106 this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ' , detail: planner.name });
107 }
108 });
109 }
110
111 ngOnDestroy() {
112 if (this.ref) {
113 this.ref.close();
114 }
115 }
116
117 onClickBackToMyPlanners(){
118 this.router.navigate(['planners']);
119 }
120}
Note: See TracBrowser for help on using the repository browser.