This commit is contained in:
Liang Ding 2015-11-24 15:42:28 +08:00
parent 0482e148e3
commit 039e826053
7 changed files with 70 additions and 59 deletions

View File

@ -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.

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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('<div style="top:'
+ (position.top + 15) + 'px;left:' + position.left
+ 'px" class="edit-exprinfo">' + data.info + '</div>');
+ 'px" class="edit-exprinfo">' + result.data + '</div>');
}
});
};
@ -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', '');
}
});
};

View File

@ -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;
}

View File

@ -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");
}
}
}