-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FileItem wrapper around oc-file
Better encapsulation of formatting methods as computed properties instead of using the mixin.
- Loading branch information
Vincent Petry
committed
Mar 17, 2020
1 parent
b6be75c
commit 2fbdb54
Showing
3 changed files
with
103 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<template> | ||
<oc-file | ||
:name="fileName" | ||
:extension="item.extension" | ||
:icon="fileTypeIcon" | ||
:iconUrl="previewUrl" | ||
:filename="item.name" | ||
/> | ||
</template> | ||
<script> | ||
import queryString from 'query-string' | ||
import fileTypeIconMappings from '../fileTypeIconMappings.json' | ||
export default { | ||
name: 'FileItem', | ||
props: { | ||
/** | ||
* The html element used for the avatar container. | ||
* `div, span` | ||
*/ | ||
item: { | ||
type: Object | ||
}, | ||
showPath: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
data: function () { | ||
return { | ||
previewUrl: undefined | ||
} | ||
}, | ||
computed: { | ||
fileName () { | ||
if (this.showPath) { | ||
const pathSplit = this.item.path.substr(1).split('/') | ||
if (pathSplit.length === 2) return `${pathSplit[pathSplit.length - 2]}/${this.item.basename}` | ||
if (pathSplit.length > 2) return `…/${pathSplit[pathSplit.length - 2]}/${this.item.basename}` | ||
} | ||
return this.item.basename | ||
}, | ||
// FIXME: duplicate in mixin | ||
fileTypeIcon () { | ||
if (this.item.type === 'folder') { | ||
return 'folder' | ||
} | ||
const icon = fileTypeIconMappings[this.item.extension] | ||
if (icon) return `${icon}` | ||
return 'x-office-document' | ||
} | ||
}, | ||
mounted () { | ||
console.log('FileItem: mounted()') | ||
this.loadPreview() | ||
}, | ||
methods: { | ||
loadPreview () { | ||
// TODO: check if previews are globally enabled (requires capability entry) | ||
if (this.item.type === 'folder') { | ||
return | ||
} | ||
const query = queryString.stringify({ | ||
x: this.thumbDimensions, | ||
y: this.thumbDimensions, | ||
c: this.item.etag, | ||
scalingup: 0, | ||
preview: 1, | ||
a: 1 | ||
}) | ||
let previewPath | ||
if (this.publicPage()) { | ||
previewPath = [ | ||
'..', | ||
'dav', | ||
'public-files', | ||
this.item.path | ||
].join('/') | ||
} else { | ||
previewPath = [ | ||
'..', | ||
'dav', | ||
'files', | ||
this.$store.getters.user.id, | ||
this.item.path | ||
].join('/') | ||
} | ||
console.log('loading preview for: ', this.item.name) | ||
const previewUrl = this.$client.files.getFileUrl(previewPath) + '?' + query | ||
this.mediaSource(previewUrl, 'url', this.requestHeaders).then(dataUrl => { | ||
this.previewUrl = dataUrl | ||
}) | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters