1 | import { Component, OnInit } from '@angular/core';
|
---|
2 | import { Planner } from '../_models/planner';
|
---|
3 | import { PlannerService } from '../_services/planner.service';
|
---|
4 | import { CreateInitialPlannerComponent } from '../create-initial-planner/create-initial-planner.component';
|
---|
5 | import { Router } from '@angular/router';
|
---|
6 | import { PlannerDto } from '../_models/dto/plannerDto';
|
---|
7 | import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
---|
8 | import { MessageService, PrimeNGConfig } from 'primeng/api';
|
---|
9 | import { UserDto } from '../_models/dto/userDto';
|
---|
10 | import { UserService } from '../_services/user.service';
|
---|
11 |
|
---|
12 |
|
---|
13 | @Component({
|
---|
14 | selector: 'app-planner',
|
---|
15 | templateUrl: './planner.component.html',
|
---|
16 | styleUrls: ['./planner.component.css'],
|
---|
17 | providers: [DialogService, MessageService]
|
---|
18 | })
|
---|
19 | export class PlannerComponent implements OnInit {
|
---|
20 |
|
---|
21 | planners: Planner[];
|
---|
22 | plannerDto: PlannerDto;
|
---|
23 | ref: DynamicDialogRef;
|
---|
24 | user: UserDto;
|
---|
25 |
|
---|
26 | constructor(private plannerService: PlannerService, private router: Router,
|
---|
27 | private dialogService: DialogService, private primengConfig: PrimeNGConfig, private messageService: MessageService,
|
---|
28 | private userService : UserService) {
|
---|
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 |
|
---|
39 | this.plannerService.getAllPlanners().subscribe(
|
---|
40 | data => {
|
---|
41 | this.planners = data;
|
---|
42 | localStorage.getItem("token");
|
---|
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((planner: Planner) => {
|
---|
64 | console.log("NOVOKREIRANIOT NAME NA PLANNER: " + planner.name);
|
---|
65 | this.plannerService.postInitialPlanner(planner).subscribe(
|
---|
66 | data=>{
|
---|
67 | console.log(data);
|
---|
68 | },
|
---|
69 | error => console.log('oops', error)
|
---|
70 | );
|
---|
71 | this.messageService.add({ severity: 'success', summary: 'The planner: ' + planner.name + ' has been created.' });
|
---|
72 | });
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 | }
|
---|