From e8b4e9af46d6e99dbeb965dd9727d9ed017d52a2 Mon Sep 17 00:00:00 2001 From: Julien Loir Date: Mon, 23 Nov 2020 19:06:37 +0100 Subject: [PATCH] feat: add single click mode (#1139) --- cmd/config.go | 1 + cmd/root.go | 5 +++-- cmd/users.go | 8 ++++++-- cmd/users_update.go | 14 ++++++++------ frontend/src/components/files/ListingItem.vue | 17 ++++++++++++----- frontend/src/components/settings/UserForm.vue | 4 ++++ frontend/src/i18n/en.json | 1 + http/auth.go | 2 ++ settings/defaults.go | 2 ++ users/users.go | 1 + 10 files changed, 40 insertions(+), 15 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 4cdd3ee2..5e4da979 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -145,6 +145,7 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut fmt.Fprintf(w, "\tScope:\t%s\n", set.Defaults.Scope) fmt.Fprintf(w, "\tLocale:\t%s\n", set.Defaults.Locale) fmt.Fprintf(w, "\tView mode:\t%s\n", set.Defaults.ViewMode) + fmt.Fprintf(w, "\tSingle Click:\t%t\n", set.Defaults.SingleClick) fmt.Fprintf(w, "\tCommands:\t%s\n", strings.Join(set.Defaults.Commands, " ")) fmt.Fprintf(w, "\tSorting:\n") fmt.Fprintf(w, "\t\tBy:\t%s\n", set.Defaults.Sorting.By) diff --git a/cmd/root.go b/cmd/root.go index 86a7e0bf..a8a484f0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -302,8 +302,9 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) { Signup: false, CreateUserDir: false, Defaults: settings.UserDefaults{ - Scope: ".", - Locale: "en", + Scope: ".", + Locale: "en", + SingleClick: false, Perm: users.Permissions{ Admin: false, Execute: true, diff --git a/cmd/users.go b/cmd/users.go index 9ef0da18..c985d827 100644 --- a/cmd/users.go +++ b/cmd/users.go @@ -27,15 +27,16 @@ var usersCmd = &cobra.Command{ func printUsers(usrs []*users.User) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) - fmt.Fprintln(w, "ID\tUsername\tScope\tLocale\tV. Mode\tAdmin\tExecute\tCreate\tRename\tModify\tDelete\tShare\tDownload\tPwd Lock") + fmt.Fprintln(w, "ID\tUsername\tScope\tLocale\tV. Mode\tS.Click\tAdmin\tExecute\tCreate\tRename\tModify\tDelete\tShare\tDownload\tPwd Lock") for _, u := range usrs { - fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t\n", + fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t%t\t\n", u.ID, u.Username, u.Scope, u.Locale, u.ViewMode, + u.SingleClick, u.Perm.Admin, u.Perm.Execute, u.Perm.Create, @@ -75,6 +76,7 @@ func addUserFlags(flags *pflag.FlagSet) { flags.String("scope", ".", "scope for users") flags.String("locale", "en", "locale for users") flags.String("viewMode", string(users.ListViewMode), "view mode for users") + flags.Bool("singleClick", false, "use single clicks only") } func getViewMode(flags *pflag.FlagSet) users.ViewMode { @@ -95,6 +97,8 @@ func getUserDefaults(flags *pflag.FlagSet, defaults *settings.UserDefaults, all defaults.Locale = mustGetString(flags, flag.Name) case "viewMode": defaults.ViewMode = getViewMode(flags) + case "singleClick": + defaults.SingleClick = mustGetBool(flags, flag.Name) case "perm.admin": defaults.Perm.Admin = mustGetBool(flags, flag.Name) case "perm.execute": diff --git a/cmd/users_update.go b/cmd/users_update.go index 040dabd5..822bb6dc 100644 --- a/cmd/users_update.go +++ b/cmd/users_update.go @@ -41,17 +41,19 @@ options you want to change.`, checkErr(err) defaults := settings.UserDefaults{ - Scope: user.Scope, - Locale: user.Locale, - ViewMode: user.ViewMode, - Perm: user.Perm, - Sorting: user.Sorting, - Commands: user.Commands, + Scope: user.Scope, + Locale: user.Locale, + ViewMode: user.ViewMode, + SingleClick: user.SingleClick, + Perm: user.Perm, + Sorting: user.Sorting, + Commands: user.Commands, } getUserDefaults(flags, &defaults, false) user.Scope = defaults.Scope user.Locale = defaults.Locale user.ViewMode = defaults.ViewMode + user.SingleClick = defaults.SingleClick user.Perm = defaults.Perm user.Commands = defaults.Commands user.Sorting = defaults.Sorting diff --git a/frontend/src/components/files/ListingItem.vue b/frontend/src/components/files/ListingItem.vue index f7a5f85b..82159a3f 100644 --- a/frontend/src/components/files/ListingItem.vue +++ b/frontend/src/components/files/ListingItem.vue @@ -6,8 +6,8 @@ @dragstart="dragStart" @dragover="dragOver" @drop="drop" - @click="click" - @dblclick="open" + @click="itemClick" + @dblclick="dblclick" @touchstart="touchstart" :data-dir="isDir" :aria-label="name" @@ -47,7 +47,7 @@ export default { }, props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'], computed: { - ...mapState(['selected', 'req', 'user', 'jwt']), + ...mapState(['user', 'selected', 'req', 'user', 'jwt']), ...mapGetters(['selectedCount']), isSelected () { return (this.selected.indexOf(this.index) !== -1) @@ -170,8 +170,12 @@ export default { action(overwrite, rename) }, + itemClick: function(event) { + if (this.user.singleClick && !this.$store.state.multiple) this.open() + else this.click(event) + }, click: function (event) { - if (this.selectedCount !== 0) event.preventDefault() + if (!this.user.singleClick && this.selectedCount !== 0) event.preventDefault() if (this.$store.state.selected.indexOf(this.index) !== -1) { this.removeSelected(this.index) return @@ -198,9 +202,12 @@ export default { return } - if (!event.ctrlKey && !this.$store.state.multiple) this.resetSelected() + if (!this.user.singleClick && !event.ctrlKey && !this.$store.state.multiple) this.resetSelected() this.addSelected(this.index) }, + dblclick: function () { + if (!this.user.singleClick) this.open() + }, touchstart () { setTimeout(() => { this.touches = 0 diff --git a/frontend/src/components/settings/UserForm.vue b/frontend/src/components/settings/UserForm.vue index 8082d5e1..d56f1f77 100644 --- a/frontend/src/components/settings/UserForm.vue +++ b/frontend/src/components/settings/UserForm.vue @@ -24,6 +24,10 @@ {{ $t('settings.lockPassword') }}

+

+ {{ $t('settings.singleClick') }} +

+ diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index f0baf26a..a925c0c4 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -174,6 +174,7 @@ "globalRules": "This is a global set of allow and disallow rules. They apply to every user. You can define specific rules on each user's settings to override this ones.", "allowSignup": "Allow users to signup", "createUserDir": "Auto create user home dir while adding new user", + "singleClick": "Use single clicks to open files and directories", "insertRegex": "Insert regex expression", "insertPath": "Insert the path", "userUpdated": "User updated!", diff --git a/http/auth.go b/http/auth.go index 4145ceb2..c73897c2 100644 --- a/http/auth.go +++ b/http/auth.go @@ -23,6 +23,7 @@ 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"` @@ -173,6 +174,7 @@ func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.Use ID: user.ID, Locale: user.Locale, ViewMode: user.ViewMode, + SingleClick: user.SingleClick, Perm: user.Perm, LockPassword: user.LockPassword, Commands: user.Commands, diff --git a/settings/defaults.go b/settings/defaults.go index b9993fbb..e340d260 100644 --- a/settings/defaults.go +++ b/settings/defaults.go @@ -11,6 +11,7 @@ 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"` @@ -22,6 +23,7 @@ func (d *UserDefaults) Apply(u *users.User) { u.Scope = d.Scope u.Locale = d.Locale u.ViewMode = d.ViewMode + u.SingleClick = d.SingleClick u.Perm = d.Perm u.Sorting = d.Sorting u.Commands = d.Commands diff --git a/users/users.go b/users/users.go index 5aba507d..c58cae0e 100644 --- a/users/users.go +++ b/users/users.go @@ -28,6 +28,7 @@ type User struct { 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"`