{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/75310689","id":75310689,"diff_hunk":"@@ -413,8 +416,27 @@ def populate_ids(ids_json)\n     end\n   end\n \n+  def for_presentation\n+    mapcapped? ? latest_mapcap.regenerate_visualization : self\n+  end\n+\n+  def state\n+    super ? super : build_state\n+  end\n+\n   private\n \n+  def build_state\n+    new_state = Carto::State.create!(user: user, visualization: self)\n+    update_attribute(:state_id, new_state.id) if persisted?\n+\n+    new_state\n+  end\n+\n+  def save_state_if_needed\n+    state.save if persisted? && !state.persisted?","path":"app/models/carto/visualization.rb","position":48,"original_position":48,"commit_id":"3df01af0c31ab36039eb65a688809b284e27d620","original_commit_id":"3df01af0c31ab36039eb65a688809b284e27d620","user":{"login":"javitonino","id":7569673,"avatar_url":"https://avatars.githubusercontent.com/u/7569673?v=3","gravatar_id":"","url":"https://api.github.com/users/javitonino","html_url":"https://github.com/javitonino","followers_url":"https://api.github.com/users/javitonino/followers","following_url":"https://api.github.com/users/javitonino/following{/other_user}","gists_url":"https://api.github.com/users/javitonino/gists{/gist_id}","starred_url":"https://api.github.com/users/javitonino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javitonino/subscriptions","organizations_url":"https://api.github.com/users/javitonino/orgs","repos_url":"https://api.github.com/users/javitonino/repos","events_url":"https://api.github.com/users/javitonino/events{/privacy}","received_events_url":"https://api.github.com/users/javitonino/received_events","type":"User","site_admin":false},"body":"This doesn't execute on state updates, only creation. Intended?","created_at":"2016-08-18T13:49:29Z","updated_at":"2016-08-18T13:49:29Z","html_url":"https://github.com/CartoDB/cartodb/pull/9374#discussion_r75310689","pull_request_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/75310689"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/9374#discussion_r75310689"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374","id":80612442,"html_url":"https://github.com/CartoDB/cartodb/pull/9374","diff_url":"https://github.com/CartoDB/cartodb/pull/9374.diff","patch_url":"https://github.com/CartoDB/cartodb/pull/9374.patch","issue_url":"https://api.github.com/repos/CartoDB/cartodb/issues/9374","number":9374,"state":"open","locked":false,"title":"State","user":{"login":"gfiorav","id":4222826,"avatar_url":"https://avatars.githubusercontent.com/u/4222826?v=3","gravatar_id":"","url":"https://api.github.com/users/gfiorav","html_url":"https://github.com/gfiorav","followers_url":"https://api.github.com/users/gfiorav/followers","following_url":"https://api.github.com/users/gfiorav/following{/other_user}","gists_url":"https://api.github.com/users/gfiorav/gists{/gist_id}","starred_url":"https://api.github.com/users/gfiorav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfiorav/subscriptions","organizations_url":"https://api.github.com/users/gfiorav/orgs","repos_url":"https://api.github.com/users/gfiorav/repos","events_url":"https://api.github.com/users/gfiorav/events{/privacy}","received_events_url":"https://api.github.com/users/gfiorav/received_events","type":"User","site_admin":false},"body":"Fixes #8463\r\nFixes #8464\r\n\r\n# Synopsis\r\n\r\nThis makes state (which had already been seen at deep insights level) a standard trade coin for visualisations in the back end. There is now a State model, whose spirit is to capture the current state of a given visualisation (its widget's filters and viewport ATM). \r\n\r\nFor example, if you apply a filter in a widget and refresh the builder view, the same applied state will be reloaded into the the deep insights dashboard (so everything is exactly how you left it). In addition, when the vis is shared, any state will be applied in the embed as you left it or map capped it.\r\n\r\nState is exportable as well.\r\n\r\n## State model\r\n\r\n```ruby\r\nUuid     :id, primary_key: true, default: 'uuid_generate_v4()'.lit\r\nDateTime :created_at, default: Sequel::CURRENT_TIMESTAMP\r\nDateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP\r\nString   :json, null: false, type: 'json'\r\n\r\nforeign_key :user_id, :users, type: :uuid, null: false, on_delete: :cascade\r\nforeign_key :visualization_id, :visualizations, type: :uuid, null: false, on_delete: :cascade\r\n\r\nadd_index [:user_id, :visualization_id]\r\n```\r\n\r\nThis model is associated to a vis and a user (see snapshots feature design in consideration). In this implementation, there is one, global, state for evert vis that can only be updated (`.../vis/:id/state`). Updates are triggered by viewport or widget changes.\r\n\r\n## Considerations\r\n\r\nIt should be considered that this same model will be reused for upcoming snapshots feature, by which different users will be able to save different embed states and interact with them (like 10 per user/vis). Although it will use the same model, it will be an entirely different endpoint (a normal CRUD).\r\n\r\nPlease review the front end @xavijam \r\nPlease review the back end @javitonino and @juanignaciosl (in that order, I expect a lot of design comments.","created_at":"2016-08-09T12:37:45Z","updated_at":"2016-08-18T13:49:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d25ee726f1bbb34e5e65411c87bfb3f3d44b972f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374/commits","review_comments_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374/comments","review_comment_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/issues/9374/comments","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/3df01af0c31ab36039eb65a688809b284e27d620","head":{"label":"CartoDB:state","ref":"state","sha":"3df01af0c31ab36039eb65a688809b284e27d620","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-08-18T05:47:53Z","pushed_at":"2016-08-18T13:38:24Z","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://carto.com","size":398667,"stargazers_count":1233,"watchers_count":1233,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":312,"mirror_url":null,"open_issues_count":1076,"forks":312,"open_issues":1076,"watchers":1233,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"e659d20e2877725077e4ae7fc1db6863140fc239","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-08-18T05:47:53Z","pushed_at":"2016-08-18T13:38:24Z","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://carto.com","size":398667,"stargazers_count":1233,"watchers_count":1233,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":312,"mirror_url":null,"open_issues_count":1076,"forks":312,"open_issues":1076,"watchers":1233,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/9374"},"issue":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/9374"},"comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/9374/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/9374/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/cartodb/statuses/3df01af0c31ab36039eb65a688809b284e27d620"}}}}
{"actor":{"display_login":"javitonino"}}