From a9e41695aaa616c0df905794b9f913fd0ff733eb Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 8 Jul 2017 12:46:19 +0100 Subject: [PATCH] Fix listing icons and more Former-commit-id: 9406455a67d31ba221f4d770c27e6b019531317a [formerly 8b09c630bb53a1402aeceb5a6aa925c30935a796] [formerly 12b8050b5f3950fbd08238b431fa2f80c7a7cf6b [formerly 338e73a8b208b8bcb09568e1b309809c4c6f45fe]] Former-commit-id: 5e065778adf3521aea2da98d4dd2054cf29f28bd [formerly c00e9fec37dd8004bb6f5cdbb41adf4f6a460e7a] Former-commit-id: 532f25d150440d2eb1254fc0d77270f8144e0e0c --- api.go | 2 +- assets/src/components/ListingItem.vue | 24 +++++++++++++++--------- file.go | 27 +++++++++++++++------------ 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/api.go b/api.go index 134d2f9e..d6e32028 100644 --- a/api.go +++ b/api.go @@ -133,7 +133,7 @@ func getHandler(c *requestContext, w http.ResponseWriter, r *http.Request) (int, } // Tries to get the file type. - if err = f.RetrieveFileType(); err != nil { + if err = f.RetrieveFileType(true); err != nil { return errorToHTTP(err, true), err } diff --git a/assets/src/components/ListingItem.vue b/assets/src/components/ListingItem.vue index 0b01dcb5..3206545a 100644 --- a/assets/src/components/ListingItem.vue +++ b/assets/src/components/ListingItem.vue @@ -6,9 +6,9 @@ @drop="drop" @click="click" @dblclick="open" - :aria-selected="isSelected()"> + :aria-selected="isSelected">
- {{ icon() }} + {{ icon }}
@@ -35,20 +35,20 @@ export default { props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'], computed: { ...mapState(['selected', 'req']), - ...mapGetters(['selectedCount']) - }, - methods: { - ...mapMutations(['addSelected', 'removeSelected', 'resetSelected']), - isSelected: function () { + ...mapGetters(['selectedCount']), + isSelected () { return (this.selected.indexOf(this.index) !== -1) }, - icon: function () { + icon () { if (this.isDir) return 'folder' if (this.type === 'image') return 'insert_photo' if (this.type === 'audio') return 'volume_up' if (this.type === 'video') return 'movie' return 'insert_drive_file' - }, + } + }, + methods: { + ...mapMutations(['addSelected', 'removeSelected', 'resetSelected']), humanSize: function () { return filesize(this.size) }, @@ -58,6 +58,12 @@ export default { dragStart: function (event) { if (this.selectedCount === 0) { this.addSelected(this.index) + return + } + + if (!this.isSelected) { + this.resetSelected() + this.addSelected(this.index) } }, dragOver: function (event) { diff --git a/file.go b/file.go index 1e15f228..4352fa68 100644 --- a/file.go +++ b/file.go @@ -64,7 +64,7 @@ type file struct { // A listing is the context used to fill out a template. type listing struct { // The items (files and folders) in the path. - Items []file `json:"items"` + Items []*file `json:"items"` // The number of directories in the listing. NumDirs int `json:"numDirs"` // The number of files (items that aren't directories) in the listing. @@ -124,7 +124,7 @@ func (i *file) getListing(c *requestContext, r *http.Request) error { } var ( - fileinfos []file + fileinfos []*file dirCount, fileCount int ) @@ -146,16 +146,19 @@ func (i *file) getListing(c *requestContext, r *http.Request) error { // Absolute URL url := url.URL{Path: i.URL + name} - i := file{ - Name: f.Name(), - Size: f.Size(), - ModTime: f.ModTime(), - Mode: f.Mode(), - IsDir: f.IsDir(), - URL: url.String(), + i := &file{ + Name: f.Name(), + Size: f.Size(), + ModTime: f.ModTime(), + Mode: f.Mode(), + IsDir: f.IsDir(), + URL: url.String(), + Extension: filepath.Ext(name), + VirtualPath: filepath.Join(i.VirtualPath, name), + Path: filepath.Join(i.Path, name), } - i.RetrieveFileType() + i.RetrieveFileType(false) fileinfos = append(fileinfos, i) } @@ -198,14 +201,14 @@ func (i *file) getEditor() error { // RetrieveFileType obtains the mimetype and converts it to a simple // type nomenclature. -func (i *file) RetrieveFileType() error { +func (i *file) RetrieveFileType(checkContent bool) error { var content []byte var err error // Tries to get the file mimetype using its extension. mimetype := mime.TypeByExtension(i.Extension) - if mimetype == "" { + if mimetype == "" && checkContent { content, err = ioutil.ReadFile(i.Path) if err != nil { return err