feat: add editor auto save
This commit is contained in:
parent
c1e6d5869a
commit
0d21de4e45
@ -178,6 +178,7 @@
|
|||||||
"brandingDirectoryPath": "Branding directory path",
|
"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}.",
|
"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",
|
"changePassword": "Change Password",
|
||||||
|
"changeEditorSettings": "Change Editor Settings",
|
||||||
"commandRunner": "Command runner",
|
"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}.",
|
"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!",
|
"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",
|
"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",
|
"scope": "Scope",
|
||||||
"setDateFormat": "Set exact date format",
|
"setDateFormat": "Set exact date format",
|
||||||
|
"editorAutoSaveInterval": "Set editor auto save interval",
|
||||||
"settingsUpdated": "Settings updated!",
|
"settingsUpdated": "Settings updated!",
|
||||||
"shareDuration": "Share Duration",
|
"shareDuration": "Share Duration",
|
||||||
"shareManagement": "Share Management",
|
"shareManagement": "Share Management",
|
||||||
|
|||||||
@ -34,6 +34,8 @@ import HeaderBar from "@/components/header/HeaderBar";
|
|||||||
import Action from "@/components/header/Action";
|
import Action from "@/components/header/Action";
|
||||||
import Breadcrumbs from "@/components/Breadcrumbs";
|
import Breadcrumbs from "@/components/Breadcrumbs";
|
||||||
|
|
||||||
|
let timeoutBox;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "editor",
|
name: "editor",
|
||||||
components: {
|
components: {
|
||||||
@ -77,9 +79,11 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
this.autoSave();
|
||||||
window.addEventListener("keydown", this.keyEvent);
|
window.addEventListener("keydown", this.keyEvent);
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
|
clearTimeout(timeoutBox);
|
||||||
window.removeEventListener("keydown", this.keyEvent);
|
window.removeEventListener("keydown", this.keyEvent);
|
||||||
this.editor.destroy();
|
this.editor.destroy();
|
||||||
},
|
},
|
||||||
@ -129,11 +133,22 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
|
this.save();
|
||||||
this.$store.commit("updateRequest", {});
|
this.$store.commit("updateRequest", {});
|
||||||
|
|
||||||
let uri = url.removeLastDir(this.$route.path) + "/";
|
let uri = url.removeLastDir(this.$route.path) + "/";
|
||||||
this.$router.push({ path: uri });
|
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>
|
</script>
|
||||||
|
|||||||
@ -68,6 +68,32 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -89,6 +115,7 @@ export default {
|
|||||||
singleClick: false,
|
singleClick: false,
|
||||||
dateFormat: false,
|
dateFormat: false,
|
||||||
locale: "",
|
locale: "",
|
||||||
|
editorAutoSaveInterval: 60,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -113,6 +140,7 @@ export default {
|
|||||||
this.hideDotfiles = this.user.hideDotfiles;
|
this.hideDotfiles = this.user.hideDotfiles;
|
||||||
this.singleClick = this.user.singleClick;
|
this.singleClick = this.user.singleClick;
|
||||||
this.dateFormat = this.user.dateFormat;
|
this.dateFormat = this.user.dateFormat;
|
||||||
|
this.editorAutoSaveInterval = this.user.editorAutoSaveInterval;
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(["updateUser", "setLoading"]),
|
...mapMutations(["updateUser", "setLoading"]),
|
||||||
@ -155,6 +183,21 @@ export default {
|
|||||||
this.$showError(e);
|
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>
|
</script>
|
||||||
|
|||||||
38
http/auth.go
38
http/auth.go
@ -20,15 +20,16 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type userInfo struct {
|
type userInfo struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Locale string `json:"locale"`
|
Locale string `json:"locale"`
|
||||||
ViewMode users.ViewMode `json:"viewMode"`
|
ViewMode users.ViewMode `json:"viewMode"`
|
||||||
SingleClick bool `json:"singleClick"`
|
SingleClick bool `json:"singleClick"`
|
||||||
Perm users.Permissions `json:"perm"`
|
Perm users.Permissions `json:"perm"`
|
||||||
Commands []string `json:"commands"`
|
Commands []string `json:"commands"`
|
||||||
LockPassword bool `json:"lockPassword"`
|
LockPassword bool `json:"lockPassword"`
|
||||||
HideDotfiles bool `json:"hideDotfiles"`
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
DateFormat bool `json:"dateFormat"`
|
DateFormat bool `json:"dateFormat"`
|
||||||
|
EditorAutoSaveInterval int `json:"editorAutoSaveInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type authToken struct {
|
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) {
|
func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.User) (int, error) {
|
||||||
claims := &authToken{
|
claims := &authToken{
|
||||||
User: userInfo{
|
User: userInfo{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Locale: user.Locale,
|
Locale: user.Locale,
|
||||||
ViewMode: user.ViewMode,
|
ViewMode: user.ViewMode,
|
||||||
SingleClick: user.SingleClick,
|
SingleClick: user.SingleClick,
|
||||||
Perm: user.Perm,
|
Perm: user.Perm,
|
||||||
LockPassword: user.LockPassword,
|
LockPassword: user.LockPassword,
|
||||||
Commands: user.Commands,
|
Commands: user.Commands,
|
||||||
HideDotfiles: user.HideDotfiles,
|
HideDotfiles: user.HideDotfiles,
|
||||||
DateFormat: user.DateFormat,
|
DateFormat: user.DateFormat,
|
||||||
|
EditorAutoSaveInterval: user.EditorAutoSaveInterval,
|
||||||
},
|
},
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
|
|||||||
@ -8,15 +8,16 @@ import (
|
|||||||
// UserDefaults is a type that holds the default values
|
// UserDefaults is a type that holds the default values
|
||||||
// for some fields on User.
|
// for some fields on User.
|
||||||
type UserDefaults struct {
|
type UserDefaults struct {
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
Locale string `json:"locale"`
|
Locale string `json:"locale"`
|
||||||
ViewMode users.ViewMode `json:"viewMode"`
|
ViewMode users.ViewMode `json:"viewMode"`
|
||||||
SingleClick bool `json:"singleClick"`
|
SingleClick bool `json:"singleClick"`
|
||||||
Sorting files.Sorting `json:"sorting"`
|
Sorting files.Sorting `json:"sorting"`
|
||||||
Perm users.Permissions `json:"perm"`
|
Perm users.Permissions `json:"perm"`
|
||||||
Commands []string `json:"commands"`
|
Commands []string `json:"commands"`
|
||||||
HideDotfiles bool `json:"hideDotfiles"`
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
DateFormat bool `json:"dateFormat"`
|
DateFormat bool `json:"dateFormat"`
|
||||||
|
EditorAutoSaveInterval int `json:"autoSaveInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply applies the default options to a user.
|
// Apply applies the default options to a user.
|
||||||
@ -30,4 +31,5 @@ func (d *UserDefaults) Apply(u *users.User) {
|
|||||||
u.Commands = d.Commands
|
u.Commands = d.Commands
|
||||||
u.HideDotfiles = d.HideDotfiles
|
u.HideDotfiles = d.HideDotfiles
|
||||||
u.DateFormat = d.DateFormat
|
u.DateFormat = d.DateFormat
|
||||||
|
u.EditorAutoSaveInterval = d.EditorAutoSaveInterval
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,21 +21,22 @@ const (
|
|||||||
|
|
||||||
// User describes a user.
|
// User describes a user.
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uint `storm:"id,increment" json:"id"`
|
ID uint `storm:"id,increment" json:"id"`
|
||||||
Username string `storm:"unique" json:"username"`
|
Username string `storm:"unique" json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
Locale string `json:"locale"`
|
Locale string `json:"locale"`
|
||||||
LockPassword bool `json:"lockPassword"`
|
LockPassword bool `json:"lockPassword"`
|
||||||
ViewMode ViewMode `json:"viewMode"`
|
ViewMode ViewMode `json:"viewMode"`
|
||||||
SingleClick bool `json:"singleClick"`
|
SingleClick bool `json:"singleClick"`
|
||||||
Perm Permissions `json:"perm"`
|
Perm Permissions `json:"perm"`
|
||||||
Commands []string `json:"commands"`
|
Commands []string `json:"commands"`
|
||||||
Sorting files.Sorting `json:"sorting"`
|
Sorting files.Sorting `json:"sorting"`
|
||||||
Fs afero.Fs `json:"-" yaml:"-"`
|
Fs afero.Fs `json:"-" yaml:"-"`
|
||||||
Rules []rules.Rule `json:"rules"`
|
Rules []rules.Rule `json:"rules"`
|
||||||
HideDotfiles bool `json:"hideDotfiles"`
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
DateFormat bool `json:"dateFormat"`
|
DateFormat bool `json:"dateFormat"`
|
||||||
|
EditorAutoSaveInterval int `json:"editorAutoSaveInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRules implements rules.Provider.
|
// GetRules implements rules.Provider.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user