[e29cc2e] | 1 | import { Component, OnInit } from '@angular/core';
|
---|
[ceaed42] | 2 | import { ActivatedRoute, Router } from '@angular/router';
|
---|
[8d391a1] | 3 | import { MessageService } from 'primeng/api';
|
---|
[e29cc2e] | 4 | import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
---|
| 5 | import { Planner } from '../_models/planner';
|
---|
[ceaed42] | 6 | import { LocationService } from '../_services/location.service';
|
---|
| 7 | import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
|
---|
[e29cc2e] | 8 | import { Location } from '../_models/location';
|
---|
| 9 | import { 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 | })
|
---|
| 18 | export 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) => {
|
---|
[b738035] | 95 | if (planner) {
|
---|
| 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 |
|
---|
| 101 | this.locationService.getAllLocationIdsForPlanner(planner.id).subscribe(
|
---|
| 102 | lid => {
|
---|
| 103 | if (lid.length == 0) {
|
---|
[8d391a1] | 104 | this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
|
---|
| 105 | data => {
|
---|
| 106 | console.log(data);
|
---|
| 107 | }
|
---|
| 108 | );
|
---|
| 109 | this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ', detail: planner.name });
|
---|
| 110 |
|
---|
[b738035] | 111 | } else if (lid.length > 0) {
|
---|
| 112 | if (lid.indexOf(this.plannerLocationDto.locationId) !== -1) {
|
---|
| 113 | console.log("LOKACIJATA VEKE JA IMA VO PLANEROT");
|
---|
| 114 | this.messageService.add({ severity: 'error', summary: 'Location ' + location.name + ' already exists in the planner.' });
|
---|
| 115 | } else {
|
---|
| 116 | this.locationService.postLocationToPlanner(this.plannerLocationDto).subscribe(
|
---|
| 117 | data => {
|
---|
| 118 | console.log(data);
|
---|
| 119 | }
|
---|
| 120 | );
|
---|
| 121 | this.messageService.add({ severity: 'success', summary: 'Location ' + location.name + ' has been added to planner: ', detail: planner.name });
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | }
|
---|
[8d391a1] | 125 | }
|
---|
[b738035] | 126 | );
|
---|
[bdd6491] | 127 | }
|
---|
[e29cc2e] | 128 | });
|
---|
[b738035] | 129 |
|
---|
[e29cc2e] | 130 | }
|
---|
| 131 |
|
---|
| 132 | ngOnDestroy() {
|
---|
| 133 | if (this.ref) {
|
---|
| 134 | this.ref.close();
|
---|
| 135 | }
|
---|
[6a3a178] | 136 | }
|
---|
[ceaed42] | 137 |
|
---|
[8d391a1] | 138 | onClickBackToMyPlanners() {
|
---|
[e29cc2e] | 139 | this.router.navigate(['planners']);
|
---|
[59329aa] | 140 | }
|
---|
[8d391a1] | 141 |
|
---|
| 142 |
|
---|
[6a3a178] | 143 | }
|
---|