comparison libervia/pages/_browser/dialog.py @ 1504:409d10211b20

server, browser: dynamic pages refactoring: dynamic pages has been reworked, to change the initial basic implementation. Pages are now dynamic by default, and a websocket is established by the first connected page of a session. The socket is used to transmit bridge signals, and then the signal is broadcasted to other tabs using broadcast channel. If the connecting tab is closed, an other one is chosen. Some tests are made to retry connecting in case of problem, and sometimes reload the pages (e.g. if profile is connected). Signals (or other data) are cached during reconnection phase, to avoid lost of data. All previous partial rendering mechanism have been removed, chat page is temporarily not working anymore, but will be eventually redone (one of the goal of this work is to have proper chat).
author Goffi <goffi@goffi.org>
date Wed, 01 Mar 2023 18:02:44 +0100
parents 4b6f711b09cb
children
comparison
equal deleted inserted replaced
1503:2796e73ed50c 1504:409d10211b20
1 """manage common dialogs""" 1 """manage common dialogs"""
2 2
3 from browser import document, window, timer 3 from browser import document, window, timer, console as log
4 from template import Template 4 from template import Template
5
6 log.warning = log.warn
5 7
6 8
7 class Confirm: 9 class Confirm:
8 10
9 def __init__(self, message, ok_label="", cancel_label="", ok_color="success"): 11 def __init__(self, message, ok_label="", cancel_label="", ok_color="success"):
76 timer.set_timeout(lambda: self.close(notif_elt), delay * 1000) 78 timer.set_timeout(lambda: self.close(notif_elt), delay * 1000)
77 for elt in notif_elt.select('.click_to_close'): 79 for elt in notif_elt.select('.click_to_close'):
78 elt.bind('click', lambda __: self.close(notif_elt)) 80 elt.bind('click', lambda __: self.close(notif_elt))
79 81
80 82
83 class RetryNotification:
84 def __init__(self, retry_cb):
85 self._tpl = Template("dialogs/retry-notification.html")
86 self.retry_cb = retry_cb
87 self.counter = 0
88 self.timer = None
89
90 def retry(self, notif_elt):
91 if self.timer is not None:
92 timer.clear_interval(self.timer)
93 self.timer = None
94 notif_elt.classList.remove('state_appended')
95 notif_elt.bind("transitionend", lambda __: notif_elt.remove())
96 self.retry_cb()
97
98 def update_counter(self, notif_elt):
99 counter = notif_elt.select_one(".retry_counter")
100 counter.text = str(self.counter)
101 self.counter -= 1
102 if self.counter < 0:
103 self.retry(notif_elt)
104
105 def show(
106 self,
107 message: str,
108 level: str = "warning",
109 delay: int = 5
110 ) -> None:
111 # we log in console error messages, may be useful
112 if level == "error":
113 log.error(message)
114 elif level == "warning":
115 log.warning(message)
116 self.counter = delay
117 notif_elt = self._tpl.get_elt({
118 "message": message,
119 "level": level,
120 })
121 self.update_counter(notif_elt)
122 document["notifs_area"] <= notif_elt
123 timer.set_timeout(lambda: notif_elt.classList.add('state_appended'), 0)
124 self.timer = timer.set_interval(self.update_counter, 1000, notif_elt)
125 for elt in notif_elt.select('.click_to_retry'):
126 elt.bind('click', lambda __: self.retry(notif_elt))
127
128
129
130
81 notification = Notification() 131 notification = Notification()