-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb01a93
commit 1415388
Showing
4 changed files
with
138 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
apps/frontend/src/pages/servers/manage/[id]/options/preferences.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<template> | ||
<div class="h-full w-full gap-2 overflow-y-auto"> | ||
<div class="card flex flex-col gap-4"> | ||
<h1 class="m-0 text-2xl font-bold">Server Preferences</h1> | ||
<div v-for="(value, key) in userPrefrences" :key="key" class="flex justify-between"> | ||
<label for="server-name-field" class="flex flex-col gap-2"> | ||
<span class="text-lg font-bold text-contrast">{{ preferences[key].displayName }}</span> | ||
<span> {{ preferences[key].description }} </span> | ||
</label> | ||
<input v-model="newUserprefrences[key]" class="switch stylized-toggle" type="checkbox" /> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="absolute bottom-[2.5%] left-[2.5%] z-10 w-[95%]"> | ||
<UiServersSaveBanner | ||
:is-visible="!!hasUnsavedChanges" | ||
:server="props.server" | ||
:is-updating="false" | ||
:save="savePreferences" | ||
:reset="resetPreferences" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useStorage } from "@vueuse/core"; | ||
import type { Server } from "~/composables/pyroServers"; | ||
const route = useNativeRoute(); | ||
const serverId = route.params.id as string; | ||
const props = defineProps<{ | ||
server: Server<["general", "mods", "backups", "network", "startup", "ws", "fs"]>; | ||
}>(); | ||
const hasUnsavedChanges = computed(() => { | ||
return JSON.stringify(newUserprefrences.value) !== JSON.stringify(userPrefrences.value); | ||
}); | ||
const savePreferences = () => { | ||
userPrefrences.value = newUserprefrences.value; | ||
newUserprefrences.value = JSON.parse(JSON.stringify(userPrefrences.value)); | ||
addNotification({ | ||
group: "serverOptions", | ||
type: "success", | ||
title: "Preferences saved", | ||
text: "Your preferences have been saved.", | ||
}); | ||
}; | ||
const resetPreferences = () => { | ||
newUserprefrences.value = userPrefrences.value; | ||
}; | ||
const preferences = { | ||
ramAsNumber: { | ||
displayName: "RAM as bytes", | ||
description: "Display RAM usage in number of bytes instead of percentage", | ||
}, | ||
autoRestart: { | ||
displayName: "Auto restart (not implemented)", | ||
description: "Automatically restart the server if it crashes", | ||
}, | ||
backupWhileRunning: { | ||
displayName: "Backup while running (not implemented)", | ||
description: | ||
"Allow creation of a backup without stoping the server. This may lead to corrupted backups, use with caution", | ||
}, | ||
}; | ||
const defaultPreferences = { | ||
ramAsNumber: false, | ||
autoRestart: false, | ||
backupWhileRunning: false, | ||
}; | ||
const userPrefrences = useStorage(`pyro-server-${serverId}-preferences`, defaultPreferences); | ||
const newUserprefrences = ref(JSON.parse(JSON.stringify(userPrefrences.value))); | ||
</script> |