77
88
99class AlertHandler ( vuetify3 .VContainer ):
10- """
11- Vuetify component used to display an alert status.
10+ """Vuetify component used to display an alert status.
1211
1312 This alert will be displayed in the bottom right corner of the screen.
1413 It will be displayed until closed by the user or after 10 seconds if it is a success or warning.
1514 """
1615
17- def __init__ ( self ):
16+ def __init__ ( self ) -> None :
17+ """Constructor."""
1818 super ().__init__ (
1919 fluid = True ,
2020 classes = "pa-0 ma-0" ,
@@ -31,31 +31,32 @@ def __init__( self ):
3131
3232 self .generate_alert_ui ()
3333
34- def generate_alert_ui ( self ):
35- """
36- Generate the alert UI.
34+ def generate_alert_ui ( self ) -> None :
35+ """Generate the alert UI.
3736
3837 The alert will be displayed in the bottom right corner of the screen.
3938
4039 Use an abritary z-index value to put the alert on top of the other components.
4140 """
42- with self :
43- with vuetify3 .VCol ( style = "width: 40%; position: fixed; right: 50px; bottom: 50px; z-index: 100;" , ):
44- vuetify3 .VAlert (
45- style = "max-height: 20vh; overflow-y: auto" ,
46- classes = "ma-2" ,
47- v_for = ( "(status, index) in alerts" , ),
48- key = "status" ,
49- type = ( "status.type" , "info" ),
50- text = ( "status.message" , "" ),
51- title = ( "status.title" , "" ),
52- closable = True ,
53- click_close = ( self .on_close , f"[status.id]" ),
54- )
55-
56- def add_alert ( self , type : str , title : str , message : str ):
57- """
58- Add a status to the stack with a unique id.
41+ with (
42+ self ,
43+ vuetify3 .VCol ( style = "width: 40%; position: fixed; right: 50px; bottom: 50px; z-index: 100;" , ),
44+ ):
45+ vuetify3 .VAlert (
46+ style = "max-height: 20vh; overflow-y: auto" ,
47+ classes = "ma-2" ,
48+ v_for = ( "(status, index) in alerts" , ),
49+ key = "status" ,
50+ type = ( "status.type" , "info" ),
51+ text = ( "status.message" , "" ),
52+ title = ( "status.title" , "" ),
53+ closable = True ,
54+ click_close = ( self .on_close , "[status.id]" ),
55+ )
56+
57+ def add_alert ( self , type : str , title : str , message : str ) -> None :
58+ """Add a status to the stack with a unique id.
59+
5960 If there are more than 5 alerts displayed, remove the oldest.
6061 A warning will be automatically closed after 10 seconds.
6162 """
@@ -77,21 +78,15 @@ def add_alert( self, type: str, title: str, message: str ):
7778 if type == "warning" :
7879 asyncio .get_event_loop ().call_later ( self .__lifetime_of_alert , self .on_close , alert_id )
7980
80- async def add_warning ( self , title : str , message : str ):
81- """
82- Add an alert of type "warning"
83- """
81+ async def add_warning ( self , title : str , message : str ) -> None :
82+ """Add an alert of type 'warning'."""
8483 self .add_alert ( "warning" , title , message )
8584
86- async def add_error ( self , title : str , message : str ):
87- """
88- Add an alert of type "error"
89- """
85+ async def add_error ( self , title : str , message : str ) -> None :
86+ """Add an alert of type 'error'."""
9087 self .add_alert ( "error" , title , message )
9188
92- def on_close ( self , alert_id ):
93- """
94- Remove in the state the alert associated to the given id.
95- """
89+ def on_close ( self , alert_id : int ) -> None :
90+ """Remove in the state the alert associated to the given id."""
9691 self .state .alerts = list ( filter ( lambda i : i [ "id" ] != alert_id , self .state .alerts ) )
9792 self .state .flush ()
0 commit comments