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

Last change on this file was 6fe77af, checked in by Ema <ema_spirova@…>, 2 years ago

add location feature

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[6a3a178]1import { Component, OnInit } from '@angular/core';
2import { Planner } from '../_models/planner';
3import { PlannerService } from '../_services/planner.service';
[fa375fe]4import { CreateInitialPlannerComponent } from '../create-initial-planner/create-initial-planner.component';
[6a80231]5import { Router } from '@angular/router';
[6c1585f]6import { PlannerDto } from '../_models/dto/plannerDto';
[e29cc2e]7import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
[1ad8e64]8import { MessageService, PrimeNGConfig } from 'primeng/api';
[84d0fbb]9import { UserDto } from '../_models/dto/userDto';
[fa375fe]10
[6a3a178]11
12@Component({
13 selector: 'app-planner',
14 templateUrl: './planner.component.html',
[1ad8e64]15 styleUrls: ['./planner.component.css'],
16 providers: [DialogService, MessageService]
[6a3a178]17})
18export class PlannerComponent implements OnInit {
19
20 planners: Planner[];
[6c1585f]21 plannerDto: PlannerDto;
[e29cc2e]22 ref: DynamicDialogRef;
[84d0fbb]23 user: UserDto;
[bdd6491]24 userDisplayName = '';
25 status = '';
[6c1585f]26
[e29cc2e]27 constructor(private plannerService: PlannerService, private router: Router,
[bdd6491]28 private dialogService: DialogService, private primengConfig: PrimeNGConfig, private messageService: MessageService) {
[6a3a178]29 this.planners = [];
[6c1585f]30 this.plannerDto = new PlannerDto();
[1ad8e64]31 this.ref = new DynamicDialogRef;
[84d0fbb]32 this.user = new UserDto();
[6a3a178]33 }
[e29cc2e]34
[6a3a178]35 ngOnInit(): void {
[e29cc2e]36
37 this.primengConfig.ripple = true;
[bdd6491]38 let name1: string = sessionStorage.getItem("username") as string;
39 this.userDisplayName = name1;
[6a3a178]40 this.plannerService.getAllPlanners().subscribe(
41 data => {
42 this.planners = data;
43 }
[bdd6491]44 );
[6a3a178]45 }
[e29cc2e]46
47 onClickEditPlannerGet(id: number) {
[6a80231]48 console.log(id);
[e29cc2e]49 this.plannerService.getPlannerById(id).subscribe(
50 data => {
51 this.router.navigate(['edit/planner/', id]);
52 }
53 );
54 }
[1ad8e64]55
[e29cc2e]56 show() {
57 this.ref = this.dialogService.open(CreateInitialPlannerComponent, {
58 header: 'Create initial planner',
59 width: '70%',
60 contentStyle: { "max-height": "500px", "overflow": "auto" },
61 baseZIndex: 10000
62 });
[bdd6491]63 this.ref.onClose.subscribe((plannerDto: PlannerDto) => {
64 if (plannerDto) {
65 console.log("NOVOKREIRANIOT NAME NA PLANNER: " + plannerDto.name);
66 this.plannerService.postInitialPlanner(plannerDto).subscribe(
67 data => {
68 console.log(data);
69 },
70 error => console.log('oops', error)
71 );
72 this.messageService.add({ severity: 'success', summary: 'The planner: ' + plannerDto.name + ' has been created.' });
73 }
[b738035]74
[1ad8e64]75 });
[bdd6491]76
77 }
78
79 ngOnDestroy() {
80 if (this.ref) {
81 this.ref.close();
82 }
83 }
84
85 onClickLogout() {
86 sessionStorage.removeItem("token");
87 console.log("SESSION HAS ENDED, THE USER IS LOGGED OUT" + sessionStorage.getItem("token"));
88 this.router.navigate(['']);
[e29cc2e]89 }
[1ad8e64]90
[bdd6491]91 onDeletePlanner(id: number) {
92 console.log("DELETE KOCHE: " + id);
93 this.plannerService.deletePlannerById(id).subscribe(
94 (data) => {
95 console.log(data);
96 },
97 (error) => console.log('error', error)
98 );
99 window.location.reload();
100 }
[6fe77af]101
102 onClickAddLocation(){
103 this.router.navigate(['add-location']);
104 }
[6a3a178]105}
Note: See TracBrowser for help on using the repository browser.