diff --git a/editor/editors.go b/editor/editors.go index b65f957..6b62e71 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -179,8 +179,8 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { // GetExprInfoHandler handles request of getting expression infomation. func GetExprInfoHandler(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) session, _ := session.HTTPSession.Get(r, "wide-session") username := session.Values["username"].(string) @@ -201,7 +201,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -211,7 +211,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -240,18 +240,18 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { exprInfo := strings.TrimSpace(string(output)) if "" == exprInfo { - data["succ"] = false + result.Succ = false return } - data["info"] = exprInfo + result.Data = exprInfo } // FindDeclarationHandler handles request of finding declaration. func FindDeclarationHandler(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) session, _ := session.HTTPSession.Get(r, "wide-session") if session.IsNew { @@ -277,7 +277,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -287,7 +287,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -316,7 +316,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { found := strings.TrimSpace(string(output)) if "" == found { - data["succ"] = false + result.Succ = false return } @@ -328,15 +328,19 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { cursorLine, _ := strconv.Atoi(found[cursorSep+1 : strings.LastIndex(found, ":")]) cursorCh, _ := strconv.Atoi(found[strings.LastIndex(found, ":")+1:]) + data := map[string]interface{}{} + data["path"] = filepath.ToSlash(path) data["cursorLine"] = cursorLine data["cursorCh"] = cursorCh + + result.Data = data } // FindUsagesHandler handles request of finding usages. func FindUsagesHandler(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) session, _ := session.HTTPSession.Get(r, "wide-session") if session.IsNew { @@ -363,7 +367,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -373,7 +377,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -399,14 +403,14 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { return } - result := strings.TrimSpace(string(output)) - if "" == result { - data["succ"] = false + out := strings.TrimSpace(string(output)) + if "" == out { + result.Succ = false return } - founds := strings.Split(result, "\n") + founds := strings.Split(out, "\n") usages := []*file.Snippet{} for _, found := range founds { found = strings.TrimSpace(found) @@ -421,7 +425,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { usages = append(usages, usage) } - data["founds"] = usages + result.Data = usages } // getCursorOffset calculates the cursor offset. diff --git a/editor/formatter.go b/editor/formatter.go index e0c79e8..d0c93e6 100644 --- a/editor/formatter.go +++ b/editor/formatter.go @@ -31,8 +31,8 @@ import ( // 1. gofmt // 2. goimports func GoFmtHandler(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) session, _ := session.HTTPSession.Get(r, "wide-session") if session.IsNew { @@ -46,7 +46,7 @@ func GoFmtHandler(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 } @@ -54,7 +54,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { filePath := args["file"].(string) if util.Go.IsAPI(filePath) { - data["succ"] = false + result.Succ = false return } @@ -63,7 +63,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -73,7 +73,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { fout.WriteString(code) if err := fout.Close(); nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } @@ -87,20 +87,20 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { output := string(bytes) if "" == output { // format error, returns the original content - data["succ"] = true - data["code"] = code + result.Succ = true + result.Code = code return } code = string(output) - data["code"] = code + result.Code = code fout, err = os.Create(filePath) fout.WriteString(code) if err := fout.Close(); nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } diff --git a/file/decompress.go b/file/decompress.go index fd431cd..c1d5f8e 100644 --- a/file/decompress.go +++ b/file/decompress.go @@ -24,13 +24,13 @@ import ( // DecompressHandler handles request of decompressing zip/tar.gz. func DecompressHandler(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 } @@ -40,8 +40,8 @@ func DecompressHandler(w http.ResponseWriter, r *http.Request) { dir := filepath.Dir(path) if !util.File.IsExist(path) { - data["succ"] = false - data["msg"] = "Can't find file [" + path + "] to descompress" + result.Succ = false + result.Msg = "Can't find file [" + path + "] to descompress" return } @@ -49,7 +49,7 @@ func DecompressHandler(w http.ResponseWriter, r *http.Request) { err := util.Zip.Unzip(path, dir) if nil != err { logger.Error(err) - data["succ"] = false + result.Succ = false return } diff --git a/file/exporter.go b/file/exporter.go index 5699a3c..0776264 100644 --- a/file/exporter.go +++ b/file/exporter.go @@ -51,13 +51,13 @@ func GetZipHandler(w http.ResponseWriter, r *http.Request) { // CreateZipHandler handles request of creating zip. func CreateZipHandler(w http.ResponseWriter, r *http.Request) { - data := map[string]interface{}{"succ": true} - defer util.RetJSON(w, r, data) + data := util.NewResult() + defer util.RetResult(w, r, data) var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - data["succ"] = false + data.Succ = false return } @@ -76,8 +76,8 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) { dir := filepath.Dir(path) if !util.File.IsExist(path) { - data["succ"] = false - data["msg"] = "Can't find file [" + path + "]" + data.Succ = false + data.Msg = "Can't find file [" + path + "]" return } @@ -86,7 +86,7 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) { zipFile, err := util.Zip.Create(zipPath + ".zip") if nil != err { logger.Error(err) - data["succ"] = false + data.Succ = false return } @@ -98,5 +98,5 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) { zipFile.AddEntry(base, path) } - data["path"] = zipPath + data.Data = zipPath } diff --git a/static/js/editors.js b/static/js/editors.js index 5186108..98f76b0 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -474,14 +474,15 @@ var editors = { url: config.context + '/exprinfo', data: JSON.stringify(request), dataType: "json", - success: function (data) { - if (!data.succ) { + success: function (result) { + if (!result.succ) { return; } + var position = wide.curEditor.cursorCoords(); $("body").append('
' + data.info + '
'); + + 'px" class="edit-exprinfo">' + result.data + ''); } }); }; @@ -621,10 +622,12 @@ var editors = { url: config.context + '/find/decl', data: JSON.stringify(request), dataType: "json", - success: function (data) { - if (!data.succ) { + success: function (result) { + if (!result.succ) { return; } + + var data = result.data; var tId = tree.getTIdByPath(data.path); wide.curNode = tree.fileTree.getNodeByTId(tId); @@ -649,12 +652,12 @@ var editors = { url: config.context + '/find/usages', data: JSON.stringify(request), dataType: "json", - success: function (data) { - if (!data.succ) { + success: function (result) { + if (!result.succ) { return; } - editors.appendSearch(data.founds, 'usages', ''); + editors.appendSearch(result.data, 'usages', ''); } }); }; diff --git a/static/js/tree.js b/static/js/tree.js index 100a16b..f04161c 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -156,9 +156,9 @@ var tree = { url: config.context + '/file/zip/new', 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; } diff --git a/static/js/wide.js b/static/js/wide.js index c1e3fb9..9322304 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -476,7 +476,7 @@ var wide = { } else { if ('cross-build' === data.cmd) { var request = newWideRequest(), - isSucc = false; + path = null; request.path = data.executable; request.name = data.name; @@ -486,16 +486,20 @@ var wide = { url: config.context + '/file/zip/new', 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; } - window.open(config.context + '/file/zip?path=' + data.path + ".zip"); + path = result.data; } }); + + if (path) { + window.open(config.context + '/file/zip?path=' + path + ".zip"); + } } }