-
Notifications
You must be signed in to change notification settings - Fork 43
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
renovate the file upload #58
Conversation
instead including the upload functionailty in an iframe directly include it in the form. The file input has no name attribute so it will not be up uploaded when submitting. When clicking the button the file will by uploaded asynchronously and a notification bar is shown to the user with the result. script and css is included via an adjunct is plain vanilla javascript.
NoFile=No file uploaded. | ||
DupName=File with this name already exists in userContent. | ||
Back=Back | ||
uploaded=Uploaded image file; use {0} in Link Icon field above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to change it to lowercase ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkstyle complained that the methods used in java start with a capital letter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it did not complain so far so I don't see reason why it starts now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was spotbugs see https://ci.jenkins.io/job/Plugins/job/sidebar-link-plugin/job/PR-58/1/spotbugs/
Probably because I changed the Messages.properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you revert those changes - I don't see value of them, just key renaming and loosing translations which were deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
What might be done is move the ja translations from the deleted startUpload_ja.properties
to the config_ja.properties
. The texts are identical except for one where just the traliing :
is removed.
@@ -0,0 +1,25 @@ | |||
Behaviour.specify("#sidebar-link-upload-button", "sidebar-link-upload", 0, function(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy to merge this JS code, prefer to have ready to use library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you mean with ready to use library?
Even when you have a library you need to customize calling the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not the only plugin that uploads the file and I believe there is one common reusable approach for Jenkins like for other controls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually files are uploaded during a form submit (e.g. when you have a build with a file parameter and you start a build).
But obviously this is not desired here as you want to upload the file and then be able to configure it without the need to press apply or save. Otherwise the existing approach with the iframe would not be here.
This iframe is not really the way to go in my eyes. After uploading you get a simple html snippet that contains no styling and you need to press back to get back to the place where you can upload files.
Of course you can include the file upload in every submit of the Jenkins config though that seems also not the right approach for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daniel-beck do we have reusable component for file upload instead of having this custom JavaScript code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about some opensource library eg https://github.com/pqina/filepond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jenkins is using pure field for uploading the pluign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to use whatever you want in your plugin.
For something provided by core, to be generally usable by plugins, it should probably come in the form of a Jelly taglib to abstract away the implementation and future-proof it. So that'll require a bit of work, and this hasn't really come up before AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using such a library is overkill. And it will not prevent that you need some javascript to connect the file input field with the library. Also for the upload you need to include a crumb, so in the end I doubt that when using the library you will get less javascript code.
And half of the code that we have now is related to notifying the user of the result.
Having a taglib might be useful, but I'm not aware of any other use case like the one here, where the upload should not be done as part of a form submission using the save or apply buttons.
If you want I can create a jelly taglib here in the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want I can create a jelly taglib here in the plugin.
Sounds like good plan @mawinter69
I also found jenkinsci/jenkins#7452
This PR is conflicted with the master branch |
@@ -0,0 +1,25 @@ | |||
Behaviour.specify("#sidebar-link-upload-button", "sidebar-link-upload", 0, function(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not the only plugin that uploads the file and I believe there is one common reusable approach for Jenkins like for other controls
+1 |
To be honest I don't feel that this change is the perfect way of fixing problem we have:
so the best for me is to have this component in Jenkins core and use it here as the reference. Same problem is for plugin upload - ugly button is presented by Jenkins from a very long time |
Just because you don't feel comfortable with js doesn't mean it is hard to maintain. The script has a total of less than 30 lines. With a minimal experience in javascript and knowledge about some basic things that Jenkins provides for use in javascript (notificationBar, Behaviour) it is easy to understand.
I fixed that, there was one text that was hard coded, I made it translatable via jelly.
I removed the css
See my note above. With some basic knowledge in javascript one can easily see that the code is uncritical. If you want I can explain you for every line what it is doing so you can assure yourself that the code is secure. You can also ask some of the core maintainers if they are willing to verify if the code is secure. In Core basically all PR with changes in the UI are looked at from a security perspective e.g. if a change will introduce a XSS vulnerability.
The custom folder icon plugin is also doing asynchronous file upload, but it also uses a js library named croppie in that method, that allows to resize/crop images.
The upload of plugins in core is done by a form submit, as it is done for file parameters in jobs and in some other places and plugins. And there is no ugly button in recent Jenkins version. You will need to decide if you want to keep your plugin broken as it is, accept this PR or find another way to fix it. |
instead including the upload functionality in an iframe directly include it in the form. The file input has no name attribute so it will not be up uploaded when submitting.
When clicking the button the file will by uploaded asynchronously and a notification bar is shown to the user with the result.
script and css is included via an adjunct is plain vanilla javascript.
requires #56
New look:
Testing done
Manual testing. Go to Jenkins -> Manage -> Configure
Click on
Upload
under theAdd Link
button -> Warning is shownNo file chosen.
Click on
Choose file
and select a file, clickUpload
-> Notification is shown where the file is found (The notification doesn't allow html) so the path is printed in single quotes. This notification is sticky so it will not disappear.Click
Upload
again -> An error is shown that the file already exists.Enter path to uploaded file in a Link and
Save
-> See the chosen image in the link.Submitter checklist