浏览代码

fixed the way that events were being added - current bug: when you "add" an event, you have to refresh the page to see it

frankvp11 1 年之前
父节点
当前提交
c25708c839

+ 0 - 27
nicegui/elements/calendarEvent.py

@@ -1,27 +0,0 @@
-
-
-
-class CalendarEvent():
-    def __init__(self) -> None:
-        self.events = []
-    def add_event(self, title, start, end, **args):
-        event_dict = {"title": title, "start": start, "end": end, **args}
-        self.events.append(event_dict)
-    def get_events(self):
-        return self.events
-
-    def remove_event(self, title, start, end, **args):
-        index_to_remove = None
-        for i, event in enumerate(self.events):
-            if (
-                event["title"] == title
-                and event["start"] == start
-                and event["end"] == end
-                and all(event[key] == args[key] for key in args)
-            ):
-                index_to_remove = i
-                break
-
-        # Remove the event if found
-        if index_to_remove is not None:
-            del self.events[index_to_remove]

+ 3 - 13
nicegui/elements/fullcalendar.js

@@ -2,7 +2,7 @@ export default {
   template: "<div></div>",
   template: "<div></div>",
   props: {
   props: {
     options: Array,
     options: Array,
-    eventToAdd: Object
+    // eventToAdd: Object
   },
   },
   mounted() {
   mounted() {
     this.options.eventClick = (info) => {
     this.options.eventClick = (info) => {
@@ -15,21 +15,11 @@ export default {
   },
   },
   methods: {
   methods: {
     update_calendar() {
     update_calendar() {
-      if (this.calendar) {
-        // this.calendar = new FullCalendar.Calendar(this.$el, this.options);
-        // this.calendar.render()
-        // this.calendar.addEvent(this.eventToAdd);
+      if (this.calendar) {    
         this.calendar.render()
         this.calendar.render()
       }
       }
     },
     },
-    add_event(eventToAdd) {
-      if (this.calendar) {
-        this.calendar.addEvent(eventToAdd);
-        this.calendar.render() 
-        console.log("hi");
-      }
-      
-    }
+
 
 
   },
   },
 };
 };

+ 25 - 18
nicegui/elements/fullcalendar.py

@@ -18,23 +18,30 @@ class FullCalendar(Element, component='fullcalendar.js', libraries=['lib/fullcal
 
 
             self.on("click", handle_on_click, ['info'])
             self.on("click", handle_on_click, ['info'])
 
 
-    def updater(self, event) -> None:
+
+
+    def addevent(self, title, start, end, **args):
+        event_dict = {"title": title, "start": start, "end": end, **args}
+        self._props['options']['events'].append(event_dict)
+        super().update()
+        self.run_method('update_calendar')
         super().update()
         super().update()
-        print("Attempting to update!")
-        self.run_method('update_calendar', event)
 
 
-    def updatecal(self, options: Dict[str, Any]) -> None:
-        # Implement your logic here to update the calendar with the new options
-        print("Updating calendar with options:", options)
-        # You might want to update the FullCalendar instance with the new options
-        self._props['options'] = options
-        self.updater(None)
-    
-
-    def addevent(self, event):
-        self._props['eventToAdd'] = event
-        self._props['options']['events'].append(event)
-        # super().update()
-        print("Attempting to add an event", event)
-        # self.run_method('add_event', event)
-        self.updater(event)
+    def remove_event(self, title, start, end, **args):
+        index_to_remove = None
+        for i, event in enumerate(self._props['options']['events']):
+            if (
+                event["title"] == title
+                and event["start"] == start
+                and event["end"] == end
+                and all(event[key] == args[key] for key in args)
+            ):
+                index_to_remove = i
+                break
+
+        # Remove the event if found
+        if index_to_remove is not None:
+            del self._props['options']['events'][index_to_remove]
+        super().update()
+        self.run_method('update_calendar')
+        

+ 1 - 2
nicegui/ui.py

@@ -99,13 +99,12 @@ __all__ = [
     'right_drawer',
     'right_drawer',
     'run',
     'run',
     'run_with',
     'run_with',
-    'calendar_event'
+    
 ]
 ]
 
 
 from .element import Element as element
 from .element import Element as element
 from .elements.aggrid import AgGrid as aggrid
 from .elements.aggrid import AgGrid as aggrid
 from .elements.audio import Audio as audio
 from .elements.audio import Audio as audio
-from .elements.calendarEvent import CalendarEvent as calendar_event
 from .elements.avatar import Avatar as avatar
 from .elements.avatar import Avatar as avatar
 from .elements.badge import Badge as badge
 from .elements.badge import Badge as badge
 from .elements.button import Button as button
 from .elements.button import Button as button

+ 37 - 35
website/more_documentation/fullcalendar_test.py

@@ -1,29 +1,7 @@
 from nicegui import app, ui
 from nicegui import app, ui
 
 
-calendarEvents = ui.calendar_event()
-# calendarEvents.add_event('MATH 1B03 - T06 - Linear Algebra I', '2023-10-11 09:30:00', '2023-10-11 10:20:00')
-# calendarEvents.add_event('MATH 1ZA3 - C01 - Engineering Mathematics I', '2023-10-11 11:30:00', '2023-10-11 12:20:00')
-# calendarEvents.add_event('COMPSCI 1MD3 - T05 - Introduction to Programming', '2023-10-11 12:30:00', '2023-10-11 13:20:00')
-# calendarEvents.add_event('MATH 1B03 - C02 - Linear Algebra I', '2023-10-11 14:30:00', '2023-10-11 15:20:00')
-# calendarEvents.add_event('FRENCH 1A06A - C04 - Introduction to French Studies: Advanced Level', '2023-10-11 20:00:00', '2023-10-11 22:00:00')
-# calendarEvents.add_event('COMPSCI 1JC3 - C01 - Introduction to Computational Thinking', '2023-10-12 10:30:00', '2023-10-12 11:20:00')
-# calendarEvents.add_event('MATH 1ZA3 - C01 - Engineering Mathematics I', '2023-10-12 11:30:00', '2023-10-12 12:20:00')
-# calendarEvents.add_event('COMPSCI 1MD3 - C01 - Introduction to Programming', '2023-10-12 13:30:00', '2023-10-12 14:20:00')
-# calendarEvents.add_event('MATH 1B03 - C02 - Linear Algebra I', '2023-10-12 14:30:00', '2023-10-12 15:20:00')
-# calendarEvents.add_event('COMPSCI 1JC3 - C01 - Introduction to Computational Thinking', '2023-10-13 10:30:00', '2023-10-13 11:20:00')
-# calendarEvents.add_event('COMPSCI 1JC3 - T01 - Introduction to Computational Thinking', '2023-10-13 11:30:00', '2023-10-13 13:20:00')
-# calendarEvents.add_event('MATH 1ZA3 - T02 - Engineering Mathematics I', '2023-10-13 14:30:00', '2023-10-13 15:20:00')
-# calendarEvents.add_event('MATH 1ZA3 - C01 - Engineering Mathematics I', '2023-10-16 11:30:00', '2023-10-16 12:20:00')
-# calendarEvents.add_event('COMPSCI 1MD3 - C01 - Introduction to Programming', '2023-10-16 13:30:00', '2023-10-16 14:20:00')
-# calendarEvents.add_event('MATH 1B03 - C02 - Linear Algebra I', '2023-10-16 14:30:00', '2023-10-16 15:20:00')
-# calendarEvents.add_event('FRENCH 1A06A - T07 - Introduction to French Studies: Advanced Level', '2023-10-16 17:30:00', '2023-10-16 18:20:00')
-# calendarEvents.add_event('FRENCH 1A06A - C04 - Introduction to French Studies: Advanced Level', '2023-10-16 19:00:00', '2023-10-16 20:00:00')
-# calendarEvents.add_event('COMPSCI 1JC3 - C01 - Introduction to Computational Thinking', '2023-10-17 10:30:00', '2023-10-17 11:20:00')
-# calendarEvents.add_event('COMPSCI 1MD3 - C01 - Introduction to Programming', '2023-10-17 14:30:00', '2023-10-17 15:20:00')
-# calendarEvents.add_event('MATH 1B03 - T06 - Linear Algebra I', '2023-10-18 09:30:00', '2023-10-18 10:20:00')
-
-
-# calendarEvents.remove_event('MATH 1B03 - T06 - Linear Algebra I', '2023-10-18 09:30:00', '2023-10-18 10:20:00')
+
+
 
 
 ui.add_head_html("<script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.9/index.global.min.js'></script>")
 ui.add_head_html("<script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.9/index.global.min.js'></script>")
 options = {
 options = {
@@ -32,15 +10,15 @@ options = {
     "slotMaxTime": "22:00:00",
     "slotMaxTime": "22:00:00",
     "allDaySlot": False,
     "allDaySlot": False,
     "timeZone": 'local',
     "timeZone": 'local',
-    "height": 'auto', "events": calendarEvents.get_events()}
-
+    "height": 'auto', "events": []
+    }
 
 
 
 
 title= None
 title= None
 def func(e):
 def func(e):
     global title, card
     global title, card
     title = None
     title = None
-    
+    print(e)
     try:
     try:
         print(e.args['info']['event']['title'])
         print(e.args['info']['event']['title'])
         title = e.args['info']['event']['title']
         title = e.args['info']['event']['title']
@@ -52,22 +30,46 @@ def func(e):
         with card:
         with card:
             ui.label(title)
             ui.label(title)
             ui.button("Close", on_click=lambda e: card.delete())
             ui.button("Close", on_click=lambda e: card.delete())
+
+
 fullcal = ui.fullcalendar(options,  on_click=lambda e: func(e))
 fullcal = ui.fullcalendar(options,  on_click=lambda e: func(e))
+fullcal.addevent('MATH 1B03 - T06 - Linear Algebra I', '2023-10-11 09:30:00', '2023-10-11 10:20:00')
+fullcal.addevent('MATH 1ZA3 - C01 - Engineering Mathematics I', '2023-10-11 11:30:00', '2023-10-11 12:20:00')
+fullcal.addevent('COMPSCI 1MD3 - T05 - Introduction to Programming', '2023-10-11 12:30:00', '2023-10-11 13:20:00')
+fullcal.addevent('MATH 1B03 - C02 - Linear Algebra I', '2023-10-11 14:30:00', '2023-10-11 15:20:00')
+fullcal.addevent('FRENCH 1A06A - C04 - Introduction to French Studies: Advanced Level', '2023-10-11 20:00:00', '2023-10-11 22:00:00')
+fullcal.addevent('COMPSCI 1JC3 - C01 - Introduction to Computational Thinking', '2023-10-12 10:30:00', '2023-10-12 11:20:00')
+fullcal.addevent('MATH 1ZA3 - C01 - Engineering Mathematics I', '2023-10-12 11:30:00', '2023-10-12 12:20:00')
+fullcal.addevent('COMPSCI 1MD3 - C01 - Introduction to Programming', '2023-10-12 13:30:00', '2023-10-12 14:20:00')
+fullcal.addevent('MATH 1B03 - C02 - Linear Algebra I', '2023-10-12 14:30:00', '2023-10-12 15:20:00')
+fullcal.addevent('COMPSCI 1JC3 - C01 - Introduction to Computational Thinking', '2023-10-13 10:30:00', '2023-10-13 11:20:00')
+fullcal.addevent('COMPSCI 1JC3 - T01 - Introduction to Computational Thinking', '2023-10-13 11:30:00', '2023-10-13 13:20:00')
+fullcal.addevent('MATH 1ZA3 - T02 - Engineering Mathematics I', '2023-10-13 14:30:00', '2023-10-13 15:20:00')
+fullcal.addevent('MATH 1ZA3 - C01 - Engineering Mathematics I', '2023-10-16 11:30:00', '2023-10-16 12:20:00')
+fullcal.addevent('COMPSCI 1MD3 - C01 - Introduction to Programming', '2023-10-16 13:30:00', '2023-10-16 14:20:00')
+fullcal.addevent('MATH 1B03 - C02 - Linear Algebra I', '2023-10-16 14:30:00', '2023-10-16 15:20:00')
+fullcal.addevent('FRENCH 1A06A - T07 - Introduction to French Studies: Advanced Level', '2023-10-16 17:30:00', '2023-10-16 18:20:00')
+fullcal.addevent('FRENCH 1A06A - C04 - Introduction to French Studies: Advanced Level', '2023-10-16 19:00:00', '2023-10-16 20:00:00')
+fullcal.addevent('COMPSCI 1JC3 - C01 - Introduction to Computational Thinking', '2023-10-17 10:30:00', '2023-10-17 11:20:00')
+fullcal.addevent('COMPSCI 1MD3 - C01 - Introduction to Programming', '2023-10-17 14:30:00', '2023-10-17 15:20:00')
+fullcal.addevent('MATH 1B03 - T06 - Linear Algebra I', '2023-10-18 09:30:00', '2023-10-18 10:20:00')
+
+
+
 
 
 def add_event():
 def add_event():
-    global fullcal, options
-    # calendarEvents.add_event('MATH 1B03 - T06 - Linear Algebra I', '2023-11-18 09:30:00', '2023-11-18 10:20:00')
-    # options['events'] = calendarEvents.get_events()
-    # fullcal._props['options'] = options
-    # fullcal.update()
-    # fullcal.updatecal(options)
-    fullcal.addevent({"title": "MATH 1B03 - T06 - Linear Algebra I", "start":"2023-11-18 09:30:00", "end":"2023-11-18 10:20:00"})
+    global fullcal
+    fullcal.addevent("Math 1b03", "2023-10-19 09:30:00", "2023-10-19 10:20:00")
     
     
     print(fullcal._props)
     print(fullcal._props)
 
 
 
 
-ui.button("click me to add event", on_click=add_event)
+def remove_event():
+    global fullcal
+    fullcal.remove_event("Math 1b03", "2023-10-19 09:30:00", "2023-10-19 10:20:00")
 
 
+ui.button("click me to add event", on_click=add_event)
+ui.button("Clcik me to delete event", on_click=remove_event)
 ui.run()
 ui.run()