Vendor app Client: Maiora
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

164 Zeilen
5.7 KiB

  1. import { Component, OnInit } from '@angular/core';
  2. import { OutletService } from '../services/outlet.service';
  3. @Component({
  4. selector: 'app-schedules',
  5. templateUrl: './schedules.component.html',
  6. styleUrls: ['./schedules.component.scss']
  7. })
  8. export class SchedulesComponent implements OnInit {
  9. currentDate: number;
  10. currentMonth: string;
  11. selectedDate: number;
  12. selectedMonth: string;
  13. selectedYear: number;
  14. dayMap: Array<string> = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  15. monthMap: Array<string> = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  16. preceedingDays: Array<number> = [];
  17. succeedingDays: Array<number> = [];
  18. selectedMonthDays: Array<number> = [];
  19. selectedTab: string = 'holiday';
  20. selectedDatePosition: any;
  21. selectedDatesForSchedule: Array<number> = [];
  22. showSchedulePopup: boolean = false;
  23. scheduleType: string = 'change time';
  24. selectedMonthIndex: number;
  25. scheduleFromTime = {
  26. hour: '09',
  27. min: '30',
  28. isBeforeMidday: true
  29. };
  30. scheduleToTime = {
  31. hour: '09',
  32. min: '00',
  33. isBeforeMidday: false
  34. };
  35. outletTimings: any
  36. profile_type: string = '';
  37. profile_info: any;
  38. outletTiming: {
  39. close_timing: string;
  40. holidays: string,
  41. open_timing: string,
  42. schedules: {
  43. outlet_id: number
  44. }
  45. } = {
  46. close_timing: "2021-10-28T09:37:05.776Z",
  47. holidays: '',
  48. open_timing: "2021-10-28T09:37:05.776Z",
  49. schedules: {
  50. outlet_id: null
  51. }
  52. }
  53. selectedHolidays: Array<string> = [];
  54. constructor(
  55. private outletService: OutletService
  56. ) { }
  57. ngOnInit() {
  58. this.selectedMonth = this.monthMap[(new Date()).getMonth()];
  59. this.selectedYear = (new Date()).getFullYear();
  60. this.currentDate = new Date().getDate();
  61. this.currentMonth = this.monthMap[(new Date()).getMonth()];
  62. this.renderCalendar();
  63. this.profile_type = localStorage.current_login_type;
  64. if (this.profile_type === 'VENDOR') {
  65. this.profile_info = JSON.parse(localStorage.vendor_info);
  66. } else if (this.profile_type === 'OUTLET') {
  67. this.profile_info = JSON.parse(localStorage.outlet_info);
  68. }
  69. console.log(this.profile_info);
  70. }
  71. selectDates(dates: Array<number>) {
  72. this.selectedDatesForSchedule = dates;
  73. }
  74. toggleDates(date: number) {
  75. this.selectedDatesForSchedule.includes(date) ? this.selectedDatesForSchedule.splice(this.selectedDatesForSchedule.indexOf(date), 1) : this.selectedDatesForSchedule.push(date);
  76. }
  77. renderCalendar() {
  78. // Generate dates for the calendar
  79. let i = 1,
  80. no_of_preceeding_days,
  81. no_of_days_in_selected_month,
  82. no_of_succeeding_days,
  83. last_date_of_previous_month,
  84. first_date_of_selected_month,
  85. last_date_of_selected_month;
  86. first_date_of_selected_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth), 1);
  87. // Add one month, and subtract one day to the selected month and year
  88. last_date_of_selected_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth) + 1, 0);
  89. last_date_of_previous_month = new Date(this.selectedYear, this.monthMap.indexOf(this.selectedMonth), 0);
  90. no_of_preceeding_days = first_date_of_selected_month.getDay();
  91. no_of_days_in_selected_month = last_date_of_selected_month.getDate();
  92. no_of_succeeding_days = 6 - last_date_of_selected_month.getDay();
  93. this.preceedingDays = [];
  94. this.selectedMonthDays = [];
  95. this.succeedingDays = [];
  96. for (i = no_of_preceeding_days - 1; i >= 0; i -= 1) {
  97. this.preceedingDays.push(last_date_of_previous_month.getDate() - i);
  98. }
  99. for (i = 1; i <= no_of_days_in_selected_month; i += 1) {
  100. this.selectedMonthDays.push(i);
  101. }
  102. for (i = 1; i <= no_of_succeeding_days; i += 1) {
  103. this.succeedingDays.push(i);
  104. }
  105. }
  106. selectNextMonth() {
  107. let next_month_index = (this.monthMap.indexOf(this.selectedMonth) + 1) % this.monthMap.length;
  108. this.selectedMonth = this.monthMap[next_month_index];
  109. if (next_month_index == 0) {
  110. this.selectedYear += 1;
  111. }
  112. this.renderCalendar();
  113. }
  114. selectPreviousMonth() {
  115. let previous_month_index = (this.monthMap.indexOf(this.selectedMonth) + (this.monthMap.length - 1)) % this.monthMap.length;
  116. this.selectedMonth = this.monthMap[previous_month_index];
  117. if (previous_month_index == (this.monthMap.length - 1)) {
  118. this.selectedYear -= 1;
  119. }
  120. this.renderCalendar();
  121. }
  122. scheduleHolidays() {
  123. this.selectedHolidays = this.selectedDatesForSchedule.map(selectedDates => this.getTodayString(selectedDates.toString()))
  124. this.outletTiming.holidays = JSON.stringify(this.selectedHolidays)
  125. console.log(this.outletTiming)
  126. this.outletService.addOutletSchedules(this.outletTiming, this.profile_info.outlet_id).then((data) => {
  127. console.log(data)
  128. }, err=>{
  129. console.log("Unable to Update Holidays")
  130. })
  131. }
  132. getTodayString(selectedMonthDay: string) {
  133. let monthIndex = this.monthMap.findIndex((month) => this.selectedMonth.toLowerCase() === month.toLowerCase()) + 1;
  134. return new Date(this.selectedYear + '-' + monthIndex.toString().padStart(2, '0') + '-' + selectedMonthDay.toString().padStart(2, '0') + 'T00:00').toString();
  135. }
  136. }