From cd7dfb725a408a9c31d531e70dd726cafeafefe3 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 15:51:48 +0800 Subject: [PATCH 1/8] #71 --- static/js/wide.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/static/js/wide.js b/static/js/wide.js index cca4ae5..f735aa2 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -496,7 +496,38 @@ var wide = { }, // 构建. build: function () { - // TODO: 构建 + var currentPath = editors.getCurrentPath(); + if (!currentPath) { + return false; + } + + if ($(".menu li.run").hasClass("disabled")) { + return false; + } + + if ($(".toolbars .ico-stop").length === 1) { + wide.stop(); + return false; + } + + var request = newWideRequest(); + request.file = currentPath; + request.code = wide.curEditor.getValue(); + request.nextCmd = ""; // 只构建,无下一步操作 + + $.ajax({ + type: 'POST', + url: '/build', + data: JSON.stringify(request), + dataType: "json", + beforeSend: function (data) { + $('.bottom-window-group .output').text(''); + }, + success: function (data) { + $(".toolbars .ico-buildrun").addClass("ico-stop") + .removeClass("ico-buildrun").attr("title", config.label.stop); + } + }); }, // 构建并运行. run: function () { @@ -517,6 +548,7 @@ var wide = { var request = newWideRequest(); request.file = currentPath; request.code = wide.curEditor.getValue(); + request.nextCmd = "run"; $.ajax({ type: 'POST', From 16a0748451820c8333d5a90bddb6fad59b2a7c45 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 15:57:51 +0800 Subject: [PATCH 2/8] #71 --- main.go | 7 +++++++ output/outputs.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c0e9ade..1630105 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,13 @@ func init() { // 定时检查无效会话 session.FixedTimeRelease() + + // 定时输出日志(TODO: 后面考虑换一个日志库) + go func() { + for _ = range time.Tick(time.Second) { + glog.Flush() + } + }() } // 登录. diff --git a/output/outputs.go b/output/outputs.go index f595645..1436d76 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -115,7 +115,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { glog.V(3).Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath) - // 在读取程序输出前先返回一次,使前端获取到 run 状态以及对应的 pid + // 在读取程序输出前先返回一次,使前端获取到 run 状态与 pid if nil != session.OutputWS[sid] { wsChannel := session.OutputWS[sid] @@ -289,7 +289,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { if 0 == count { // 说明构建成功,没有错误信息输出 // 设置下一次执行命令(前端会根据这个发送请求) - channelRet["nextCmd"] = "run" + channelRet["nextCmd"] = args["nextCmd"] go func() { // 运行 go install,生成的库用于 gocode lib-path cmd := exec.Command("go", "install") From c2c6ab7ff1b62dc1182d32af486eeb525f46fb3b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 16:29:49 +0800 Subject: [PATCH 3/8] . --- main.go | 7 ------- static/js/wide.js | 9 --------- 2 files changed, 16 deletions(-) diff --git a/main.go b/main.go index 1630105..c0e9ade 100644 --- a/main.go +++ b/main.go @@ -48,13 +48,6 @@ func init() { // 定时检查无效会话 session.FixedTimeRelease() - - // 定时输出日志(TODO: 后面考虑换一个日志库) - go func() { - for _ = range time.Tick(time.Second) { - glog.Flush() - } - }() } // 登录. diff --git a/static/js/wide.js b/static/js/wide.js index f735aa2..95826a0 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -501,15 +501,6 @@ var wide = { return false; } - if ($(".menu li.run").hasClass("disabled")) { - return false; - } - - if ($(".toolbars .ico-stop").length === 1) { - wide.stop(); - return false; - } - var request = newWideRequest(); request.file = currentPath; request.code = wide.curEditor.getValue(); From 05c9b592f44efdbf1918f78a9ccf436e087e8d41 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 16:35:54 +0800 Subject: [PATCH 4/8] . --- static/js/wide.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/static/js/wide.js b/static/js/wide.js index 95826a0..b0aba36 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -515,8 +515,6 @@ var wide = { $('.bottom-window-group .output').text(''); }, success: function (data) { - $(".toolbars .ico-buildrun").addClass("ico-stop") - .removeClass("ico-buildrun").attr("title", config.label.stop); } }); }, From 3dc91f8d469db9056cab741e1af357baf22537a4 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 16:37:07 +0800 Subject: [PATCH 5/8] l --- output/outputs.go | 4 ++-- static/js/wide.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/output/outputs.go b/output/outputs.go index 1436d76..f595645 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -115,7 +115,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { glog.V(3).Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath) - // 在读取程序输出前先返回一次,使前端获取到 run 状态与 pid + // 在读取程序输出前先返回一次,使前端获取到 run 状态以及对应的 pid if nil != session.OutputWS[sid] { wsChannel := session.OutputWS[sid] @@ -289,7 +289,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { if 0 == count { // 说明构建成功,没有错误信息输出 // 设置下一次执行命令(前端会根据这个发送请求) - channelRet["nextCmd"] = args["nextCmd"] + channelRet["nextCmd"] = "run" go func() { // 运行 go install,生成的库用于 gocode lib-path cmd := exec.Command("go", "install") diff --git a/static/js/wide.js b/static/js/wide.js index 95826a0..f735aa2 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -501,6 +501,15 @@ var wide = { return false; } + if ($(".menu li.run").hasClass("disabled")) { + return false; + } + + if ($(".toolbars .ico-stop").length === 1) { + wide.stop(); + return false; + } + var request = newWideRequest(); request.file = currentPath; request.code = wide.curEditor.getValue(); From 438d4fed1b3aa102239a1805e70a4ad230b9f73d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 16:42:03 +0800 Subject: [PATCH 6/8] . --- output/outputs.go | 4 ++-- static/js/wide.js | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/output/outputs.go b/output/outputs.go index f595645..1436d76 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -115,7 +115,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { glog.V(3).Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath) - // 在读取程序输出前先返回一次,使前端获取到 run 状态以及对应的 pid + // 在读取程序输出前先返回一次,使前端获取到 run 状态与 pid if nil != session.OutputWS[sid] { wsChannel := session.OutputWS[sid] @@ -289,7 +289,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { if 0 == count { // 说明构建成功,没有错误信息输出 // 设置下一次执行命令(前端会根据这个发送请求) - channelRet["nextCmd"] = "run" + channelRet["nextCmd"] = args["nextCmd"] go func() { // 运行 go install,生成的库用于 gocode lib-path cmd := exec.Command("go", "install") diff --git a/static/js/wide.js b/static/js/wide.js index 1a26bd8..b0aba36 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -501,15 +501,6 @@ var wide = { return false; } - if ($(".menu li.run").hasClass("disabled")) { - return false; - } - - if ($(".toolbars .ico-stop").length === 1) { - wide.stop(); - return false; - } - var request = newWideRequest(); request.file = currentPath; request.code = wide.curEditor.getValue(); From ce1ebda2a6dea0aca8a192af18c7a37b6168ca00 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 16:55:38 +0800 Subject: [PATCH 7/8] . --- static/js/wide.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/static/js/wide.js b/static/js/wide.js index b0aba36..165d9cb 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -496,6 +496,8 @@ var wide = { }, // 构建. build: function () { + wide.saveAllFiles(); + var currentPath = editors.getCurrentPath(); if (!currentPath) { return false; @@ -520,6 +522,8 @@ var wide = { }, // 构建并运行. run: function () { + wide.saveAllFiles(); + var currentPath = editors.getCurrentPath(); if (!currentPath) { return false; @@ -579,6 +583,8 @@ var wide = { }); }, goinstall: function () { + wide.saveAllFiles(); + var currentPath = editors.getCurrentPath(); if (!currentPath) { return false; From bc9145790ce9df23edacc3d895bd1c8749bf413d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 22 Oct 2014 17:06:49 +0800 Subject: [PATCH 8/8] . --- .gitignore | 1 + static/js/wide.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7893291..959d75d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /wide.exe /wide +/main /data/workspace/bin/ /data/workspace/pkg/ diff --git a/static/js/wide.js b/static/js/wide.js index 165d9cb..25c70d2 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -432,6 +432,8 @@ var wide = { if ($(".menu li.save-all").hasClass("disabled")) { return false; } + + // TODO: 只保存未保存过的文件 for (var i = 0, ii = editors.data.length; i < ii; i++) { this.fmt(tree.fileTree.getNodeByTId(editors.data[i].id).path, editors.data[i].editor);