{"action":"created","issue":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/2412","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/2412/labels{/name}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/2412/comments","events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/2412/events","html_url":"https://github.com/ManageIQ/manageiq/pull/2412","id":64869436,"number":2412,"title":"POC: convert EmsCloudController to use restful routes.","user":{"login":"tenderlove","id":3124,"avatar_url":"https://avatars.githubusercontent.com/u/3124?v=3","gravatar_id":"","url":"https://api.github.com/users/tenderlove","html_url":"https://github.com/tenderlove","followers_url":"https://api.github.com/users/tenderlove/followers","following_url":"https://api.github.com/users/tenderlove/following{/other_user}","gists_url":"https://api.github.com/users/tenderlove/gists{/gist_id}","starred_url":"https://api.github.com/users/tenderlove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tenderlove/subscriptions","organizations_url":"https://api.github.com/users/tenderlove/orgs","repos_url":"https://api.github.com/users/tenderlove/repos","events_url":"https://api.github.com/users/tenderlove/events{/privacy}","received_events_url":"https://api.github.com/users/tenderlove/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/gem%20changes","name":"gem changes","color":"6A92BC"},{"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/refactoring","name":"refactoring","color":"fbca04"},{"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/ui","name":"ui","color":"5319e7"}],"state":"open","locked":false,"assignee":{"login":"tenderlove","id":3124,"avatar_url":"https://avatars.githubusercontent.com/u/3124?v=3","gravatar_id":"","url":"https://api.github.com/users/tenderlove","html_url":"https://github.com/tenderlove","followers_url":"https://api.github.com/users/tenderlove/followers","following_url":"https://api.github.com/users/tenderlove/following{/other_user}","gists_url":"https://api.github.com/users/tenderlove/gists{/gist_id}","starred_url":"https://api.github.com/users/tenderlove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tenderlove/subscriptions","organizations_url":"https://api.github.com/users/tenderlove/orgs","repos_url":"https://api.github.com/users/tenderlove/repos","events_url":"https://api.github.com/users/tenderlove/events{/privacy}","received_events_url":"https://api.github.com/users/tenderlove/received_events","type":"User","site_admin":false},"milestone":null,"comments":38,"created_at":"2015-03-27T23:19:21Z","updated_at":"2015-08-27T21:53:09Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/2412","html_url":"https://github.com/ManageIQ/manageiq/pull/2412","diff_url":"https://github.com/ManageIQ/manageiq/pull/2412.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/2412.patch"},"body":"This is a Proof of Concept pull request.  It converts the `EmsCloudController` to use resful routes and puts changes in place to allow other controllers to be RESTful too.\r\n\r\n## Benefits\r\n\r\n### Statelessness\r\n\r\n`EmsCloudController` no longer has to store things in `@edit` every time someone types in text boxes.  It posts all form data to the `create` action on the controller.  That means that the controller doesn't need to maintain state in the session.  This makes testing easier and eliminates the need for RJS calls on each keypress.\r\n\r\n### Testability\r\n\r\nSince the controller is stateless, it's very easy to set up tests for this controller.  The amount of data needed in the session is little to none.  See the tests in this pull request as a demonstration.\r\n\r\n### Extensibility\r\n\r\nSince the controller is stateless, and all form info is posted at the same time, it will be very easy to convert this controller to a REST API endpoint.  All we have to do is add a `responds` block that returns JSON.\r\n\r\nThe controller uses Rails' polymorphic URL generation helpers to generate links and form paths.  This means it will \"do the right thing\" depending on the type of object that we're editing / updating / deleting.\r\n\r\n### Speed\r\n\r\nOur AJAX code has a built in delay in order to wait for any requests to update `@edit`.  Since this form posts all data at once, we don't need that delay, and the site is much more responsive.\r\n\r\n## Further work\r\n\r\nWe need to separate actions in the controllers.  Right now we have actions that perform two tasks.  For example [the create action will do different things depending on which button is pressed](https://github.com/ManageIQ/manageiq/blob/2ebedb620e30697102e77af81d627144187b06b9/vmdb/app/controllers/ems_common.rb#L271-281).  We need to either split those in to multiple actions, or do them on the client side. #2398 is an example of how we can accomplish some of these tasks the server is doing on the client side.\r\n\r\nSecond, this PR needs to implement Audit events.  Audit events [are tightly coupled with `@edit`](https://github.com/tenderlove/manageiq/blob/26e9b81251c82a35b9b43bd964715ea695a80086/vmdb/app/controllers/ems_common.rb#L301).  Since this PR doesn't use `@edit` at all, we need to figure out how to do the same thing but without information from the session.\r\n\r\nFinally, this PR adds a few hacks in places like routes.rb and application_helper in order to get around the code that assumes there are no restful routes in the system.\r\n\r\n## END\r\n\r\nThis is how I would like UI development on our system to work going forward.  I believe this PR demonstrates how we can incrementally decouple ourselves from the session data, simplify testing, *and* put the application in a place where it's easy to add new features (like JSON endpoints)."},"comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments/135566016","html_url":"https://github.com/ManageIQ/manageiq/pull/2412#issuecomment-135566016","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/2412","id":135566016,"user":{"login":"AparnaKarve","id":1538216,"avatar_url":"https://avatars.githubusercontent.com/u/1538216?v=3","gravatar_id":"","url":"https://api.github.com/users/AparnaKarve","html_url":"https://github.com/AparnaKarve","followers_url":"https://api.github.com/users/AparnaKarve/followers","following_url":"https://api.github.com/users/AparnaKarve/following{/other_user}","gists_url":"https://api.github.com/users/AparnaKarve/gists{/gist_id}","starred_url":"https://api.github.com/users/AparnaKarve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AparnaKarve/subscriptions","organizations_url":"https://api.github.com/users/AparnaKarve/orgs","repos_url":"https://api.github.com/users/AparnaKarve/repos","events_url":"https://api.github.com/users/AparnaKarve/events{/privacy}","received_events_url":"https://api.github.com/users/AparnaKarve/received_events","type":"User","site_admin":false},"created_at":"2015-08-27T21:53:09Z","updated_at":"2015-08-27T21:53:09Z","body":"@tenderlove So the plan is, we will hold off merging this PR for now.\r\nI will be be rebasing my Angular Cloud Provider branch with this (restful) branch, and fix the above issue at the same time.\r\nOnce its confirmed that your restful branch + my Angular changes resolve all known issues, we can then close this PR.\r\nThanks.\r\n\r\n/cc @dclarizio "}}