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
RevLine 
[e29cc2e]1import { Component, OnInit } from '@angular/core';
[ceaed42]2import { ActivatedRoute, Router } from '@angular/router';
[8d391a1]3import { MessageService } from 'primeng/api';
[e29cc2e]4import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
5import { Planner } from '../_models/planner';
[ceaed42]6import { LocationService } from '../_services/location.service';
7import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
[e29cc2e]8import { Location } from '../_models/location';
9import { PlannerLocationDto } from '../_models/dto/plannerLocationDto';
10
[6a3a178]11
12@Component({
13 selector: 'app-location',
14 templateUrl: './location.component.html',
[e29cc2e]15 styleUrls: ['./location.component.css'],
16 providers: [DialogService, MessageService]
[6a3a178]17})
18export class LocationComponent implements OnInit {
19
[ceaed42]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;
[59329aa]28 locationId: number;
[e29cc2e]29 plannerLocationDto: PlannerLocationDto;
30 ref: DynamicDialogRef;
[8d391a1]31 locationIdsPlanner: number[];
[e29cc2e]32
33
34 constructor(private route: ActivatedRoute, private locationService: LocationService,
35 private router: Router, private dialogService: DialogService, private messageService: MessageService) {
[ceaed42]36 this.cityId = 1;
37 this.companionId = 1;
38 this.lengthOfStay = 1;
39 this.categoryIds = '';
40 this.listLocations = [];
41 this.regionId = 1;
[59329aa]42 this.locationId = 1;
[8d391a1]43 this.ref = new DynamicDialogRef();
[e29cc2e]44 this.plannerLocationDto = new PlannerLocationDto();
[8d391a1]45 this.locationIdsPlanner = [];
[ceaed42]46 }
47
[6a3a178]48 ngOnInit(): void {
[ceaed42]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
[e29cc2e]81 onClickSeeDetails(id: number) {
82 this.router.navigate(['location'], { queryParams: { id: id } });
83 }
84
85 show(location: Location) {
[8d391a1]86 console.log(location.id);
[e29cc2e]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);
[8d391a1]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 }
[e29cc2e]124 }
125 );
126 });
127 }
128
129 ngOnDestroy() {
130 if (this.ref) {
131 this.ref.close();
132 }
[6a3a178]133 }
[ceaed42]134
[8d391a1]135 onClickBackToMyPlanners() {
[e29cc2e]136 this.router.navigate(['planners']);
[59329aa]137 }
[8d391a1]138
139
[6a3a178]140}
Note: See TracBrowser for help on using the repository browser.