-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
263 lines (231 loc) · 6.91 KB
/
__main__.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
import warnings
import dash, dash_bootstrap_components as dbc
from dash import dcc, html
from dash.dependencies import Input, Output, State
from homepage.homepage_layout import home_layout
from pre_ten.pre_ten_layout import register_pre_ten_layout_callbacks, pre_ten_layout
from post_twenty.post_twenty_layout import register_post_twenty_layout_callbacks, post_twenty_layout
from overall_scrap.overall_scrap_layout import overall_scrap_layout_callbacks, overall_scrap_layout
from utils import PASSWORD
warnings.filterwarnings('ignore')
app = dash.Dash(
__name__,
suppress_callback_exceptions=True,
external_stylesheets=[
dbc.themes.FLATLY,
dbc.themes.BOOTSTRAP,
dbc.icons.BOOTSTRAP,
'/assets/bootstrap.min.css',
'/assets/styles.css'
]
)
# Collapse Button of Dashboard
@app.callback(
Output("collapse", "is_open"),
[
Input("collapse-button", "n_clicks")
],
[
State("collapse", "is_open")
],
)
def toggle_nav(n, is_open):
if n:
return not is_open
return is_open
# Filter Option 1 of Dashboard
@app.callback(
Output("modal1", "is_open"),
[
Input("open1", "n_clicks"),
Input("close1", "n_clicks")
],
[
State("modal1", "is_open")
],
)
def toggle_modal1(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
# Filter Option 2 of Dashboard
@app.callback(
Output("modal2", "is_open"),
[
Input("open2", "n_clicks"),
Input("close2", "n_clicks")
],
[
State("modal2", "is_open")
],
)
def toggle_modal2(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
# Filter Option 3 of Dashboard
@app.callback(
Output("modal3", "is_open"),
[
Input("open3", "n_clicks"),
Input("close3", "n_clicks")
],
[
State("modal3", "is_open")
],
)
def toggle_modal3(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
# Filter Option 4 of Dashboard
@app.callback(
Output("modal4", "is_open"),
[
Input("open4", "n_clicks"),
Input("close4", "n_clicks")
],
[
State("modal4", "is_open")
],
)
def toggle_modal4(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
# Filter Option 5 of Dashboard
@app.callback(
Output("modal5", "is_open"),
[
Input("open5", "n_clicks"),
Input("close5", "n_clicks")
],
[
State("modal5", "is_open")
],
)
def toggle_modal5(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
# Filter Option 6 of Dashboard
@app.callback(
Output("modal6", "is_open"),
[
Input("open6", "n_clicks"),
Input("close6", "n_clicks")
],
[
State("modal6", "is_open")
],
)
def toggle_modal7(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
# Filter Option 7 of Dashboard
@app.callback(
Output("modal7", "is_open"),
[
Input("open7", "n_clicks"),
Input("close7", "n_clicks")
],
[
State("modal7", "is_open")
],
)
def toggle_modal7(n1, n2, is_open):
if n1 or n2:
return not is_open
return is_open
app.layout = html.Div([
dcc.Location(id="url"),
html.Div(id='dynamic-layout'),
])
@app.callback(
Output('dynamic-layout', 'children'),
Input('url', 'search')
)
def update_layout(search):
if search != PASSWORD:
return html.Div([
html.Div(className='hover-trigger'),
# Sidebar
html.Div(id="sidebar", className="sidebar", children=[
html.H2("Q-Dot Scrap Data", className='my-4'),
html.Hr(),
dbc.Nav([
# Home Page Button
dbc.NavLink("Home Page", href="/", active="exact"),
# Scraps Button
dbc.NavLink("Scraps", id="collapse-button", className="mb-3"),
dbc.Collapse(dbc.Nav([
# pre-Ten Access
dbc.NavLink("pre-Ten", href="/mu", active="exact"),
# Post-Processing Access
dbc.NavLink("Post Processing", href="/pp", active="exact"),
# Global Scraps Access
dbc.NavLink("Global", href="/os", active="exact"),
]), id="collapse", is_open=False),
], vertical=True, pills=True),
]),
html.Div(id="page-content", style={"padding": "2rem 1rem"}),
])
else:
return html.Div([
html.Div(className='hover-trigger'),
# Sidebar
html.Div(id="sidebar", className="sidebar", children=[
html.H2("Scrap Data", className='my-4'),
html.Hr(),
dbc.Nav([
# Home Page Button
dbc.NavLink("Home Page", href="/", active="exact"),
# Scraps Button
dbc.NavLink("Scraps", id="collapse-button", className="mb-3"),
dbc.Collapse(dbc.Nav([
# pre-Ten Access
dbc.NavLink("pre-Ten", href="/mu?admin", active="exact"),
# Post-Processing Access
dbc.NavLink("Post Processing", href="/pp?admin", active="exact"),
# Global Scraps Access
dbc.NavLink("Global", href="/os?admin", active="exact"),
]), id="collapse", is_open=False),
], vertical=True, pills=True),
]),
html.Div(id="page-content", style={"padding": "2rem 1rem"}),
])
register_pre_ten_layout_callbacks(app)
register_post_twenty_layout_callbacks(app)
overall_scrap_layout_callbacks(app)
@app.callback(
Output('page-content', 'children'),
[
Input('url', 'pathname'),
Input('url', 'search')
]
)
def render_page_content(pathname, search):
if pathname in ["/", "/ho"]:
return home_layout()
elif (pathname == "/mu") and (search == PASSWORD):
return pre_ten_layout(operator_show = True)
elif (pathname == "/os") and (search == PASSWORD):
return overall_scrap_layout(operator_show = True)
elif pathname == "/mu":
return pre_ten_layout(operator_show = False)
elif pathname == "/pp":
return post_twenty_layout()
elif pathname == "/os":
return overall_scrap_layout(operator_show = False)
else:
return html.Div([
html.H3("404 Error: Page not found"),
html.P(f"The requested path '{pathname}' is not a valid page."),
html.P(f"Query parameters: {search}"),
])
if __name__ == '__main__':
"""
Add debug=True if you want the blue circle on bottom right for traceback (most recent call last).
"""
app.run(debug=True, host="localhost", port=8180)