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

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

spring security

  • Property mode set to 100644
File size: 4.6 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { ActivatedRoute, Router } from '@angular/router';
3import { MessageService } from 'primeng/api';
4import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
5import { Planner } from '../_models/planner';
6import { LocationService } from '../_services/location.service';
7import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
8import { Location } from '../_models/location';
9import { PlannerLocationDto } from '../_models/dto/plannerLocationDto';
10
11
12@Component({
13 selector: 'app-location',
14 templateUrl: './location.component.html',
15 styleUrls: ['./location.component.css'],
16 providers: [DialogService, MessageService]
17})
18export class LocationComponent implements OnInit {
19
20 categoryIds: string;
21 cityId: number;
22 companionId: number;
23 lengthOfStay: number;
24 listLocations: any[];
25 cityOption: boolean = false;
26 regionOption: boolean = false;
27 regionId: number;
28 locationId: number;
29 plannerLocationDto: PlannerLocationDto;
30 ref: DynamicDialogRef;
31 locationIdsPlanner: number[];
32
33
34 constructor(private route: ActivatedRoute, private locationService: LocationService,
35 private router: Router, private dialogService: DialogService, private messageService: MessageService) {
36 this.cityId = 1;
37 this.companionId = 1;
38 this.lengthOfStay = 1;
39 this.categoryIds = '';
40 this.listLocations = [];
41 this.regionId = 1;
42 this.locationId = 1;
43 this.ref = new DynamicDialogRef();
44 this.plannerLocationDto = new PlannerLocationDto();
45 this.locationIdsPlanner = [];
46 }
47
48 ngOnInit(): void {
49
50 this.route.queryParams
51 .subscribe(params => {
52 console.log(params);
53 this.cityId = params.cityId;
54 this.regionId = params.regionId;
55 this.companionId = params.companionId;
56 this.lengthOfStay = params.lengthOfStay;
57 this.categoryIds = params.categoryIds;
58 }
59 );
60
61 if (this.route.snapshot.queryParams['cityId']) {
62 this.locationService.getLocationsFromCity(this.cityId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
63 result => {
64 console.log(result);
65 this.listLocations = result;
66 }
67 );
68 } else
69 if (this.route.snapshot.queryParams['regionId']) {
70 console.log("I am in region console");
71 this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
72 result => {
73 console.log(result);
74 this.listLocations = result;
75 }
76 );
77 }
78
79 }
80
81 onClickSeeDetails(id: number) {
82 this.router.navigate(['location'], { queryParams: { id: id } });
83 }
84
85 show(location: Location) {
86 console.log(location.id);
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 this.plannerLocationDto.locationId = location.id;
96 this.plannerLocationDto.plannerId = planner.id;
97 console.log("LOC ID: " + this.plannerLocationDto.locationId);
98 console.log("PLANNER ID: " + this.plannerLocationDto.plannerId);
99
100 this.locationService.getAllLocationIdsForPlanner(planner.id).subscribe(
101 lid => {
102 if (lid.length == 0) {
103 this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
104 data => {
105 console.log(data);
106 }
107 );
108 this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ', detail: planner.name });
109
110 } else if (lid.length > 0) {
111 if (lid.indexOf(this.plannerLocationDto.locationId) !== -1) {
112 console.log("LOKACIJATA VEKE JA IMA VO PLANEROT");
113 this.messageService.add({ severity: 'error', summary: 'Location ' + location.name + ' already exists in the planner.' });
114 } else {
115 this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
116 data => {
117 console.log(data);
118 }
119 );
120 this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ', detail: planner.name });
121 }
122
123 }
124 }
125 );
126 });
127 }
128
129 ngOnDestroy() {
130 if (this.ref) {
131 this.ref.close();
132 }
133 }
134
135 onClickBackToMyPlanners() {
136 this.router.navigate(['planners']);
137 }
138
139
140}
Note: See TracBrowser for help on using the repository browser.