add user settings

This commit is contained in:
Simon Vieille
2025-04-13 20:32:13 +02:00
parent 6c4f9120ff
commit fdd8f8850d
20 changed files with 839 additions and 316 deletions
@@ -0,0 +1,90 @@
<template>
<div class="side-menu-setting-save">
<NcButton
variant="success"
@click="save"
>
<template v-if="!loading">
{{ t('side_menu', 'Save') }}
</template>
<NcLoadingIcon v-else />
</NcButton>
<div v-if="error" id="error">
</div>
</div>
</template>
<style scoped>
#error {
padding-top: 10px;
color: red;
}
</style>
<script setup>
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { ref } from 'vue'
const loading = ref(false)
const error = ref(null)
const { config } = defineProps({
config: {
type: Object,
required: true,
},
})
const filterConfig = (value) => {
const result = {}
for (let key in value) {
if (['cache-categories', 'cache', 'langs', 'enabled'].includes(key) === false) {
result[key] = value[key]
}
}
return result
}
const save = async () => {
const data = filterConfig(config)
const size = Object.keys(data).length
let counter = 0
loading.value = true
error.value = null
const update = () => {
++counter;
if (counter === size) {
loading.value = false
if (!error.value) {
location.reload()
}
}
}
for (let key in data) {
let value = data[key]
if (Array.isArray(value) || typeof(value) === 'object') {
value = JSON.stringify(value)
} else if (typeof(value) === 'boolean') {
value = value ? 1 : 0
}
OCP.AppConfig.setValue('side_menu', key, value, {
success() {
update()
},
error() {
error.value = `Error while saving ${key}`
update()
}
})
}
}
</script>
+10 -1
View File
@@ -27,7 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<template v-if="help">
<br />
<em>{{ help }}</em>
<em>{{ t('side_menu', help) }}</em>
</template>
<template v-if="help2">
<br />
<em>{{ t('side_menu', help2) }}</em>
</template>
</div>
</template>
@@ -58,5 +62,10 @@ const { short, label } = defineProps({
required: false,
default: null,
},
help2: {
type: [String, null],
required: false,
default: null,
},
})
</script>
+20 -1
View File
@@ -15,7 +15,26 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div class="side-menu-setting-row">
<div
class="side-menu-setting-row"
:class="{'side-menu-setting-row--disabled': disabled }"
>
<slot></slot>
</div>
</template>
<style scoped>
.disabled {
display: block;
}
</style>
<script setup>
const { disabled } = defineProps({
disabled: {
type: Boolean,
required: false,
default: false,
}
})
</script>
@@ -0,0 +1,97 @@
<template>
<div class="side-menu-setting-save">
<NcButton
variant="success"
@click="save"
>
<template v-if="!loading">
{{ t('side_menu', 'Save') }}
</template>
<NcLoadingIcon v-else />
</NcButton>
<div v-if="error" id="error">
</div>
</div>
</template>
<style scoped>
#error {
padding-top: 10px;
color: red;
}
</style>
<script setup>
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { ref } from 'vue'
const loading = ref(false)
const error = ref(null)
const { config } = defineProps({
config: {
type: Object,
required: true,
},
})
const filterConfig = (value) => {
const result = {}
for (let key in value) {
result[key] = value[key]
}
return result
}
const save = async () => {
const data = filterConfig(config)
const size = Object.keys(data).length
const url = OC.generateUrl('/apps/side_menu/user/valueSet')
let counter = 0
loading.value = true
error.value = null
const update = () => {
++counter;
if (counter === size) {
loading.value = false
if (!error.value) {
location.reload()
}
}
}
for (let key in data) {
let value = data[key]
let formData = []
if (Array.isArray(value) || typeof(value) === 'object') {
value = JSON.stringify(value)
} else if (typeof(value) === 'boolean') {
value = value ? 1 : 0
}
formData.push('name=' + encodeURIComponent(key))
formData.push('value=' + encodeURIComponent(value))
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: formData.join('&'),
})
.then(update)
.catch(() => {
error.value = `Error while saving ${key}`
update()
})
}
}
</script>
@@ -74,7 +74,7 @@ const closeModal = () => {
}
onMounted(async () => {
apps.value = await navStore.getApps()
apps.value = await navStore.getCoreApps()
})
</script>
+1 -1
View File
@@ -104,7 +104,7 @@ const update = () => {
}
onMounted(async () => {
const items = await navStore.getApps()
const items = await navStore.getCoreApps()
window.setTimeout(() => {
setApps(items)
+2 -3
View File
@@ -35,10 +35,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
@end="update"
>
<template #item="{ element }">
<div class="draggable">
<div class="draggable" v-if="element.name !== ''">
<span class="arrow">⇅</span>
<span v-if="element.name !== ''">{{ element.name }}</span>
<span v-else>{{ t('side_menu', 'Other') }}</span>
{{ element.name }}
</div>
</template>
</draggable>