{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/56132842","id":56132842,"diff_hunk":"@@ -22,6 +22,7 @@ def show\n         @visualization_data = Carto::Api::VisualizationPresenter.new(@visualization, current_viewer, self).to_poro\n         @layers_data = @visualization.layers.map { |l| Carto::Api::LayerPresenter.new(l).to_poro }\n         @vizjson = generate_vizjson3(@visualization, params)\n+        @analyses_data = @visualization.analyses.map { |a| Carto::Api::AnalysisPresenter.new(a).to_poro }","path":"app/controllers/carto/editor/visualizations_controller.rb","position":4,"original_position":4,"commit_id":"dabcdd83a9ba78ed520ffe262b2340cbf9db5078","original_commit_id":"dabcdd83a9ba78ed520ffe262b2340cbf9db5078","user":{"login":"juanignaciosl","id":932968,"avatar_url":"https://avatars.githubusercontent.com/u/932968?v=3","gravatar_id":"","url":"https://api.github.com/users/juanignaciosl","html_url":"https://github.com/juanignaciosl","followers_url":"https://api.github.com/users/juanignaciosl/followers","following_url":"https://api.github.com/users/juanignaciosl/following{/other_user}","gists_url":"https://api.github.com/users/juanignaciosl/gists{/gist_id}","starred_url":"https://api.github.com/users/juanignaciosl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanignaciosl/subscriptions","organizations_url":"https://api.github.com/users/juanignaciosl/orgs","repos_url":"https://api.github.com/users/juanignaciosl/repos","events_url":"https://api.github.com/users/juanignaciosl/events{/privacy}","received_events_url":"https://api.github.com/users/juanignaciosl/received_events","type":"User","site_admin":false},"body":"After a second look, this LGTM. Iterating models in the controller is ok. Template doesn't do a direct usage of the models.","created_at":"2016-03-15T09:10:18Z","updated_at":"2016-03-15T09:10:18Z","html_url":"https://github.com/CartoDB/cartodb/pull/6827#discussion_r56132842","pull_request_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/56132842"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/6827#discussion_r56132842"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827","id":62241929,"html_url":"https://github.com/CartoDB/cartodb/pull/6827","diff_url":"https://github.com/CartoDB/cartodb/pull/6827.diff","patch_url":"https://github.com/CartoDB/cartodb/pull/6827.patch","issue_url":"https://api.github.com/repos/CartoDB/cartodb/issues/6827","number":6827,"state":"open","locked":false,"title":"6780 persist analysis models","user":{"login":"viddo","id":978461,"avatar_url":"https://avatars.githubusercontent.com/u/978461?v=3","gravatar_id":"","url":"https://api.github.com/users/viddo","html_url":"https://github.com/viddo","followers_url":"https://api.github.com/users/viddo/followers","following_url":"https://api.github.com/users/viddo/following{/other_user}","gists_url":"https://api.github.com/users/viddo/gists{/gist_id}","starred_url":"https://api.github.com/users/viddo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viddo/subscriptions","organizations_url":"https://api.github.com/users/viddo/orgs","repos_url":"https://api.github.com/users/viddo/repos","events_url":"https://api.github.com/users/viddo/events{/privacy}","received_events_url":"https://api.github.com/users/viddo/received_events","type":"User","site_admin":false},"body":"Waypoint for #6780 \r\n\r\nFirst, read the commit msgs to understand _why_ the things were changed in the way they were.\r\n\r\nContinuing on the snippets from [previous PR](https://github.com/CartoDB/cartodb/pull/6821), one can create analysis by:\r\n```js\r\nl = layerDefinitionsCollection.first();\r\nm1 = analysisDefinitionNodesCollection.add({\r\n  type: 'trade-area',\r\n  kind: 'walk',\r\n  time: 300,\r\n  source_id: l.get('source')\r\n}, {\r\n  parse: false\r\n});\r\nl.save({ source: m1.id })\r\n\r\n// or source from node \"owned\" by the other layer\r\nl = layerDefinitionsCollection.first();\r\nl1 = layerDefinitionsCollection.at(1); \r\nm1 = analysisDefinitionNodesCollection.add({\r\n  id: analysisDefinitionNodesCollection.nextId(l.get('source')),\r\n  type: 'trade-area',\r\n  kind: 'walk',\r\n  time: 300,\r\n  source_id: l1.get('source')\r\n}, {\r\n  parse: false\r\n});\r\nl.save({ source: m1.id })\r\n```\r\n\r\nIn case everything is :boom: one can always delete all analyses by:\r\n```js\r\n// clone is necessary to avoid underscore's iterator to not throw errors due to removed models from the iterated list… >_<\r\nanalysisDefinitionsCollection.chain().clone().invoke('destroy')\r\n```\r\n\r\n@xavijam please review (frontend part at least)\r\ncc @juanignaciosl @alonsogarciapablo @javierarce \r\n\r\n---\r\nTODOs:\r\n- [x] enable persisting \r\n- [x] update layer definition on analysis deletion\r\n- [x] adhere to new format for backend #6832 \r\n- [x] create/update analysis-defs on node models changes\r\n- [x] ~~if a source id is already referenced throw error~~ --> backend will check this, https://github.com/CartoDB/cartodb/issues/6856\r\n- [x] views to use nodes collection, instead of definitions\r\n- [x] implement routing-n-to-n node\r\n- [x] nextId supports nodes with multiple sources (through defined \"primary\" source)\r\n- [x] table_name from layer instead of analysis?\r\n- [x] error handling, rollback node creation after adding node?\r\n- [x] layer-ref-view, why not use layerDefModel as this.model?\r\n- [x] ~~removal of node(s) should remove dependent nodes, and update/destroy analysis accordingly~~ postponed to later\r\n- [x] bump frontend assets version\r\n- [x] fix the temporary hack for serializing analysis models for client-side on initial page load (see `show.html.erb`)","created_at":"2016-03-09T15:07:14Z","updated_at":"2016-03-15T09:10:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"820abd9ad218f4e7be0fd065d19628472c479385","assignee":{"login":"viddo","id":978461,"avatar_url":"https://avatars.githubusercontent.com/u/978461?v=3","gravatar_id":"","url":"https://api.github.com/users/viddo","html_url":"https://github.com/viddo","followers_url":"https://api.github.com/users/viddo/followers","following_url":"https://api.github.com/users/viddo/following{/other_user}","gists_url":"https://api.github.com/users/viddo/gists{/gist_id}","starred_url":"https://api.github.com/users/viddo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viddo/subscriptions","organizations_url":"https://api.github.com/users/viddo/orgs","repos_url":"https://api.github.com/users/viddo/repos","events_url":"https://api.github.com/users/viddo/events{/privacy}","received_events_url":"https://api.github.com/users/viddo/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/CartoDB/cartodb/milestones/65","html_url":"https://github.com/CartoDB/cartodb/milestones/Getafe%20-%20editor%203","labels_url":"https://api.github.com/repos/CartoDB/cartodb/milestones/65/labels","id":1642186,"number":65,"title":"Getafe - editor 3","description":"","creator":{"login":"xavijam","id":132146,"avatar_url":"https://avatars.githubusercontent.com/u/132146?v=3","gravatar_id":"","url":"https://api.github.com/users/xavijam","html_url":"https://github.com/xavijam","followers_url":"https://api.github.com/users/xavijam/followers","following_url":"https://api.github.com/users/xavijam/following{/other_user}","gists_url":"https://api.github.com/users/xavijam/gists{/gist_id}","starred_url":"https://api.github.com/users/xavijam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavijam/subscriptions","organizations_url":"https://api.github.com/users/xavijam/orgs","repos_url":"https://api.github.com/users/xavijam/repos","events_url":"https://api.github.com/users/xavijam/events{/privacy}","received_events_url":"https://api.github.com/users/xavijam/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":0,"state":"open","created_at":"2016-03-14T09:45:26Z","updated_at":"2016-03-14T10:33:58Z","due_on":"2016-03-23T23:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827/commits","review_comments_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827/comments","review_comment_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/issues/6827/comments","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/dabcdd83a9ba78ed520ffe262b2340cbf9db5078","head":{"label":"CartoDB:6780-persist-analysis","ref":"6780-persist-analysis","sha":"dabcdd83a9ba78ed520ffe262b2340cbf9db5078","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-03-13T18:31:43Z","pushed_at":"2016-03-15T08:16:02Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":377336,"stargazers_count":1077,"watchers_count":1077,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":268,"mirror_url":null,"open_issues_count":848,"forks":268,"open_issues":848,"watchers":1077,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"e2527eb6baaa373098136ccd53a2af674ae008d6","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-03-13T18:31:43Z","pushed_at":"2016-03-15T08:16:02Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":377336,"stargazers_count":1077,"watchers_count":1077,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":268,"mirror_url":null,"open_issues_count":848,"forks":268,"open_issues":848,"watchers":1077,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/6827"},"issue":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/6827"},"comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/6827/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6827/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/cartodb/statuses/dabcdd83a9ba78ed520ffe262b2340cbf9db5078"}}}}