浏览代码

made it so that you can add an event - without needing to update the entire ui

frankvp11 1 年之前
父节点
当前提交
3d20dda247

+ 27 - 0
nicegui/elements/calendarEvent.py

@@ -0,0 +1,27 @@
+
+
+
+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]

+ 25 - 16
nicegui/elements/fullcalendar.js

@@ -1,26 +1,35 @@
 export default {
   template: "<div></div>",
   props: {
-    eventsData: Array,
+    options: Array,
+    eventToAdd: Object
   },
   mounted() {
-    this.calendar = new FullCalendar.Calendar(this.$el, {
-      initialView: "timeGridWeek",
-      slotMinTime: "05:00:00",
-      slotMaxTime: "22:00:00",
-      allDaySlot: false,
-      timeZone: "local",
-      height: "auto",
-      events: this.eventsData,
-      eventClick: function(info) {
-          alert('Event: ' + info.event.title);
-          this.$emit("click", {"click":info});
-        
-      }
-    });
+    this.options.eventClick = (info) => {
+      console.log("hi2");
+      this.$emit("click", { info: info });
+    };
 
+    this.calendar = new FullCalendar.Calendar(this.$el, this.options);
     this.calendar.render();
   },
   methods: {
+    update_calendar() {
+      if (this.calendar) {
+        // this.calendar = new FullCalendar.Calendar(this.$el, this.options);
+        // this.calendar.render()
+        // this.calendar.addEvent(this.eventToAdd);
+        this.calendar.render()
+      }
+    },
+    add_event(eventToAdd) {
+      if (this.calendar) {
+        this.calendar.addEvent(eventToAdd);
+        this.calendar.render() 
+        console.log("hi");
+      }
+      
+    }
+
   },
-};
+};

+ 29 - 9
nicegui/elements/fullcalendar.py

@@ -1,20 +1,40 @@
-from typing import Dict, List, Optional, Callable
+from typing import Any, Callable, Dict, List, Optional
 
 from ..element import Element
 from ..events import GenericEventArguments, handle_event
 
+
+
+
 class FullCalendar(Element, component='fullcalendar.js', libraries=['lib/fullcalendar/index.global.min.js']):
-    def __init__(self, events_data: List[Dict], on_click: Optional[Callable] = None) -> None:
+    def __init__(self, options: Dict[str, Any], on_click: Optional[Callable] = None) -> None:
         super().__init__()
-        self._props['eventsData'] = events_data
+        self._props['options'] = options
+        
         if on_click:
             def handle_on_click(e: GenericEventArguments):
-                print(e)
+                # print(e)
                 handle_event(on_click, e)
-        
-            self.on("click", handle_on_click, ['click'])
 
+            self.on("click", handle_on_click, ['info'])
+
+    def updater(self, event) -> None:
+        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 on_event_clicked(self, event_info):
-        # Implement your logic to handle the clicked event in Python
-        print("Event clicked in Python:", event_info)
+    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)

+ 2 - 0
nicegui/ui.py

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

文件差异内容过多而无法显示
+ 113 - 2
website/more_documentation/fullcalendar_test.py


部分文件因为文件数量过多而无法显示