forked from lablup/backend.ai-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend-ai-app.ts
150 lines (142 loc) · 4.28 KB
/
backend-ai-app.ts
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
/**
@license
Copyright (c) 2015-2020 Lablup Inc. All rights reserved.
*/
export const UPDATE_PAGE = 'UPDATE_PAGE';
export const UPDATE_OFFLINE = 'UPDATE_OFFLINE';
export const UPDATE_DRAWER_STATE = 'UPDATE_DRAWER_STATE';
export const OPEN_SNACKBAR = 'OPEN_SNACKBAR';
export const CLOSE_SNACKBAR = 'CLOSE_SNACKBAR';
export const navigate = (path: any, params: Object = {}) => (dispatch: any) => {
// Extract the page name from path.
if (['/summary', '/job', '/experiment', '/data', '/statistics', '/usersettings',
'/agent', '/resource', '/user', '/credential', '/environment', '/settings',
'/maintenance', '/information', '/github', '/import'].includes(path) !== true) { // Fallback for Electron Shell/Windows OS
let fragments = path.split(/[\/]+/);
if (fragments.length > 1 && fragments[0] === "") {
path = fragments[1];
params['requestURL'] = fragments.slice(2).join("/");
}
}
params['queryString'] = window.location.search;
if (path === 'index.html' || path === '') {
path = '/';
}
let page;
if (['/', 'build', '/build', 'app', '/app'].includes(path)) {
page = 'summary';
} else if (path[0] === '/') {
page = path.slice(1);
} else {
page = path;
}
//const page = path === '/' ? 'summary' : path.slice(1);
// Any other info you might want to extract from the path (like page type),
// you can do here
dispatch(loadPage(page, params));
// Close the drawer - in case the *path* change came from a link in the drawer.
dispatch(updateDrawerState(false));
};
const loadPage = (page, params: Object = {}) => (dispatch) => {
switch (page) {
case 'summary':
import('./components/backend-ai-summary-view.js').then((module) => {
// TODO: after page changing?
});
break;
case 'job':
import('./components/backend-ai-session-view.js');
break;
case 'experiment':
import('./components/backend-ai-experiment-view.js');
break;
case 'data':
import('./components/backend-ai-data-view.js');
break;
case 'usersettings':
import('./components/backend-ai-usersettings-view.js');
break;
case 'agent':
case 'resource':
import('./components/backend-ai-agent-view.js');
break;
case 'credential':
case 'user':
import('./components/backend-ai-credential-view.js');
break;
case 'environment':
import('./components/backend-ai-environment-view.js');
break;
case 'settings':
import('./components/backend-ai-settings-view.js');
break;
case 'maintenance':
import('./components/backend-ai-maintenance-view.js');
break;
case 'information':
import('./components/backend-ai-information-view.js');
break;
case 'statistics':
import('./components/backend-ai-statistics-view.js');
break;
case 'logs':
import('./components/backend-ai-error-log-view.js');
break;
case 'verify-email':
import('./components/backend-ai-email-verification-view.js');
break;
case 'change-password':
import('./components/backend-ai-change-forgot-password-view.js');
break;
case 'github':
case 'gitlab':
case 'import':
import('./components/backend-ai-import-view.js');
break;
default:
if (typeof globalThis.backendaiPage !== 'undefined') {
for (let item of globalThis.backendaiPage) {
if ('url' in item) {
import('./plugins/' + item.url);
break;
}
}
}
import('./components/backend-ai-error-view.js').then((module) => {
});
break;
}
dispatch(updatePage(page, params));
};
const updatePage = (page, params) => {
return {
type: UPDATE_PAGE,
page,
params
};
};
let offlineTimer;
export const showOffline = () => (dispatch) => {
dispatch({
type: OPEN_SNACKBAR
});
window.clearTimeout(offlineTimer);
offlineTimer = window.setTimeout(() =>
dispatch({type: CLOSE_SNACKBAR}), 3000);
};
export const updateOffline = (offline) => (dispatch, getState) => {
// Show the snackbar only if offline status changes.
if (offline !== getState().app.offline) {
dispatch(showOffline());
}
dispatch({
type: UPDATE_OFFLINE,
offline
});
};
export const updateDrawerState = (opened) => {
return {
type: UPDATE_DRAWER_STATE,
opened
};
};