nice-gui-utils 0.1.8.dev0__tar.gz → 0.2.0.dev4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/PKG-INFO +2 -2
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/pyproject.toml +3 -2
- nice-gui-utils-0.2.0.dev4/src/keycloak_js/keycloak.js +42 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/keycloak_js/keycloak.py +9 -20
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/PKG-INFO +2 -2
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/SOURCES.txt +3 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/top_level.txt +1 -0
- nice-gui-utils-0.2.0.dev4/src/router/__init__.py +0 -0
- nice-gui-utils-0.2.0.dev4/src/router/router.py +55 -0
- nice-gui-utils-0.2.0.dev4/src/router/router_frame.js +26 -0
- nice-gui-utils-0.1.8.dev0/src/keycloak_js/keycloak.js +0 -33
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/LICENSE +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/README.md +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/requirements.txt +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/setup.cfg +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/keycloak_js/__init__.py +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/dependency_links.txt +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/requires.txt +0 -0
- {nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/tests/test_login.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nice-gui-utils
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0.dev4
|
|
4
4
|
Summary: Utils to use with NiceGUI.
|
|
5
5
|
Author: Harter Kern
|
|
6
6
|
Project-URL: Homepage, https://gitlab.com/harter-kern-public/nice-gui-utils
|
|
@@ -8,7 +8,7 @@ Project-URL: Bug Tracker, https://gitlab.com/harter-kern-public/nice-gui-utils/-
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: nicegui>=1.4.0
|
|
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nice-gui-utils"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0dev4"
|
|
8
8
|
dynamic = ["dependencies"]
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "Harter Kern" },
|
|
11
11
|
]
|
|
12
12
|
description = "Utils to use with NiceGUI."
|
|
13
13
|
readme = "README.md"
|
|
14
|
-
requires-python = ">=3.
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
15
|
classifiers = [
|
|
16
16
|
"Programming Language :: Python :: 3",
|
|
17
17
|
"License :: OSI Approved :: MIT License",
|
|
@@ -23,6 +23,7 @@ dependencies = { file = ["requirements.txt"] }
|
|
|
23
23
|
where = ["src"]
|
|
24
24
|
[tool.setuptools.package-data]
|
|
25
25
|
keycloak_js = ["*.js"]
|
|
26
|
+
router = ["*.js"]
|
|
26
27
|
|
|
27
28
|
[project.urls]
|
|
28
29
|
"Homepage" = "https://gitlab.com/harter-kern-public/nice-gui-utils"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
template: "<div></div>",
|
|
3
|
+
mounted() {
|
|
4
|
+
this.keycloak = new Keycloak({
|
|
5
|
+
url: this.url,
|
|
6
|
+
realm: this.realm,
|
|
7
|
+
clientId: this.clientId
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
this.keycloak.init(this.initOptions).then(
|
|
11
|
+
authenticated => {
|
|
12
|
+
if (authenticated) {
|
|
13
|
+
this.keycloak.onTokenExpired = this.keycloak.updateToken;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
methods: {
|
|
20
|
+
token() {
|
|
21
|
+
return this.keycloak.token;
|
|
22
|
+
},
|
|
23
|
+
refreshToken() {
|
|
24
|
+
return this.keycloak.refreshToken;
|
|
25
|
+
},
|
|
26
|
+
authenticated() {
|
|
27
|
+
return this.keycloak.authenticated;
|
|
28
|
+
},
|
|
29
|
+
login(options) {
|
|
30
|
+
return this.keycloak.login(options);
|
|
31
|
+
},
|
|
32
|
+
logout(options) {
|
|
33
|
+
return this.keycloak.logout(options);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
props: {
|
|
37
|
+
url: String,
|
|
38
|
+
realm: String,
|
|
39
|
+
clientId: String,
|
|
40
|
+
initOptions: Object
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
|
-
from typing import AnyStr, Dict
|
|
2
|
+
from typing import AnyStr, Dict, Any
|
|
3
3
|
|
|
4
4
|
from nicegui import ui
|
|
5
5
|
from nicegui.awaitable_response import AwaitableResponse
|
|
@@ -22,25 +22,14 @@ class Keycloak(ui.element, component='keycloak.js'):
|
|
|
22
22
|
init_options: Dict = None):
|
|
23
23
|
super().__init__()
|
|
24
24
|
|
|
25
|
-
ui.add_head_html('<script src="'
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}}</script>""")
|
|
34
|
-
ui.add_head_html(
|
|
35
|
-
"<script>const globalKeycloakInstance = new Keycloak(keycloakConfig);</script>")
|
|
36
|
-
|
|
37
|
-
if not init_options:
|
|
38
|
-
self.init_options = {}
|
|
39
|
-
else:
|
|
40
|
-
self.init_options = init_options
|
|
41
|
-
|
|
42
|
-
def initialize(self, options=None) -> AwaitableResponse:
|
|
43
|
-
return self.run_method('initialize', self.init_options if not options else options)
|
|
25
|
+
ui.add_head_html(f'<script src="{js_source}"></script>')
|
|
26
|
+
|
|
27
|
+
props: Dict[str, Any] = self._props
|
|
28
|
+
props['url'] = config.url
|
|
29
|
+
props['realm'] = config.realm
|
|
30
|
+
props['clientId'] = config.client_id
|
|
31
|
+
|
|
32
|
+
props['initOptions'] = init_options if init_options else {}
|
|
44
33
|
|
|
45
34
|
def token(self) -> AwaitableResponse:
|
|
46
35
|
return self.run_method('token')
|
{nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nice-gui-utils
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0.dev4
|
|
4
4
|
Summary: Utils to use with NiceGUI.
|
|
5
5
|
Author: Harter Kern
|
|
6
6
|
Project-URL: Homepage, https://gitlab.com/harter-kern-public/nice-gui-utils
|
|
@@ -8,7 +8,7 @@ Project-URL: Bug Tracker, https://gitlab.com/harter-kern-public/nice-gui-utils/-
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: nicegui>=1.4.0
|
{nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/SOURCES.txt
RENAMED
|
@@ -10,4 +10,7 @@ src/nice_gui_utils.egg-info/SOURCES.txt
|
|
|
10
10
|
src/nice_gui_utils.egg-info/dependency_links.txt
|
|
11
11
|
src/nice_gui_utils.egg-info/requires.txt
|
|
12
12
|
src/nice_gui_utils.egg-info/top_level.txt
|
|
13
|
+
src/router/__init__.py
|
|
14
|
+
src/router/router.py
|
|
15
|
+
src/router/router_frame.js
|
|
13
16
|
tests/test_login.py
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from functools import singledispatchmethod
|
|
2
|
+
from typing import Callable, Dict, Optional, AnyStr, Union, Any
|
|
3
|
+
|
|
4
|
+
from nicegui import background_tasks, helpers, ui
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class _RouterFrame(ui.element, component='router_frame.js'):
|
|
8
|
+
|
|
9
|
+
def __init__(self, check_interval: int):
|
|
10
|
+
super().__init__()
|
|
11
|
+
|
|
12
|
+
props: Dict[AnyStr, Any] = self._props
|
|
13
|
+
props['checkInterval'] = check_interval
|
|
14
|
+
|
|
15
|
+
def update_history(self, path):
|
|
16
|
+
self.run_method('updateHistory', path)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Router:
|
|
20
|
+
|
|
21
|
+
def __init__(self, check_interval: int = None) -> None:
|
|
22
|
+
self.routes: Dict[AnyStr, Callable] = {}
|
|
23
|
+
self.content: Optional[ui.element] = None
|
|
24
|
+
self.router_frame: _RouterFrame = _RouterFrame(check_interval if check_interval else 10)
|
|
25
|
+
|
|
26
|
+
def path(self, path: str):
|
|
27
|
+
def decorator(func: Callable):
|
|
28
|
+
self.routes[path] = func
|
|
29
|
+
return func
|
|
30
|
+
|
|
31
|
+
return decorator
|
|
32
|
+
|
|
33
|
+
@singledispatchmethod
|
|
34
|
+
def go_to(self, target: Union[Callable, AnyStr]):
|
|
35
|
+
path = {target: path for path, target in self.routes.items()}[target]
|
|
36
|
+
self.go_to(path)
|
|
37
|
+
|
|
38
|
+
@go_to.register
|
|
39
|
+
def _(self, target: str):
|
|
40
|
+
path = target
|
|
41
|
+
builder = self.routes[target]
|
|
42
|
+
|
|
43
|
+
async def build() -> None:
|
|
44
|
+
with self.content:
|
|
45
|
+
self.router_frame.update_history(path)
|
|
46
|
+
result = builder()
|
|
47
|
+
if helpers.is_coroutine_function(builder):
|
|
48
|
+
await result
|
|
49
|
+
|
|
50
|
+
self.content.clear()
|
|
51
|
+
background_tasks.create(build())
|
|
52
|
+
|
|
53
|
+
def frame(self) -> ui.element:
|
|
54
|
+
self.content = self.router_frame.on('open', lambda e: self.go_to(e.args))
|
|
55
|
+
return self.content
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
template: "<div><slot></slot></div>",
|
|
3
|
+
mounted() {
|
|
4
|
+
window.addEventListener("popstate", (event) => {
|
|
5
|
+
if (event.state?.page) {
|
|
6
|
+
this.$emit("open", event.state.page);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
const connectInterval = setInterval(async () => {
|
|
10
|
+
if (window.socket.id === undefined)
|
|
11
|
+
return;
|
|
12
|
+
this.$emit("open", window.location.pathname);
|
|
13
|
+
clearInterval(connectInterval);
|
|
14
|
+
}, this.checkInterval);
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
checkInterval: Number
|
|
18
|
+
},
|
|
19
|
+
methods: {
|
|
20
|
+
updateHistory(path) {
|
|
21
|
+
if (window.location.pathname !== path) {
|
|
22
|
+
history.pushState({page: path}, "", path);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
template: "<div></div>",
|
|
3
|
-
mounted() {
|
|
4
|
-
this.keycloak = globalKeycloakInstance;
|
|
5
|
-
},
|
|
6
|
-
methods: {
|
|
7
|
-
initialize(initConfig) {
|
|
8
|
-
this.keycloak.init(initConfig).then(
|
|
9
|
-
authenticated => {
|
|
10
|
-
if (authenticated) {
|
|
11
|
-
this.keycloak.onTokenExpired = this.keycloak.updateToken;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
);
|
|
16
|
-
},
|
|
17
|
-
token() {
|
|
18
|
-
return this.keycloak.token;
|
|
19
|
-
},
|
|
20
|
-
refreshToken() {
|
|
21
|
-
return this.keycloak.refreshToken;
|
|
22
|
-
},
|
|
23
|
-
authenticated() {
|
|
24
|
-
return this.keycloak.authenticated;
|
|
25
|
-
},
|
|
26
|
-
login(options) {
|
|
27
|
-
return this.keycloak.login(options);
|
|
28
|
-
},
|
|
29
|
-
logout(options) {
|
|
30
|
-
return this.keycloak.logout(options);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nice-gui-utils-0.1.8.dev0 → nice-gui-utils-0.2.0.dev4}/src/nice_gui_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|