Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
0c973e9d
Commit
0c973e9d
authored
4 years ago
by
Bekerle, Patrizio
Committed by
Reiter, Christoph
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Show indicator while files are uploaded/queued (VPU/Apps/Signature#5)
parent
d093a41f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/file-handling/src/fileupload.js
+32
-7
32 additions, 7 deletions
packages/file-handling/src/fileupload.js
with
32 additions
and
7 deletions
packages/file-handling/src/fileupload.js
+
32
−
7
View file @
0c973e9d
...
@@ -5,7 +5,7 @@ import {ScopedElementsMixin} from '@open-wc/scoped-elements';
...
@@ -5,7 +5,7 @@ import {ScopedElementsMixin} from '@open-wc/scoped-elements';
// import JSONLD from 'vpu-common/jsonld';
// import JSONLD from 'vpu-common/jsonld';
import
VPULitElement
from
'
vpu-common/vpu-lit-element
'
;
import
VPULitElement
from
'
vpu-common/vpu-lit-element
'
;
import
*
as
commonUtils
from
"
vpu-common/utils
"
;
import
*
as
commonUtils
from
"
vpu-common/utils
"
;
import
{
Icon
}
from
'
vpu-common
'
;
import
{
Icon
,
MiniSpinner
}
from
'
vpu-common
'
;
import
*
as
commonStyles
from
'
vpu-common/styles
'
;
import
*
as
commonStyles
from
'
vpu-common/styles
'
;
/**
/**
...
@@ -21,6 +21,7 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
...
@@ -21,6 +21,7 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
this
.
text
=
''
;
this
.
text
=
''
;
this
.
buttonLabel
=
''
;
this
.
buttonLabel
=
''
;
this
.
uploadInProgress
=
false
;
this
.
uploadInProgress
=
false
;
this
.
multipleUploadInProgress
=
false
;
this
.
alwaysSendFile
=
false
;
this
.
alwaysSendFile
=
false
;
this
.
isDeferred
=
false
;
this
.
isDeferred
=
false
;
this
.
queuedFiles
=
[];
this
.
queuedFiles
=
[];
...
@@ -29,7 +30,8 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
...
@@ -29,7 +30,8 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
static
get
scopedElements
()
{
static
get
scopedElements
()
{
return
{
return
{
'
vpu-icon
'
:
Icon
,
'
vpu-icon
'
:
Icon
,
'
vpu-mini-spinner
'
:
MiniSpinner
,
};
};
}
}
...
@@ -44,6 +46,7 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
...
@@ -44,6 +46,7 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
text
:
{
type
:
String
},
text
:
{
type
:
String
},
buttonLabel
:
{
type
:
String
,
attribute
:
'
button-label
'
},
buttonLabel
:
{
type
:
String
,
attribute
:
'
button-label
'
},
uploadInProgress
:
{
type
:
Boolean
,
attribute
:
false
},
uploadInProgress
:
{
type
:
Boolean
,
attribute
:
false
},
multipleUploadInProgress
:
{
type
:
Boolean
,
attribute
:
false
},
alwaysSendFile
:
{
type
:
Boolean
,
attribute
:
'
always-send-file
'
},
alwaysSendFile
:
{
type
:
Boolean
,
attribute
:
'
always-send-file
'
},
isDeferred
:
{
type
:
Boolean
,
attribute
:
'
deferred
'
},
isDeferred
:
{
type
:
Boolean
,
attribute
:
'
deferred
'
},
queuedFilesCount
:
{
type
:
Number
,
attribute
:
false
},
queuedFilesCount
:
{
type
:
Number
,
attribute
:
false
},
...
@@ -130,18 +133,37 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
...
@@ -130,18 +133,37 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
fileElem
.
value
=
''
;
fileElem
.
value
=
''
;
}
}
/**
* Handles files that were dropped to or selected in the component
*
* @param files
* @returns {Promise<void>}
*/
async
handleFiles
(
files
)
{
async
handleFiles
(
files
)
{
console
.
log
(
'
handleFiles: files.length =
'
+
files
.
length
);
console
.
log
(
'
handleFiles: files.length =
'
+
files
.
length
);
this
.
multipleUploadInProgress
=
true
;
this
.
dispatchEvent
(
new
CustomEvent
(
"
vpu-fileupload-all-start
"
,
this
.
dispatchEvent
(
new
CustomEvent
(
"
vpu-fileupload-all-start
"
,
{
"
detail
"
:
{},
bubbles
:
true
,
composed
:
true
}));
{
"
detail
"
:
{},
bubbles
:
true
,
composed
:
true
}));
// we need to wait for each upload until we start the next one
// we need to copy the files to another array or else they will be gone in the setTimeout function!
await
commonUtils
.
asyncArrayForEach
(
files
,
async
(
file
)
=>
let
tempFilesToHandle
=
[];
this
.
isDeferred
?
this
.
queueFile
(
file
)
:
this
.
uploadFile
(
file
));
await
commonUtils
.
asyncArrayForEach
(
files
,
async
(
file
)
=>
{
tempFilesToHandle
.
push
(
file
);
});
this
.
dispatchEvent
(
new
CustomEvent
(
"
vpu-fileupload-all-finished
"
,
// the browsers don't render updates to the dom while these files are handled!
{
"
detail
"
:
{},
bubbles
:
true
,
composed
:
true
}));
// if we set a small delay the dom changes will be rendered
setTimeout
(
async
()
=>
{
// we need to wait for each upload until we start the next one
await
commonUtils
.
asyncArrayForEach
(
tempFilesToHandle
,
async
(
file
)
=>
this
.
isDeferred
?
this
.
queueFile
(
file
)
:
this
.
uploadFile
(
file
));
this
.
multipleUploadInProgress
=
false
;
this
.
dispatchEvent
(
new
CustomEvent
(
"
vpu-fileupload-all-finished
"
,
{
"
detail
"
:
{},
bubbles
:
true
,
composed
:
true
}));
},
100
);
}
}
async
sendFinishedEvent
(
response
,
file
,
sendFile
=
false
)
{
async
sendFinishedEvent
(
response
,
file
,
sendFile
=
false
)
{
...
@@ -267,6 +289,8 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
...
@@ -267,6 +289,8 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
return
css
`
return
css
`
${
commonStyles
.
getButtonCSS
()}
${
commonStyles
.
getButtonCSS
()}
.hidden { display: none; }
#dropArea {
#dropArea {
border: var(--FUBorderWidth, 2px) var(--FUBorderStyle, dashed) var(--FUBBorderColor, black);
border: var(--FUBorderWidth, 2px) var(--FUBorderStyle, dashed) var(--FUBBorderColor, black);
border-radius: var(--FUBorderRadius, 0);
border-radius: var(--FUBorderRadius, 0);
...
@@ -300,6 +324,7 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
...
@@ -300,6 +324,7 @@ export class FileUpload extends ScopedElementsMixin(VPULitElement) {
<p>
${
this
.
text
||
i18n
.
t
(
'
intro
'
)}
</p>
<p>
${
this
.
text
||
i18n
.
t
(
'
intro
'
)}
</p>
<input ?disabled="
${
this
.
uploadInProgress
}
" type="file" id="fileElem" multiple accept="
${
ifDefined
(
this
.
accept
)}
" name='file'>
<input ?disabled="
${
this
.
uploadInProgress
}
" type="file" id="fileElem" multiple accept="
${
ifDefined
(
this
.
accept
)}
" name='file'>
<label class="button is-primary" for="fileElem"><vpu-icon style="display:
${
this
.
uploadInProgress
?
"
inline-block
"
:
"
none
"
}
" name="lock"></vpu-icon>
${
this
.
buttonLabel
||
i18n
.
t
(
'
upload-label
'
)}
</label>
<label class="button is-primary" for="fileElem"><vpu-icon style="display:
${
this
.
uploadInProgress
?
"
inline-block
"
:
"
none
"
}
" name="lock"></vpu-icon>
${
this
.
buttonLabel
||
i18n
.
t
(
'
upload-label
'
)}
</label>
<vpu-mini-spinner style="display:
${
this
.
multipleUploadInProgress
?
"
inline-block
"
:
"
none
"
}
"></vpu-mini-spinner>
</div>
</div>
</div>
</div>
`
;
`
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment