Browse Source

code review

Falko Schindler 1 year ago
parent
commit
ccb8103378

+ 13 - 0
DEPENDENCIES.md

@@ -1,3 +1,16 @@
 # Included Web Dependencies
 
+- vue: 3.3.6 ([MIT](https://opensource.org/licenses/MIT))
+- quasar: 2.13.0 ([MIT](https://opensource.org/licenses/MIT))
+- tailwindcss: 3.2.0 ([MIT](https://opensource.org/licenses/MIT))
+- socket.io: 4.7.2 ([MIT](https://opensource.org/licenses/MIT))
+- es-module-shims: 1.8.0 ([MIT](https://opensource.org/licenses/MIT))
+- aggrid: 30.2.0 ([MIT](https://opensource.org/licenses/MIT))
+- echarts: 5.4.3 ([Apache-2.0](https://opensource.org/licenses/Apache-2.0))
+- mermaid: 10.5.1 ([MIT](https://opensource.org/licenses/MIT))
+- nipplejs: 0.10.1 ([MIT](https://opensource.org/licenses/MIT))
+- plotly: 2.27.0 ([MIT](https://opensource.org/licenses/MIT))
+- three: 0.157.0 ([MIT](https://opensource.org/licenses/MIT))
+- tween: 21.0.0 ([MIT](https://opensource.org/licenses/MIT))
+- vanilla-jsoneditor: 0.18.10 ([ISC](https://opensource.org/licenses/ISC))
 - fullcalendar: 6.1.9 ([MIT](https://opensource.org/licenses/MIT))

+ 5 - 11
nicegui/elements/fullcalendar.js

@@ -4,22 +4,16 @@ export default {
     options: Array,
   },
   mounted() {
-    this.options.eventClick = (info) => {
-      this.$emit("click", { info: info });
-    };
-
+    this.options.eventClick = (info) => this.$emit("click", { info });
     this.calendar = new FullCalendar.Calendar(this.$el, this.options);
     this.calendar.render();
   },
   methods: {
     update_calendar() {
-      if (this.calendar) {   
-        this.calendar.setOption('events', this.options.events)
+      if (this.calendar) {
+        this.calendar.setOption("events", this.options.events);
         this.calendar.render();
-          }
+      }
     },
-
-
-
   },
-};
+};

+ 17 - 27
nicegui/elements/fullcalendar.py

@@ -1,49 +1,39 @@
 from typing import Any, Callable, Dict, List, Optional
 
 from ..element import Element
-from ..events import GenericEventArguments, handle_event
-
-
+from ..events import handle_event
 
 
 class FullCalendar(Element, component='fullcalendar.js', libraries=['lib/fullcalendar/index.global.min.js']):
     def __init__(self, options: Dict[str, Any], on_click: Optional[Callable] = None) -> None:
-        """ FullCalendar
-            An element that integrates the FullCalendar library (https://fullcalendar.io/) to create an interactive calendar display.
-            
-            
-            :param properties: dictionary of FullCalendar properties for customization, such as "initialView", "slotMinTime", "slotMaxTime", "allDaySlot", "timeZone", "height", and "events".
-            :param on_click: callback function that is called when a calendar event is clicked.
-            :return: FullCalendar element with the specified properties and event handling.
-                
-        """
+        """FullCalendar
 
+        An element that integrates the FullCalendar library (https://fullcalendar.io/) to create an interactive calendar display.
+
+        :param options: dictionary of FullCalendar properties for customization, such as "initialView", "slotMinTime", "slotMaxTime", "allDaySlot", "timeZone", "height", and "events".
+        :param on_click: callback function that is called when a calendar event is clicked.
+        """
         super().__init__()
         self._props['options'] = options
-        
-        if on_click:
-            def handle_on_click(e: GenericEventArguments):
-                handle_event(on_click, e)
-
-            self.on("click", handle_on_click, ['info'])
-
 
+        if on_click:
+            self.on('click', lambda e: handle_event(on_click, e))
 
-    def addevent(self, title, start, end, **args):
-        event_dict = {"title": title, "start": start, "end": end, **args}
+    def add_event(self, title: str, start: str, end: str, **kwargs) -> None:
+        event_dict = {'title': title, 'start': start, 'end': end, **kwargs}
         self._props['options']['events'].append(event_dict)
-        super().update()
+        self.update()
         self.run_method('update_calendar')
 
-    def remove_event(self, title, start, end, **args):
-
+    def remove_event(self, title: str, start: str, end: str) -> None:
         for event in self._props['options']['events']:
             if event['title'] == title and event['start'] == start and event['end'] == end:
                 self._props['options']['events'].remove(event)
                 break
 
-        super().update()
+        self.update()
         self.run_method('update_calendar')
-    def get_events(self):
+
+    @property
+    def events(self) -> List[Dict]:
         return self._props['options']['events']
-        

+ 2 - 3
nicegui/ui.py

@@ -25,6 +25,7 @@ __all__ = [
     'echart',
     'editor',
     'expansion',
+    'fullcalendar',
     'grid',
     'highchart',
     'html',
@@ -58,7 +59,6 @@ __all__ = [
     'scroll_area',
     'select',
     'separator',
-    'fullcalendar',
     'slider',
     'spinner',
     'splitter',
@@ -99,7 +99,6 @@ __all__ = [
     'right_drawer',
     'run',
     'run_with',
-    
 ]
 
 from .element import Element as element
@@ -128,6 +127,7 @@ from .elements.dialog import Dialog as dialog
 from .elements.echart import EChart as echart
 from .elements.editor import Editor as editor
 from .elements.expansion import Expansion as expansion
+from .elements.fullcalendar import FullCalendar as fullcalendar
 from .elements.grid import Grid as grid
 from .elements.highchart import highchart
 from .elements.html import Html as html
@@ -178,7 +178,6 @@ from .elements.time import Time as time
 from .elements.timeline import Timeline as timeline
 from .elements.timeline import TimelineEntry as timeline_entry
 from .elements.timer import Timer as timer
-from .elements.fullcalendar import FullCalendar as fullcalendar
 from .elements.toggle import Toggle as toggle
 from .elements.tooltip import Tooltip as tooltip
 from .elements.tree import Tree as tree

+ 1 - 2
npm.json

@@ -107,8 +107,7 @@
     "rename": {
       "package/": ""
     }
-  }
-  ,
+  },
   "fullcalendar": {
     "destination": "nicegui/elements/lib",
     "keep": ["package/index.global.min.js"],

+ 2 - 0
website/documentation.py

@@ -81,6 +81,7 @@ def create_full() -> None:
     load_demo(ui.upload)
     load_demo(ui.chat_message)
     load_demo(ui.element)
+
     heading('Markdown and HTML')
 
     load_demo(ui.markdown)
@@ -146,6 +147,7 @@ def create_full() -> None:
     load_demo(ui.code)
     load_demo(ui.json_editor)
     load_demo(ui.fullcalendar)
+
     heading('Layout')
 
     load_demo(ui.card)

+ 14 - 23
website/more_documentation/full_calendar_documentation.py

@@ -1,32 +1,23 @@
 from nicegui import ui
 
 
-
 def main_demo() -> None:
     from datetime import datetime
-    def format_date(date_str):
-        # Parse the date string and format it consistently
-        parsed_date = datetime.fromisoformat(date_str)
-        return parsed_date.strftime('%Y-%m-%d %H:%M:%S')
-
 
+    def format_date(dt: datetime) -> str:
+        """Parse the date string and format it consistently."""
+        return dt.strftime(r'%Y-%m-%d %H:%M:%S')
 
-    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 = {
-        "initialView": 'timeGridWeek',
-        "slotMinTime": "05:00:00",
-        "slotMaxTime": "22:00:00",
-        "allDaySlot": False,
-        "timeZone": 'local',
-        "height": 'auto',
-        "width": 'auto',
-        "events": []
+        'initialView': 'timeGridWeek',
+        'slotMinTime': '05:00:00',
+        'slotMaxTime': '22:00:00',
+        'allDaySlot': False,
+        'timeZone': 'local',
+        'height': 'auto',
+        'width': 'auto',
+        'events': [],
     }
-    global fullcal
-
-    fullcal = ui.fullcalendar(options) # on_click=lambda e: handle_calendar_click(e)
-    fullcal.addevent("Math 1b03", format_date(str(datetime.now())), format_date(str(datetime.now())), color="red")
-
-
-main_demo()
-ui.run()
+    calendar = ui.fullcalendar(options, on_click=ui.notify)
+    calendar.add_event('Math 1b03', format_date(datetime.now()), format_date(datetime.now()), color='red')

File diff suppressed because it is too large
+ 0 - 3
website/more_documentation/testtemp.py


Some files were not shown because too many files changed in this diff