mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
Progress bar. Close #199
Former-commit-id: cf8ec044a2531b295b89da915cee439eba6ccd0b [formerly 6d77a48968796dc6db51602486c07d6f2ecc00e6] [formerly 4aa44181ea637eeaba8e7756a76bbf5cd47b6928 [formerly ec190d28a8
]]
Former-commit-id: 5e8e25fee1ae1119d5aaf5bf25e83f258ad13d2a [formerly 574db23a689aaf5bbe533d2e322ae98fc0b6d1de]
Former-commit-id: 5b5dfebfb692b62188c216f0cb22f8cdefdd82ab
This commit is contained in:
parent
4071a58107
commit
e4144ad2b2
@ -318,18 +318,36 @@ export default {
|
|||||||
handleFiles (files, base, overwrite = false) {
|
handleFiles (files, base, overwrite = false) {
|
||||||
buttons.loading('upload')
|
buttons.loading('upload')
|
||||||
let promises = []
|
let promises = []
|
||||||
|
let progress = new Array(files.length).fill(0)
|
||||||
|
|
||||||
for (let file of files) {
|
let onupload = (id) => (event) => {
|
||||||
promises.push(api.post(this.$route.path + base + file.name, file, overwrite))
|
progress[id] = (event.loaded / event.total) * 100
|
||||||
|
|
||||||
|
let sum = 0
|
||||||
|
for (let i = 0; i < progress.length; i++) {
|
||||||
|
sum += progress[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$store.commit('setProgress', Math.ceil(sum / progress.length))
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
let file = files[i]
|
||||||
|
promises.push(api.post(this.$route.path + base + file.name, file, overwrite, onupload(i)))
|
||||||
|
}
|
||||||
|
|
||||||
|
let finish = () => {
|
||||||
|
buttons.success('upload')
|
||||||
|
this.$store.commit('setProgress', 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
buttons.success('upload')
|
finish()
|
||||||
this.$store.commit('setReload', true)
|
this.$store.commit('setReload', true)
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
buttons.done('upload')
|
finish()
|
||||||
this.$store.commit('showError', error)
|
this.$store.commit('showError', error)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -145,3 +145,19 @@ main {
|
|||||||
#breadcrumbs span a {
|
#breadcrumbs span a {
|
||||||
padding: .2em;
|
padding: .2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#progress {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 3px;
|
||||||
|
z-index: 9999999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
#progress div {
|
||||||
|
height: 100%;
|
||||||
|
background-color: #40c4ff;
|
||||||
|
width: 0;
|
||||||
|
transition: .2s ease width;
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ const state = {
|
|||||||
staticGen: document.querySelector('meta[name="staticgen"]').getAttribute('content'),
|
staticGen: document.querySelector('meta[name="staticgen"]').getAttribute('content'),
|
||||||
baseURL: document.querySelector('meta[name="base"]').getAttribute('content'),
|
baseURL: document.querySelector('meta[name="base"]').getAttribute('content'),
|
||||||
jwt: '',
|
jwt: '',
|
||||||
|
progress: 0,
|
||||||
schedule: '',
|
schedule: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
reload: false,
|
reload: false,
|
||||||
|
@ -61,6 +61,9 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
setSchedule: (state, value) => {
|
setSchedule: (state, value) => {
|
||||||
state.schedule = value
|
state.schedule = value
|
||||||
|
},
|
||||||
|
setProgress: (state, value) => {
|
||||||
|
state.progress = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export function remove (url) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function post (url, content = '', overwrite = false) {
|
export function post (url, content = '', overwrite = false, onupload) {
|
||||||
url = removePrefix(url)
|
url = removePrefix(url)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -64,6 +64,10 @@ export function post (url, content = '', overwrite = false) {
|
|||||||
request.open('POST', `${store.state.baseURL}/api/resource${url}`, true)
|
request.open('POST', `${store.state.baseURL}/api/resource${url}`, true)
|
||||||
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
|
request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
|
||||||
|
|
||||||
|
if (typeof onupload === 'function') {
|
||||||
|
request.upload.onprogress = onupload
|
||||||
|
}
|
||||||
|
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
request.setRequestHeader('Action', `override`)
|
request.setRequestHeader('Action', `override`)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<div id="progress">
|
||||||
|
<div v-bind:style="{ width: $store.state.progress + '%' }"></div>
|
||||||
|
</div>
|
||||||
<site-header></site-header>
|
<site-header></site-header>
|
||||||
<sidebar></sidebar>
|
<sidebar></sidebar>
|
||||||
<main>
|
<main>
|
||||||
|
@ -1 +1 @@
|
|||||||
4b205fed13570c943ad67f9fc4db4f51aeb62cec
|
e6431a506c73616a73d9a490fffb4e5098bb7fb4
|
Loading…
Reference in New Issue
Block a user