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. // GetExprInfoHandler handles request of getting expression infomation.
func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} result := util.NewResult()
defer util.RetJSON(w, r, data) defer util.RetResult(w, r, result)
session, _ := session.HTTPSession.Get(r, "wide-session") session, _ := session.HTTPSession.Get(r, "wide-session")
username := session.Values["username"].(string) username := session.Values["username"].(string)
@ -201,7 +201,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -211,7 +211,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -240,18 +240,18 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
exprInfo := strings.TrimSpace(string(output)) exprInfo := strings.TrimSpace(string(output))
if "" == exprInfo { if "" == exprInfo {
data["succ"] = false result.Succ = false
return return
} }
data["info"] = exprInfo result.Data = exprInfo
} }
// FindDeclarationHandler handles request of finding declaration. // FindDeclarationHandler handles request of finding declaration.
func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} result := util.NewResult()
defer util.RetJSON(w, r, data) defer util.RetResult(w, r, result)
session, _ := session.HTTPSession.Get(r, "wide-session") session, _ := session.HTTPSession.Get(r, "wide-session")
if session.IsNew { if session.IsNew {
@ -277,7 +277,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -287,7 +287,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -316,7 +316,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
found := strings.TrimSpace(string(output)) found := strings.TrimSpace(string(output))
if "" == found { if "" == found {
data["succ"] = false result.Succ = false
return return
} }
@ -328,15 +328,19 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
cursorLine, _ := strconv.Atoi(found[cursorSep+1 : strings.LastIndex(found, ":")]) cursorLine, _ := strconv.Atoi(found[cursorSep+1 : strings.LastIndex(found, ":")])
cursorCh, _ := strconv.Atoi(found[strings.LastIndex(found, ":")+1:]) cursorCh, _ := strconv.Atoi(found[strings.LastIndex(found, ":")+1:])
data := map[string]interface{}{}
data["path"] = filepath.ToSlash(path) data["path"] = filepath.ToSlash(path)
data["cursorLine"] = cursorLine data["cursorLine"] = cursorLine
data["cursorCh"] = cursorCh data["cursorCh"] = cursorCh
result.Data = data
} }
// FindUsagesHandler handles request of finding usages. // FindUsagesHandler handles request of finding usages.
func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} result := util.NewResult()
defer util.RetJSON(w, r, data) defer util.RetResult(w, r, result)
session, _ := session.HTTPSession.Get(r, "wide-session") session, _ := session.HTTPSession.Get(r, "wide-session")
if session.IsNew { if session.IsNew {
@ -363,7 +367,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -373,7 +377,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -399,14 +403,14 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
result := strings.TrimSpace(string(output)) out := strings.TrimSpace(string(output))
if "" == result { if "" == out {
data["succ"] = false result.Succ = false
return return
} }
founds := strings.Split(result, "\n") founds := strings.Split(out, "\n")
usages := []*file.Snippet{} usages := []*file.Snippet{}
for _, found := range founds { for _, found := range founds {
found = strings.TrimSpace(found) found = strings.TrimSpace(found)
@ -421,7 +425,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
usages = append(usages, usage) usages = append(usages, usage)
} }
data["founds"] = usages result.Data = usages
} }
// getCursorOffset calculates the cursor offset. // getCursorOffset calculates the cursor offset.

View File

