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

Add Picture support in Generic Object Definition editor #2339

Merged
merged 9 commits into from
Oct 12, 2017

Conversation

AparnaKarve
Copy link
Contributor

@AparnaKarve AparnaKarve commented Oct 10, 2017

Requires - ManageIQ/manageiq-api#116

https://www.pivotaltracker.com/n/projects/1613907/stories/151742686

Automation > Automate > Generic Objects


Create Generic Object Screen

screen shot 2017-10-10 at 10 19 56 am

screen shot 2017-10-10 at 10 21 03 am

screen shot 2017-10-10 at 10 20 46 am


Generic Object Definition Summary Screen

screen shot 2017-10-10 at 10 21 26 am


Edit Generic Object Screen

screen shot 2017-10-10 at 10 21 41 am

"ng-model" => "vm.changeImage"}

:javascript
$(":file").filestyle({placeholder: _("No file chosen"), icon: false});
Copy link
Contributor

Choose a reason for hiding this comment

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

__ ? This is 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.

But it's a JS inside a haml. So do we still need the __?

Copy link
Contributor

@himdel himdel Oct 11, 2017

Choose a reason for hiding this comment

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

Well, it can be either placeholder: __("No file chosen"), or placeholder: "#{_("No file chosen")}",

it is haml, but not ruby unless interpolating

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in fb22a12

vm.picture.extension = 'jpeg';
} else {
vm.angularForm.generic_object_definition_image_file_status.$setValidity("incompatibleFileType", false);
vm.imageUploadStatus = __("Incompatible image type");
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this show the message while the file is still loading? (or is the time really close to 0 even for huge images?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this stage the file upload (or loading) hasn't even begun - it's just being vetted for the right extension.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.. but the file is being processed by the browser, in the background.

So, between you setting this and that onload event firing, the message will be visible.

Will test.. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh.. sorry, I read the code wrong, no such problem here :). (I thought this happened always, not only on bad type.)

It does feel a bit weird that you have to punch the Upload button after chosing the file, but that's not a blocker, more of a detail for UX :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using the exact same UX in Catalog Explorer as well where we set custom images for Catalog Items. And that UX comes from Bootstrap Filestyle - http://markusslima.github.io/bootstrap-filestyle/

I did give a shot to "angularize" Bootstrap Filestyle, as in, keep the Upload button disabled until a file is available to be uploaded, but once you run the JS script $(":file").filestyle, it pretty much disregards all angular directives etc

Copy link
Contributor

Choose a reason for hiding this comment

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

We are using the exact same UX in Catalog Explorer ..

Ah, ok, then definitely not a problem here :)

(Though just to be clear, my objection was not to what I see in bootstrap-filestyle, but to the extra button they have to press after they chose the file.)


