danielsantoso

widget doctor schedule table ts

Dec 11th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import { Component, Injector, OnInit } from '@angular/core';
  2. import { Router, ActivatedRoute } from '@angular/router';
  3. import { DoctorService} from "../service/doctor.service";
  4. import { FormGroup, FormControl, Validators } from '@angular/forms';
  5.  
  6. @Component({
  7. selector: 'app-widget-doctor-schedule-table',
  8. templateUrl: './widget-doctor-schedule-table.component.html',
  9. styleUrls: ['./widget-doctor-schedule-table.component.css']
  10. })
  11. export class WidgetDoctorScheduleTableComponent implements OnInit {
  12. model: any = {};
  13. returnUrl: string;
  14. id: number = 3;
  15. days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
  16. reloadMessage: string;
  17. doctorName: string;
  18.  
  19. constructor(
  20. private route: ActivatedRoute,
  21. private router: Router,
  22. private doctorService: DoctorService,
  23. private injector: Injector,) {
  24. this.doctorName = this.injector.get('doctorName');
  25. this.reloadMessage = this.injector.get('reloadMessage');
  26. }
  27.  
  28. public postScheduleForm = new FormGroup({
  29. day: new FormControl("day", Validators.required),
  30. time_start: new FormControl("time_start", Validators.required),
  31. time_end: new FormControl("time_start", Validators.required),
  32. room: new FormControl("room", Validators.required),
  33. });
  34.  
  35. postSchedule(event) {
  36. let formData = this.postScheduleForm.value;
  37. console.log(formData);
  38.  
  39. console.log('success');
  40. console.log(this.model.id);
  41. console.log(this.model.day);
  42. console.log(this.model.time_start);
  43. console.log(this.model.time_start.hour);
  44. console.log(this.model.time_end);
  45. console.log(this.model.room);
  46.  
  47. this.model.time_start = this.model.time_start.hour + ':' + this.model.time_start.minute + ':' + this.model.time_start.second;
  48. this.model.time_end = this.model.time_end.hour + ':' + this.model.time_end.minute + ':' + this.model.time_end.second;
  49.  
  50. this.doctorService.postDoctorSchedule(this.id, 'OP', this.model)
  51. .subscribe(
  52. data => {
  53.  
  54. if(data == null) {
  55. console.log('Error');
  56. }
  57. else {
  58. this.router.navigate([this.returnUrl]);
  59. }
  60. },
  61. error => {
  62. console.log('failed');
  63. });
  64. }
  65.  
  66. ngOnInit() {
  67. this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
  68. }
  69.  
  70. }
Add Comment
Please, Sign In to add comment