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/planner
Files:
3 edited

Legend:

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

    r6c1585f rceaed42  
    2828                            <td> <button mat-raised-button color="primary" (click)="onClickAddLocation()">
    2929                                 Add locations
    30                               </button>
     30                                 </button>
     31                            </td>
     32                        </tr>
     33                        <tr *ngFor ="let location of locations">
     34                            <td>
     35                                {{location.name}}
    3136                            </td>
    3237                        </tr>
  • 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 }
  • trip-planner-front/src/app/planner/planner.component.ts

    r6c1585f rceaed42  
    2222
    2323
    24   constructor(private plannerService: PlannerService, public dialog: MatDialog, private router: Router,
     24  constructor(private plannerService: PlannerService, private dialog: MatDialog, private router: Router,
    2525    private fb : FormBuilder) {
    2626    this.planners = [];
     
    4949    console.log(id);
    5050        this.plannerService.getPlannerById(id).subscribe(
    51             data => {
    52              
    53               this.router.navigate(['edit/planner/', id])
     51            data => {         
     52              this.router.navigate(['edit/planner/', id]);
    5453            }
    5554     );
Note: See TracChangeset for help on using the changeset viewer.