-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponants.py
344 lines (316 loc) · 14.7 KB
/
componants.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
from dash import dash_table, dcc, html
import dash_bootstrap_components as dbc
from enums import SUPPORTED_DATA_COMPONANT
import labels
import dash_mantine_components as dmc
import random
from datetime import datetime
from dash_iconify import DashIconify
availables_themes = [
{
"name" : "crepes",
"icon" : ["🎉","🥞"],
"month" : [1]
},
{
"name" : "saint_valetin",
"icon" : ["💙"],
"month" : [2]
},
{
"name" : "fete_du_citron",
"icon" : ["🍋", "🍊", "🌷"],
"month" : [3]
},
{
"name" : "paques",
"icon" : ["🔔","🍫","🐇", "🥚", "🐣"],
"month" : [4]
},
{
"name" : "Bebe",
"icon" : ["🍼","🧸","🎂"],
"month" : [5]
},
{
"name" : "haloween",
"icon" : ["🎃", "🍂"],
"month" : [10,11]
},
{
"name" : "noel",
"icon" : ["🎄", "❄️", "🎁"],
"month" : [12]
},
{
"name" : "default",
"icon" : ["⭐️"],
"month" : [1,2,3,4,5,6,7,8,9,10,11,12]
},
]
def get_icons(month) :
for theme in availables_themes :
if month in theme["month"] :
return theme["icon"]
def get_project_icon() :
now = datetime.now().month
current_theme_icones = get_icons(now)
return current_theme_icones[random.randint(0, len(current_theme_icones)-1)]
def generate_header():
return html.Div([
html.H1('Zooscan Quality Checks', className="inline"),
dcc.Link(html.Img(className="help-btn", src="../assets/help.png", alt="help", title="Help"), href='/QC/zooscan/doc'),
html.Span(className='elementor-divider-separator'),
enable_notification(),
generate_name_of_saver()
],
className="container-header")
def generate_project_selector(drives):
return html.Div([
html.H2("Drive"),
dcc.Dropdown(
id='app-1-dropdown-drives',
value="zooscan_lov" if "zooscan_lov" in [drive["label"] for drive in drives] else "zooscan_embrc" if "zooscan_embrc" in [drive["label"] for drive in drives] else "zooscan_test",
clearable = False,
options=[
{'label': drive['label'] + " 🔒" if drive['disabled'] else drive['label'],
'value': drive['label'],
'disabled': drive['disabled']} for drive in drives
]
),
html.H2("Project"),
dcc.Dropdown(
id='app-1-dropdown-projects',
value=[],
multi=True
)
], className="container-prj-selector")
def generate_check_block(checkBlock):
return html.Div([ # -- check list title --###
# dcc.Store stores the intermediate value
dcc.Store(id='intermediate-value-'+ checkBlock["id"]),
html.Div([
html.Div(
checkBlock["title"],
className="label inline"
),
html.Img(
className="runQC-btn",
id="runQC-btn-" + checkBlock["id"],
src="../assets/play.png",
alt="Run "+checkBlock["title"]+" QCs",
title="Run "+checkBlock["title"]+" QCs",
n_clicks=0),
html.Img(
className="runQC-btn",
id="open-"+checkBlock["id"],
src="../assets/download.svg",
alt="Save "+checkBlock["title"]+" QCs on plankton server",
title="Save "+checkBlock["title"]+" QCs on plankton server",
n_clicks=0,
hidden=True),
],
className="check-block-title"),
###-- check list tab --###
html.Div([
dcc.Tabs(
id="tabs-" + checkBlock["id"],
value='tab-' + checkBlock["id"],
parent_className='custom-tabs',
className='custom-tabs-container',
children=[
dcc.Tab(
label='Infos',
value='tab-details-' + checkBlock["id"],
className='custom-tab',
selected_className='custom-tab--selected'
),
dcc.Tab(
label='Results',
value='tab-result-' + checkBlock["id"],
className='custom-tab',
selected_className='custom-tab--selected'
)
],
persistence=True
),
dcc.Loading(
id="loading-1-"+checkBlock["id"],
type="default",
className="loader",
color="#10698d",
children=[html.Div(id="tabs-content-"+checkBlock["id"],
className="tabs-content")]
)
])
])
def generate_checks_block(checks):
checks_layout = []
for check in checks:
checks_layout.append(
html.Div([
html.H5(check["title"] + " :"),
html.Div(check["description"], style={'whiteSpace': 'pre-wrap'}, className="details_doc")
])
)
return html.Div(checks_layout, className="checks-block")
def generate_sub_block(sub_block):
return html.Div([
html.H3(sub_block["title"]),
html.P(sub_block["description"]),
generate_checks_block(sub_block["checks"]),
], className="sub-block")
def generate_details(checkBlock):
sub_blocks = []
for sub_block in checkBlock["blocks"]:
sub_blocks.append(generate_sub_block(sub_block))
return html.Div(sub_blocks, className="tab-div-common details")
def generate_result(html_result):
return html.Div(html_result, className="tab-div-common results")
def emptyResult(block_id, projects):
emptyResLayout = []
if len(projects) == 0:
emptyResLayout.append(html.P("Select one or more projects and, "))
emptyResLayout.append(html.P("Run '" + block_id + "' QC to see results"))
return emptyResLayout
def sub_block_execution_result(project, subBlock, data):
results_content= [html.H3(subBlock)]
for indice, result in enumerate(data) :
if result["type"] == SUPPORTED_DATA_COMPONANT.DATA_TABLE or result["type"] == SUPPORTED_DATA_COMPONANT.DATA_TABLE_XS:
dash_comp = dash_table.DataTable(
id='tbl-' + subBlock + "-" + project + "-" + str(indice),
data=result["dataframe"].to_dict('records'), # the contents of the table
columns=[{"name": i, "id": i} for i in result["dataframe"].columns],
filter_action="native", # allow filtering of data by user ('native') or not ('none')
sort_action="native", # enables data to be sorted per-column by user or not ('none')
sort_mode="single", # sort across 'multi' or 'single' columns
style_data_conditional=style_table_data(result["dataframe"]),
fixed_rows={'headers': True},
style_cell={ # ensure adequate header width when text is shorter than cell's text, and allign the text to left (default right)
'minWidth': 120, 'width': 120, 'textAlign': 'left', 'font-family': '"IMTITLE", Sans-serif', 'padding': '5px'
},
style_header={ # ensure adequate header width when text is shorter than cell's text, and allign the text to left (default right)
'padding-left': '5px',
'textAlign': 'center',
'whiteSpace': 'normal',
'height': 'auto',
},
style_data={ # overflow cells' content into multiple lines
'whiteSpace': 'normal',
'height': 'auto',
'font-size': '14px'
}
)
if result["type"] == SUPPORTED_DATA_COMPONANT.DATA_TABLE_XS :
dash_comp.fill_width=False
results_content.append(dash_comp)
div = html.Div(
results_content,
className="sub-block-div")
return div
def qc_execution_result(project, qcExecutionLayout):
icon=get_project_icon()
return html.Div([
html.P(icon+" "+project+" "+icon, className="project-sep"),
html.Div(qcExecutionLayout)
], className="result-project-title")
#TODO JCE : add this color to header background where at leat one QC exec is a ko
# background-color : #ed43371f,
def style_table_data(dataframe):
ret = [{
'if': {'state': 'active'},
'backgroundColor': 'lightgrey',
'border-left': 'lightgrey',
'border-right': 'lightgrey',
'border-top': 'lightgrey',
'border-bottom': 'lightgrey',
'z-index': '200'
}]
#Red text if cell (header and data) contains an error message
for errors_label in labels.errors.values():
ret += [{
'if': {
'filter_query': '{{{}}} contains "{}"'.format(col, errors_label),
'column_id': col
},
'color': '#ED4337'
}for col in dataframe.columns
]
return ret
def generate_name_of_saver():
return html.Div([
# html.Img(
# className="runQC-btn",
# id="open-"+checkblock["id"],
# src="../assets/download.png",
# alt="Save "+checkblock["title"]+" QCs on plankton server",
# title="Save "+checkblock["title"]+" QCs on plankton server",
# n_clicks=0,
# hidden=True),
dbc.Modal(
[
dbc.ModalHeader("Save report"),
dbc.ModalBody(
html.Div([
"Please enter your FULL first name and last name",
html.Div(
[
html.P('Last name', className="label-popup"),
dcc.Input(
className="operator_last_name",
id="operator_last_name",
type="text",
placeholder="Nom",
required=True,
autoFocus=True,
pattern=u"^[^-\s][^0-9]*[A-Za-zÀ-ÖØ-öø-ÿ]+",
debounce = True
),
html.P('First name', className="label-popup"),
dcc.Input(
className="operator_first_name",
id="operator_first_name",
type="text",
placeholder="Prénom",
required=True,
pattern=u"^[^-\s][^0-9]*[A-Za-zÀ-ÖØ-öø-ÿ]+",
debounce = True
),
html.P('Email', className="label-popup"),
dcc.Input(
className="operator_email",
id="operator_email",
type="text",
placeholder="Email",
required=True,
pattern=u"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$",
debounce = True
)]
)
])
),
dbc.ModalFooter([
dbc.Button("SAVE", id="saveQC-btn", className="ml-auto"),
dbc.Button("CANCEL", id="close", className="ml-auto", outline=True, color="secondary")]
),
],
id="modal-save",
),
])
def generate_version_info(version):
return html.Div("Version : "+version,id="version", className="version_info")
def enable_notification():
return html.Div(id="notifications-container")
def notification(data_array):
tmp=[]
for execution_data in data_array :
tmp.append(dmc.Notification(
title=execution_data["title"],
id="sucess-pdf-saved-notify-"+execution_data["message"],
action="show",
message=execution_data["message"],
color="green",
#autoClose=False,
icon=DashIconify(icon="akar-icons:circle-check")
))
return tmp