{"action":"created","comment":{"url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/comments/23784424","id":23784424,"diff_hunk":"@@ -1,13 +1,64 @@\n class Step\n   include Mongoid::Document\n-  include Mongoid::Orderable\n+  include Mongoid::Timestamps\n \n   MESSAGE_TYPES = %w(single_command read_status pin_write move_abs move_rel)\n \n   embedded_in :sequence\n-  orderable base: 0\n+\n   field :message_type\n   validates :message_type, presence: true\n \n   field :command, type: Hash, default: {}\n+  field :position, type: Integer, default: -> do\n+    (self.try(:sequence).try(:steps).try(:size) || 1) - 1 || 0\n+  end\n+  validates :position, presence: true\n+  # TODO : Move this into a refinement =========================================\n+\n+  def all_steps\n+    (sequence.try(:steps) || Step.none).order_by(:position.asc)\n+  end\n+\n+  def move_to!(position)\n+    new_steps = all_steps.to_a\n+    new_steps.delete_at(new_steps.index(self))\n+    new_steps.insert(position, self)\n+    new_steps.each_with_index do |step, index|\n+      step.position = index\n+      step.save!\n+    end\n+  end\n+\n+  def untangle!\n+    passed_self = false\n+    all_steps.each_with_index do |step, i|\n+      passed_self = true && next if step == self\n+      step.position = i\n+      step.position += 1 if passed_self\n+      step.save!\n+    end\n+  end\n+\n+  def reshuffle!\n+    all_steps.each_with_index do |step, index|\n+      step.position = index\n+      step.save!\n+    end\n+  end\n+\n+  def destroy(*args)\n+    result = super(*args)\n+    self.reshuffle!\n+    result\n+  end\n+\n+  def set_relation(name, relation)\n+    if name == 'sequence' && self.sequence.present?","path":"app/models/step.rb","position":59,"original_position":59,"commit_id":"d3d046847ee1f300edf62e844979cfbc320fc78f","original_commit_id":"d3d046847ee1f300edf62e844979cfbc320fc78f","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Redundant `self` detected.","created_at":"2015-01-29T17:18:05Z","updated_at":"2015-01-29T17:18:05Z","html_url":"https://github.com/FarmBot/farmbot-web-app/pull/131#discussion_r23784424","pull_request_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131","_links":{"self":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/comments/23784424"},"html":{"href":"https://github.com/FarmBot/farmbot-web-app/pull/131#discussion_r23784424"},"pull_request":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131"}}},"pull_request":{"url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131","id":28297046,"html_url":"https://github.com/FarmBot/farmbot-web-app/pull/131","diff_url":"https://github.com/FarmBot/farmbot-web-app/pull/131.diff","patch_url":"https://github.com/FarmBot/farmbot-web-app/pull/131.patch","issue_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues/131","number":131,"state":"open","locked":false,"title":"Issues with caching of step sort data","user":{"login":"RickCarlino","id":1388608,"avatar_url":"https://avatars.githubusercontent.com/u/1388608?v=3","gravatar_id":"","url":"https://api.github.com/users/RickCarlino","html_url":"https://github.com/RickCarlino","followers_url":"https://api.github.com/users/RickCarlino/followers","following_url":"https://api.github.com/users/RickCarlino/following{/other_user}","gists_url":"https://api.github.com/users/RickCarlino/gists{/gist_id}","starred_url":"https://api.github.com/users/RickCarlino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RickCarlino/subscriptions","organizations_url":"https://api.github.com/users/RickCarlino/orgs","repos_url":"https://api.github.com/users/RickCarlino/repos","events_url":"https://api.github.com/users/RickCarlino/events{/privacy}","received_events_url":"https://api.github.com/users/RickCarlino/received_events","type":"User","site_admin":false},"body":"# What's New?\r\n\r\n * Upgrade lodash\r\n * Ditch mongoid-sortable in favor of handrolled solution\r\n * Cruft cleanup in the sequence controller (angular)\r\n * Add show action for steps\r\n * Wrote the most detailed test spec you've ever seen in your life.\r\n\r\n# What's Next?\r\n\r\n * Figure out why sorting is acting up on the front end.","created_at":"2015-01-29T17:17:58Z","updated_at":"2015-01-29T17:18:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b5064de870da6d6cc0b0e12fa43598088cda2ffd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131/commits","review_comments_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131/comments","review_comment_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/comments/{number}","comments_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues/131/comments","statuses_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/statuses/d3d046847ee1f300edf62e844979cfbc320fc78f","head":{"label":"RickCarlino:master","ref":"master","sha":"d3d046847ee1f300edf62e844979cfbc320fc78f","user":{"login":"RickCarlino","id":1388608,"avatar_url":"https://avatars.githubusercontent.com/u/1388608?v=3","gravatar_id":"","url":"https://api.github.com/users/RickCarlino","html_url":"https://github.com/RickCarlino","followers_url":"https://api.github.com/users/RickCarlino/followers","following_url":"https://api.github.com/users/RickCarlino/following{/other_user}","gists_url":"https://api.github.com/users/RickCarlino/gists{/gist_id}","starred_url":"https://api.github.com/users/RickCarlino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RickCarlino/subscriptions","organizations_url":"https://api.github.com/users/RickCarlino/orgs","repos_url":"https://api.github.com/users/RickCarlino/repos","events_url":"https://api.github.com/users/RickCarlino/events{/privacy}","received_events_url":"https://api.github.com/users/RickCarlino/received_events","type":"User","site_admin":false},"repo":{"id":17667164,"name":"farmbot-web-app","full_name":"RickCarlino/farmbot-web-app","owner":{"login":"RickCarlino","id":1388608,"avatar_url":"https://avatars.githubusercontent.com/u/1388608?v=3","gravatar_id":"","url":"https://api.github.com/users/RickCarlino","html_url":"https://github.com/RickCarlino","followers_url":"https://api.github.com/users/RickCarlino/followers","following_url":"https://api.github.com/users/RickCarlino/following{/other_user}","gists_url":"https://api.github.com/users/RickCarlino/gists{/gist_id}","starred_url":"https://api.github.com/users/RickCarlino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RickCarlino/subscriptions","organizations_url":"https://api.github.com/users/RickCarlino/orgs","repos_url":"https://api.github.com/users/RickCarlino/repos","events_url":"https://api.github.com/users/RickCarlino/events{/privacy}","received_events_url":"https://api.github.com/users/RickCarlino/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RickCarlino/farmbot-web-app","description":"A web based decision support system for controlling FarmBot.","fork":true,"url":"https://api.github.com/repos/RickCarlino/farmbot-web-app","forks_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/forks","keys_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/teams","hooks_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/hooks","issue_events_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/issues/events{/number}","events_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/events","assignees_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/assignees{/user}","branches_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/branches{/branch}","tags_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/tags","blobs_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/statuses/{sha}","languages_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/languages","stargazers_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/stargazers","contributors_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/contributors","subscribers_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/subscribers","subscription_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/subscription","commits_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/issues/comments/{number}","contents_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/contents/{+path}","compare_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/merges","archive_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/downloads","issues_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/issues{/number}","pulls_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/pulls{/number}","milestones_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/milestones{/number}","notifications_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/labels{/name}","releases_url":"https://api.github.com/repos/RickCarlino/farmbot-web-app/releases{/id}","created_at":"2014-03-12T13:04:56Z","updated_at":"2015-01-29T17:07:52Z","pushed_at":"2015-01-29T17:07:52Z","git_url":"git://github.com/RickCarlino/farmbot-web-app.git","ssh_url":"git@github.com:RickCarlino/farmbot-web-app.git","clone_url":"https://github.com/RickCarlino/farmbot-web-app.git","svn_url":"https://github.com/RickCarlino/farmbot-web-app","homepage":null,"size":2717,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"FarmBot:master","ref":"master","sha":"90caeb0e3d8dc1decac0527b69846e3a13dca40a","user":{"login":"FarmBot","id":5784869,"avatar_url":"https://avatars.githubusercontent.com/u/5784869?v=3","gravatar_id":"","url":"https://api.github.com/users/FarmBot","html_url":"https://github.com/FarmBot","followers_url":"https://api.github.com/users/FarmBot/followers","following_url":"https://api.github.com/users/FarmBot/following{/other_user}","gists_url":"https://api.github.com/users/FarmBot/gists{/gist_id}","starred_url":"https://api.github.com/users/FarmBot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FarmBot/subscriptions","organizations_url":"https://api.github.com/users/FarmBot/orgs","repos_url":"https://api.github.com/users/FarmBot/repos","events_url":"https://api.github.com/users/FarmBot/events{/privacy}","received_events_url":"https://api.github.com/users/FarmBot/received_events","type":"Organization","site_admin":false},"repo":{"id":17652873,"name":"farmbot-web-app","full_name":"FarmBot/farmbot-web-app","owner":{"login":"FarmBot","id":5784869,"avatar_url":"https://avatars.githubusercontent.com/u/5784869?v=3","gravatar_id":"","url":"https://api.github.com/users/FarmBot","html_url":"https://github.com/FarmBot","followers_url":"https://api.github.com/users/FarmBot/followers","following_url":"https://api.github.com/users/FarmBot/following{/other_user}","gists_url":"https://api.github.com/users/FarmBot/gists{/gist_id}","starred_url":"https://api.github.com/users/FarmBot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FarmBot/subscriptions","organizations_url":"https://api.github.com/users/FarmBot/orgs","repos_url":"https://api.github.com/users/FarmBot/repos","events_url":"https://api.github.com/users/FarmBot/events{/privacy}","received_events_url":"https://api.github.com/users/FarmBot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FarmBot/farmbot-web-app","description":"Manages user data, account information, credentials of hardware ownership; takes the schedule of operations from the DSS and sends it to raspberry-pi-controller via the SkyNet platform; receives data from bot via SkyNet and stores it; other services such as user account creation, email alerts, etc","fork":false,"url":"https://api.github.com/repos/FarmBot/farmbot-web-app","forks_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/forks","keys_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/teams","hooks_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/hooks","issue_events_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues/events{/number}","events_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/events","assignees_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/assignees{/user}","branches_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/branches{/branch}","tags_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/tags","blobs_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/statuses/{sha}","languages_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/languages","stargazers_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/stargazers","contributors_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/contributors","subscribers_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/subscribers","subscription_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/subscription","commits_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues/comments/{number}","contents_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/contents/{+path}","compare_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/merges","archive_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/downloads","issues_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues{/number}","pulls_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls{/number}","milestones_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/milestones{/number}","notifications_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/labels{/name}","releases_url":"https://api.github.com/repos/FarmBot/farmbot-web-app/releases{/id}","created_at":"2014-03-12T02:38:25Z","updated_at":"2015-01-28T15:23:17Z","pushed_at":"2015-01-28T15:23:15Z","git_url":"git://github.com/FarmBot/farmbot-web-app.git","ssh_url":"git@github.com:FarmBot/farmbot-web-app.git","clone_url":"https://github.com/FarmBot/farmbot-web-app.git","svn_url":"https://github.com/FarmBot/farmbot-web-app","homepage":"","size":2749,"stargazers_count":20,"watchers_count":20,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":46,"forks":12,"open_issues":46,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131"},"html":{"href":"https://github.com/FarmBot/farmbot-web-app/pull/131"},"issue":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues/131"},"comments":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/issues/131/comments"},"review_comments":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131/comments"},"review_comment":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/pulls/131/commits"},"statuses":{"href":"https://api.github.com/repos/FarmBot/farmbot-web-app/statuses/d3d046847ee1f300edf62e844979cfbc320fc78f"}}}}