Skip to content

Commit 01e1b3c

Browse files
authored
Merge pull request #633 from arabcoders/dev
QoL improvements
2 parents 8fb21d0 + c921430 commit 01e1b3c

File tree

20 files changed

+1272
-1137
lines changed

20 files changed

+1272
-1137
lines changed

composer.lock

Lines changed: 79 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/components/BackendAdd.vue

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -269,34 +269,30 @@
269269
</p>
270270
</div>
271271
</div>
272-
<div class="field" v-if="backends.length > 0">
272+
<div class="field">
273273
<hr>
274-
<label class="label has-text-danger" for="force_export">
275-
Export current local database state to this backend?
274+
<label class="label has-text-danger" for="backup_data">
275+
Create backup for this backend data?
276276
</label>
277277
<div class="control">
278-
<input id="force_export" type="checkbox" class="switch is-success"
279-
v-model="forceExport">
280-
<label for="force_export">Yes</label>
278+
<input id="backup_data" type="checkbox" class="switch is-success" v-model="backup_data">
279+
<label for="backup_data">Yes</label>
281280
<p class="help">
282-
<span class="icon has-text-danger"><i class="fas fa-exclamation-triangle"></i></span>
283-
If this is a new backend, you need to get it in sync with your current database,
284-
enabling this option will initiate a one time force export the current local database state to the
285-
backend. This will override the backend state to be inline with the local database state.
281+
This will run a one time backup for the backend data.
286282
</p>
287283
</div>
288284
</div>
289-
<div class="field" v-else>
285+
<div class="field" v-if="backends.length > 0">
290286
<hr>
291-
<label class="label has-text-danger" for="run_import">
292-
Export current local database state to this backend?
287+
<label class="label has-text-danger" for="force_export">
288+
Force Export local data to this backend?
293289
</label>
294290
<div class="control">
295-
<input id="run_import" type="checkbox" class="switch is-success" v-model="runImport">
296-
<label for="run_import">Yes</label>
297-
<p class="help">
298-
<span class="icon has-text-danger"><i class="fas fa-info-circle"></i></span>
299-
Do you want to run a one time import for this backend after adding this backend?
291+
<input id="force_export" type="checkbox" class="switch is-success" v-model="force_export">
292+
<label for="force_export">Yes</label>
293+
<p class="help has-text-danger">
294+
<span class="icon"><i class="fas fa-info-circle"></i></span>
295+
THIS OPTION WILL OVERRIDE THE BACKEND DATA with locally stored data.
300296
</p>
301297
</div>
302298
</div>
@@ -335,7 +331,7 @@ import request from '~/utils/request'
335331
import {awaitElement, explode, notification, ucFirst} from '~/utils/index'
336332
import {useStorage} from "@vueuse/core";
337333
338-
const emit = defineEmits(['addBackend', 'forceExport', 'runImport'])
334+
const emit = defineEmits(['addBackend', 'backupData', 'forceExport'])
339335
340336
const props = defineProps({
341337
backends: {
@@ -377,8 +373,8 @@ const uuidLoading = ref(false)
377373
const serversLoading = ref(false)
378374
const exposeToken = ref(false)
379375
const error = ref()
380-
const forceExport = ref(false)
381-
const runImport = ref(false)
376+
const backup_data = ref(true)
377+
const force_export = ref(false)
382378
383379
const isLimited = ref(false)
384380
const accessTokenResponse = ref({})
@@ -674,16 +670,15 @@ const addBackend = async () => {
674670
675671
notification('success', 'Information', `Backend ${backend.value.name} added successfully.`)
676672
677-
let event
678-
if (true === Boolean(forceExport?.value ?? false)) {
679-
event = 'forceExport'
680-
} else if (true === Boolean(runImport?.value ?? false)) {
681-
event = 'runImport'
682-
} else {
683-
event = 'addBackend'
673+
if (true === Boolean(backup_data?.value ?? false)) {
674+
emit('backupData', backend)
675+
}
676+
677+
if (true === Boolean(force_export?.value ?? false)) {
678+
emit('forceExport', backend)
684679
}
685680
686-
emit(event, backend)
681+
emit('addBackend')
687682
688683
return true
689684
}

frontend/components/UserSelection.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ onMounted(async () => {
5050
}
5151
const json = await response.json();
5252
if ('users' in json) {
53-
users.value = json?.users;
53+
json.users.forEach(user => {
54+
const username = user.user
55+
if (!users.value.includes(username)) {
56+
users.value.push(username);
57+
}
58+
});
5459
}
5560
} catch (e) {
5661
notification('error', `Failed to fetch users. ${e}`);

frontend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"@vueuse/nuxt": "^13.0.0",
1616
"@xterm/addon-fit": "^0.10.0",
1717
"@xterm/xterm": "^5.5.0",
18-
"cronstrue": "^2.49.0",
18+
"cronstrue": "^2.57.0",
1919
"floating-vue": "^5.2.2",
20-
"hls.js": "^1.4.14",
20+
"hls.js": "^1.6.0",
2121
"marked": "^15.0.7",
2222
"marked-base-url": "^1.1.3",
2323
"moment": "^2.30.1",
24-
"nuxt": "^3.16",
24+
"nuxt": "^3.16.2",
2525
"plyr": "^3.7.8",
2626
"vue": "^3.4.21",
2727
"vue-router": "^4.3.0",

frontend/pages/backends/index.vue

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
</div>
3636

3737
<div class="column is-12" v-if="toggleForm">
38-
<BackendAdd @forceExport="e => handleEvents('forceExport', e)" :backends="backends"
39-
@runImport="e => handleEvents('runImport', e)" @addBackend="e => handleEvents('addBackend', e)"/>
38+
<BackendAdd @backupData="e => handleEvents('backupData', e)" :backends="backends"
39+
@forceExport="e => handleEvents('forceExport', e)"
40+
@addBackend="e => handleEvents('addBackend', e)"/>
4041
</div>
4142
<template v-else>
4243
<div class="column is-12" v-if="backends.length<1">
@@ -188,7 +189,7 @@ import 'assets/css/bulma-switch.css'
188189
import moment from 'moment'
189190
import request from '~/utils/request'
190191
import BackendAdd from '~/components/BackendAdd'
191-
import {ag, copyText, makeConsoleCommand, notification, r, TOOLTIP_DATE_FORMAT} from '~/utils/index'
192+
import {ag, copyText, makeConsoleCommand, notification, queue_event, r, TOOLTIP_DATE_FORMAT} from '~/utils/index'
192193
import {useStorage} from '@vueuse/core'
193194
import Message from '~/components/Message'
194195
@@ -206,31 +207,31 @@ const usefulCommands = {
206207
export_now: {
207208
id: 1,
208209
title: "Run normal export.",
209-
command: 'state:export -v -s {name}',
210+
command: 'state:export -v -u {user} -s {name}',
210211
state_key: 'export.enabled',
211212
},
212213
import_now: {
213214
id: 2,
214215
title: "Run normal import.",
215-
command: 'state:import -v -s {name}',
216+
command: 'state:import -v -u {user} -s {name}',
216217
state_key: 'import.enabled'
217218
},
218219
force_export: {
219220
id: 3,
220221
title: "Force export local play state to this backend.",
221-
command: 'state:export -fi -v -s {name}',
222+
command: 'state:export -fi -v -u {user} -s {name}',
222223
state_key: 'export.enabled',
223224
},
224225
backup_now: {
225226
id: 4,
226227
title: "Backup this backend play state.",
227-
command: "state:backup -v -s {name} --file '{date}.manual_{name}.json'",
228+
command: "state:backup -v -u {user} -s {name} --file '{date}.manual_{name}.json'",
228229
state_key: 'import.enabled',
229230
},
230231
metadata_only: {
231232
id: 5,
232233
title: "Import this backend metadata.",
233-
command: "state:import -v --metadata-only -s {name}",
234+
command: "state:import -v --metadata-only -u {user} -s {name}",
234235
state_key: 'import.enabled',
235236
},
236237
}
@@ -247,7 +248,7 @@ const forwardCommand = async backend => {
247248
date: moment().format('YYYYMMDD'),
248249
}
249250
250-
await navigateTo(makeConsoleCommand(r(usefulCommands[index].command, {...backend, ...util})));
251+
await navigateTo(makeConsoleCommand(r(usefulCommands[index].command, {...backend, ...util, user: api_user.value})));
251252
}
252253
253254
const loadContent = async () => {
@@ -285,18 +286,54 @@ const updateValue = async (backend, key, newValue) => {
285286
286287
const handleEvents = async (event, backend) => {
287288
switch (event) {
288-
case 'forceExport':
289-
notification('warning', 'Warning', `We are going to sync '${backend.value.name}' play state to match the current local database.`, 10000)
290-
await navigateTo(makeConsoleCommand(`state:export -fi -v -s ${backend.value.name}`, true))
289+
case 'backupData':
290+
try {
291+
const backup_status = await queue_event('run_console', {
292+
command: 'state:backup',
293+
args: [
294+
'-v',
295+
'--user',
296+
api_user.value,
297+
'--select-backend',
298+
backend.value.name,
299+
'--file',
300+
'{user}.{backend}.{date}.initial_backup.json',
301+
]
302+
})
303+
console.log(backup_status);
304+
305+
notification('info', 'Info', `We are going to initiate a backup for '${backend.value.name}' in little bit.`, 5000)
306+
} catch (e) {
307+
notification('error', 'Error', `Failed to queue backup request. ${e.message}`)
308+
}
291309
break
292-
case 'runImport':
293-
notification('info', 'Info', `We are going to import '${backend.value.name}' play state to the local database.`, 10000)
294-
await navigateTo(makeConsoleCommand(`state:import -v -s ${backend.value.name}`, true))
310+
case 'forceExport':
311+
try {
312+
const export_status = await queue_event('run_console', {
313+
command: 'state:export',
314+
args: [
315+
'-fi',
316+
'-v',
317+
'--user',
318+
api_user.value,
319+
'--dry-run',
320+
'--select-backend',
321+
backend.value.name,
322+
]
323+
}, 180)
324+
325+
console.log(export_status);
326+
327+
notification('info', 'Info', `Soon we are going to force export the local data to '${backend.value.name}'.`, 5000)
328+
} catch (e) {
329+
notification('error', 'Error', `Failed to queue force export request. ${e.message}`)
330+
}
295331
break
296332
case 'addBackend':
297333
toggleForm.value = false
298334
await loadContent()
299335
break
300336
}
301337
}
338+
302339
</script>

0 commit comments

Comments
 (0)