feat: add download size on modal download button
This commit is contained in:
parent
822bf92a47
commit
47e44bdaf5
@ -40,6 +40,7 @@
|
||||
:image="modalEpisode.image"
|
||||
:link="modalEpisode.link"
|
||||
:name="modalEpisode.name"
|
||||
:size="modalEpisode.size"
|
||||
:title="title"
|
||||
:url="modalEpisode.url" />
|
||||
</NcModal>
|
||||
|
@ -22,7 +22,7 @@
|
||||
<template #icon>
|
||||
<Download :size="20" />
|
||||
</template>
|
||||
{{ t('repod', 'Download') }}
|
||||
{{ t('repod', 'Download') }} {{ size ? `(${humanFileSize(size)})` : '' }}
|
||||
</NcButton>
|
||||
</div>
|
||||
</div>
|
||||
@ -32,6 +32,7 @@
|
||||
import { NcAvatar, NcButton } from '@nextcloud/vue'
|
||||
import Download from 'vue-material-design-icons/Download.vue'
|
||||
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
|
||||
import { humanFileSize } from '../../utils/size.js'
|
||||
|
||||
export default {
|
||||
name: 'Modal',
|
||||
@ -66,6 +67,10 @@ export default {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
size: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
strippedDescription() {
|
||||
@ -75,6 +80,9 @@ export default {
|
||||
return strippedDescription.replace(/\n/g, '<br>')
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
humanFileSize,
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
// https://stackoverflow.com/a/53486112
|
||||
|
||||
export const debounce = (fn, delay) => {
|
||||
let timeoutID = null
|
||||
return function() {
|
||||
|
5
src/utils/size.js
Normal file
5
src/utils/size.js
Normal file
@ -0,0 +1,5 @@
|
||||
// https://stackoverflow.com/a/20732091
|
||||
export const humanFileSize = (size) => {
|
||||
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024))
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]
|
||||
}
|
Loading…
Reference in New Issue
Block a user