GitHub PullRequestReviewCommentEvent at 2014-01-02 10:09:27
Repository: jsoneditor
Actor: QuentinFchx
Payload: {"comment":{"url":"https://api.github.com/repos/Work4Labs/jsoneditor/pulls/comments/8609961","id":8609961,"diff_hunk":"@@ -2729,23 +2743,38 @@ Node.prototype.showContextMenu = function (anchor, onClose) {\n     });\n   }\n \n-  if(node.hasOwnProperty('parent') && node.parent.field === undefined) {\n-    console.log(\"parent is unknown so no specific context menu here!\");\n-  }\n-  else if(node.hasOwnProperty('parent') && node.parent.hasOwnProperty('field')) {\n-    console.log(\"parent is: \" + node.parent.field + \"\\npossible children:\");\n-    var possible_children = this.editor.map_schema[node.parent.field];\n-    console.log(possible_children);\n-  }\n-  else {\n-    console.log(\"parent is the root, so no context menu here!\");\n-  }\n-\n-\n   var menu = new ContextMenu(items, {close: onClose});\n   menu.show(anchor);\n };\n \n+Node.prototype._addItemsToMenu = function (possible_children, menu, onclick)\n+{\n+  var separator = {'type': 'separator'};\n+  var items_retrieved = this._analyseSchema(possible_children, onclick);\n+  menu.submenu = menu.submenu.concat(separator).concat(items_retrieved);\n+};\n+\n+Node.prototype._analyseSchema = function (schema, onclick)\n+{\n+  var items = [];\n+  schema.forEach(function(obj) {\n+    var text = obj.id;\n+    var title = text;\n+    var class_name = ['array', 'string', 'object'].indexOf(obj.type) < 0 ? \"type-auto\" : \"type-\" + obj.type;\n+    var value = {};\n+    if(obj.default === undefined)\n+      switch(obj.type)\n+      {\n+        case \"object\": value = {}; break;\n+        case \"array\" : value = []; break;\n+        case \"string\": value = \"\"; break;\n+      }\n+    else value = obj.default;\n+    items.push({\"text\": text, \"className\": class_name, \"title\": title , \"value\": value, 'click': onclick});","path":"jsoneditor/js/node.js","position":95,"original_position":95,"commit_id":"ba9db50108347e20b43bd31a553c0dc58639ca88","original_commit_id":"ba9db50108347e20b43bd31a553c0dc58639ca88","user":{"login":"QuentinFchx","id":3251963,"avatar_url":"https://gravatar.com/avatar/fdb0ef6207d29146db52a12aadca6b7d?d=https%3A%2F%2Fidenticons.github.com%2F14a9fa2ff6b29f4afc8d9e70df41c1a5.png&r=x","gravatar_id":"fdb0ef6207d29146db52a12aadca6b7d","url":"https://api.github.com/users/QuentinFchx","html_url":"https://github.com/QuentinFchx","followers_url":"https://api.github.com/users/QuentinFchx/followers","following_url":"https://api.github.com/users/QuentinFchx/following{/other_user}","gists_url":"https://api.github.com/users/QuentinFchx/gists{/gist_id}","starred_url":"https://api.github.com/users/QuentinFchx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuentinFchx/subscriptions","organizations_url":"https://api.github.com/users/QuentinFchx/orgs","repos_url":"https://api.github.com/users/QuentinFchx/repos","events_url":"https://api.github.com/users/QuentinFchx/events{/privacy}","received_events_url":"https://api.github.com/users/QuentinFchx/received_events","type":"User","site_admin":false},"body":"Add line-breaks after commas to make it more readable (same for the switch statement above)","created_at":"2014-01-02T10:09:27Z","updated_at":"2014-01-02T10:09:27Z","html_url":"https://github.com/Work4Labs/jsoneditor/pull/5#discussion_r8609961","pull_request_url":"https://api.github.com/repos/Work4Labs/jsoneditor/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/Work4Labs/jsoneditor/pulls/comments/8609961"},"html":{"href":"https://github.com/Work4Labs/jsoneditor/pull/5#discussion_r8609961"},"pull_request":{"href":"https://api.github.com/repos/Work4Labs/jsoneditor/pulls/5"}}}}