{"action":"created","comment":{"url":"https://api.github.com/repos/vijos/vj4/pulls/comments/67707724","id":67707724,"diff_hunk":"@@ -0,0 +1,448 @@\n+import React from 'react';\n+import './ide.styl';\n+import Codemirror from 'react-codemirror';\n+import ResultItem from './resultitem';\n+import _ from 'lodash';\n+import sockJS from 'sockjs-client';\n+import { post } from '../../misc/Util';\n+\n+import 'codemirror/mode/clike/clike';\n+import 'codemirror/mode/pascal/pascal';\n+import 'codemirror/mode/python/python';\n+import 'codemirror/mode/javascript/javascript';\n+import 'codemirror/mode/ruby/ruby';\n+import 'codemirror/mode/php/php';\n+\n+class Ide extends React.Component {\n+\n+  static supportLangTypes = {\n+    c: 'C',\n+    cc: 'C++',\n+    pas: 'Pascal',\n+    java: 'Java',\n+    cs: 'C#',\n+    py: 'Python 2.x',\n+    py3: 'Python 3',\n+    js: 'JavaScript',\n+    php: 'PHP',\n+    ruby: 'Ruby',\n+  }\n+\n+  static mapLangToMode = {\n+    c: 'text/x-csrc',\n+    cc: 'text/x-c++src',\n+    pas: 'text/x-pascal',\n+    java: 'text/x-java',\n+    cs: 'text/x-csharp',\n+    py: {\n+      name: 'text/x-cython',\n+      version: 2,\n+      singleLineStringErrors: false,\n+    },\n+    py3: {\n+      name: 'python',\n+      version: 3,\n+      singleLineStringErrors: false,\n+    },\n+    js: 'text/javascript',\n+    php: 'text/x-php',\n+    ruby: 'text/x-ruby',\n+  }\n+\n+  static spanSupportLanguageList() {\n+    const ret = [];\n+    let i = 0;\n+    for (let key of Object.keys(Ide.supportLangTypes)) {\n+      ret.push(<option value={key} key={i}>{Ide.supportLangTypes[key]}</option>);\n+      i += 1;\n+    }\n+    return ret;\n+  }\n+\n+  constructor(props) {\n+    super(props);\n+    this.state = {\n+      displayTesting: false,\n+      displayEvalutating: false,\n+      code: '',\n+      currentTestingInputText: '',\n+      currentTestingOutputText: '',\n+      language: 'c',\n+      testingData: [],\n+      resultData: [],\n+      currentActiveTabIndex: -1,\n+    };\n+    this.sock = null;\n+  }\n+\n+  componentDidMount() {\n+    if (!this.sock) {\n+      this.sock = sockJS('/records-conn');\n+      const self = this;\n+      this.sock.onmessage = (message) => {\n+        const nextResultData = self.state.resultData.slice();\n+        const rdoc = JSON.parse(message.data).rdoc;\n+        const existedRdoc = nextResultData.filter(val => val._id === rdoc._id)[0];\n+        if (existedRdoc) {\n+          const idx = nextResultData.indexOf(existedRdoc);\n+          nextResultData[idx] = rdoc;\n+        } else {\n+          nextResultData.unshift(rdoc);\n+        }\n+        return self.setState({\n+          resultData: nextResultData,\n+        });\n+      };\n+    }\n+  }\n+\n+  onLeaveIDEMode() {\n+    if (window.confirm('确认退出IDE模式吗？')) {\n+      $('body').removeClass('ide-mode');\n+      window.location.hash = '';\n+    }\n+  }\n+\n+  onLanguageChange(ev) {\n+    // console.log(this.refs.editor.getCodeMirror());\n+    this.setState({\n+      language: ev.target.value,\n+    });\n+    this.refs.editor.getCodeMirror().setOption('mode', Ide.mapLangToMode[ev.target.value]);\n+  }\n+\n+  onCodeUpdate(newCode) {\n+    this.setState({\n+      code: newCode,\n+    });\n+  }\n+\n+  onAddTestCase(ev, cb = () => {}) {\n+    const newTestcase = {\n+      input: '',\n+      output: '',\n+    };\n+    const nextTestingData = _.cloneDeep(this.state.testingData);\n+    nextTestingData.push(newTestcase);\n+    this.setState({\n+      currentTestingInputText: '',\n+      currentTestingOutputText: '',\n+      testingData: nextTestingData,\n+      currentActiveTabIndex: nextTestingData.length - 1,\n+    }, cb);\n+  }\n+\n+  onDeleteTestCase() {\n+    const nextTestingData = _.cloneDeep(this.state.testingData);\n+    nextTestingData.splice(this.state.currentActiveTabIndex, 1);\n+    let nextActiveTabIndex = 0;\n+\n+    if ((this.state.currentActiveTabIndex === 0) && (this.state.testingData.length !== 1)) {\n+      nextActiveTabIndex = 0;\n+    } else if ((this.state.currentActiveTabIndex === 0) && (this.state.testingData.length === 1)) {\n+      return this.setState({\n+        currentTestingInputText: '',\n+        currentTestingOutputText: '',\n+        testingData: [],\n+        currentActiveTabIndex: -1,\n+      });\n+    } else {\n+      nextActiveTabIndex = this.state.currentActiveTabIndex - 1;\n+    }\n+    return this.setState({\n+      testingData: nextTestingData,\n+      currentActiveTabIndex: nextActiveTabIndex,\n+      currentTestingInputText: nextTestingData[nextActiveTabIndex].input,\n+      currentTestingOutputText: nextTestingData[nextActiveTabIndex].output,\n+    });\n+  }\n+\n+  onClickTestCaseTab(idx) {\n+    return () => {\n+      this.setState({\n+        currentActiveTabIndex: idx,\n+        currentTestingInputText: this.state.testingData[idx].input,\n+        currentTestingOutputText: this.state.testingData[idx].output,\n+      });\n+    };\n+  }\n+\n+  onUpdateTestingCaseInput(ev) {","path":"vj4/ui/components/ide/ide.js","position":170,"original_position":170,"commit_id":"f04f3ccd9bf40ca59f3db381a1d4dc54a78bf4de","original_commit_id":"f04f3ccd9bf40ca59f3db381a1d4dc54a78bf4de","user":{"login":"SummerWish","id":1916485,"avatar_url":"https://avatars.githubusercontent.com/u/1916485?v=3","gravatar_id":"","url":"https://api.github.com/users/SummerWish","html_url":"https://github.com/SummerWish","followers_url":"https://api.github.com/users/SummerWish/followers","following_url":"https://api.github.com/users/SummerWish/following{/other_user}","gists_url":"https://api.github.com/users/SummerWish/gists{/gist_id}","starred_url":"https://api.github.com/users/SummerWish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SummerWish/subscriptions","organizations_url":"https://api.github.com/users/SummerWish/orgs","repos_url":"https://api.github.com/users/SummerWish/repos","events_url":"https://api.github.com/users/SummerWish/events{/privacy}","received_events_url":"https://api.github.com/users/SummerWish/received_events","type":"User","site_admin":false},"body":"the behaviour of input and output is almost the same. reduce to one function.","created_at":"2016-06-20T15:14:40Z","updated_at":"2016-06-20T15:14:40Z","html_url":"https://github.com/vijos/vj4/pull/18#discussion_r67707724","pull_request_url":"https://api.github.com/repos/vijos/vj4/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/vijos/vj4/pulls/comments/67707724"},"html":{"href":"https://github.com/vijos/vj4/pull/18#discussion_r67707724"},"pull_request":{"href":"https://api.github.com/repos/vijos/vj4/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/vijos/vj4/pulls/18","id":74454104,"html_url":"https://github.com/vijos/vj4/pull/18","diff_url":"https://github.com/vijos/vj4/pull/18.diff","patch_url":"https://github.com/vijos/vj4/pull/18.patch","issue_url":"https://api.github.com/repos/vijos/vj4/issues/18","number":18,"state":"open","locked":false,"title":"IDE mode for feature pretest","user":{"login":"JoshOY","id":6657354,"avatar_url":"https://avatars.githubusercontent.com/u/6657354?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshOY","html_url":"https://github.com/JoshOY","followers_url":"https://api.github.com/users/JoshOY/followers","following_url":"https://api.github.com/users/JoshOY/following{/other_user}","gists_url":"https://api.github.com/users/JoshOY/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshOY/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshOY/subscriptions","organizations_url":"https://api.github.com/users/JoshOY/orgs","repos_url":"https://api.github.com/users/JoshOY/repos","events_url":"https://api.github.com/users/JoshOY/events{/privacy}","received_events_url":"https://api.github.com/users/JoshOY/received_events","type":"User","site_admin":false},"body":"@SummerWish ","created_at":"2016-06-20T14:38:22Z","updated_at":"2016-06-20T15:14:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52c821813128bfe9ca9fb057a81a0f3171402a89","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/vijos/vj4/pulls/18/commits","review_comments_url":"https://api.github.com/repos/vijos/vj4/pulls/18/comments","review_comment_url":"https://api.github.com/repos/vijos/vj4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vijos/vj4/issues/18/comments","statuses_url":"https://api.github.com/repos/vijos/vj4/statuses/f04f3ccd9bf40ca59f3db381a1d4dc54a78bf4de","head":{"label":"JoshOY:master","ref":"master","sha":"f04f3ccd9bf40ca59f3db381a1d4dc54a78bf4de","user":{"login":"JoshOY","id":6657354,"avatar_url":"https://avatars.githubusercontent.com/u/6657354?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshOY","html_url":"https://github.com/JoshOY","followers_url":"https://api.github.com/users/JoshOY/followers","following_url":"https://api.github.com/users/JoshOY/following{/other_user}","gists_url":"https://api.github.com/users/JoshOY/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshOY/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshOY/subscriptions","organizations_url":"https://api.github.com/users/JoshOY/orgs","repos_url":"https://api.github.com/users/JoshOY/repos","events_url":"https://api.github.com/users/JoshOY/events{/privacy}","received_events_url":"https://api.github.com/users/JoshOY/received_events","type":"User","site_admin":false},"repo":{"id":61085889,"name":"vj4","full_name":"JoshOY/vj4","owner":{"login":"JoshOY","id":6657354,"avatar_url":"https://avatars.githubusercontent.com/u/6657354?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshOY","html_url":"https://github.com/JoshOY","followers_url":"https://api.github.com/users/JoshOY/followers","following_url":"https://api.github.com/users/JoshOY/following{/other_user}","gists_url":"https://api.github.com/users/JoshOY/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshOY/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshOY/subscriptions","organizations_url":"https://api.github.com/users/JoshOY/orgs","repos_url":"https://api.github.com/users/JoshOY/repos","events_url":"https://api.github.com/users/JoshOY/events{/privacy}","received_events_url":"https://api.github.com/users/JoshOY/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JoshOY/vj4","description":"Next generation Vijos. Built with asyncio on Python 3.5.","fork":true,"url":"https://api.github.com/repos/JoshOY/vj4","forks_url":"https://api.github.com/repos/JoshOY/vj4/forks","keys_url":"https://api.github.com/repos/JoshOY/vj4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JoshOY/vj4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JoshOY/vj4/teams","hooks_url":"https://api.github.com/repos/JoshOY/vj4/hooks","issue_events_url":"https://api.github.com/repos/JoshOY/vj4/issues/events{/number}","events_url":"https://api.github.com/repos/JoshOY/vj4/events","assignees_url":"https://api.github.com/repos/JoshOY/vj4/assignees{/user}","branches_url":"https://api.github.com/repos/JoshOY/vj4/branches{/branch}","tags_url":"https://api.github.com/repos/JoshOY/vj4/tags","blobs_url":"https://api.github.com/repos/JoshOY/vj4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JoshOY/vj4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JoshOY/vj4/git/refs{/sha}","trees_url":"https://api.github.com/repos/JoshOY/vj4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JoshOY/vj4/statuses/{sha}","languages_url":"https://api.github.com/repos/JoshOY/vj4/languages","stargazers_url":"https://api.github.com/repos/JoshOY/vj4/stargazers","contributors_url":"https://api.github.com/repos/JoshOY/vj4/contributors","subscribers_url":"https://api.github.com/repos/JoshOY/vj4/subscribers","subscription_url":"https://api.github.com/repos/JoshOY/vj4/subscription","commits_url":"https://api.github.com/repos/JoshOY/vj4/commits{/sha}","git_commits_url":"https://api.github.com/repos/JoshOY/vj4/git/commits{/sha}","comments_url":"https://api.github.com/repos/JoshOY/vj4/comments{/number}","issue_comment_url":"https://api.github.com/repos/JoshOY/vj4/issues/comments{/number}","contents_url":"https://api.github.com/repos/JoshOY/vj4/contents/{+path}","compare_url":"https://api.github.com/repos/JoshOY/vj4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JoshOY/vj4/merges","archive_url":"https://api.github.com/repos/JoshOY/vj4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JoshOY/vj4/downloads","issues_url":"https://api.github.com/repos/JoshOY/vj4/issues{/number}","pulls_url":"https://api.github.com/repos/JoshOY/vj4/pulls{/number}","milestones_url":"https://api.github.com/repos/JoshOY/vj4/milestones{/number}","notifications_url":"https://api.github.com/repos/JoshOY/vj4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JoshOY/vj4/labels{/name}","releases_url":"https://api.github.com/repos/JoshOY/vj4/releases{/id}","deployments_url":"https://api.github.com/repos/JoshOY/vj4/deployments","created_at":"2016-06-14T02:36:01Z","updated_at":"2016-06-14T02:36:02Z","pushed_at":"2016-06-20T14:37:21Z","git_url":"git://github.com/JoshOY/vj4.git","ssh_url":"git@github.com:JoshOY/vj4.git","clone_url":"https://github.com/JoshOY/vj4.git","svn_url":"https://github.com/JoshOY/vj4","homepage":"https://vijos.org","size":2520,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"vijos:feature-duipai","ref":"feature-duipai","sha":"f303a640373cc6afe1bf74cd94c01551eb8541dc","user":{"login":"vijos","id":4272237,"avatar_url":"https://avatars.githubusercontent.com/u/4272237?v=3","gravatar_id":"","url":"https://api.github.com/users/vijos","html_url":"https://github.com/vijos","followers_url":"https://api.github.com/users/vijos/followers","following_url":"https://api.github.com/users/vijos/following{/other_user}","gists_url":"https://api.github.com/users/vijos/gists{/gist_id}","starred_url":"https://api.github.com/users/vijos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijos/subscriptions","organizations_url":"https://api.github.com/users/vijos/orgs","repos_url":"https://api.github.com/users/vijos/repos","events_url":"https://api.github.com/users/vijos/events{/privacy}","received_events_url":"https://api.github.com/users/vijos/received_events","type":"Organization","site_admin":false},"repo":{"id":58306028,"name":"vj4","full_name":"vijos/vj4","owner":{"login":"vijos","id":4272237,"avatar_url":"https://avatars.githubusercontent.com/u/4272237?v=3","gravatar_id":"","url":"https://api.github.com/users/vijos","html_url":"https://github.com/vijos","followers_url":"https://api.github.com/users/vijos/followers","following_url":"https://api.github.com/users/vijos/following{/other_user}","gists_url":"https://api.github.com/users/vijos/gists{/gist_id}","starred_url":"https://api.github.com/users/vijos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijos/subscriptions","organizations_url":"https://api.github.com/users/vijos/orgs","repos_url":"https://api.github.com/users/vijos/repos","events_url":"https://api.github.com/users/vijos/events{/privacy}","received_events_url":"https://api.github.com/users/vijos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vijos/vj4","description":"Next generation Vijos. Built with asyncio on Python 3.5.","fork":false,"url":"https://api.github.com/repos/vijos/vj4","forks_url":"https://api.github.com/repos/vijos/vj4/forks","keys_url":"https://api.github.com/repos/vijos/vj4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vijos/vj4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vijos/vj4/teams","hooks_url":"https://api.github.com/repos/vijos/vj4/hooks","issue_events_url":"https://api.github.com/repos/vijos/vj4/issues/events{/number}","events_url":"https://api.github.com/repos/vijos/vj4/events","assignees_url":"https://api.github.com/repos/vijos/vj4/assignees{/user}","branches_url":"https://api.github.com/repos/vijos/vj4/branches{/branch}","tags_url":"https://api.github.com/repos/vijos/vj4/tags","blobs_url":"https://api.github.com/repos/vijos/vj4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vijos/vj4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vijos/vj4/git/refs{/sha}","trees_url":"https://api.github.com/repos/vijos/vj4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vijos/vj4/statuses/{sha}","languages_url":"https://api.github.com/repos/vijos/vj4/languages","stargazers_url":"https://api.github.com/repos/vijos/vj4/stargazers","contributors_url":"https://api.github.com/repos/vijos/vj4/contributors","subscribers_url":"https://api.github.com/repos/vijos/vj4/subscribers","subscription_url":"https://api.github.com/repos/vijos/vj4/subscription","commits_url":"https://api.github.com/repos/vijos/vj4/commits{/sha}","git_commits_url":"https://api.github.com/repos/vijos/vj4/git/commits{/sha}","comments_url":"https://api.github.com/repos/vijos/vj4/comments{/number}","issue_comment_url":"https://api.github.com/repos/vijos/vj4/issues/comments{/number}","contents_url":"https://api.github.com/repos/vijos/vj4/contents/{+path}","compare_url":"https://api.github.com/repos/vijos/vj4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vijos/vj4/merges","archive_url":"https://api.github.com/repos/vijos/vj4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vijos/vj4/downloads","issues_url":"https://api.github.com/repos/vijos/vj4/issues{/number}","pulls_url":"https://api.github.com/repos/vijos/vj4/pulls{/number}","milestones_url":"https://api.github.com/repos/vijos/vj4/milestones{/number}","notifications_url":"https://api.github.com/repos/vijos/vj4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vijos/vj4/labels{/name}","releases_url":"https://api.github.com/repos/vijos/vj4/releases{/id}","deployments_url":"https://api.github.com/repos/vijos/vj4/deployments","created_at":"2016-05-08T09:55:54Z","updated_at":"2016-06-06T11:31:33Z","pushed_at":"2016-06-20T14:38:31Z","git_url":"git://github.com/vijos/vj4.git","ssh_url":"git@github.com:vijos/vj4.git","clone_url":"https://github.com/vijos/vj4.git","svn_url":"https://github.com/vijos/vj4","homepage":"https://vijos.org","size":2520,"stargazers_count":24,"watchers_count":24,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":9,"forks":3,"open_issues":9,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vijos/vj4/pulls/18"},"html":{"href":"https://github.com/vijos/vj4/pull/18"},"issue":{"href":"https://api.github.com/repos/vijos/vj4/issues/18"},"comments":{"href":"https://api.github.com/repos/vijos/vj4/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/vijos/vj4/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/vijos/vj4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vijos/vj4/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/vijos/vj4/statuses/f04f3ccd9bf40ca59f3db381a1d4dc54a78bf4de"}}}}
{"actor":{"display_login":"SummerWish"}}