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 |
|
---|
10 |
|
---|
11 | @Component({
|
---|
12 | selector: 'app-planner',
|
---|
13 | templateUrl: './planner.component.html',
|
---|
14 | styleUrls: ['./planner.component.css'],
|
---|
15 | providers: [DialogService, MessageService]
|
---|
16 | })
|
---|
17 | export class PlannerComponent implements OnInit {
|
---|
18 |
|
---|
19 | planners: Planner[];
|
---|
20 | plannerDto: PlannerDto;
|
---|
21 | ref: DynamicDialogRef;
|
---|
22 |
|
---|
23 |
|
---|
24 | constructor(private plannerService: PlannerService, private router: Router,
|
---|
25 | private dialogService: DialogService, private primengConfig: PrimeNGConfig, private messageService: MessageService) {
|
---|
26 | this.planners = [];
|
---|
27 | this.plannerDto = new PlannerDto();
|
---|
28 | this.ref = new DynamicDialogRef;
|
---|
29 | }
|
---|
30 |
|
---|
31 | ngOnInit(): void {
|
---|
32 |
|
---|
33 | this.primengConfig.ripple = true;
|
---|
34 |
|
---|
35 | this.plannerService.getAllPlanners().subscribe(
|
---|
36 | data => {
|
---|
37 | this.planners = data;
|
---|
38 | }
|
---|
39 | );
|
---|
40 | }
|
---|
41 |
|
---|
42 | onClickEditPlannerGet(id: number) {
|
---|
43 | console.log(id);
|
---|
44 | this.plannerService.getPlannerById(id).subscribe(
|
---|
45 | data => {
|
---|
46 | this.router.navigate(['edit/planner/', id]);
|
---|
47 | }
|
---|
48 | );
|
---|
49 | }
|
---|
50 |
|
---|
51 | show() {
|
---|
52 | this.ref = this.dialogService.open(CreateInitialPlannerComponent, {
|
---|
53 | header: 'Create initial planner',
|
---|
54 | width: '70%',
|
---|
55 | contentStyle: { "max-height": "500px", "overflow": "auto" },
|
---|
56 | baseZIndex: 10000
|
---|
57 | });
|
---|
58 | this.ref.onClose.subscribe((planner: Planner) => {
|
---|
59 | console.log("NOVOKREIRANIOT NAME NA PLANNER: " + planner.name);
|
---|
60 | this.plannerService.postInitialPlanner(planner).subscribe(
|
---|
61 | data=>{
|
---|
62 | console.log(data);
|
---|
63 | },
|
---|
64 | error => console.log('oops', error)
|
---|
65 | );
|
---|
66 | this.messageService.add({ severity: 'success', summary: 'The planner: ' + planner.name + ' has been created.' });
|
---|
67 | });
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|