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
5a4c6c6e
Commit
5a4c6c6e
authored
4 years ago
by
Tögl, Christina
Browse files
Options
Downloads
Patches
Plain Diff
Improve overwrite file dialog functionality for multiple files
parent
b1f25b8a
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Filehandling overwrite dialog
Pipeline
#12453
failed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/file-handling/src/dbp-nextcloud-file-picker.js
+59
-57
59 additions, 57 deletions
packages/file-handling/src/dbp-nextcloud-file-picker.js
packages/file-handling/src/file-sink.js
+18
-4
18 additions, 4 deletions
packages/file-handling/src/file-sink.js
with
77 additions
and
61 deletions
packages/file-handling/src/dbp-nextcloud-file-picker.js
+
59
−
57
View file @
5a4c6c6e
...
...
@@ -41,6 +41,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
this
.
uploadFileObject
=
null
;
this
.
uploadFileDirectory
=
null
;
this
.
isDialogOpen
=
true
;
this
.
fileList
=
[];
}
static
get
scopedElements
()
{
...
...
@@ -66,6 +67,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
allowedMimeTypes
:
{
type
:
String
,
attribute
:
'
allowed-mime-types
'
},
directoriesOnly
:
{
type
:
Boolean
,
attribute
:
'
directories-only
'
},
maxSelectedItems
:
{
type
:
Number
,
attribute
:
'
max-selected-items
'
},
loading
:
{
type
:
Boolean
,
attribute
:
false
},
replaceFilename
:
{
type
:
String
,
attribute
:
false
},
uploadFileObject
:
{
type
:
Object
,
attribute
:
false
},
uploadFileDirectory
:
{
type
:
String
,
attribute
:
false
},
...
...
@@ -363,52 +365,53 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
}
async
uploadFiles
(
files
,
directory
)
{
console
.
log
(
"
before all file finished
"
);
let
ret
=
false
;
let
ret_outer
=
true
;
const
start
=
async
()
=>
{
for
(
let
index
=
0
;
index
<
files
.
length
;
index
++
)
{
ret
=
await
this
.
uploadFile
(
files
[
index
],
directory
);
if
(
ret
===
false
)
{
ret_outer
=
false
;
break
;
uploadFiles
(
files
,
directory
)
{
this
.
fileList
=
files
;
this
.
uploadFile
(
directory
);
}
async
uploadFile
(
directory
)
{
if
(
this
.
fileList
.
length
!==
0
)
{
let
file
=
this
.
fileList
[
0
];
this
.
replaceFilename
=
file
.
name
;
console
.
log
(
"
before one file finished
"
);
let
path
=
directory
+
"
/
"
+
file
.
name
;
// https://github.com/perry-mitchell/webdav-client#putfilecontents
let
ret
=
false
;
try
{
let
contents
=
await
this
.
webDavClient
.
putFileContents
(
path
,
file
,
{
overwrite
:
false
,
onUploadProgress
:
progress
=>
{
console
.
log
(
`Uploaded
${
progress
.
loaded
}
bytes of
${
progress
.
total
}
`
);
}}).
then
(
function
()
{
this
.
loading
=
false
;
this
.
statusText
=
""
;
console
.
log
(
"
try finished
"
);
console
.
log
(
"
after one file finished
"
);
this
.
fileList
.
shift
();
console
.
log
(
"
FileList:
"
,
this
.
fileList
);
this
.
uploadFile
(
directory
);
}
);
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
this
.
loading
=
false
;
this
.
statusText
=
error
.
message
;
console
.
log
(
"
----
"
,
error
.
message
);
if
(
error
.
message
.
search
(
"
412
"
)
!==
-
1
)
{
this
.
replaceModalDialog
(
file
,
directory
);
console
.
log
(
"
dialog open after upload?
"
,
this
.
isDialogOpen
);
}
}
}
else
{
const
event
=
new
CustomEvent
(
"
dbp-nextcloud-file-picker-file-uploaded-finished
"
,
{
bubbles
:
true
,
composed
:
true
});
this
.
dispatchEvent
(
event
);
}
await
start
();
//let ret = await files.forEach((file) => this.uploadFile(file, directory));
console
.
log
(
"
all files finished
"
,
ret_outer
);
return
ret_outer
;
}
async
uploadFile
(
file
,
directory
)
{
console
.
log
(
"
before one file finished
"
);
let
path
=
directory
+
"
/
"
+
file
.
name
;
// https://github.com/perry-mitchell/webdav-client#putfilecontents
let
ret
=
false
;
try
{
let
contents
=
await
this
.
webDavClient
.
putFileContents
(
path
,
file
,
{
overwrite
:
false
,
onUploadProgress
:
progress
=>
{
console
.
log
(
`Uploaded
${
progress
.
loaded
}
bytes of
${
progress
.
total
}
`
);
}});
this
.
loading
=
false
;
this
.
statusText
=
""
;
console
.
log
(
"
try finished
"
);
ret
=
true
;
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
this
.
loading
=
false
;
//this.statusText = error.message;
console
.
log
(
"
----
"
,
error
.
message
);
if
(
error
.
message
.
search
(
"
412
"
)
!==
-
1
)
{
this
.
replaceModalDialog
(
file
,
directory
);
console
.
log
(
"
dialog open after upload?
"
,
this
.
isDialogOpen
);
}
}
console
.
log
(
"
after one file finished
"
);
return
ret
;
}
async
uploadFileWithNewName
()
{
...
...
@@ -419,20 +422,21 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
if
(
this
.
_
(
"
input[name='replacement']:checked
"
).
value
===
"
ignore
"
)
{
MicroModal
.
close
();
this
.
fileList
.
shift
();
return
true
;
}
else
if
(
this
.
_
(
"
input[name='replacement']:checked
"
).
value
===
"
new-name
"
)
{
path
=
directory
+
"
/
"
+
this
.
_
(
"
#replace-filename
"
).
value
;
console
.
log
(
"
new name checked
"
);
console
.
log
(
"
############# new name checked
"
);
this
.
replaceFilename
=
this
.
_
(
"
#replace-filename
"
).
value
;
}
else
{
path
=
directory
+
"
/
"
+
this
.
uploadFileObject
.
name
;
overwrite
=
true
;
console
.
log
(
"
replace checked
"
);
console
.
log
(
"
###############
replace checked
"
);
}
// https://github.com/perry-mitchell/webdav-client#putfilecontents
let
ret
=
false
;
try
{
let
contents
=
await
this
.
webDavClient
.
putFileContents
(
path
,
file
,
{
overwrite
:
overwrite
,
onUploadProgress
:
progress
=>
{
...
...
@@ -441,19 +445,24 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
this
.
loading
=
false
;
this
.
statusText
=
""
;
console
.
log
(
"
try finished
"
);
ret
=
true
;
console
.
log
(
"
after one file finished
"
);
this
.
fileList
.
shift
();
console
.
log
(
"
FileList length:
"
,
this
.
fileList
.
length
);
console
.
log
(
"
########## after one file finished
"
);
MicroModal
.
close
();
this
.
uploadFile
(
directory
);
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
this
.
loading
=
false
;
this
.
statusText
=
error
.
message
;
console
.
log
(
"
----
"
,
error
.
message
);
if
(
error
.
message
.
search
(
"
412
"
)
!==
-
1
)
{
MicroModal
.
close
();
this
.
replaceModalDialog
(
file
,
directory
);
console
.
log
(
"
dialog open after upload?
"
,
this
.
isDialogOpen
);
}
}
console
.
log
(
"
after one file finished
"
);
MicroModal
.
close
();
return
ret
;
}
/**
...
...
@@ -465,15 +474,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
console
.
log
(
"
zeig uns an.
"
);
this
.
uploadFileObject
=
file
;
this
.
uploadFileDirectory
=
directory
;
this
.
replaceFilename
=
file
.
name
;
this
.
isDialogOpen
=
true
;
/*MicroModal.init({
onShow: modal => { this.isDialogOpen = true },
onClose: modal => { this.isDialogOpen = false; },
});*/
MicroModal
.
show
(
this
.
_
(
'
#replace-modal
'
),
{
onClose
:
modal
=>
{
this
.
isDialogOpen
=
false
;
}
});
MicroModal
.
show
(
this
.
_
(
'
#replace-modal
'
));
console
.
log
(
"
dialog is open?
"
,
this
.
isDialogOpen
);
}
...
...
This diff is collapsed.
Click to expand it.
packages/file-handling/src/file-sink.js
+
18
−
4
View file @
5a4c6c6e
...
...
@@ -118,8 +118,8 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
let
that
=
this
;
const
element
=
that
.
_
(
'
#nextcloud-file-picker
'
);
console
.
log
(
"
davor
"
);
const
finished
=
await
element
.
uploadFiles
(
that
.
files
,
directory
);
console
.
log
(
"
fertig
"
,
finished
);
await
element
.
uploadFiles
(
that
.
files
,
directory
);
/*
console.log("fertig", finished);
if(finished) {
MicroModal.close();
console.log("close");
...
...
@@ -129,11 +129,22 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
"type": "success",
"timeout": 5,
});
}
}
*/
}
finishedFileUpload
()
{
MicroModal
.
close
();
console
.
log
(
"
close
"
);
send
({
"
summary
"
:
i18n
.
t
(
'
file-sink.upload-success-title
'
),
"
body
"
:
i18n
.
t
(
'
file-sink.upload-success-body
'
,
{
name
:
this
.
nextcloudName
}),
"
type
"
:
"
success
"
,
"
timeout
"
:
5
,
});
}
preventDefaults
(
e
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
...
...
@@ -228,7 +239,10 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
nextcloud-name="
${
this
.
nextcloudName
}
"
@dbp-nextcloud-file-picker-file-uploaded="
${(
event
)
=>
{
this
.
uploadToNextcloud
(
event
.
detail
);
}}
"></dbp-nextcloud-file-picker>
}}
"
@dbp-nextcloud-file-picker-file-uploaded-finished="
${(
event
)
=>
{
this
.
finishedFileUpload
();
}}
"></dbp-nextcloud-file-picker>
</div>
</main>
</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