full_calendar_documentation.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from nicegui import ui
  2. def main_demo() -> None:
  3. from datetime import datetime
  4. def format_date(date_str):
  5. # Parse the date string and format it consistently
  6. parsed_date = datetime.fromisoformat(date_str)
  7. return parsed_date.strftime('%Y-%m-%d %H:%M:%S')
  8. # def handle_calendar_click(event):
  9. # try:
  10. # start = format_date(event.args['info']['event']['start'])
  11. # end = format_date(event.args['info']['event']['end'])
  12. # title = event.args['info']['event']['title']
  13. # except Exception as e:
  14. # title = None
  15. # if title:
  16. # show_event_card(title, start, end)
  17. # def show_event_card(title, start, end):
  18. # card = ui.card().style("background-color: #f0f0f0; position: absolute; z-index: 10000; top: 50%; left: 50%; transform: translate(-50%, -50%);")
  19. # with card:
  20. # ui.label(title)
  21. # ui.button("Click me to remove the event!", on_click=lambda: (fullcal.remove_event(title=title.strip(), start=start, end=end), card.delete()))
  22. # ui.button("Close", on_click=lambda e: card.delete())
  23. # def add_event(fullcal):
  24. ui.add_head_html("<script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.9/index.global.min.js'></script>")
  25. options = {
  26. "initialView": 'timeGridWeek',
  27. "slotMinTime": "05:00:00",
  28. "slotMaxTime": "22:00:00",
  29. "allDaySlot": False,
  30. "timeZone": 'local',
  31. "height": 'auto',
  32. "width": 'auto',
  33. "events": []
  34. }
  35. global fullcal
  36. # button1 = ui.button("Click me to add event", on_click=lambda: add_event(fullcal))
  37. # button = ui.button("Print out all the events", on_click=lambda: ui.notify(fullcal.get_events()))
  38. fullcal = ui.fullcalendar(options) # on_click=lambda e: handle_calendar_click(e)
  39. fullcal.addevent("Math 1b03", format_date("2023-11-18 09:30:00"), format_date("2023-11-18 10:20:00"), color="red")
  40. # main_demo()
  41. # ui.run()