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

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

pre final presentation

  • Property mode set to 100644
File size: 2.9 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { Planner } from '../_models/planner';
3import { PlannerService } from '../_services/planner.service';
4import { CreateInitialPlannerComponent } from '../create-initial-planner/create-initial-planner.component';
5import { Router } from '@angular/router';
6import { PlannerDto } from '../_models/dto/plannerDto';
7import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
8import { MessageService, PrimeNGConfig } from 'primeng/api';
9import { UserDto } from '../_models/dto/userDto';
10
11
12@Component({
13 selector: 'app-planner',
14 templateUrl: './planner.component.html',
15 styleUrls: ['./planner.component.css'],
16 providers: [DialogService, MessageService]
17})
18export class PlannerComponent implements OnInit {
19
20 planners: Planner[];
21 plannerDto: PlannerDto;
22 ref: DynamicDialogRef;
23 user: UserDto;
24 userDisplayName = '';
25 status = '';
26
27 constructor(private plannerService: PlannerService, private router: Router,
28 private dialogService: DialogService, private primengConfig: PrimeNGConfig, private messageService: MessageService) {
29 this.planners = [];
30 this.plannerDto = new PlannerDto();
31 this.ref = new DynamicDialogRef;
32 this.user = new UserDto();
33 }
34
35 ngOnInit(): void {
36
37 this.primengConfig.ripple = true;
38 let name1: string = sessionStorage.getItem("username") as string;
39 this.userDisplayName = name1;
40 this.plannerService.getAllPlanners().subscribe(
41 data => {
42 this.planners = data;
43 }
44 );
45 }
46
47 onClickEditPlannerGet(id: number) {
48 console.log(id);
49 this.plannerService.getPlannerById(id).subscribe(
50 data => {
51 this.router.navigate(['edit/planner/', id]);
52 }
53 );
54 }
55
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 });
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 }
74
75 });
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(['']);
89 }
90
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 }
101}
Note: See TracBrowser for help on using the repository browser.