Vendor app Client: Maiora
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

93 lines
3.2 KiB

  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-schedules',
  4. templateUrl: './schedules.component.html',
  5. styleUrls: ['./schedules.component.scss']
  6. })
  7. export class SchedulesComponent implements OnInit {
  8. currentDate: number;
  9. currentMonth: string;
  10. selectedDate: number;
  11. selectedMonth: string;
  12. selectedYear: number;
  13. dayMap: Array<string> = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  14. monthMap: Array<string> = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  15. preceedingDays: Array<number> = [];
  16. succeedingDays: Array<number> = [];
  17. selectedMonthDays: Array<number> = [];
  18. selectedTab: string = 'holiday';
  19. constructor() { }
  20. ngOnInit() {
  21. this.selectedMonth = this.monthMap[(new Date()).getMonth()];
  22. this.selectedYear = (new Date()).getFullYear();
  23. this.currentDate = new Date().getDate();
  24. this.currentMonth = this.monthMap[(new Date()).getMonth()];
  25. this.renderCalendar();
  26. }
  27. selectDay(selectedMonthDay: number) {
  28. this.selectedDate = selectedMonthDay;
  29. }
  30. renderCalendar() {
  31. // Generate dates for the calendar
  32. let i = 1,
  33. no_of_preceeding_days,
  34. no_of_days_in_selected_month,
  35. no_of_succeeding_days,
  36. last_date_of_previous_month,
  37. first_date_of_selected_month,
  38. last_date_of_selected_month;
  39. first_date_of_selected_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth), 1);
  40. // Add one month, and subtract one day to the selected month and year
  41. last_date_of_selected_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth) + 1, 0);
  42. last_date_of_previous_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth), 0);
  43. no_of_preceeding_days = first_date_of_selected_month.getDay();
  44. no_of_days_in_selected_month = last_date_of_selected_month.getDate();
  45. no_of_succeeding_days = 6 - last_date_of_selected_month.getDay();
  46. this.preceedingDays = [];
  47. this.selectedMonthDays = [];
  48. this.succeedingDays = [];
  49. for (i = no_of_preceeding_days - 1; i >= 0; i -= 1) {
  50. this.preceedingDays.push(last_date_of_previous_month.getDate() - i);
  51. }
  52. for (i = 1; i <= no_of_days_in_selected_month; i += 1) {
  53. this.selectedMonthDays.push(i);
  54. }
  55. for (i = 1; i <= no_of_succeeding_days; i += 1) {
  56. this.succeedingDays.push(i);
  57. }
  58. }
  59. selectNextMonth() {
  60. let next_month_index = (this.monthMap.indexOf(this.selectedMonth) + 1) % this.monthMap.length;
  61. this.selectedMonth = this.monthMap[next_month_index];
  62. if (next_month_index == 0) {
  63. this.selectedYear += 1;
  64. }
  65. this.renderCalendar();
  66. }
  67. selectPreviousMonth() {
  68. let previous_month_index = (this.monthMap.indexOf(this.selectedMonth) + (this.monthMap.length - 1)) % this.monthMap.length;
  69. this.selectedMonth = this.monthMap[previous_month_index];
  70. if (previous_month_index == (this.monthMap.length - 1)) {
  71. this.selectedYear -= 1;
  72. }
  73. this.renderCalendar();
  74. }
  75. }