source: trip-planner-front/src/app/planner/edit-planner/edit-planner.component.ts@ e29cc2e

Last change on this file since e29cc2e was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[6a80231]1import { Component, OnInit } from '@angular/core';
[6c1585f]2import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3import { ActivatedRoute, Router } from '@angular/router';
4import { PlannerDto } from 'src/app/_models/dto/plannerDto';
[ceaed42]5import { Location } from 'src/app/_models/location';
[6a80231]6import { Planner } from 'src/app/_models/planner';
[ceaed42]7import { LocationService } from 'src/app/_services/location.service';
[6c1585f]8import { PlannerService } from 'src/app/_services/planner.service';
[6a80231]9
10@Component({
11 selector: 'app-edit-planner',
12 templateUrl: './edit-planner.component.html',
13 styleUrls: ['./edit-planner.component.css']
14})
15export class EditPlannerComponent implements OnInit {
16
17 planner: Planner;
[6c1585f]18 planners: Planner[];
19 form: FormGroup;
20 plannerDto: PlannerDto;
21 id: number;
[ceaed42]22 locations: Location[];
[6a80231]23
24
[ceaed42]25 constructor(private router: Router, private route: ActivatedRoute, private fb: FormBuilder, private plannerService: PlannerService,
26 private locationService : LocationService) {
[6a80231]27 this.planner = new Planner();
[6c1585f]28 this.planners = [];
29 this.form = fb.group({
30 title: fb.control('initial value', Validators.required)
[ceaed42]31 });
[6c1585f]32 this.plannerDto = new PlannerDto();
33 this.id = 1;
[ceaed42]34 this.locations = [];
[6a80231]35 }
36
37 ngOnInit(): void {
[6c1585f]38 this.id = this.route.snapshot.params['id'];
39
40 this.form = this.fb.group({
[ceaed42]41 name: [''],
42 description: [''],
43 locationList: []
[6c1585f]44 });
45
46 this.plannerService.getPlannerById(this.id)
[ceaed42]47 .pipe()
48 .subscribe(x => this.form.patchValue(x));
[6a80231]49
[59329aa]50 this.locationService.getLocationsForPlanner(this.id).subscribe(
[ceaed42]51 data => {
52 this.locations = data;
53 }
54 );
55 }
56
57 onSubmit() {
[6c1585f]58 this.updatePlanner();
[ceaed42]59
[6a80231]60 }
61
[ceaed42]62 onClickAddLocation() {
[6a80231]63 this.router.navigate(['form']);
64 }
[6c1585f]65
66 private updatePlanner() {
67 this.plannerService.updatePlanner(this.id, this.form.value)
[ceaed42]68 .pipe()
69 .subscribe({
70 next: () => {
71 this.router.navigate(['planners']);
72 },
73 error: error => {
74 console.log("error");
75 }
76 });
77 }
78
[e29cc2e]79 onClickBack(){
80 console.log("promena");
81 this.router.navigate(['planners']);
82 }
[6a80231]83}
Note: See TracBrowser for help on using the repository browser.