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

Added support to delete Generic Object Definitions using REST API DELETE #2262

Merged
merged 7 commits into from
Oct 3, 2017

Conversation

AparnaKarve
Copy link
Contributor

The C-R-U for Generic Object Definitions was implemented in #2137.

This PR implements the D (Delete) using REST API.

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

screen shot 2017-09-28 at 3 52 53 pm

screen shot 2017-09-28 at 3 53 23 pm

to block the Delete operation in the `show` screen if there
are instances associated with a record
The observable in the toolbar listens for `delete` and then
deletes a single record (i.e. applicable from the `show` screen only)
using API
Only records with 0 instances would be deleted
For records with > 0 instances a warning message would be displayed
indicating why they could not be deleted
@AparnaKarve
Copy link
Contributor Author

AparnaKarve commented Sep 29, 2017

@martinpovolny Please take a look at the codeclimate report here.

IMO, the Similar code found in 1 other location errors here look completely absurd.
Plus not to mention the fact that despite the clean and well-structured code in the JS, codeclimate has decided to grade it a C -- which is not reasonable at all.
Now hypothetically, if I did not have the other file (physical-server-toolbar.js /cloud_volume_form_controller.js ) in the picture, the grade would have been an A, which makes the whole CC grading extremely questionable.

We should definitely disable these errors by tweaking the mass value in CC settings if we can.

Are you able to understand how CC came up with those mass value numbers -
(mass = 112) and (mass = 41)?
(I'm finding it hard to interpret those values)

/cc @dclarizio

@gmcculloug
Copy link
Member

@lfu Please review

Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

Working as expected for me. 👍

@lfu
Copy link
Member

lfu commented Sep 29, 2017

LGTM 👍

@@ -0,0 +1,17 @@
class ApplicationHelper::Button::GenericObjectDefinitionDeleteButton < ApplicationHelper::Button::Basic
def visible?
Copy link
Member

Choose a reason for hiding this comment

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

def visible?
@display != 'generic_objects'
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 446f7c4

end

def disabled?
if @record.generic_objects.count > 0
Copy link
Member

Choose a reason for hiding this comment

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

def disabled?
@record.generic_objects.count.zero?
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 446f7c4

%generic-object-definition-toolbar#generic_object_definition_show_list_form

:javascript
miq_bootstrap('#generic_object_definition_show_list_form');
Copy link
Member

Choose a reason for hiding this comment

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

@himdel : we discussed this as an anti-pattern. Do we have a replacement yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would miq_bootstrap on the angular component be an anti-pattern?
@himdel Pray tell me how.

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 an anti-pattern simply because a GTL show-list should not have any other components .. what is this generic-object-definition-toolbar actually for? Should it not be an actual toolbar?

Also, it's a component without a template - sounds like something is very wrong there :).

Copy link
Contributor

Choose a reason for hiding this comment

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

Aah.. and it is an invisible toolbar because you're actuall trying to do things right and call the API for all the toolbar actions, am I right? :)

Sounds maybe we could just move this outside the DOM, since it has no effect on any actual html...

And we can actually listen for Rx messages even outside Angular code.. so maybe this should be a simple file that just starts listening for messages wherever - it means we would have the listeners on every screen but... so what :).

We just need the messages to be discoverable - but genericObjectDefinitionToolbarController pretty much solves that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean.. instead of using a component (and having a non-standard show_list), this could just be a js file which just starts the listeners directly, without anything angulary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GTL show-list should not have any other components

Seems very restrictive for no real reason.
Why wouldn't be more components allowed?

generic-object-definition-toolbar

generic-object-definition-toolbar is the controller for the toolbar commands.
BTW, there are no groundbreaking changes here.
Something similar has already been implemented for Physical Servers - #1380

Also, it's a component without a template - sounds like something is very wrong there

I have one simple answer to that - Delete operation does not need a form/template. A flash message is good enough
Nothing went wrong ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean.. instead of using a component (and having a non-standard show_list), this could just be a js file which just starts the listeners directly, without anything angulary.

(Looks like I missed this message since I did not refresh the page as I was typing mine)

  • It cannot be non-angulary because I'm using the API service, which is available only if you use angular.
  • Also there is some advantage to using the the controller/component approach that I see.
    All messages that are triggered by the Generic Object Definition toolbar would only be directed to the observable in the generic-object-definition-toolbar component.
    It's like I'm channeling the messages in a particular area of interest and not going in the common application-wide listeners pool.

Copy link
Member

Choose a reason for hiding this comment

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

@AparnaKarve : You are correct, there's no other way to do this right now. It is 100% ok for this PR.

The comment was ment more as a note that this is something we have to deal with and ping to @himdel to look for a solution ;-)

I am looking at all the "extra" content in the "show" partials because I would like to delete all the "show" partials on our way towards more declarative and client-side UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martinpovolny Thanks for that clarification.

%generic-object-definition-toolbar#generic_object_definition_show_form{'generic-object-definition-id' => @record.id,
'redirect-url' => "/#{controller_name}/show_list",}
:javascript
miq_bootstrap('#generic_object_definition_show_form');
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.. I'll say fine for this PR :)...

So just FYI Aparna..

we're trying to remove all those specific things from these show partials, so that miq_bootstrap will have to go as well..
but the idea is that instead, the controllers would have a method which gets called from all the show partials, and can create that miq_bootstrap in a declarative way, maybe ideally with the option to create that component element as well.

But that's really just an idea for now, without any specifics worked out.

Copy link
Member

Choose a reason for hiding this comment

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

It's in the TODO list that is growing...

@martinpovolny
Copy link
Member

@AparnaKarve : will you, please, replace the 2 methods with corresponding one-liners so that we can merge this?

@miq-bot
Copy link
Member

miq-bot commented Oct 2, 2017

Checked commits AparnaKarve/manageiq-ui-classic@7fd40c9~...446f7c4 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks fine. ⭐

@AparnaKarve
Copy link
Contributor Author

@martinpovolny I have simplified the 2 methods with simple one-liners as you suggested. Thanks.

@martinpovolny martinpovolny merged commit ea7e1c0 into ManageIQ:master Oct 3, 2017
@martinpovolny martinpovolny added this to the Sprint 71 Ending Oct 16, 2017 milestone Oct 3, 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.

7 participants