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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/planner/edit-planner/edit-planner.component.ts

    r6c1585f rceaed42  
    33import { ActivatedRoute, Router } from '@angular/router';
    44import { PlannerDto } from 'src/app/_models/dto/plannerDto';
     5import { Location } from 'src/app/_models/location';
    56import { Planner } from 'src/app/_models/planner';
     7import { LocationService } from 'src/app/_services/location.service';
    68import { PlannerService } from 'src/app/_services/planner.service';
    79
     
    1820  plannerDto: PlannerDto;
    1921  id: number;
     22  locations: Location[];
    2023
    2124
    22   constructor(private router: Router, private route: ActivatedRoute ,private fb: FormBuilder, private plannerService: PlannerService) {
     25  constructor(private router: Router, private route: ActivatedRoute, private fb: FormBuilder, private plannerService: PlannerService,
     26    private locationService : LocationService) {
    2327    this.planner = new Planner();
    2428    this.planners = [];
    2529    this.form = fb.group({
    2630      title: fb.control('initial value', Validators.required)
    27   });
     31    });
    2832    this.plannerDto = new PlannerDto();
    2933    this.id = 1;
     34    this.locations = [];
    3035  }
    3136
     
    3439
    3540    this.form = this.fb.group({
    36         name: [''],
    37         description: [''],
    38         locationList: []
     41      name: [''],
     42      description: [''],
     43      locationList: []
    3944    });
    4045
    4146    this.plannerService.getPlannerById(this.id)
    42     .pipe()
    43     .subscribe(x => this.form.patchValue(x));
     47      .pipe()
     48      .subscribe(x => this.form.patchValue(x));
     49
     50    this.locationService.getLocationsFroPlanner(this.id).subscribe(
     51      data => {
     52          this.locations = data;
     53      }
     54    );
     55    }
     56 
     57  onSubmit() {
     58    this.updatePlanner();
     59
    4460  }
    4561
    46 
    47   onSubmit(){
    48     this.updatePlanner();
    49      
    50   }
    51 
    52   onClickAddLocation()
    53   {
     62  onClickAddLocation() {
    5463    this.router.navigate(['form']);
    5564  }
     
    5766  private updatePlanner() {
    5867    this.plannerService.updatePlanner(this.id, this.form.value)
    59         .pipe()
    60         .subscribe({
    61             next: () => {
    62               this.router.navigate(['planners']);
    63             },
    64             error: error => {
    65                 console.log("error");
    66             }
    67         });
     68      .pipe()
     69      .subscribe({
     70        next: () => {
     71          this.router.navigate(['planners']);
     72        },
     73        error: error => {
     74          console.log("error");
     75        }
     76      });
     77  }
     78
    6879}
    69  
    70 }
Note: See TracChangeset for help on using the changeset viewer.