Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix drag and drop #1094

Merged
merged 9 commits into from Aug 25, 2017
Merged

Fix drag and drop #1094

merged 9 commits into from Aug 25, 2017

Conversation

noirbizarre
Copy link
Contributor

@noirbizarre noirbizarre commented Aug 22, 2017

This PR fixes a lot of issue on file upload:

  • Update to latest fine uploader
  • fix upload endpoint detection (and use more explicit endpoint names)
  • restore missing dropzone highlight on resource form
  • fix filesize handling (when not defined, switch from legacy File.fileSize to Blob.size)
  • fix broken resource list inline upload layout:
    • column numbers where mismatching (did not follow column addition)
    • progress bar styles where not included
    • mime type (way too long) was displayed instead of extension into format column
  • uploaded files where not replaced but duplicated
  • error handling on upload does not remove nor mark as errored the faulty files

@noirbizarre noirbizarre added this to the 1.1.2 milestone Aug 22, 2017
@noirbizarre noirbizarre requested a review from a team August 22, 2017 13:01
.resource-upload-dropzone {
border: 4px dashed #bbb;
border: 4px dashed @gray-lte;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noirbizarre I can see you hooked on the variables thingy 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I always had, but there was no proper @import ~ support in vue-loader initially so it was not possible to properly use them.
When I encounter a case were I can use them, I try to do/fix it

@@ -22,7 +28,7 @@
</span>
<div class="info-box-content">
<span class="info-box-text">{{file.name}}</span>
<span class="info-box-number">{{file.filesize | filesize}}</span>
<span class="info-box-number">{{file.size | filesize}}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure a linter would have caught this issue — @noirbizarre @vinyll do you know of anything to enforce data models for Vue.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that a linter can find that a variable name is removed from the spec on a non-typed variable. File(s) in this component (is)are provided by fineuploader. The fact it's a File object is not indicated anywhere else than the fineuploader documentation :/

}
endpoint += this.is_community ? 'community_' : 'dataset_';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems very error prone. Could we rather build a string like this?

const route_new = this.resource.id ? '' : 'new_';
const route_namespace = this.is_community ? 'community_' : 'dataset_'; 

const endpoint = `upload_${route_new}${route_namespace}resource`;

Would make stuff more explicit, and probably simplify the above logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can (and I will), but that's only working for the string building part, not the parameters.

@@ -155,13 +161,17 @@ export default {
},
events: {
'uploader:progress': function(id, uploaded, total) {
const el = this.$el.getElementById(`progress-${id}`);
const el = document.getElementById(`progress-${id}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we breaking the rules of the Vue component? Right now it seems we are looking for something outside of the component itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we are looking for a component inside (defined in the associated template). Sadly, getElementById is not defined on Element this is why I had to use document (which is weird because I though I was able to do it before)
In Vue.js 2.0, referencing raw Elements for direct access in a loop is supported (using the ref attribute on components or elements and accessing them using this.$refs. Sadly, it's only supported on component in Vue.js 1.x :/

const file = this.$uploader.getFile(id);
this.files.$remove(this.files.indexOf(file));
'uploader:complete': function(id, response, file) {
this.files.splice(this.files.indexOf(file), 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intent of this line? Loos like we are modifying the files list in place but not sure why.

The previously used $remove invocation did not work for any specific reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we remove the file from the array, and for Vue.js to be able to detect the change, we need to use splice() (See https://v1.vuejs.org/guide/list.html#Array-Change-Detection)
The previous $remove() was removed (:wink:) from Vue.js 1.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, the syntax is just not the same (and there is not a dedicated section about it): https://v1.vuejs.org/guide/list.html#Caveats
I wil change to this.files.$remove(file) and see if it's working 👍

@noirbizarre noirbizarre merged commit 2c24f72 into opendatateam:master Aug 25, 2017
@noirbizarre noirbizarre deleted the fix-drag-and-drop branch August 25, 2017 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants