Skip to content

Commit 00cd011

Browse files
committed
feat(alert): add success alert type for the saving feature
1 parent d5b9ad4 commit 00cd011

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

geos-trame/geos_trame/app/components/alertHandler.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
from trame.widgets import vuetify3
77

8+
from enum import Enum
9+
10+
11+
class AlertType( str, Enum ):
12+
"""Enum representing the type of VAlert.
13+
14+
For more information, see the uetify documentation:
15+
https://vuetifyjs.com/en/api/VAlert/#props-type
16+
"""
17+
SUCCESS = 'success'
18+
WARNING = 'warning'
19+
ERROR = 'error'
20+
821

922
class AlertHandler( vuetify3.VContainer ):
1023
"""Vuetify component used to display an alert status.
@@ -26,8 +39,9 @@ def __init__( self ) -> None:
2639

2740
self.state.alerts = []
2841

29-
self.server.controller.on_add_error.add_task( self.add_error )
42+
self.server.controller.on_add_success.add_task( self.add_success )
3043
self.server.controller.on_add_warning.add_task( self.add_warning )
44+
self.server.controller.on_add_error.add_task( self.add_error )
3145

3246
self.generate_alert_ui()
3347

@@ -75,7 +89,7 @@ def add_alert( self, type: str, title: str, message: str ) -> None:
7589
self.state.dirty( "alerts" )
7690
self.state.flush()
7791

78-
if type == "warning":
92+
if type == AlertType.WARNING:
7993
asyncio.get_event_loop().call_later( self.__lifetime_of_alert, self.on_close, alert_id )
8094

8195
async def add_warning( self, title: str, message: str ) -> None:
@@ -86,6 +100,10 @@ async def add_error( self, title: str, message: str ) -> None:
86100
"""Add an alert of type 'error'."""
87101
self.add_alert( "error", title, message )
88102

103+
async def add_success( self, title: str, message: str ) -> None:
104+
"""Add an alert of type 'success'."""
105+
self.add_alert( AlertType.SUCCESS, title, message )
106+
89107
def on_close( self, alert_id: int ) -> None:
90108
"""Remove in the state the alert associated to the given id."""
91109
self.state.alerts = list( filter( lambda i: i[ "id" ] != alert_id, self.state.alerts ) )

geos-trame/geos_trame/app/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__( self, server: Server, file_name: str ) -> None:
6161
self.ctrl.simput_reload_data = self.simput_widget.reload_data
6262

6363
# Tree
64-
self.tree = DeckTree( self.state.sm_id )
64+
self.tree = DeckTree( self.state.sm_id, self.ctrl )
6565

6666
# Viewers
6767
self.region_viewer = RegionViewer()

geos-trame/geos_trame/app/deck/tree.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
import os
55
from collections import defaultdict
66
from typing import Any
7-
87
import dpath
98
import funcy
109
from pydantic import BaseModel
11-
from trame_simput import get_simput_manager
10+
1211
from xsdata.formats.dataclass.parsers.config import ParserConfig
1312
from xsdata.formats.dataclass.serializers.config import SerializerConfig
1413
from xsdata.utils import text
1514
from xsdata_pydantic.bindings import DictDecoder, XmlContext, XmlSerializer
1615

16+
from trame_server.controller import Controller
17+
from trame_simput import get_simput_manager
18+
1719
from geos_trame.app.deck.file import DeckFile
1820
from geos_trame.app.geosTrameException import GeosTrameException
1921
from geos_trame.app.utils.file_utils import normalize_path, format_xml
@@ -23,7 +25,7 @@
2325
class DeckTree( object ):
2426
"""A tree that represents a deck file along with all the available blocks and parameters."""
2527

26-
def __init__( self, sm_id: str | None = None, **kwargs: Any ) -> None:
28+
def __init__( self, sm_id: str | None = None, ctrl: Controller = None, **kwargs: Any ) -> None:
2729
"""Constructor."""
2830
super( DeckTree, self ).__init__( **kwargs )
2931

@@ -33,6 +35,7 @@ def __init__( self, sm_id: str | None = None, **kwargs: Any ) -> None:
3335
self.root = None
3436
self.input_has_errors = False
3537
self._sm_id = sm_id
38+
self._ctrl = ctrl
3639

3740
def set_input_file( self, input_filename: str ) -> None:
3841
"""Set a new input file.
@@ -172,6 +175,8 @@ def write_files( self ) -> None:
172175
file.write( model_as_xml )
173176
file.close()
174177

178+
self._ctrl.on_add_success( title="File saved", message=f"File {basename} has been saved." )
179+
175180
@staticmethod
176181
def _append_include_file( model: Problem, included_file_path: str ) -> None:
177182
"""Append an Included object which follows this structure according to the documentation.

0 commit comments

Comments
 (0)