Add settings: Editor Auto Save Interval

Change-Id: I9ce890d9f9a264582f26a1d4cb4fcc0a924ae949
This commit is contained in:
lihengxin 2022-09-07 14:31:47 +08:00
parent c1e6d5869a
commit b28f8e58a4
6 changed files with 108 additions and 43 deletions

View File

@ -178,6 +178,7 @@
"brandingDirectoryPath": "Branding directory path",
"brandingHelp": "You can customize how your File Browser instance looks and feels by changing its name, replacing the logo, adding custom styles and even disable external links to GitHub.\nFor more information about custom branding, please check out the {0}.",
"changePassword": "Change Password",
"changeEditorSettings": "Change Editor Settings",
"commandRunner": "Command runner",
"commandRunnerHelp": "Here you can set commands that are executed in the named events. You must write one per line. The environment variables {0} and {1} will be available, being {0} relative to {1}. For more information about this feature and the available environment variables, please read the {2}.",
"commandsUpdated": "Commands updated!",
@ -224,6 +225,7 @@
"rulesHelp": "Here you can define a set of allow and disallow rules for this specific user. The blocked files won't show up in the listings and they wont be accessible to the user. We support regex and paths relative to the users scope.\n",
"scope": "Scope",
"setDateFormat": "Set exact date format",
"editorAutoSaveInterval": "Set editor auto save interval",
"settingsUpdated": "Settings updated!",
"shareDuration": "Share Duration",
"shareManagement": "Share Management",

View File

@ -34,6 +34,8 @@ import HeaderBar from "@/components/header/HeaderBar";
import Action from "@/components/header/Action";
import Breadcrumbs from "@/components/Breadcrumbs";
let timeoutBox;
export default {
name: "editor",
components: {
@ -77,9 +79,11 @@ export default {
},
},
created() {
this.autoSave();
window.addEventListener("keydown", this.keyEvent);
},
beforeDestroy() {
clearTimeout(timeoutBox);
window.removeEventListener("keydown", this.keyEvent);
this.editor.destroy();
},
@ -129,11 +133,22 @@ export default {
}
},
close() {
this.save();
this.$store.commit("updateRequest", {});
let uri = url.removeLastDir(this.$route.path) + "/";
this.$router.push({ path: uri });
},
autoSave() {
let editorAutoSaveInterval = this.user.editorAutoSaveInterval;
if (editorAutoSaveInterval < 0) {
return;
}
clearTimeout(timeoutBox);
timeoutBox = setTimeout(() => {
this.save();
this.autoSave();
}, editorAutoSaveInterval * 1000);
},
},
};
</script>

View File

@ -68,6 +68,32 @@
</div>
</form>
</div>
<div class="column">
<form class="card" @submit="updateEditorSettings">
<div class="card-title">
<h2>{{ $t("settings.changeEditorSettings") }}</h2>
</div>
<div class="card-content">
<label for="editorAutoSaveInterval">
Set Editor Auto Save Interval
</label>
<input
:placeholder="$t('settings.editorAutoSaveInterval')"
type="number"
v-model.number="editorAutoSaveInterval"
name="editorAutoSaveInterval"
/>
<label for="editorAutoSaveInterval"> s </label>
</div>
<div class="card-action">
<input
class="button button--flat"
type="submit"
:value="$t('buttons.update')"
/>
</div>
</form>
</div>
</div>
</template>
@ -89,6 +115,7 @@ export default {
singleClick: false,
dateFormat: false,
locale: "",
editorAutoSaveInterval: 60,
};
},
computed: {
@ -113,6 +140,7 @@ export default {
this.hideDotfiles = this.user.hideDotfiles;
this.singleClick = this.user.singleClick;
this.dateFormat = this.user.dateFormat;
this.editorAutoSaveInterval = this.user.editorAutoSaveInterval;
},
methods: {
...mapMutations(["updateUser", "setLoading"]),
@ -155,6 +183,21 @@ export default {
this.$showError(e);
}
},
async updateEditorSettings(event) {
event.preventDefault();
try {
const data = {
id: this.user.id,
editorAutoSaveInterval: this.editorAutoSaveInterval,
};
await api.update(data, ["editorAutoSaveInterval"]);
this.updateUser(data);
this.$showSuccess(this.$t("settings.settingsUpdated"));
} catch (e) {
this.$showError(e);
}
},
},
};
</script>

View File

