[e29cc2e] | 1 | import { Component, OnInit } from '@angular/core';
|
---|
[ceaed42] | 2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
---|
| 3 | import { ActivatedRoute, Router } from '@angular/router';
|
---|
[e29cc2e] | 4 | import { MessageService, PrimeNGConfig } from 'primeng/api';
|
---|
| 5 | import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
---|
| 6 | import { Planner } from '../_models/planner';
|
---|
[ceaed42] | 7 | import { LocationService } from '../_services/location.service';
|
---|
| 8 | import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
|
---|
[e29cc2e] | 9 | import { Location } from '../_models/location';
|
---|
| 10 | import { PlannerLocationDto } from '../_models/dto/plannerLocationDto';
|
---|
| 11 |
|
---|
[6a3a178] | 12 |
|
---|
| 13 | @Component({
|
---|
| 14 | selector: 'app-location',
|
---|
| 15 | templateUrl: './location.component.html',
|
---|
[e29cc2e] | 16 | styleUrls: ['./location.component.css'],
|
---|
| 17 | providers: [DialogService, MessageService]
|
---|
[6a3a178] | 18 | })
|
---|
| 19 | export class LocationComponent implements OnInit {
|
---|
| 20 |
|
---|
[ceaed42] | 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;
|
---|
[59329aa] | 29 | locationId: number;
|
---|
[e29cc2e] | 30 | plannerLocationDto: PlannerLocationDto;
|
---|
| 31 | ref: DynamicDialogRef;
|
---|
[ceaed42] | 32 |
|
---|
[e29cc2e] | 33 |
|
---|
| 34 |
|
---|
| 35 | constructor(private route: ActivatedRoute, private locationService: LocationService,
|
---|
| 36 | private router: Router, private dialogService: DialogService, private messageService: MessageService) {
|
---|
[ceaed42] | 37 | this.cityId = 1;
|
---|
| 38 | this.companionId = 1;
|
---|
| 39 | this.lengthOfStay = 1;
|
---|
| 40 | this.categoryIds = '';
|
---|
| 41 | this.listLocations = [];
|
---|
| 42 | this.regionId = 1;
|
---|
[59329aa] | 43 | this.locationId = 1;
|
---|
[e29cc2e] | 44 | this.ref = new DynamicDialogRef;
|
---|
| 45 | this.plannerLocationDto = new PlannerLocationDto();
|
---|
| 46 |
|
---|
[ceaed42] | 47 | }
|
---|
| 48 |
|
---|
[6a3a178] | 49 | ngOnInit(): void {
|
---|
[ceaed42] | 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 |
|
---|
[e29cc2e] | 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 | }
|
---|
[6a3a178] | 115 | }
|
---|
[ceaed42] | 116 |
|
---|
[e29cc2e] | 117 | onClickBackToMyPlanners(){
|
---|
| 118 | this.router.navigate(['planners']);
|
---|
[59329aa] | 119 | }
|
---|
[6a3a178] | 120 | }
|
---|