-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_step2.svelte
More file actions
326 lines (295 loc) Β· 19.6 KB
/
Copy pathtemp_step2.svelte
File metadata and controls
326 lines (295 loc) Β· 19.6 KB
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
ο»Ώ<style>
.cursor-pointer {
cursor: pointer;
}
</style>
<div class="animate__animated animate__fadeIn animate__slower">
<div class="card-header">
{$_("steps.database.title")}
</div>
<form on:submit|preventDefault={submit}>
<div class="card-body vstack gap-3">
<ErrorAlert error={error} />
<div class="vstack gap-2">
<label
class="form-check-label d-block p-3 border rounded cursor-pointer"
for="dbPortable"
class:border-primary={dbType === "portable"}
class:opacity-50={!portableSupported}>
<div class="d-flex align-items-center gap-3">
<input
class="form-check-input mt-0"
type="radio"
name="dbType"
id="dbPortable"
value="portable"
disabled={!portableSupported}
bind:group={dbType} />
<div class="vstack">
<strong
>{$_("steps.database.databases.local-portable-db")}</strong>
<small>
>{$_(
"steps.database.databases.local-portable-db-description",
)}</small>
{#if !portableSupported}
<div class="alert alert-warning mt-2 mb-0 p-2">
<small class="d-block">
{$_(
"steps.database.databases.portable-not-supported",
)}<br />
{$_("steps.database.databases.supported-systems", {
values: { systems: supportedSystems.join(", ") },
})}
</small>
</div>
{:else if dbType === "portable" && !installed}
<div class="mt-3">
<button
type="button"
class="btn btn-primary btn-sm"
on:click={installPortableDB}
disabled={installLoading}>
{#if installLoading}
<span
class="spinner-border spinner-border-sm me-2"
role="status"></span>
{$_("steps.database.databases.installing")}
{:else}
{$_("steps.database.databases.download-and-install")}
{/if}
</button>
</div>
{:else if dbType === "portable" && installed}
<div class="mt-2">
<span class="badge bg-success"
>{$_("steps.database.databases.portable-installed")}</span>
</div>
{/if}
</div>
</div>
</label>
<label
class="form-check-label d-block p-3 border rounded cursor-pointer"
for="dbManual"
class:border-primary={dbType === "mariadb"}>
<div class="d-flex align-items-center gap-3">
<input
class="form-check-input mt-0"
type="radio"
name="dbType"
id="dbManual"
value="mariadb"
bind:group={dbType} />
<div class="vstack">
<strong>{$_("steps.database.databases.mysql-or-mariadb")}</strong>
<small>
>{$_(
"steps.database.databases.mysql-or-mariadb-description",
)}</small>
</div>
</div>
</label>
</div>
<div class="row g-3" class:opacity-50={dbType === "portable"}>
<div class="col-lg-6">
<div class="form-floating">
<input
class="form-control"
id="databaseAddress"
placeholder="localhost:3306"
bind:value={database.host}
disabled={dbType === "portable"}
type="text" />
<label class="form-label" for="databaseAddress"
>{$_("steps.database.inputs.address")}</label>
</div>
</div>
<div class="col-lg-6">
<div class="form-floating">
<input
class="form-control"
id="databaseName"
placeholder="pano"
bind:value={database.dbName}
disabled={dbType === "portable"}
type="text" />
<label class="form-label" for="databaseName"
>{$_("steps.database.inputs.name")}</label>
</div>
</div>
<div class="col-lg-6">
<div class="form-floating">
<input
class="form-control"
id="databaseUserName"
placeholder="root"
bind:value={database.username}
disabled={dbType === "portable"}
type="text" />
<label class="form-label" for="databaseUserName"
>{$_("steps.database.inputs.username")}</label>
</div>
</div>
<div class="col-lg-6">
<div class="form-floating">
<input
class="form-control"
id="databaseUserPassword"
placeholder="****************"
bind:value={database.password}
disabled={dbType === "portable"}
type="password" />
<label class="form-label" for="databaseUserPassword"
>{$_("steps.database.inputs.password")}</label>
</div>
</div>
<div class="col-12">
<div class="form-floating">
<input
class="form-control"
id="databaseTablePrefix"
placeholder="pano_"
bind:value={database.prefix}
disabled={dbType === "portable"}
type="text" />
<label class="form-label" for="databaseTablePrefix"
>{$_("steps.database.inputs.prefix")}</label>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-6">
<button
type="button"
class="btn btn-link w-100"
on:click={back}
class:disabled={loading || installLoading}
disabled={loading || installLoading}
>{$_("buttons.back")}
</button>
</div>
<div class="col-6">
<div class="animate__animated animate__zoomIn animate__slow">
<button
type="submit"
class="btn btn-secondary w-100"
class:disabled={loading || disabled || installLoading}
disabled={loading || disabled || installLoading}
>{$_("buttons.next")}
{#if nextLoading}
<span
class="spinner-border spinner-border-sm text-primary ms-2"
role="status"></span>
{/if}
</button>
</div>
</div>
</div>
</div>
</form>
</div>
<script context="module">
/** @type {import('./$types').PageLoad} */
export async function load({ parent }) {
const parentData = await parent();
const { stepInfo } = parentData;
return { stepInfo };
}
</script>
<script>
import { _ } from "svelte-i18n";
import { backStep, nextStep } from "$lib/Store.js";
import ApiUtil, { NETWORK_ERROR } from "$lib/api.util.js";
import ErrorAlert from "$lib/component/ErrorAlert.svelte";
let loading = false;
let nextLoading;
let error = null;
export let dbType = "mariadb";
let installLoading = false;
export let installed = false;
export let portableDatabaseSupported = false;
export let supportedSystems = [];
$: portableSupported = portableDatabaseSupported;
$: if (!portableSupported && dbType === "portable") dbType = "mariadb";
export let database = {
host: "",
dbName: "",
username: "",
password: "",
prefix: "",
};
$: disabled =
dbType === "mariadb"
? database.host === "" ||
database.dbName === "" ||
database.username === ""
: !installed;
function installPortableDB() {
if (!portableSupported) return;
installLoading = true;
error = null;
ApiUtil.post({
path: "/api/setup/steps/2/install-portable",
})
.then((body) => {
if (body.result === "ok") {
database = body.database;
installed = true;
installLoading = false;
} else if (body.error) {
showError(body.error);
installLoading = false;
} else {
showError(NETWORK_ERROR);
installLoading = false;
}
})
.catch(() => {
showError(NETWORK_ERROR);
installLoading = false;
});
}
function submit() {
loading = true;
error = null;
if (dbType === "portable" && installed) {
next();
return;
}
ApiUtil.post({
path: "/api/setup/steps/2/verify",
body: database,
})
.then((body) => {
if (body.result === "ok") {
next();
} else if (body.error) {
showError(
body.error === "INVALID_DATA" ? "INVALID_DB_DATA" : body.error,
);
} else showError(NETWORK_ERROR);
})
.catch(() => {
showError(NETWORK_ERROR);
});
}
function next() {
loading = true;
nextLoading = true;
// ensure dbType is manual if portable not supported
if (!portableSupported && dbType === "portable") dbType = "mariadb";
nextStep({ ...database, dbType });
}
function back() {
if (!loading && !installLoading) {
loading = true;
error = null;
backStep();
}
}
function showError(errorCode) {
loading = false;
error = errorCode;
}
</script>