From 359219136724b6ba39f9a9861b67ac10d305ab21 Mon Sep 17 00:00:00 2001 From: jr-k Date: Sun, 12 May 2024 21:16:13 +0200 Subject: [PATCH] prepare schedule end + fix hot reload --- data/www/css/main.css | 13 +++++++++++-- data/www/js/slideshow.js | 13 +++++++++++++ lang/en.json | 11 +++++++---- lang/fr.json | 9 ++++++--- src/controller/SlideshowController.py | 2 ++ src/manager/SlideManager.py | 8 +++++--- src/model/entity/Slide.py | 13 ++++++++++++- src/service/WebServer.py | 8 ++------ src/utils.py | 1 - views/auth/modal/edit.jinja.html | 2 +- views/fleet/modal/edit.jinja.html | 2 +- views/settings/modal/edit.jinja.html | 2 +- views/slideshow/modal/add.jinja.html | 22 ++++++++++++++++++++++ views/slideshow/modal/edit.jinja.html | 26 +++++++++++++++++++++++++- 14 files changed, 108 insertions(+), 24 deletions(-) diff --git a/data/www/css/main.css b/data/www/css/main.css index 2aafa25..ed9f811 100644 --- a/data/www/css/main.css +++ b/data/www/css/main.css @@ -469,6 +469,7 @@ button.purple:hover { min-width: 30%; display: flex; flex-direction: column; + overflow: auto; } .modals-outer .modal-close { @@ -479,7 +480,7 @@ button.purple:hover { justify-content: flex-end; align-items: center; margin-bottom: 20px; - margin-top: -100px; + margin-top: 0px; } .modals-inner { @@ -494,6 +495,14 @@ button.purple:hover { margin: 0; } + +.modals-inner .modal h3 { + align-self: stretch; + border-bottom: 1px solid #DDD; + padding: 15px 15px; + margin: 0; +} + form { display: flex; flex-direction: column; @@ -503,7 +512,7 @@ form { } form .form-group { - margin: 20px; + margin: 10px 20px 5px 20px; display: flex; flex-direction: row; justify-content: flex-start; diff --git a/data/www/js/slideshow.js b/data/www/js/slideshow.js index 15f8916..fedc915 100644 --- a/data/www/js/slideshow.js +++ b/data/www/js/slideshow.js @@ -154,6 +154,10 @@ jQuery(document).ready(function ($) { const hasCron = slide.cron_schedule && slide.cron_schedule.length > 0; const hasDateTime = hasCron && validateCronDateTime(slide.cron_schedule); + + const hasCronEnd = slide.cron_schedule_end && slide.cron_schedule_end.length > 0; + const hasDateTimeEnd = hasCronEnd && validateCronDateTime(slide.cron_schedule_end); + let location = slide.location; if (slide.type == 'youtube') { @@ -165,11 +169,20 @@ jQuery(document).ready(function ($) { $('#slide-edit-type').val(slide.type); $('#slide-edit-location').val(location).prop('disabled', !slide.is_editable); $('#slide-edit-duration').val(slide.duration); + $('#slide-edit-cron-schedule').val(slide.cron_schedule).toggleClass('hidden', !hasCron || hasDateTime); $('#slide-edit-cron-schedule-trigger').val(hasDateTime ? 'datetime' : (hasCron ? 'cron' : 'loop')); + + $('#slide-edit-cron-schedule-end').val(slide.cron_schedule_end).toggleClass('hidden', !hasCronEnd || hasDateTimeEnd); + $('#slide-edit-cron-schedule-end-trigger').val(hasDateTimeEnd ? 'datetime' : (hasCronEnd ? 'cron' : 'loop')); + $('#slide-edit-cron-schedule-datetimepicker').toggleClass('hidden', !hasDateTime).val( hasDateTime ? getCronDateTime(slide.cron_schedule) : '' ); + + $('#slide-edit-cron-schedule-end-datetimepicker').toggleClass('hidden', !hasDateTimeEnd).val( + hasDateTimeEnd ? getCronDateTime(slide.cron_schedule_end) : '' + ); $('#slide-edit-id').val(slide.id); }); diff --git a/lang/en.json b/lang/en.json index c037acf..ae16078 100644 --- a/lang/en.json +++ b/lang/en.json @@ -8,10 +8,10 @@ "slideshow_slide_panel_inactive": "Inactive slides", "slideshow_slide_panel_empty": "Currently, there are no slides. %link% now.", "slideshow_slide_panel_th_name": "Name", - "slideshow_slide_panel_th_duration": "Duration", + "slideshow_slide_panel_th_duration": "Ends after", "slideshow_slide_panel_th_duration_unit": "sec", "slideshow_slide_panel_th_enabled": "Enabled", - "slideshow_slide_panel_th_cron_scheduled": "Scheduled", + "slideshow_slide_panel_th_cron_scheduled": "Scheduled Start", "slideshow_slide_panel_th_activity": "Activity", "slideshow_slide_panel_td_cron_scheduled_loop": "Loop", "slideshow_slide_panel_td_cron_scheduled_bad_cron": "Bad cron value", @@ -19,13 +19,16 @@ "slideshow_slide_form_add_submit": "Add", "slideshow_slide_form_edit_title": "Edit Slide", "slideshow_slide_form_edit_submit": "Save", + "slideshow_slide_form_section_content": "Content", + "slideshow_slide_form_section_scheduling": "Scheduling", "slideshow_slide_form_label_name": "Name", "slideshow_slide_form_label_location": "Location", "slideshow_slide_form_label_type": "Type", "slideshow_slide_form_label_object": "Object", "slideshow_slide_form_label_duration": "Duration", "slideshow_slide_form_label_duration_unit": "seconds", - "slideshow_slide_form_label_cron_scheduled": "Scheduled", + "slideshow_slide_form_label_cron_scheduled": "Start", + "slideshow_slide_form_label_cron_scheduled_end": "End", "slideshow_slide_form_label_cron_scheduled_loop": "In the loop", "slideshow_slide_form_label_cron_scheduled_datetime": "Date & Time", "slideshow_slide_form_label_cron_scheduled_datetime_placeholder": "Set a date and time", @@ -79,7 +82,7 @@ "settings_variable_panel_th_description": "Description", "settings_variable_panel_th_value": "Value", "settings_variable_panel_th_activity": "Options", - "settings_variable_form_edit_title": "Edit Variable", + "settings_variable_form_edit_title": "Edit Setting", "settings_variable_form_edit_submit": "Save", "settings_variable_form_label_name": "Name", "settings_variable_form_label_value": "Value", diff --git a/lang/fr.json b/lang/fr.json index 95369db..ce356f3 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -8,7 +8,7 @@ "slideshow_slide_panel_inactive": "Slides inactives", "slideshow_slide_panel_empty": "Actuellement, il n'y a aucune slide. %link% maintenant.", "slideshow_slide_panel_th_name": "Nom", - "slideshow_slide_panel_th_duration": "Durée", + "slideshow_slide_panel_th_duration": "Fin après", "slideshow_slide_panel_th_duration_unit": "sec", "slideshow_slide_panel_th_enabled": "Activé", "slideshow_slide_panel_th_cron_scheduled": "Programmation", @@ -19,13 +19,16 @@ "slideshow_slide_form_add_submit": "Ajouter", "slideshow_slide_form_edit_title": "Modification d'une slide", "slideshow_slide_form_edit_submit": "Enregistrer", + "slideshow_slide_form_section_content": "Contenu", + "slideshow_slide_form_section_scheduling": "Programmation", "slideshow_slide_form_label_name": "Nom", "slideshow_slide_form_label_location": "Chemin", "slideshow_slide_form_label_type": "Type", "slideshow_slide_form_label_object": "Objet", "slideshow_slide_form_label_duration": "Durée", "slideshow_slide_form_label_duration_unit": "secondes", - "slideshow_slide_form_label_cron_scheduled": "Programmer", + "slideshow_slide_form_label_cron_scheduled": "Début", + "slideshow_slide_form_label_cron_scheduled_end": "Fin", "slideshow_slide_form_label_cron_scheduled_loop": "Dans la boucle", "slideshow_slide_form_label_cron_scheduled_datetime": "Date & Heure", "slideshow_slide_form_label_cron_scheduled_datetime_placeholder": "Choisir une date et une heure", @@ -79,7 +82,7 @@ "settings_variable_panel_th_description": "Description", "settings_variable_panel_th_value": "Valeur", "settings_variable_panel_th_activity": "Options", - "settings_variable_form_edit_title": "Modification de la variable", + "settings_variable_form_edit_title": "Modification du paramètre", "settings_variable_form_edit_submit": "Enregistrer", "settings_variable_form_label_name": "Nom", "settings_variable_form_label_value": "Valeur", diff --git a/src/controller/SlideshowController.py b/src/controller/SlideshowController.py index 481cac7..5f014f1 100644 --- a/src/controller/SlideshowController.py +++ b/src/controller/SlideshowController.py @@ -42,6 +42,7 @@ class SlideshowController(ObController): type=str_to_enum(request.form['type'], SlideType), duration=request.form['duration'], cron_schedule=get_optional_string(request.form['cron_schedule']), + cron_schedule_end=get_optional_string(request.form['cron_schedule_end']), ) if slide.has_file(): @@ -72,6 +73,7 @@ class SlideshowController(ObController): name=request.form['name'], duration=request.form['duration'], cron_schedule=request.form['cron_schedule'], + cron_schedule_end=request.form['cron_schedule_end'], location=request.form['location'] if 'location' in request.form else None ) self._post_update() diff --git a/src/manager/SlideManager.py b/src/manager/SlideManager.py index c0b3976..364fbac 100644 --- a/src/manager/SlideManager.py +++ b/src/manager/SlideManager.py @@ -21,7 +21,8 @@ class SlideManager(ModelManager): "duration", "position", "location", - "cron_schedule" + "cron_schedule", + "cron_schedule_end" ] def __init__(self, lang_manager: LangManager, database_manager: DatabaseManager): @@ -83,7 +84,7 @@ class SlideManager(ModelManager): for slide_id, slide_position in positions.items(): self._db.update_by_id(slide_id, {"position": slide_position}) - def update_form(self, id: str, name: str, duration: int, cron_schedule: Optional[str] = '', location: Optional[str] = None) -> None: + def update_form(self, id: str, name: str, duration: int, cron_schedule: Optional[str] = '', cron_schedule_end: Optional[str] = '', location: Optional[str] = None) -> None: slide = self.get(id) if not slide: @@ -92,7 +93,8 @@ class SlideManager(ModelManager): form = { "name": name, "duration": duration, - "cron_schedule": get_optional_string(cron_schedule) + "cron_schedule": get_optional_string(cron_schedule), + "cron_schedule_end": get_optional_string(cron_schedule_end) } if location is not None and location: diff --git a/src/model/entity/Slide.py b/src/model/entity/Slide.py index 16219ce..a735be8 100644 --- a/src/model/entity/Slide.py +++ b/src/model/entity/Slide.py @@ -7,7 +7,7 @@ from src.utils import str_to_enum class Slide: - def __init__(self, location: str = '', duration: int = 3, type: Union[SlideType, str] = SlideType.URL, enabled: bool = False, name: str = 'Untitled', position: int = 999, id: Optional[str] = None, cron_schedule: Optional[str] = None): + def __init__(self, location: str = '', duration: int = 3, type: Union[SlideType, str] = SlideType.URL, enabled: bool = False, name: str = 'Untitled', position: int = 999, id: Optional[str] = None, cron_schedule: Optional[str] = None, cron_schedule_end: Optional[str] = None): self._id = id if id else None self._location = location self._duration = duration @@ -16,6 +16,7 @@ class Slide: self._name = name self._position = position self._cron_schedule = cron_schedule + self._cron_schedule_end = cron_schedule_end @property def id(self) -> Optional[str]: @@ -45,6 +46,14 @@ class Slide: def cron_schedule(self, value: Optional[str]): self._cron_schedule = value + @property + def cron_schedule_end(self) -> Optional[str]: + return self._cron_schedule_end + + @cron_schedule_end.setter + def cron_schedule_end(self, value: Optional[str]): + self._cron_schedule_end = value + @property def duration(self) -> int: return self._duration @@ -87,6 +96,7 @@ class Slide: f"position='{self.position}',\n" \ f"location='{self.location}',\n" \ f"cron_schedule='{self.cron_schedule}',\n" \ + f"cron_schedule_end='{self.cron_schedule_end}',\n" \ f")" def to_json(self) -> str: @@ -102,6 +112,7 @@ class Slide: "duration": self.duration, "location": self.location, "cron_schedule": self.cron_schedule, + "cron_schedule_end": self.cron_schedule_end, } if with_virtual: diff --git a/src/service/WebServer.py b/src/service/WebServer.py index 2d03587..db5c39a 100644 --- a/src/service/WebServer.py +++ b/src/service/WebServer.py @@ -105,12 +105,8 @@ class WebServer: SlideshowController(self, self._app, auth_required, self._model_store, self._template_renderer) SettingsController(self, self._app, auth_required, self._model_store, self._template_renderer) SysinfoController(self, self._app, auth_required, self._model_store, self._template_renderer) - - if self._model_store.variable().map().get('fleet_enabled').as_bool(): - FleetController(self, self._app, auth_required, self._model_store, self._template_renderer) - - if self._login_manager: - AuthController(self, self._app, auth_required, self._model_store, self._template_renderer) + FleetController(self, self._app, auth_required, self._model_store, self._template_renderer) + AuthController(self, self._app, auth_required, self._model_store, self._template_renderer) def _setup_web_globals(self) -> None: @self._app.context_processor diff --git a/src/utils.py b/src/utils.py index b18d9ce..5b4f0f4 100644 --- a/src/utils.py +++ b/src/utils.py @@ -109,7 +109,6 @@ def get_keys(dict_or_object, key_list_name: str, key_attr_name: str = 'key') -> def enum_to_str(enum: Optional[Enum]) -> Optional[str]: if enum: - print(enum) return str(enum.value) return None diff --git a/views/auth/modal/edit.jinja.html b/views/auth/modal/edit.jinja.html index b4a7057..becb910 100644 --- a/views/auth/modal/edit.jinja.html +++ b/views/auth/modal/edit.jinja.html @@ -1,6 +1,6 @@