Fix listing icons and more

This commit is contained in:
Henrique Dias 2017-07-08 12:46:19 +01:00
parent 55c097b2aa
commit 338e73a8b2
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
3 changed files with 31 additions and 22 deletions

2
api.go
View File

@ -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
}

View File

@ -6,9 +6,9 @@
@drop="drop"
@click="click"
@dblclick="open"
:aria-selected="isSelected()">
:aria-selected="isSelected">
<div>
<i class="material-icons">{{ icon() }}</i>
<i class="material-icons">{{ icon }}</i>
</div>
<div>
@ -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) {

27
file.go
View File

@ -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