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

124 lines
4.1 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. selectedDatePosition: any;
  20. selectedDatesForSchedule: Array<number> = [];
  21. showSchedulePopup: boolean = false;
  22. scheduleType: string = 'change time';
  23. scheduleFromTime = {
  24. hour: '09',
  25. min: '30',
  26. isBeforeMidday: true
  27. };
  28. scheduleToTime = {
  29. hour: '09',
  30. min: '00',
  31. isBeforeMidday: false
  32. };
  33. profile_type: string = '';
  34. profile_info: any;
  35. constructor() { }
  36. ngOnInit() {
  37. this.selectedMonth = this.monthMap[(new Date()).getMonth()];
  38. this.selectedYear = (new Date()).getFullYear();
  39. this.currentDate = new Date().getDate();
  40. this.currentMonth = this.monthMap[(new Date()).getMonth()];
  41. this.renderCalendar();
  42. this.profile_type = localStorage.current_login_type;
  43. if (this.profile_type === 'VENDOR') {
  44. this.profile_info = JSON.parse(localStorage.vendor_info);
  45. } else if (this.profile_type === 'OUTLET') {
  46. this.profile_info = JSON.parse(localStorage.outlet_info);
  47. }
  48. console.log(this.profile_info);
  49. }
  50. selectDates(dates: Array<number>) {
  51. this.selectedDatesForSchedule = dates;
  52. }
  53. toggleDates(date: number) {
  54. this.selectedDatesForSchedule.includes(date)? this.selectedDatesForSchedule.splice(this.selectedDatesForSchedule.indexOf(date), 1): this.selectedDatesForSchedule.push(date);
  55. }
  56. renderCalendar() {
  57. // Generate dates for the calendar
  58. let i = 1,
  59. no_of_preceeding_days,
  60. no_of_days_in_selected_month,
  61. no_of_succeeding_days,
  62. last_date_of_previous_month,
  63. first_date_of_selected_month,
  64. last_date_of_selected_month;
  65. first_date_of_selected_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth), 1);
  66. // Add one month, and subtract one day to the selected month and year
  67. last_date_of_selected_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth) + 1, 0);
  68. last_date_of_previous_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth), 0);
  69. no_of_preceeding_days = first_date_of_selected_month.getDay();
  70. no_of_days_in_selected_month = last_date_of_selected_month.getDate();
  71. no_of_succeeding_days = 6 - last_date_of_selected_month.getDay();
  72. this.preceedingDays = [];
  73. this.selectedMonthDays = [];
  74. this.succeedingDays = [];
  75. for (i = no_of_preceeding_days - 1; i >= 0; i -= 1) {
  76. this.preceedingDays.push(last_date_of_previous_month.getDate() - i);
  77. }
  78. for (i = 1; i <= no_of_days_in_selected_month; i += 1) {
  79. this.selectedMonthDays.push(i);
  80. }
  81. for (i = 1; i <= no_of_succeeding_days; i += 1) {
  82. this.succeedingDays.push(i);
  83. }
  84. }
  85. selectNextMonth() {
  86. let next_month_index = (this.monthMap.indexOf(this.selectedMonth) + 1) % this.monthMap.length;
  87. this.selectedMonth = this.monthMap[next_month_index];
  88. if (next_month_index == 0) {
  89. this.selectedYear += 1;
  90. }
  91. this.renderCalendar();
  92. }
  93. selectPreviousMonth() {
  94. let previous_month_index = (this.monthMap.indexOf(this.selectedMonth) + (this.monthMap.length - 1)) % this.monthMap.length;
  95. this.selectedMonth = this.monthMap[previous_month_index];
  96. if (previous_month_index == (this.monthMap.length - 1)) {
  97. this.selectedYear -= 1;
  98. }
  99. this.renderCalendar();
  100. }
  101. }