$timeout(function() {
vm.angularForm.generic_object_definition_image_file_status.$setValidity("incompatibleFileType", true);
vm.imageUploadStatus = __("Image upload complete");
Copy link
Contributor

Choose a reason for hiding this comment

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

Would a different message make more sense here given this does not actually upload the image yet?

I mean, if I see "Image upload complete" I will think the image is already on the server. (And will wonder why submitting the form takes so long.)

(I guess there's no support for uploading the image in the background yet, right?)

Copy link
Contributor Author

@AparnaKarve AparnaKarve Oct 10, 2017

Choose a reason for hiding this comment

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

"Image upload complete" is just a helpful acknowledgement to the user that the chosen file is now ready to be saved.
LMK if you have other wording suggestions for that message.

I guess there's no support for uploading the image in the background yet, right?

No background support - it all happens in the main thread.
In my testing so far, I haven't come across a situation where the file loading is like a really lengthy, time-consuming operation -- it has been almost instantaneous in my tests.

Copy link
Contributor

@himdel himdel Oct 11, 2017

Choose a reason for hiding this comment

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

Take a 40 MB png file, and connect to manageiq running on the network, not on localhost.

And suddenly it takes about 40 seconds to upload (and 2s to even show the spinner :)).

But I guess we don't have to optimize for such huge image users quite yet, but I wouldn't mislead them either .. what about "Image will be uploaded when you submit the form"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Will change that text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thoughts, saying "...submit the form" sounds a bit techy, let's try and keep it very generic.
How about "Image is ready to be uploaded"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in fb22a12

Copy link
Contributor

Choose a reason for hiding this comment

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

Better, thanks! :)

@@ -76,6 +81,8 @@ function genericObjectDefinitionFormController(API, miqService, $q) {

assignAllObjectsToKeyValueArrays(true);

vm.pictureReset = ! vm.pictureReset;
Copy link
Contributor

@himdel himdel Oct 10, 2017

Choose a reason for hiding this comment

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

clicking reset twice will remove the picture?

I guess this should be always vm.pictureReset = false;? (Unless I'm misunderstanding pictureReset)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vm.pictureReset is just a toggle to trigger $onChanges in the custom-image-component every time Reset is clicked.

$onChanges in the custom-image-component is in-charge of resetting the UI in the component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aaah, can you make this explicit please?

Because now it looks like you're just switching the var for no reason, and not actually using it.

(I mean, if you look for pictureReset in the code, you will just see that you set it to false, and that you negate it here. But never actually read that. .. So it's a bit hard to notice that you're using it for the side effect caused by changing it.)

I would make $onChanges do that only when changes.pictureReset, not on any change, unless you're relying on it happening for other changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in fb22a12

@himdel
Copy link
Contributor

himdel commented Oct 10, 2017

Overall LGTM, will test in the morning...

(I vaguelly remember IE having some difference in the filetypes, but not sure if relevant here, so I want to check.)

With this change there is no need for a virtual column for
`picture_url_path` as once thought would be necessary.
It is important to set `picture.image_href` to
undefined in the model to avoid API failure during a Save operation
@gmcculloug
Copy link
Member

@lfu Please test.

} else if (imageFile.type === 'image/jpg') {
vm.picture.extension = 'jpg';
} else if (imageFile.type === 'image/jpeg') {
vm.picture.extension = 'jpeg';
Copy link
Contributor

@himdel himdel Oct 11, 2017

Choose a reason for hiding this comment

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

{"error":{"kind":"bad_request","message":"Failed to update generic object definition - Validation failed: Extension must be a png, jpg, or svg","klass":"Api::BadRequestError"}}

This has to be jpg as well, not jpeg.

And it seems like you may want to add a condition for SVG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in fb22a12

@himdel
Copy link
Contributor

himdel commented Oct 11, 2017

Tested in UI .. except for being unable to upload jpg images, everything seemed to work :).

Have not tested in IE as I'm unable to get it working.. so fingers crossed :). (That said, MDN claims IE11 supports File fully, so, what I remember may have been for previous versions.)

@miq-bot
Copy link
Member

miq-bot commented Oct 11, 2017

Checked commits AparnaKarve/manageiq-ui-classic@5486e6b~...fb22a12 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 1 offense detected

app/views/generic_object_definition/show.html.haml

  • ⚠️ - Line 14 - Prefer to_s over string interpolation.

@lfu
Copy link
Member

lfu commented Oct 11, 2017

Testing looks good 👍

@AparnaKarve
Copy link
Contributor Author

@himdel @lfu Thank you for testing.

@himdel I have addressed the feedback in fb22a12

@himdel
Copy link
Contributor

himdel commented Oct 12, 2017

Oh, @AparnaKarve I found one more bug, sorry :)..

  1. edit an existing generic object which already has an image
  2. toggle the Update current image switch to yes
  3. add a different image
  4. toggle the Update current image switch back to no
  5. save

Expected:
toggling update current image back to no should mean the image does not get replaced

Actual:
it uploads the new image

(Otherwise LGTM)

@AparnaKarve
Copy link
Contributor Author

@himdel Yes, I found that one too, and I'm thinking the fix should be to just hide the Update current image checkbox once the new image is actually uploaded.
(Reset is the way to get back things in the original status)

How about I do this in a follow-up PR, and close the chapter on this one since the core functionality is in?

@dclarizio
Copy link

@AparnaKarve follow up sounds good, merging

@dclarizio dclarizio merged commit e9762a2 into ManageIQ:master Oct 12, 2017
@dclarizio dclarizio added this to the Sprint 71 Ending Oct 16, 2017 milestone Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants