123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // CalendarViewController.swift
- // LMS
- //
- // Created by Suraj Kumar Mandal on 26/12/22.
- //
- import UIKit
- import FSCalendar
- import SideMenu
- import Toast_Swift
- class CalendarViewController: UIViewController {
-
- @IBOutlet var navigationBar: UINavigationBar!
- @IBOutlet var calendar: FSCalendar!
-
- let userData = DBManager.sharedInstance.database.objects(UserDetailsModel.self)
- var datesWithEvent = [String]()
- // var datesWithMultipleEvents = [String]()
-
- var viewModel = CalendarViewModel()
- var calendarData = [CalendarModel]()
-
- fileprivate lazy var dateFormatter2: DateFormatter = {
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd"
- return formatter
- }()
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- // Do any additional setup after loading the view.
- viewModel.delegate = self
- setupUI()
- self.getCalendarData()
- calendar.dataSource = self
- calendar.delegate = self
- }
-
- func setupUI() {
- navigationBar.topItem?.title = "Calendar"
- calendar.layer.cornerRadius = 10
- calendar.dropShadow()
- }
-
- func getCurrentMonth() -> String {
- let date = Date()
- let format = DateFormatter()
- format.dateFormat = "MM-yyyy"
- let formattedMonth = format.string(from: date)
- print(formattedMonth)
- return formattedMonth
- }
-
- func getCalendarData() {
- if Reachability.isConnectedToNetwork() {
- viewModel.getCalendarData(id: userData[0].id, month: getCurrentMonth())
- } else {
- Alert.showInternetFailureAlert(on: self)
- }
- }
-
-
- /*
- // MARK: - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
-
-
- @IBAction func sideMenuAction(_ sender: UIBarButtonItem) {
- let menu = storyboard!.instantiateViewController(withIdentifier: "SideMenuNavigationController") as! SideMenuNavigationController
- present(menu, animated: true, completion: nil)
- }
-
- }
- extension CalendarViewController: FSCalendarDataSource, FSCalendarDelegate, FSCalendarDelegateAppearance {
- func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
- let dateString = dateFormatter2.string(from: date)
- if self.datesWithEvent.contains(dateString) {
- return 1
- }
- // if self.datesWithMultipleEvents.contains(dateString) {
- // return 2
- // }
- return 0
- }
-
-
- // func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, eventDefaultColorsFor date: Date) -> [UIColor]? {
- //
- // let key = self.dateFormatter2.string(from: date)
- //
- // if self.datesWithMultipleEvents.contains(key) {
- // return [UIColor.blue]
- // }
- // return nil
- // }
-
- func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "MeetingListViewController") as! MeetingListViewController
- vc.calendarData = self.calendarData
- vc.meetingDate = dateFormatter2.string(from: date)
- vc.selectedDate = date
- self.present(vc, animated: true, completion: nil)
- }
-
- func minimumDate(for calendar: FSCalendar) -> Date {
- return Date()
- }
- }
- extension CalendarViewController: CalendarProtocol {
- func startLoader() {
- ActivityIndicator.start()
- }
-
- func stopLoader() {
- ActivityIndicator.stop()
- }
-
- func showError(error: String) {
- self.view.makeToast(error)
- }
-
- func loadData(model: [CalendarModel]) {
- self.calendarData = model
- for data in model {
- let date = data.date
- datesWithEvent.append(date ?? "")
- }
- print(datesWithEvent)
- self.calendar.reloadData()
- }
- }
|