This commit is contained in:
parent
039e826053
commit
a732640bc1
|
@ -164,14 +164,14 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -186,12 +186,14 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
size := util.File.GetFileSize(path)
|
||||
if size > 5242880 { // 5M
|
||||
data["succ"] = false
|
||||
data["msg"] = "This file is too large to open :("
|
||||
result.Succ = false
|
||||
result.Msg = "This file is too large to open :("
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{}
|
||||
|
||||
buf, _ := ioutil.ReadFile(path)
|
||||
|
||||
extension := filepath.Ext(path)
|
||||
|
@ -219,12 +221,14 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
content := string(buf)
|
||||
|
||||
if util.File.IsBinary(content) {
|
||||
data["succ"] = false
|
||||
data["msg"] = "Can't open a binary file :("
|
||||
result.Succ = false
|
||||
result.Msg = "Can't open a binary file :("
|
||||
} else {
|
||||
data["content"] = content
|
||||
data["path"] = path
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
}
|
||||
|
||||
// SaveFileHandler handles request of saving file.
|
||||
|
@ -237,14 +241,14 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -262,7 +266,7 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -273,7 +277,7 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err := fout.Close(); nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
wSession := session.WideSessions.Get(sid)
|
||||
wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
|
||||
|
@ -293,14 +297,14 @@ func NewFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -319,7 +323,7 @@ func NewFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
wSession := session.WideSessions.Get(sid)
|
||||
|
||||
if !createFile(path, fileType) {
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
|
||||
Data: "can't create file " + path}
|
||||
|
@ -345,14 +349,14 @@ func RemoveFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -370,7 +374,7 @@ func RemoveFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
wSession := session.WideSessions.Get(sid)
|
||||
|
||||
if !removeFile(path) {
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
|
||||
Data: "can't remove file " + path}
|
||||
|
@ -391,14 +395,14 @@ func RenameFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -423,7 +427,7 @@ func RenameFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
wSession := session.WideSessions.Get(sid)
|
||||
|
||||
if !renameFile(oldPath, newPath) {
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
|
||||
Data: "can't rename file " + oldPath}
|
||||
|
@ -456,13 +460,13 @@ func FindHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -497,7 +501,7 @@ func FindHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
sort.Sort(founds)
|
||||
|
||||
data["founds"] = founds
|
||||
result.Data = founds
|
||||
}
|
||||
|
||||
// SearchTextHandler handles request of searching files under the specified directory with the specified keyword.
|
||||
|
@ -509,14 +513,14 @@ func SearchTextHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -524,7 +528,7 @@ func SearchTextHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sid := args["sid"].(string)
|
||||
wSession := session.WideSessions.Get(sid)
|
||||
if nil == wSession {
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -548,7 +552,7 @@ func SearchTextHandler(w http.ResponseWriter, r *http.Request) {
|
|||
founds = searchInFile(dir, text)
|
||||
}
|
||||
|
||||
data["founds"] = founds
|
||||
result.Data = founds
|
||||
}
|
||||
|
||||
// walk traverses the specified path to build a file tree.
|
||||
|
|
|
@ -67,11 +67,11 @@ func handleUploads(r *http.Request, dir string) (fileInfos []*fileInfo) {
|
|||
|
||||
// UploadHandler handles request of file upload.
|
||||
func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
q := r.URL.Query()
|
||||
dir := q["path"][0]
|
||||
|
||||
data["files"] = handleUploads(r, dir)
|
||||
result.Data = handleUploads(r, dir)
|
||||
}
|
||||
|
|
|
@ -34,14 +34,14 @@ type element struct {
|
|||
|
||||
// GetOutlineHandler gets outfile of a go file.
|
||||
func GetOutlineHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -51,11 +51,12 @@ func GetOutlineHandler(w http.ResponseWriter, r *http.Request) {
|
|||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "", code, 0)
|
||||
if err != nil {
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{}
|
||||
// ast.Print(fset, f)
|
||||
|
||||
line, ch := getCursor(code, int(f.Name.Pos()))
|
||||
|
@ -128,6 +129,8 @@ func GetOutlineHandler(w http.ResponseWriter, r *http.Request) {
|
|||
data["structDecls"] = structDecls
|
||||
data["interfaceDecls"] = interfaceDecls
|
||||
data["typeDecls"] = typeDecls
|
||||
|
||||
result.Data = data
|
||||
}
|
||||
|
||||
// getCursor calculates the cursor position (line, ch) by the specified offset.
|
||||
|
|
|
@ -35,8 +35,8 @@ import (
|
|||
|
||||
// BuildHandler handles request of building.
|
||||
func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := map[string]interface{}{"succ": true}
|
||||
defer util.RetJSON(w, r, data)
|
||||
result := util.NewResult()
|
||||
defer util.RetResult(w, r, result)
|
||||
|
||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||
if httpSession.IsNew {
|
||||
|
@ -51,7 +51,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err := fout.Close(); nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
stdout, err := cmd.StdoutPipe()
|
||||
if nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -112,12 +112,12 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
stderr, err := cmd.StderrPipe()
|
||||
if nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if !data["succ"].(bool) {
|
||||
if !result.Succ {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err := cmd.Start(); nil != err {
|
||||
logger.Error(err)
|
||||
data["succ"] = false
|
||||
result.Succ = false
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -304,10 +304,10 @@ var menu = {
|
|||
url: config.context + '/build',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
beforeSend: function (data) {
|
||||
beforeSend: function (result) {
|
||||
bottomGroup.resetOutput();
|
||||
},
|
||||
success: function (data) {
|
||||
success: function (result) {
|
||||
$("#buildRun").addClass("ico-stop")
|
||||
.removeClass("ico-buildrun").attr("title", config.label.stop);
|
||||
}
|
||||
|
@ -336,10 +336,10 @@ var menu = {
|
|||
url: config.context + '/build',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
beforeSend: function (data) {
|
||||
beforeSend: function (result) {
|
||||
bottomGroup.resetOutput();
|
||||
},
|
||||
success: function (data) {
|
||||
success: function (result) {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
@ -239,7 +239,7 @@ var tree = {
|
|||
url: "/file/upload?path=" + request.path,
|
||||
dataType: 'json',
|
||||
formData: request,
|
||||
done: function (e, data) {
|
||||
done: function (e, result) {
|
||||
tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh");
|
||||
},
|
||||
fail: function () {
|
||||
|
@ -413,13 +413,15 @@ var tree = {
|
|||
url: config.context + '/file',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
$("#dialogAlert").dialog("open", data.msg);
|
||||
success: function (result) {
|
||||
if (!result.succ) {
|
||||
$("#dialogAlert").dialog("open", result.msg);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = result.data;
|
||||
|
||||
if (!data.mode) {
|
||||
var mode = CodeMirror.findModeByFileName(treeNode.path);
|
||||
data.mode = mode.mime;
|
||||
|
@ -496,13 +498,13 @@ var tree = {
|
|||
url: config.context + '/file/search/text',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
success: function (result) {
|
||||
if (!result.succ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$("#dialogSearchForm").dialog("close");
|
||||
editors.appendSearch(data.founds, 'founds', request.text);
|
||||
editors.appendSearch(result.data, 'founds', request.text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,11 +34,13 @@ var wide = {
|
|||
url: config.context + '/outline',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
success: function (result) {
|
||||
if (!result.succ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = result.data;
|
||||
|
||||
var outlineHTML = '<ul class="list">',
|
||||
decls = ['constDecls', 'varDecls', 'funcDecls',
|
||||
'structDecls', 'interfaceDecls', 'typeDecls'];
|
||||
|
@ -258,14 +260,16 @@ var wide = {
|
|||
url: config.context + '/file/find/name',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.succ) {
|
||||
success: function (result) {
|
||||
if (!result.succ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = result.data;
|
||||
|
||||
var goFileHTML = '';
|
||||
for (var i = 0, max = data.founds.length; i < max; i++) {
|
||||
var path = data.founds[i].path,
|
||||
for (var i = 0, max = data.length; i < max; i++) {
|
||||
var path = data[i].path,
|
||||
name = path.substr(path.lastIndexOf("/") + 1),
|
||||
icoSkin = wide.getClassBySuffix(name.split(".")[1]);
|
||||
if (i === 0) {
|
||||
|
@ -577,7 +581,7 @@ var wide = {
|
|||
url: config.context + '/file/save',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
success: function (result) {
|
||||
// reset the save state
|
||||
editor.doc.markClean();
|
||||
$(".edit-panel .tabs > div").each(function () {
|
||||
|
@ -613,10 +617,10 @@ var wide = {
|
|||
url: config.context + '/build',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
beforeSend: function (data) {
|
||||
beforeSend: function (result) {
|
||||
bottomGroup.resetOutput();
|
||||
},
|
||||
success: function (data) {
|
||||
success: function (result) {
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue