Skip to content

Commit

Permalink
feat(loading): enable loading screen to be overriden
Browse files Browse the repository at this point in the history
For that just provide your own ./loading/index.html

Then in vue3, you can also override dynamically the error view for disconnect or disconnect-with-reconnect.
You just need to define layout for "error" and "error_reconnect". Also a variable "trame_error_report_msg" will be available for you to leverage in your custom template.
  • Loading branch information
jourdain committed Feb 14, 2024
1 parent e7d8981 commit 9d13b21
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 187 deletions.
1 change: 1 addition & 0 deletions examples/loading/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loading
25 changes: 25 additions & 0 deletions examples/loading/loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from trame.app import get_server
from trame.widgets import html
from trame.ui.html import DivLayout
import time

server = get_server(client_type=os.environ.get("TRAME_CLIENT_TYPE", "vue3"))

# -----------------------------------------------------------------------------
# Only with Vue3
# -----------------------------------------------------------------------------
with DivLayout(server, template_name="error") as layout:
html.Div("App disconnected: {{ trame_error_report_msg }}")

with DivLayout(server, template_name="error_reconnect") as layout:
html.Div("App disconnected but you can reconnect: {{ trame_error_report_msg }}")
# -----------------------------------------------------------------------------

with DivLayout(server) as layout:
html.Div("App is fully loaded")

# Busy wait
time.sleep(5)

server.start()
22 changes: 22 additions & 0 deletions examples/loading/loading_launcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

{
"configuration": {
"host" : "localhost",
"port" : 8080,
"endpoint": "paraview",
"content": "loading/loading_www",
"proxy_file" : "loading/proxy-mapping.txt",
"sessionURL" : "ws://${host}:${port}/ws",
"timeout" : 50,
"log_dir" : "loading",
"fields" : []
},
"resources" : [ { "host" : "localhost", "port_range" : [9001, 9020] } ],
"properties" : {},
"apps" : {
"trame" : {
"cmd" : ["python", "loading.py", "--port", "$port", "--server", "--authKey", "${secret}"],
"ready_line" : "App running at"
}
}
}
7 changes: 7 additions & 0 deletions examples/loading/run_loading.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# export TRAME_CLIENT_TYPE=vue2
export TRAME_CLIENT_TYPE=vue3

rm -rf ./loading/
mkdir -p ./loading/loading_www
python -m trame.tools.www --client-type "$TRAME_CLIENT_TYPE" --output ./loading/loading_www
python -m wslink.launcher ./loading_launcher.json
96 changes: 2 additions & 94 deletions vue2-app/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,106 +12,14 @@
<link rel="icon" href="<%= BASE_URL %>logo.png">
<script src="vue.global.js"></script>
<title>trame is built by Kitware</title>
<style>
.text-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.trame__loader {
display: block;
position: relative;
left: 50%;
top: calc(50% - 50px);
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #ac262c;

-webkit-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 2s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__loader:before {
content: "";
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #258e44;

-webkit-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 3s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__loader:after {
content: "";
position: absolute;
top: 20px;
left: 20px;
right: 20px;
bottom: 20px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #1c4678;

-webkit-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 1.5s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__message {
position: absolute;
text-align: center;
width: 100%;
top: calc(50% + 50px);
font-size: 200%;
user-select: none;
}

@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(0deg); /* IE 9 */
transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100% {
-webkit-transform: rotate(360deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(360deg); /* IE 9 */
transform: rotate(360deg); /* Firefox 16+, IE 10+, Opera */
}
}
@keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(0deg); /* IE 9 */
transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100% {
-webkit-transform: rotate(360deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(360deg); /* IE 9 */
transform: rotate(360deg); /* Firefox 16+, IE 10+, Opera */
}
}
</style>
</head>
<body style="margin: 0; padding: 0;">
<noscript>
<strong>We're sorry but trame built by Kitware doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app">
<div style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:1000;">
<div class="trame__loader">
</div>
<div class="trame__message">
Loading...
</div>
</div>
<iframe src="./loading/index.html" style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:1000;border:none;">
</iframe>
</div>
<!-- built files will be auto injected -->
</body>
Expand Down
101 changes: 101 additions & 0 deletions vue2-app/public/loading/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1">
<title>Loading...</title>
<style>
.text-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.trame__loader {
display: block;
position: relative;
left: 50%;
top: calc(50% - 50px);
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #ac262c;

-webkit-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 2s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__loader:before {
content: "";
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #258e44;

-webkit-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 3s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__loader:after {
content: "";
position: absolute;
top: 20px;
left: 20px;
right: 20px;
bottom: 20px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #1c4678;

-webkit-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 1.5s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__message {
position: absolute;
text-align: center;
width: 100%;
top: calc(50% + 50px);
font-size: 200%;
user-select: none;
}

@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(0deg); /* IE 9 */
transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100% {
-webkit-transform: rotate(360deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(360deg); /* IE 9 */
transform: rotate(360deg); /* Firefox 16+, IE 10+, Opera */
}
}
@keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(0deg); /* IE 9 */
transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100% {
-webkit-transform: rotate(360deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(360deg); /* IE 9 */
transform: rotate(360deg); /* Firefox 16+, IE 10+, Opera */
}
}
</style>
</head>
<body>
<div style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:1000;">
<div class="trame__loader"></div>
<div class="trame__message">Loading...</div>
</div>
</body>
</html>
93 changes: 2 additions & 91 deletions vue3-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,103 +11,14 @@
<link rel="icon" href="logo.png">
<title>trame is built by Kitware</title>
<script src="vue.global.js"></script>
<style>
.text-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.trame__loader {
display: block;
position: relative;
left: 50%;
top: calc(50% - 50px);
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #ac262c;

-webkit-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 2s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__loader:before {
content: "";
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #258e44;

-webkit-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 3s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__loader:after {
content: "";
position: absolute;
top: 20px;
left: 20px;
right: 20px;
bottom: 20px;
border-radius: 50%;
border: 10px solid transparent;
border-top-color: #1c4678;

-webkit-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ */
animation: spin 1.5s linear infinite; /* Chrome, Firefox 16+, IE 10+, Opera */
}

.trame__message {
position: absolute;
text-align: center;
width: 100%;
top: calc(50% + 50px);
font-size: 200%;
user-select: none;
}

@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(0deg); /* IE 9 */
transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100% {
-webkit-transform: rotate(360deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(360deg); /* IE 9 */
transform: rotate(360deg); /* Firefox 16+, IE 10+, Opera */
}
}
@keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(0deg); /* IE 9 */
transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100% {
-webkit-transform: rotate(360deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(360deg); /* IE 9 */
transform: rotate(360deg); /* Firefox 16+, IE 10+, Opera */
}
}
</style>
</head>
<body>
<noscript>
<strong>We're sorry but trame built by Kitware doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app">
<div style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:1000;">
<div class="trame__loader"></div>
<div class="trame__message">Loading...</div>
</div>
<iframe src="./loading/index.html" style="position:absolute;top:0;left:0;width:100%;height:100%;z-index:1000;border:none;">
</iframe>
</div>
<script type="module" src="/src/main.js"></script>
</body>
Expand Down
Loading

0 comments on commit 9d13b21

Please sign in to comment.