-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_callbacks.py
136 lines (109 loc) · 4.07 KB
/
js_callbacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from bokeh.util.compiler import JavaScript
from bokeh.models import CustomJS
from bokeh.model import Model
from bokeh.core.properties import Int, String
class LoadingProps(Model):
__implementation__ = JavaScript("""
import * as p from "core/properties"
import {Model} from "model"
export class LoadingProps extends Model {}
LoadingProps.define({
num_loaded: [ p.Int ],
num_to_load: [ p.Int ],
file_loading: [ p.String ],
loading_error: [ p.String ],
workflow_loading: [ p.String ],
})
"""
)
num_loaded = Int(0)
num_to_load = Int(0)
file_loading = String()
loading_error = String()
workflow_loading = String()
def get_loading_modal_update_callback():
callback = CustomJS(code="""
var modalTxt = document.getElementById('loadModalText');
modalTxt.textContent = 'Loading ' + cb_obj.file_loading + ' (' + cb_obj.num_loaded + '/' + cb_obj.num_to_load + ')...';
console.log('cb_obj.num_loaded:' + cb_obj.num_loaded);
"""
)
return callback
def get_loading_modal_callback():
callback = CustomJS(code="""
// Get the modal
var modal = document.getElementById('myModal');
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
var modalTxt = document.getElementById('loadModalText');
if ( cb_obj.num_to_load == 0 ) {
modal.style.display = "none";
} else {
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
modalTxt.textContent = 'Loading ' + cb_obj.file_loading + ' (0/' + cb_obj.num_to_load + ')...';
modal.style.display = "block";
}
"""
)
return callback
def get_loading_error_callback():
callback = CustomJS(code="""
// Get the modal
var modal = document.getElementById('myModal');
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
var modalTxt = document.getElementById('loadModalText');
var err_msg = cb_obj.loading_error;
if ( err_msg.length > 0 ) {
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
modalTxt.textContent = err_msg;
modal.style.display = "block";
}
"""
)
return callback
def get_loading_workflow_callback():
callback = CustomJS(code="""
// Get the modal
var modal = document.getElementById('myModal');
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
var modalTxt = document.getElementById('loadModalText');
var wf_msg = cb_obj.workflow_loading;
if ( wf_msg.length > 0 ) {
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
modalTxt.textContent = wf_msg;
modal.style.display = "block";
} else {
modal.style.display = "none";
}
"""
)
return callback