filebrowser/frontend/src/views/settings/Profile.vue

223 lines
5.8 KiB
Vue
Raw Normal View History

2018-02-01 12:17:04 +00:00
<template>
2024-09-16 21:01:16 +00:00
<div class="card" :class="{ active: active }">
2024-08-24 22:02:33 +00:00
<div class="card-title">
<h2>{{ $t("settings.profileSettings") }}</h2>
</div>
<div class="card-content">
<form @submit="updateSettings">
2021-02-19 13:15:46 +00:00
<div class="card-content">
<p>
<input type="checkbox" v-model="darkMode" />
Dark Mode
</p>
2021-03-21 11:51:58 +00:00
<p>
<input type="checkbox" v-model="hideDotfiles" />
{{ $t("settings.hideDotfiles") }}
</p>
<p>
<input type="checkbox" v-model="singleClick" />
{{ $t("settings.singleClick") }}
</p>
<p>
<input type="checkbox" v-model="dateFormat" />
2021-12-20 20:59:07 +00:00
{{ $t("settings.setDateFormat") }}
</p>
<h3>Listing View Style</h3>
<ViewMode
class="input input--block"
:viewMode="viewMode"
@update:viewMode="updateViewMode"
></ViewMode>
2024-08-24 22:02:33 +00:00
<br />
<h3>Default View Size</h3>
<p>
Note: only applicable for normal and gallery views. Changes here will persist
accross logins.
</p>
<div>
<input
v-model="gallerySize"
type="range"
id="gallary-size"
name="gallary-size"
min="0"
max="10"
/>
</div>
2021-03-21 11:51:58 +00:00
<h3>{{ $t("settings.language") }}</h3>
<Languages
2021-03-21 11:51:58 +00:00
class="input input--block"
:locale="locale"
@update:locale="updateLocale"
></Languages>
2021-02-19 13:15:46 +00:00
</div>
2018-02-01 12:17:04 +00:00
2021-02-19 13:15:46 +00:00
<div class="card-action">
2021-03-21 11:51:58 +00:00
<input
class="button button--flat"
type="submit"
:value="$t('buttons.update')"
/>
2021-02-19 13:15:46 +00:00
</div>
</form>
2024-08-24 22:02:33 +00:00
<hr />
<form v-if="!user.lockPassword" @submit="updatePassword">
2021-02-19 13:15:46 +00:00
<div class="card-title">
2021-03-21 11:51:58 +00:00
<h2>{{ $t("settings.changePassword") }}</h2>
2021-02-19 13:15:46 +00:00
</div>
2018-02-01 12:17:04 +00:00
2021-02-19 13:15:46 +00:00
<div class="card-content">
2021-03-21 11:51:58 +00:00
<input
:class="passwordClass"
type="password"
:placeholder="$t('settings.newPassword')"
v-model="password"
name="password"
/>
<input
:class="passwordClass"
type="password"
:placeholder="$t('settings.newPasswordConfirm')"
v-model="passwordConf"
name="password"
/>
2021-02-19 13:15:46 +00:00
</div>
2018-02-01 12:17:04 +00:00
2021-02-19 13:15:46 +00:00
<div class="card-action">
2021-03-21 11:51:58 +00:00
<input
class="button button--flat"
type="submit"
:value="$t('buttons.update')"
/>
2021-02-19 13:15:46 +00:00
</div>
</form>
</div>
2018-02-01 12:17:04 +00:00
</div>
</template>
<script>
2024-09-16 21:01:16 +00:00
import { notify } from "@/notify";
2024-07-30 17:45:27 +00:00
import { state, mutations } from "@/store";
2024-11-21 00:15:30 +00:00
import { usersApi } from "@/api";
2024-07-30 17:45:27 +00:00
import Languages from "@/components/settings/Languages.vue";
import ViewMode from "@/components/settings/ViewMode.vue";
2022-10-21 16:07:11 +00:00
import i18n, { rtlLanguages } from "@/i18n";
2018-02-01 12:17:04 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "settings",
2018-02-01 12:17:04 +00:00
components: {
ViewMode,
2021-03-21 11:51:58 +00:00
Languages,
2018-02-01 12:17:04 +00:00
},
data() {
2018-02-01 12:17:04 +00:00
return {
2021-03-21 11:51:58 +00:00
password: "",
passwordConf: "",
hideDotfiles: false,
singleClick: false,
dateFormat: false,
darkMode: false,
viewMode: "list",
2021-03-21 11:51:58 +00:00
locale: "",
2024-08-24 22:02:33 +00:00
gallerySize: 0,
2021-03-21 11:51:58 +00:00
};
2018-02-01 12:17:04 +00:00
},
computed: {
2024-08-24 22:02:33 +00:00
settings() {
return state.settings;
},
active() {
return state.activeSettingsView === "profile-main";
},
2024-07-30 17:45:27 +00:00
user() {
return state.user;
},
2021-03-21 11:51:58 +00:00
passwordClass() {
const baseClass = "input input--block";
2021-03-21 11:51:58 +00:00
if (this.password === "" && this.passwordConf === "") {
return baseClass;
2018-02-01 12:17:04 +00:00
}
if (this.password === this.passwordConf) {
2021-03-21 11:51:58 +00:00
return `${baseClass} input--green`;
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
return `${baseClass} input--red`;
},
2018-02-01 12:17:04 +00:00
},
2021-03-21 11:51:58 +00:00
created() {
2024-07-30 17:45:27 +00:00
this.darkMode = state.user.darkMode;
this.locale = state.user.locale;
this.viewMode = state.user.viewMode;
this.hideDotfiles = state.user.hideDotfiles;
this.singleClick = state.user.singleClick;
this.dateFormat = state.user.dateFormat;
2024-08-24 22:02:33 +00:00
this.gallerySize = state.user.gallerySize;
2018-02-01 12:17:04 +00:00
},
2024-08-03 15:34:12 +00:00
watch: {
2024-08-24 22:02:33 +00:00
gallerySize(newValue) {
this.gallerySize = parseInt(newValue, 0); // Update the user object
2024-08-03 15:34:12 +00:00
},
},
2018-02-01 12:17:04 +00:00
methods: {
2021-03-21 11:51:58 +00:00
async updatePassword(event) {
event.preventDefault();
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
if (this.password !== this.passwordConf || this.password === "") {
return;
2018-02-01 12:17:04 +00:00
}
try {
2024-07-30 17:45:27 +00:00
let newUserSettings = state.user;
newUserSettings.id = state.user.id;
newUserSettings.password = this.password;
2024-11-21 00:15:30 +00:00
await usersApi.update(newUserSettings, ["password"]);
2024-09-16 21:01:16 +00:00
notify.showSuccess(this.$t("settings.passwordUpdated"));
} catch (e) {
2024-09-16 21:01:16 +00:00
notify.showError(e);
}
2018-02-01 12:17:04 +00:00
},
2021-03-21 11:51:58 +00:00
async updateSettings(event) {
event.preventDefault();
try {
2021-03-21 11:51:58 +00:00
const data = {
2024-07-30 17:45:27 +00:00
id: state.user.id,
2021-03-21 11:51:58 +00:00
locale: this.locale,
darkMode: this.darkMode,
viewMode: this.viewMode,
2021-03-21 11:51:58 +00:00
hideDotfiles: this.hideDotfiles,
singleClick: this.singleClick,
dateFormat: this.dateFormat,
2024-08-24 22:02:33 +00:00
gallerySize: this.gallerySize,
2021-03-21 11:51:58 +00:00
};
2022-10-21 16:07:11 +00:00
const shouldReload =
2024-07-30 17:45:27 +00:00
rtlLanguages.includes(data.locale) !== rtlLanguages.includes(i18n.locale);
2024-11-21 00:15:30 +00:00
await usersApi.update(data, [
2021-12-20 20:59:07 +00:00
"locale",
"darkMode",
"viewMode",
2021-12-20 20:59:07 +00:00
"hideDotfiles",
"singleClick",
"dateFormat",
2024-08-24 22:02:33 +00:00
"gallerySize",
2021-12-20 20:59:07 +00:00
]);
2024-09-16 21:01:16 +00:00
mutations.updateCurrentUser(data);
2022-10-21 16:07:11 +00:00
if (shouldReload) {
location.reload();
}
2024-09-16 21:01:16 +00:00
notify.showSuccess(this.$t("settings.settingsUpdated"));
} catch (e) {
2024-09-16 21:01:16 +00:00
notify.showError(e);
}
2021-03-21 11:51:58 +00:00
},
updateViewMode(updatedMode) {
this.viewMode = updatedMode;
},
updateLocale(updatedLocale) {
this.locale = updatedLocale;
},
2021-03-21 11:51:58 +00:00
},
};
2018-02-01 12:17:04 +00:00
</script>