@ -20,15 +20,16 @@ const (
)
type userInfo struct {
ID uint `json:"id"`
Locale string `json:"locale"`
ViewMode users.ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
Perm users.Permissions `json:"perm"`
Commands []string `json:"commands"`
LockPassword bool `json:"lockPassword"`
HideDotfiles bool `json:"hideDotfiles"`
DateFormat bool `json:"dateFormat"`
ID uint `json:"id"`
Locale string `json:"locale"`
ViewMode users.ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
Perm users.Permissions `json:"perm"`
Commands []string `json:"commands"`
LockPassword bool `json:"lockPassword"`
HideDotfiles bool `json:"hideDotfiles"`
DateFormat bool `json:"dateFormat"`
EditorAutoSaveInterval int `json:"editorAutoSaveInterval"`
}
type authToken struct {
@ -179,15 +180,16 @@ var renewHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data
func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.User) (int, error) {
claims := &authToken{
User: userInfo{
ID: user.ID,
Locale: user.Locale,
ViewMode: user.ViewMode,
SingleClick: user.SingleClick,
Perm: user.Perm,
LockPassword: user.LockPassword,
Commands: user.Commands,
HideDotfiles: user.HideDotfiles,
DateFormat: user.DateFormat,
ID: user.ID,
Locale: user.Locale,
ViewMode: user.ViewMode,
SingleClick: user.SingleClick,
Perm: user.Perm,
LockPassword: user.LockPassword,
Commands: user.Commands,
HideDotfiles: user.HideDotfiles,
DateFormat: user.DateFormat,
EditorAutoSaveInterval: user.EditorAutoSaveInterval,
},
RegisteredClaims: jwt.RegisteredClaims{
IssuedAt: jwt.NewNumericDate(time.Now()),

View File

@ -8,15 +8,16 @@ import (
// UserDefaults is a type that holds the default values
// for some fields on User.
type UserDefaults struct {
Scope string `json:"scope"`
Locale string `json:"locale"`
ViewMode users.ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
Sorting files.Sorting `json:"sorting"`
Perm users.Permissions `json:"perm"`
Commands []string `json:"commands"`
HideDotfiles bool `json:"hideDotfiles"`
DateFormat bool `json:"dateFormat"`
Scope string `json:"scope"`
Locale string `json:"locale"`
ViewMode users.ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
Sorting files.Sorting `json:"sorting"`
Perm users.Permissions `json:"perm"`
Commands []string `json:"commands"`
HideDotfiles bool `json:"hideDotfiles"`
DateFormat bool `json:"dateFormat"`
EditorAutoSaveInterval int `json:"autoSaveInterval"`
}
// Apply applies the default options to a user.
@ -30,4 +31,5 @@ func (d *UserDefaults) Apply(u *users.User) {
u.Commands = d.Commands
u.HideDotfiles = d.HideDotfiles
u.DateFormat = d.DateFormat
u.EditorAutoSaveInterval = d.EditorAutoSaveInterval
}

View File

@ -21,21 +21,22 @@ const (
// User describes a user.
type User struct {
ID uint `storm:"id,increment" json:"id"`
Username string `storm:"unique" json:"username"`
Password string `json:"password"`
Scope string `json:"scope"`
Locale string `json:"locale"`
LockPassword bool `json:"lockPassword"`
ViewMode ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
Perm Permissions `json:"perm"`
Commands []string `json:"commands"`
Sorting files.Sorting `json:"sorting"`
Fs afero.Fs `json:"-" yaml:"-"`
Rules []rules.Rule `json:"rules"`
HideDotfiles bool `json:"hideDotfiles"`
DateFormat bool `json:"dateFormat"`
ID uint `storm:"id,increment" json:"id"`
Username string `storm:"unique" json:"username"`
Password string `json:"password"`
Scope string `json:"scope"`
Locale string `json:"locale"`
LockPassword bool `json:"lockPassword"`
ViewMode ViewMode `json:"viewMode"`
SingleClick bool `json:"singleClick"`
Perm Permissions `json:"perm"`
Commands []string `json:"commands"`
Sorting files.Sorting `json:"sorting"`
Fs afero.Fs `json:"-" yaml:"-"`
Rules []rules.Rule `json:"rules"`
HideDotfiles bool `json:"hideDotfiles"`
DateFormat bool `json:"dateFormat"`
EditorAutoSaveInterval int `json:"editorAutoSaveInterval"`
}
// GetRules implements rules.Provider.