Ignore:
Timestamp:
11/11/21 12:59:26 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
59329aa
Parents:
6c1585f
Message:

add location to planner

Location:
trip-planner-front/src/app/location
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/location/location.component.html

    r6c1585f rceaed42  
    1 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
     1<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
     2  integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
    23
    34<h3>Here are all locations</h3>
    45
    5 <div class="container">
    6   <table mat-table  class="mat-elevation-z8">
    7 
    8     <!--- Note that these columns can be defined in any order.
    9           The actual rendered columns are set as a property on the row definition" -->
    10  
    11     <!-- Position Column -->
    12     <ng-container matColumnDef="position">
    13       <th mat-header-cell *matHeaderCellDef> Location name </th>
    14       <td mat-cell *matCellDef="let element">  </td>
    15     </ng-container>
    16  
    17  
    18     <!-- Symbol Column -->
    19     <ng-container matColumnDef="symbol">
    20       <th mat-header-cell *matHeaderCellDef> Symbol </th>
    21       <td mat-cell *matCellDef="let element">  </td>
    22     </ng-container>
    23  
    24     <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    25     <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
    26   </table>
    27 </div>
     6<table class="table" >
     7  <thead>
     8    <tr>
     9      <th scope="col">#</th>
     10      <th scope="col">Location name</th>
     11      <th scope="col"> Add to my planner</th>
     12      <th scope="col">See details </th>
     13    </tr>
     14  </thead>
     15  <tbody>
     16    <tr *ngFor="let location of listLocations">
     17      <td>{{location.id}}</td>
     18      <td>{{location.name}}</td>
     19      <td><button mat-raised-button color="primary" (click)="openDialogSave(location.id)">Add to my planner</button></td>
     20      <td><button mat-raised-button color="primary">See details</button></td>
     21    </tr> 
     22  </tbody>
     23</table>
  • trip-planner-front/src/app/location/location.component.ts

    r6c1585f rceaed42  
    1 import { Component, OnInit } from '@angular/core';
    2 import { Category } from '../_models/category';
    3 import { City } from '../_models/city';
    4 import { Companion } from '../_models/companion';
    5 import { Country } from '../_models/country';
    6 import { CategoryService } from '../_services/cateogry.service';
    7 import { CityService } from '../_services/city.service';
    8 import { CompanionService } from '../_services/companion.service';
    9 import { CountryService } from '../_services/country.service';
     1import { Route } from '@angular/compiler/src/core';
     2import { Component, Input, OnInit, Output } from '@angular/core';
     3import { FormBuilder, FormGroup, Validators } from '@angular/forms';
     4import { MatDialog } from '@angular/material/dialog';
     5import { ActivatedRoute, Router } from '@angular/router';
     6import { Location } from '../_models/location';
     7import { LocationService } from '../_services/location.service';
     8import { AddLocationToPlannerPanelComponent } from './add-location-to-planner-panel/add-location-to-planner-panel.component';
    109
    1110@Component({
     
    1615export class LocationComponent implements OnInit {
    1716
    18   constructor() {
    19    
    20    }
    21    
     17  form: FormGroup;
     18  categoryIds: string;
     19  cityId: number;
     20  companionId: number;
     21  lengthOfStay: number;
     22  listLocations: any[];
     23  cityOption: boolean = false;
     24  regionOption: boolean = false;
     25  regionId: number;
     26
     27  constructor(private fb: FormBuilder, private route: ActivatedRoute, private locationService: LocationService,
     28    private router: Router, private dialog: MatDialog) {
     29    this.form = fb.group({
     30      title: fb.control('initial value', Validators.required)
     31    });
     32    this.cityId = 1;
     33    this.companionId = 1;
     34    this.lengthOfStay = 1;
     35    this.categoryIds = '';
     36    this.listLocations = [];
     37    this.regionId = 1;
     38  }
     39
    2240  ngOnInit(): void {
    23    
     41
     42    this.route.queryParams
     43      .subscribe(params => {
     44        console.log(params);
     45        this.cityId = params.cityId;
     46        this.regionId = params.regionId;
     47        this.companionId = params.companionId;
     48        this.lengthOfStay = params.lengthOfStay;
     49        this.categoryIds = params.categoryIds;
     50      }
     51      );
     52
     53    if (this.route.snapshot.queryParams['cityId']) {
     54      this.locationService.getLocationsFromCity(this.cityId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     55        result => {
     56          console.log(result);
     57          this.listLocations = result;
     58        }
     59      );
     60    } else
     61      if (this.route.snapshot.queryParams['regionId']) {
     62        console.log("I am in region console");
     63        this.locationService.getLocationsFromRegion(this.regionId, this.companionId, this.lengthOfStay, this.categoryIds).subscribe(
     64          result => {
     65            console.log(result);
     66            this.listLocations = result;
     67          }
     68        );
     69      }
     70
    2471  }
     72
     73  openDialogSave(locationId: number){
     74    console.log(locationId);
     75      const dialogRef = this.dialog.open(AddLocationToPlannerPanelComponent, {
     76        width: '250px',
     77        data: {}
     78      });
     79      this.router.navigate(['locations'], {queryParams: {locationId: locationId}});
     80  }
     81
    2582}
Note: See TracChangeset for help on using the changeset viewer.