@ -31,8 +31,8 @@ import (
// 1. gofmt // 1. gofmt
// 2. goimports // 2. goimports
func GoFmtHandler(w http.ResponseWriter, r *http.Request) { func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} result := util.NewResult()
defer util.RetJSON(w, r, data) defer util.RetResult(w, r, result)
session, _ := session.HTTPSession.Get(r, "wide-session") session, _ := session.HTTPSession.Get(r, "wide-session")
if session.IsNew { 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 { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -54,7 +54,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
filePath := args["file"].(string) filePath := args["file"].(string)
if util.Go.IsAPI(filePath) { if util.Go.IsAPI(filePath) {
data["succ"] = false result.Succ = false
return return
} }
@ -63,7 +63,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -73,7 +73,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
fout.WriteString(code) fout.WriteString(code)
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -87,20 +87,20 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
output := string(bytes) output := string(bytes)
if "" == output { if "" == output {
// format error, returns the original content // format error, returns the original content
data["succ"] = true result.Succ = true
data["code"] = code result.Code = code
return return
} }
code = string(output) code = string(output)
data["code"] = code result.Code = code
fout, err = os.Create(filePath) fout, err = os.Create(filePath)
fout.WriteString(code) fout.WriteString(code)
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }

View File

@ -24,13 +24,13 @@ import (
// DecompressHandler handles request of decompressing zip/tar.gz. // DecompressHandler handles request of decompressing zip/tar.gz.
func DecompressHandler(w http.ResponseWriter, r *http.Request) { func DecompressHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} result := util.NewResult()
defer util.RetJSON(w, r, data) defer util.RetResult(w, r, result)
var args map[string]interface{} var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }
@ -40,8 +40,8 @@ func DecompressHandler(w http.ResponseWriter, r *http.Request) {
dir := filepath.Dir(path) dir := filepath.Dir(path)
if !util.File.IsExist(path) { if !util.File.IsExist(path) {
data["succ"] = false result.Succ = false
data["msg"] = "Can't find file [" + path + "] to descompress" result.Msg = "Can't find file [" + path + "] to descompress"
return return
} }
@ -49,7 +49,7 @@ func DecompressHandler(w http.ResponseWriter, r *http.Request) {
err := util.Zip.Unzip(path, dir) err := util.Zip.Unzip(path, dir)
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false result.Succ = false
return return
} }

View File

@ -51,13 +51,13 @@ func GetZipHandler(w http.ResponseWriter, r *http.Request) {
// CreateZipHandler handles request of creating zip. // CreateZipHandler handles request of creating zip.
func CreateZipHandler(w http.ResponseWriter, r *http.Request) { func CreateZipHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} data := util.NewResult()
defer util.RetJSON(w, r, data) defer util.RetResult(w, r, data)
var args map[string]interface{} var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
data["succ"] = false data.Succ = false
return return
} }
@ -76,8 +76,8 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) {
dir := filepath.Dir(path) dir := filepath.Dir(path)
if !util.File.IsExist(path) { if !util.File.IsExist(path) {
data["succ"] = false data.Succ = false
data["msg"] = "Can't find file [" + path + "]" data.Msg = "Can't find file [" + path + "]"
return return
} }
@ -86,7 +86,7 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) {
zipFile, err := util.Zip.Create(zipPath + ".zip") zipFile, err := util.Zip.Create(zipPath + ".zip")
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
data["succ"] = false data.Succ = false
return return
} }
@ -98,5 +98,5 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) {
zipFile.AddEntry(base, path) zipFile.AddEntry(base, path)
} }
data["path"] = zipPath data.Data = zipPath
} }

View File

@ -474,14 +474,15 @@ var editors = {
url: config.context + '/exprinfo', url: config.context + '/exprinfo',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function (data) { success: function (result) {
if (!data.succ) { if (!result.succ) {
return; return;
} }
var position = wide.curEditor.cursorCoords(); var position = wide.curEditor.cursorCoords();
$("body").append('<div style="top:' $("body").append('<div style="top:'
+ (position.top + 15) + 'px;left:' + position.left + (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', url: config.context + '/find/decl',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function (data) { success: function (result) {
if (!data.succ) { if (!result.succ) {
return; return;
} }
var data = result.data;
var tId = tree.getTIdByPath(data.path); var tId = tree.getTIdByPath(data.path);
wide.curNode = tree.fileTree.getNodeByTId(tId); wide.curNode = tree.fileTree.getNodeByTId(tId);
@ -649,12 +652,12 @@ var editors = {
url: config.context + '/find/usages', url: config.context + '/find/usages',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function (data) { success: function (result) {
if (!data.succ) { if (!result.succ) {
return; 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', url: config.context + '/file/zip/new',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function (data) { success: function (result) {
if (!data.succ) { if (!result.succ) {
$("#dialogAlert").dialog("open", data.msg); $("#dialogAlert").dialog("open", result.msg);
return false; return false;
} }

View File

@ -476,7 +476,7 @@ var wide = {
} else { } else {
if ('cross-build' === data.cmd) { if ('cross-build' === data.cmd) {
var request = newWideRequest(), var request = newWideRequest(),
isSucc = false; path = null;
request.path = data.executable; request.path = data.executable;
request.name = data.name; request.name = data.name;
@ -486,16 +486,20 @@ var wide = {
url: config.context + '/file/zip/new', url: config.context + '/file/zip/new',
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function (data) { success: function (result) {
if (!data.succ) { if (!result.succ) {
$("#dialogAlert").dialog("open", data.msg); $("#dialogAlert").dialog("open", result.msg);
return false; 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");
}
} }
} }