diff --git a/editor/editors.go b/editor/editors.go index 0465b85..771808d 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -201,7 +201,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -211,7 +211,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -240,7 +240,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { exprInfo := strings.TrimSpace(string(output)) if "" == exprInfo { - result.Succ = false + result.Code = -1 return } @@ -277,7 +277,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -287,7 +287,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -316,7 +316,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { found := strings.TrimSpace(string(output)) if "" == found { - result.Succ = false + result.Code = -1 return } @@ -366,7 +366,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -376,7 +376,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -404,7 +404,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { out := strings.TrimSpace(string(output)) if "" == out { - result.Succ = false + result.Code = -1 return } diff --git a/editor/formatter.go b/editor/formatter.go index 145347c..d7eedb4 100644 --- a/editor/formatter.go +++ b/editor/formatter.go @@ -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) - result.Succ = false + result.Code = -1 return } @@ -54,7 +54,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { filePath := args["file"].(string) if gulu.Go.IsAPI(filePath) { - result.Succ = false + result.Code = -1 return } @@ -63,7 +63,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 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) - result.Succ = false + result.Code = -1 return } @@ -94,7 +94,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { output := string(bytes) if "" == output { // format error, returns the original content - result.Succ = true + result.Code = 0 return } @@ -106,7 +106,7 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { fout.WriteString(code) if err := fout.Close(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/file/exporter.go b/file/exporter.go index 963349c..fd2abdb 100644 --- a/file/exporter.go +++ b/file/exporter.go @@ -57,7 +57,7 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - data.Succ = false + data.Code = -1 return } @@ -76,7 +76,7 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) { dir := filepath.Dir(path) if !gulu.File.IsExist(path) { - data.Succ = false + data.Code = -1 data.Msg = "Can't find file [" + path + "]" return @@ -86,7 +86,7 @@ func CreateZipHandler(w http.ResponseWriter, r *http.Request) { zipFile, err := gulu.Zip.Create(zipPath + ".zip") if nil != err { logger.Error(err) - data.Succ = false + data.Code = -1 return } diff --git a/file/files.go b/file/files.go index dbd69eb..5efabec 100644 --- a/file/files.go +++ b/file/files.go @@ -170,7 +170,7 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -185,7 +185,7 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { size := gulu.File.GetFileSize(path) if size > 5242880 { // 5M - result.Succ = false + result.Code = -1 result.Msg = "This file is too large to open :(" return @@ -221,7 +221,7 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { content := string(buf) if gulu.File.IsBinary(content) { - result.Succ = false + result.Code = -1 result.Msg = "Can't open a binary file :(" } else { data["content"] = content @@ -246,7 +246,7 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -264,7 +264,7 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -275,7 +275,7 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 wSession := session.WideSessions.Get(sid) wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid, @@ -302,7 +302,7 @@ func NewFileHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -321,7 +321,7 @@ func NewFileHandler(w http.ResponseWriter, r *http.Request) { wSession := session.WideSessions.Get(sid) if !createFile(path, fileType) { - result.Succ = false + result.Code = -1 wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid, Data: "can't create file " + path} @@ -354,7 +354,7 @@ func RemoveFileHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -372,7 +372,7 @@ func RemoveFileHandler(w http.ResponseWriter, r *http.Request) { wSession := session.WideSessions.Get(sid) if !removeFile(path) { - result.Succ = false + result.Code = -1 wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid, Data: "can't remove file " + path} @@ -400,7 +400,7 @@ func RenameFileHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -425,7 +425,7 @@ func RenameFileHandler(w http.ResponseWriter, r *http.Request) { wSession := session.WideSessions.Get(sid) if !renameFile(oldPath, newPath) { - result.Succ = false + result.Code = -1 wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid, Data: "can't rename file " + oldPath} @@ -464,7 +464,7 @@ func FindHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -518,7 +518,7 @@ func SearchTextHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -526,7 +526,7 @@ func SearchTextHandler(w http.ResponseWriter, r *http.Request) { sid := args["sid"].(string) wSession := session.WideSessions.Get(sid) if nil == wSession { - result.Succ = false + result.Code = -1 return } diff --git a/file/outline.go b/file/outline.go index a9c861c..bbe5f27 100755 --- a/file/outline.go +++ b/file/outline.go @@ -41,7 +41,7 @@ func GetOutlineHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -51,7 +51,7 @@ func GetOutlineHandler(w http.ResponseWriter, r *http.Request) { fset := token.NewFileSet() f, err := parser.ParseFile(fset, "", code, 0) if err != nil { - result.Succ = false + result.Code = -1 return } diff --git a/go.mod b/go.mod index 690ecd7..bd25ac5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/b3log/wide go 1.12 require ( - github.com/b3log/gulu v0.0.0-20190524125155-0ed03084217c + github.com/b3log/gulu v0.0.0-20190524134307-1c13d074e5e7 github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect github.com/fsnotify/fsnotify v1.4.7 @@ -18,5 +18,5 @@ require ( golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect golang.org/x/sys v0.0.0-20190524122548-abf6ff778158 // indirect - golang.org/x/tools v0.0.0-20190523174634-38d8bcfa38af // indirect + golang.org/x/tools v0.0.0-20190524125531-991f2949994b // indirect ) diff --git a/go.sum b/go.sum index 2809895..83b7985 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/b3log/gulu v0.0.0-20190524124046-926f105c6dd8 h1:Ir8QVO1dwv6MEdkAE7L1 github.com/b3log/gulu v0.0.0-20190524124046-926f105c6dd8/go.mod h1:UmyB0pe8jv1K3dZy/4UE3uCpM8zYkB4nbiIgjemuQ7A= github.com/b3log/gulu v0.0.0-20190524125155-0ed03084217c h1:1+Pr5/IUfYBTiZVyzX7CfdkLVtL+LZa5yrxhjLlPYXY= github.com/b3log/gulu v0.0.0-20190524125155-0ed03084217c/go.mod h1:UmyB0pe8jv1K3dZy/4UE3uCpM8zYkB4nbiIgjemuQ7A= +github.com/b3log/gulu v0.0.0-20190524134307-1c13d074e5e7 h1:fdRlxbAj3hLIQmllGS7C1VJOoFssDEscxbSIPgugbjQ= +github.com/b3log/gulu v0.0.0-20190524134307-1c13d074e5e7/go.mod h1:UmyB0pe8jv1K3dZy/4UE3uCpM8zYkB4nbiIgjemuQ7A= github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f h1:8GDPb0tCY8LQ+OJ3dbHb5sA6YZWXFORQYZx5sdsTlMs= github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f h1:AUj1VoZUfhPhOPHULCQQDnGhRelpFWHMLhQVWDsS0v4= @@ -51,3 +53,4 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190523174634-38d8bcfa38af/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524125531-991f2949994b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= diff --git a/output/build.go b/output/build.go index 85e0da3..520ea59 100644 --- a/output/build.go +++ b/output/build.go @@ -51,7 +51,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -68,7 +68,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { fout, err := os.Create(filePath) if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -76,7 +76,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { code := args["code"].(string) if _, err := fout.WriteString(code); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -110,7 +110,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { output := string(outputBytes) if nil != err && strings.Contains(output, "go.mod already exists") { logger.Error(err.Error() + ": " + output) - result.Succ = false + result.Code = -1 return } @@ -136,7 +136,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { stdout, err := cmd.StdoutPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -144,18 +144,18 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { stderr, err := cmd.StderrPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } - if !result.Succ { + if 0 != result.Code { return } if err := cmd.Start(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/output/cross.go b/output/cross.go index 69eec6f..60404ac 100644 --- a/output/cross.go +++ b/output/cross.go @@ -50,7 +50,7 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -106,7 +106,7 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) { stdout, err := cmd.StdoutPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -114,12 +114,12 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) { stderr, err := cmd.StderrPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } - if !result.Succ { + if 0 != result.Code { return } @@ -146,7 +146,7 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) { if err := cmd.Start(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/output/install.go b/output/install.go index 1367b77..1fa05c9 100644 --- a/output/install.go +++ b/output/install.go @@ -50,7 +50,7 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -70,7 +70,7 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) { stdout, err := cmd.StdoutPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -78,12 +78,12 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) { stderr, err := cmd.StderrPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } - if !result.Succ { + if 0 != result.Code { return } @@ -110,7 +110,7 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) { if err := cmd.Start(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/output/test.go b/output/test.go index 2c1373e..6d84110 100644 --- a/output/test.go +++ b/output/test.go @@ -48,7 +48,7 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -66,7 +66,7 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) { stdout, err := cmd.StdoutPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -74,12 +74,12 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) { stderr, err := cmd.StderrPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } - if !result.Succ { + if 0 != result.Code { return } @@ -106,7 +106,7 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) { if err := cmd.Start(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/output/vet.go b/output/vet.go index ce408c9..2f73426 100644 --- a/output/vet.go +++ b/output/vet.go @@ -48,7 +48,7 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -66,7 +66,7 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) { stdout, err := cmd.StdoutPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -74,12 +74,12 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) { stderr, err := cmd.StderrPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } - if !result.Succ { + if 0 != result.Code { return } @@ -106,7 +106,7 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) { if err := cmd.Start(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/playground/build.go b/playground/build.go index b12e60a..780f589 100644 --- a/playground/build.go +++ b/playground/build.go @@ -42,7 +42,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -66,7 +66,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { data["output"] = template.HTML(string(out)) if nil != err { - result.Succ = false + result.Code = -1 return } diff --git a/playground/file.go b/playground/file.go index 4e29038..1544431 100644 --- a/playground/file.go +++ b/playground/file.go @@ -44,7 +44,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -57,7 +57,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) { stdin, err := cmd.StdinPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -89,7 +89,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) { fout.WriteString(code) if err := fout.Close(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 return } diff --git a/session/oauth.go b/session/oauth.go index 9e37622..0e23601 100644 --- a/session/oauth.go +++ b/session/oauth.go @@ -94,7 +94,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) { msg := addUser(githubId, userName, avatar) if userCreated != msg { result := gulu.Ret.NewResult() - result.Succ = false + result.Code = -1 result.Msg = msg gulu.Ret.RetResult(w, r, result) diff --git a/session/processes.go b/session/processes.go index e72b3f4..dd916a5 100644 --- a/session/processes.go +++ b/session/processes.go @@ -52,13 +52,13 @@ func RunHandler(w http.ResponseWriter, r *http.Request, channel map[string]*util if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 } sid := args["sid"].(string) wSession := WideSessions.Get(sid) if nil == wSession { - result.Succ = false + result.Code = -1 } filePath := args["executable"].(string) @@ -78,13 +78,13 @@ func RunHandler(w http.ResponseWriter, r *http.Request, channel map[string]*util stdout, err := cmd.StdoutPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 } stderr, err := cmd.StderrPipe() if nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 } outReader := bufio.NewReader(stdout) @@ -92,11 +92,11 @@ func RunHandler(w http.ResponseWriter, r *http.Request, channel map[string]*util if err := cmd.Start(); nil != err { logger.Error(err) - result.Succ = false + result.Code = -1 } wsChannel := channel[sid] channelRet := map[string]interface{}{} - if !result.Succ { + if 0 != result.Code { channelRet["cmd"] = "run-done" channelRet["output"] = "" wsChannel.WriteJSON(&channelRet) @@ -204,7 +204,7 @@ func StopHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -214,7 +214,7 @@ func StopHandler(w http.ResponseWriter, r *http.Request) { wSession := WideSessions.Get(sid) if nil == wSession { - result.Succ = false + result.Code = -1 return } diff --git a/session/sessions.go b/session/sessions.go index 6caeeec..4c05ef1 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -294,14 +294,14 @@ func SaveContentHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } wSession := WideSessions.Get(args.Sid) if nil == wSession { - result.Succ = false + result.Code = -1 return } diff --git a/session/users.go b/session/users.go index 855999e..4f36e20 100644 --- a/session/users.go +++ b/session/users.go @@ -117,7 +117,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - result.Succ = false + result.Code = -1 return } @@ -146,7 +146,11 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { user.Lived = now user.Updated = now - result.Succ = user.Save() + if user.Save() { + result.Code = 0 + } else { + result.Code = -1 + } } // FixedTimeSave saves online users' configurations periodically (1 minute). diff --git a/static/js/editors.js b/static/js/editors.js index 547fcaa..bb9e635 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -439,7 +439,7 @@ var editors = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { return; } @@ -587,7 +587,7 @@ var editors = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { return; } @@ -617,7 +617,7 @@ var editors = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { return; } diff --git a/static/js/menu.js b/static/js/menu.js index 50fff15..098cc61 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -163,7 +163,7 @@ var menu = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (result.succ) { + if (0 == result.code) { window.location.href = "/login"; } } @@ -440,7 +440,7 @@ var menu = { url: '/preference', data: JSON.stringify(request), success: function (result, textStatus, jqXHR) { - if (!result.succ) { + if (0 != result.code) { return false; } diff --git a/static/js/playground.js b/static/js/playground.js index e170422..9155039 100644 --- a/static/js/playground.js +++ b/static/js/playground.js @@ -373,7 +373,7 @@ var playground = { playground.editor.setValue(data.code); - if (!result.succ) { + if (0 != result.code) { console.log(data); return; } @@ -446,7 +446,7 @@ var playground = { playground.editor.setValue(data.code); playground.editor.setCursor(cursor); - if (!result.succ) { + if (0 != result.code) { return; } @@ -466,7 +466,7 @@ var playground = { $("#output").html(data.output); - if (!result.succ) { + if (0 != result.code) { return; } diff --git a/static/js/tree.js b/static/js/tree.js index e38701a..eff8869 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -164,7 +164,7 @@ var tree = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogAlert").dialog("open", result.msg); return false; @@ -190,7 +190,7 @@ var tree = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogAlert").dialog("open", result.msg); return false; @@ -220,7 +220,7 @@ var tree = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (result.succ) { + if (0 == result.code) { var $dirRMenu = $("#dirRMenu"); var $fileRMenu = $("#fileRMenu"); var setting = { @@ -374,7 +374,7 @@ var tree = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogAlert").dialog("open", result.msg); return false; @@ -463,7 +463,7 @@ var tree = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { return; } @@ -499,7 +499,7 @@ var tree = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogRenamePrompt").dialog("close"); bottomGroup.tabs.setCurrent("notification"); windows.flowBottom(); diff --git a/static/js/wide.js b/static/js/wide.js index 7bfc19b..ab13d8c 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -42,7 +42,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { return; } @@ -125,7 +125,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogRemoveConfirm").dialog("close"); bottomGroup.tabs.setCurrent("notification"); windows.flowBottom(); @@ -163,7 +163,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogNewFilePrompt").dialog("close"); bottomGroup.tabs.setCurrent("notification"); windows.flowBottom(); @@ -207,7 +207,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogNewDirPrompt").dialog("close"); bottomGroup.tabs.setCurrent("notification"); windows.flowBottom(); @@ -268,7 +268,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { return; } @@ -443,7 +443,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (!result.succ) { + if (0 != result.code) { $("#dialogAlert").dialog("open", result.msg); return false; @@ -614,7 +614,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (result.succ) { + if (0 == result.code) { editor.setValue(result.data.code); editor.setCursor(cursor); editor.scrollTo(null, scrollInfo.top); @@ -647,7 +647,7 @@ var wide = { data: JSON.stringify(request), dataType: "json", success: function (result) { - if (result.succ) { + if (0 == result.code) { formatted = result.data.code; } } diff --git a/static/js/wide.min.js b/static/js/wide.min.js index 454d7af..8345027 100644 --- a/static/js/wide.min.js +++ b/static/js/wide.min.js @@ -1,11 +1,11 @@ var Tabs=function(e){e._$tabsPanel=$(e.id+" > .tabs-panel"),e._$tabs=$(e.id+" > .tabs"),e._stack=[],this.obj=e,this.obj.STACKSIZE=64,this._init(e);var i=this;$(e.id+" > .tabs > div").each(function(){var t=$(this).data("index");e._stack.length===i.obj.STACKSIZE&&e._stack.splice(0,1),e._stack[e._stack.length-1]!==t&&i.obj._stack.push(t)})};$.extend(Tabs.prototype,{_init:function(r){var n=this;r._$tabs.on("click","div",function(t){if($(this).hasClass("current"))return!1;var e=$(this).data("index");n.setCurrent(e),"function"==typeof r.clickAfter&&r.clickAfter(e)}),r._$tabs.on("click",".ico-close",function(t){var e=$(this).parent().data("index"),i=!0;"function"==typeof r.removeBefore&&(i=r.removeBefore(e)),i&&n.del(e),t.stopPropagation()})},_hasId:function(t){return 0!==this.obj._$tabs.find('div[data-index="'+t+'"]').length},add:function(t){if(this.getCurrentId()===t.id)return!1;if(this._hasId(t.id))return this.setCurrent(t.id),!1;var e=this.obj._$tabsPanel;this.obj._$tabs.append('
"+t.output+""),wide.curProcessId=t.pid;break;case"run-done":bottomGroup.fillOutput($(".bottom-window-group .output > div").html().replace(/<\/pre>$/g,t.output+"")),wide.curProcessId=void 0,$("#buildRun").removeClass("ico-stop").addClass("ico-buildrun").attr("title",config.label.build_n_run);break;case"start-build":case"start-test":case"start-vet":case"start-install":bottomGroup.fillOutput(t.output);break;case"go test":case"go vet":case"go install":bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output);break;case"git clone":bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output),tree.fileTree.reAsyncChildNodes(wide.curNode,"refresh",!1);break;case"build":case"cross-build":if(bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output),t.lints){for(var i={},a=0;a
"+t.output+""),wide.curProcessId=t.pid;break;case"run-done":bottomGroup.fillOutput($(".bottom-window-group .output > div").html().replace(/<\/pre>$/g,t.output+"")),wide.curProcessId=void 0,$("#buildRun").removeClass("ico-stop").addClass("ico-buildrun").attr("title",config.label.build_n_run);break;case"start-build":case"start-test":case"start-vet":case"start-install":bottomGroup.fillOutput(t.output);break;case"go test":case"go vet":case"go install":bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output);break;case"git clone":bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output),tree.fileTree.reAsyncChildNodes(wide.curNode,"refresh",!1);break;case"build":case"cross-build":if(bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output),t.lints){for(var i={},a=0;a
' + data.output + '');\r\n } else {\r\n bottomGroup.fillOutput(content.replace(/<\\/pre>$/g, data.output + ''));\r\n }\r\n\r\n wide.curProcessId = data.pid;\r\n\r\n break;\r\n case 'run-done':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html().replace(/<\\/pre>$/g, data.output + ''));\r\n\r\n wide.curProcessId = undefined;\r\n $(\"#buildRun\").removeClass(\"ico-stop\")\r\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\r\n\r\n break;\r\n case 'start-build':\r\n case 'start-test':\r\n case 'start-vet':\r\n case 'start-install':\r\n bottomGroup.fillOutput(data.output);\r\n\r\n break;\r\n case 'go test':\r\n case 'go vet':\r\n case 'go install':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\r\n\r\n break;\r\n case 'git clone':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\r\n tree.fileTree.reAsyncChildNodes(wide.curNode, \"refresh\", false);\r\n\r\n break;\r\n case 'build':\r\n case 'cross-build':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\r\n\r\n if (data.lints) { // has build error\r\n var files = {};\r\n\r\n for (var i = 0; i < data.lints.length; i++) {\r\n var lint = data.lints[i];\r\n\r\n goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0),\r\n to: CodeMirror.Pos(lint.lineNo, 0),\r\n message: lint.msg, severity: lint.severity});\r\n\r\n files[lint.file] = lint.file;\r\n }\r\n\r\n $(\"#buildRun\").removeClass(\"ico-stop\")\r\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\r\n\r\n // trigger gutter lint\r\n for (var path in files) {\r\n var editor = editors.getEditorByPath(path);\r\n CodeMirror.signal(editor, \"change\", editor);\r\n }\r\n } else {\r\n if ('cross-build' === data.cmd) {\r\n var request = newWideRequest(),\r\n path = null;\r\n request.path = data.executable;\r\n request.name = data.name;\r\n\r\n $.ajax({\r\n async: false,\r\n type: 'POST',\r\n url: '/file/zip/new',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n if (!result.succ) {\r\n $(\"#dialogAlert\").dialog(\"open\", result.msg);\r\n\r\n return false;\r\n }\r\n\r\n path = result.data;\r\n }\r\n });\r\n\r\n if (path) {\r\n window.open('/file/zip?path=' + path + \".zip\");\r\n }\r\n }\r\n }\r\n\r\n break;\r\n }\r\n };\r\n outputWS.onclose = function (e) {\r\n console.log('[output onclose] disconnected (' + e.code + ')');\r\n };\r\n outputWS.onerror = function (e) {\r\n console.log('[output onerror]');\r\n };\r\n },\r\n _initFooter: function () {\r\n $(\".footer .cursor\").dblclick(function () {\r\n $(\"#dialogGoLinePrompt\").dialog(\"open\");\r\n });\r\n },\r\n init: function () {\r\n this._initFooter();\r\n\r\n this._initWS();\r\n\r\n // 点击隐藏弹出层\r\n $(\"body\").bind(\"mouseup\", function (event) {\r\n // MAC 右键文件树失效\r\n if (event.which === 3) {\r\n return false;\r\n }\r\n\r\n $(\".frame\").hide();\r\n\r\n if (!($(event.target).closest(\".frame\").length === 1 || event.target.className === \"frame\")) {\r\n $(\".menu > ul > li\").unbind().removeClass(\"selected\");\r\n menu.subMenu();\r\n }\r\n });\r\n\r\n // 刷新提示\r\n window.onbeforeunload = function () {\r\n if (editors.data.length > 0) {\r\n return config.label.confirm_save;\r\n }\r\n };\r\n\r\n // 禁止鼠标右键菜单\r\n document.oncontextmenu = function () {\r\n return false;\r\n };\r\n\r\n this._initDialog();\r\n },\r\n _save: function (path, editor) {\r\n if (!path) {\r\n return false;\r\n }\r\n\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: '/file/save',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n // reset the save state\r\n editor.doc.markClean();\r\n $(\".edit-panel .tabs > div\").each(function () {\r\n var $span = $(this).find(\"span:eq(0)\");\r\n if ($span.attr(\"title\") === path) {\r\n $span.removeClass(\"changed\");\r\n }\r\n });\r\n }\r\n });\r\n },\r\n saveFile: function () {\r\n var path = editors.getCurrentPath();\r\n if (!path) {\r\n return false;\r\n }\r\n\r\n var editor = wide.curEditor;\r\n if (editor.doc.isClean()) { // no modification\r\n return false;\r\n }\r\n\r\n if (\"text/x-go\" === editor.getOption(\"mode\")) {\r\n wide.gofmt(path, wide.curEditor); // go fmt will save\r\n\r\n // build the file at once\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n request.nextCmd = \"\"; // build only, no following operation\r\n $.ajax({\r\n type: 'POST',\r\n url: '/build',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n beforeSend: function () {\r\n bottomGroup.resetOutput();\r\n },\r\n success: function (result) {\r\n }\r\n });\r\n\r\n // refresh outline\r\n wide.refreshOutline();\r\n\r\n return;\r\n }\r\n\r\n wide._save(path, wide.curEditor);\r\n },\r\n stop: function () {\r\n if ($(\"#buildRun\").hasClass(\"ico-buildrun\")) {\r\n menu.run();\r\n return false;\r\n }\r\n\r\n if (!wide.curProcessId) {\r\n return false;\r\n }\r\n\r\n var request = newWideRequest();\r\n request.pid = wide.curProcessId;\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: '/stop',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n $(\"#buildRun\").removeClass(\"ico-stop\")\r\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\r\n }\r\n });\r\n },\r\n gofmt: function (path, editor) {\r\n var cursor = editor.getCursor();\r\n var scrollInfo = editor.getScrollInfo();\r\n\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n request.cursorLine = cursor.line;\r\n request.cursorCh = cursor.ch;\r\n\r\n $.ajax({\r\n async: false, // sync\r\n type: 'POST',\r\n url: '/go/fmt',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n if (result.succ) {\r\n editor.setValue(result.data.code);\r\n editor.setCursor(cursor);\r\n editor.scrollTo(null, scrollInfo.top);\r\n\r\n wide._save(path, editor);\r\n }\r\n }\r\n });\r\n },\r\n fmt: function (path, editor) {\r\n var mode = editor.getOption(\"mode\");\r\n\r\n var cursor = editor.getCursor();\r\n var scrollInfo = editor.getScrollInfo();\r\n\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n request.cursorLine = cursor.line;\r\n request.cursorCh = cursor.ch;\r\n\r\n var formatted = null;\r\n\r\n switch (mode) {\r\n case \"text/x-go\":\r\n $.ajax({\r\n async: false, // sync\r\n type: 'POST',\r\n url: '/go/fmt',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n if (result.succ) {\r\n formatted = result.data.code;\r\n }\r\n }\r\n });\r\n\r\n break;\r\n case \"text/html\":\r\n formatted = html_beautify(editor.getValue());\r\n break;\r\n case \"text/javascript\":\r\n case \"application/json\":\r\n formatted = js_beautify(editor.getValue());\r\n break;\r\n case \"text/css\":\r\n formatted = css_beautify(editor.getValue());\r\n break;\r\n default :\r\n break;\r\n }\r\n\r\n if (formatted) {\r\n editor.setValue(formatted);\r\n editor.setCursor(cursor);\r\n editor.scrollTo(null, scrollInfo.top);\r\n\r\n wide._save(path, editor);\r\n }\r\n },\r\n getClassBySuffix: function (suffix) {\r\n var iconSkin = \"ico-ztree-other \";\r\n switch (suffix) {\r\n case \"html\":\r\n case \"htm\":\r\n iconSkin = \"ico-ztree-html \";\r\n break;\r\n case \"go\":\r\n iconSkin = \"ico-ztree-go \";\r\n break;\r\n case \"css\":\r\n iconSkin = \"ico-ztree-css \";\r\n break;\r\n case \"txt\":\r\n iconSkin = \"ico-ztree-text \";\r\n break;\r\n case \"sql\":\r\n iconSkin = \"ico-ztree-sql \";\r\n break;\r\n case \"properties\":\r\n iconSkin = \"ico-ztree-pro \";\r\n break;\r\n case \"md\":\r\n iconSkin = \"ico-ztree-md \";\r\n break;\r\n case \"js\", \"json\":\r\n iconSkin = \"ico-ztree-js \";\r\n break;\r\n case \"xml\":\r\n iconSkin = \"ico-ztree-xml \";\r\n break;\r\n case \"jpg\":\r\n case \"jpeg\":\r\n case \"bmp\":\r\n case \"gif\":\r\n case \"png\":\r\n case \"svg\":\r\n case \"ico\":\r\n iconSkin = \"ico-ztree-img \";\r\n break;\r\n }\r\n\r\n return iconSkin;\r\n }\r\n};\r\n\r\n$(document).ready(function () {\r\n wide.init();\r\n tree.init();\r\n menu.init();\r\n hotkeys.init();\r\n session.init();\r\n notification.init();\r\n editors.init();\r\n windows.init();\r\n bottomGroup.init();\r\n});\r\n","/*\r\n * Copyright (c) 2014-present, b3log.org\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * https://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/*\r\n * @file session.js\r\n *\r\n * @author Liyuan Li\r\n * @version 1.1.0.1, Dec 8, 2015\r\n */\r\nvar session = {\r\n init: function () {\r\n this._initWS();\r\n\r\n var getLayoutState = function (paneState) {\r\n var state = 'normal';\r\n if (paneState.isClosed) {\r\n state = 'min';\r\n } else if (paneState.size >= $('body').width()) {\r\n state = 'max';\r\n }\r\n\r\n return state;\r\n };\r\n\r\n // save session content every 30 seconds\r\n setInterval(function () {\r\n var request = newWideRequest(),\r\n filse = [],\r\n fileTree = [],\r\n currentId = editors.getCurrentId(),\r\n currentFile = currentId ? editors.getCurrentPath() : \"\";\r\n\r\n editors.tabs.obj._$tabs.find(\"div\").each(function () {\r\n var $it = $(this);\r\n if ($it.find(\"span:eq(0)\").attr(\"title\") !== config.label.start_page) {\r\n filse.push($it.find(\"span:eq(0)\").attr(\"title\"));\r\n }\r\n });\r\n\r\n fileTree = tree.getOpenPaths();\r\n\r\n request.currentFile = currentFile; // current editor file\r\n request.fileTree = fileTree; // file tree expansion state\r\n request.files = filse; // editor tabs\r\n\r\n\r\n request.layout = {\r\n \"side\": {\r\n \"size\": windows.outerLayout.west.state.size,\r\n \"state\": getLayoutState(windows.outerLayout.west.state)\r\n },\r\n \"sideRight\": {\r\n \"size\": windows.innerLayout.east.state.size,\r\n \"state\": getLayoutState(windows.innerLayout.east.state)\r\n },\r\n \"bottom\": {\r\n \"size\": windows.innerLayout.south.state.size,\r\n \"state\": getLayoutState(windows.innerLayout.south.state)\r\n }\r\n };\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: '/session/save',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n }\r\n });\r\n }, 30000);\r\n },\r\n restore: function () {\r\n if (!config.latestSessionContent) {\r\n return;\r\n }\r\n\r\n var fileTree = config.latestSessionContent.fileTree,\r\n files = config.latestSessionContent.files,\r\n currentFile = config.latestSessionContent.currentFile,\r\n id = \"\",\r\n nodesToOpen = [];\r\n\r\n var nodes = tree.fileTree.transformToArray(tree.fileTree.getNodes());\r\n\r\n for (var i = 0, ii = nodes.length; i < ii; i++) {\r\n // expand tree\r\n for (var j = 0, jj = fileTree.length; j < jj; j++) {\r\n if (nodes[i].path === fileTree[j]) {\r\n // expand this node only if its parents are open\r\n var parents = tree.getAllParents(tree.fileTree.getNodeByTId(nodes[i].tId)),\r\n isOpen = true;\r\n for (var l = 0, max = parents.length; l < max; l++) {\r\n if (parents[l].open === false) {\r\n isOpen = false;\r\n }\r\n }\r\n if (isOpen) {\r\n tree.fileTree.expandNode(nodes[i], true, false, true);\r\n } else {\r\n // flag it is open\r\n nodes[i].open = true;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n // open editors\r\n for (var k = 0, kk = files.length; k < kk; k++) {\r\n if (nodes[i].path === files[k]) {\r\n nodesToOpen.push(nodes[i]);\r\n break;\r\n }\r\n }\r\n\r\n if (nodes[i].path === currentFile) {\r\n id = nodes[i].path;\r\n\r\n // FIXME: 上面的展开是异步进行的,所以执行到这里的时候可能还没有展开完,导致定位不了可视区域\r\n tree.fileTree.selectNode(nodes[i]);\r\n wide.curNode = nodes[i];\r\n }\r\n }\r\n\r\n // handle the open sequence of editors\r\n for (var m = 0, mm = files.length; m < mm; m++) {\r\n for (var n = 0, nn = nodesToOpen.length; n < nn; n++) {\r\n if (nodesToOpen[n].path === files[m]) {\r\n tree.openFile(nodesToOpen[n]);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // set the current editor\r\n editors.tabs.setCurrent(id);\r\n for (var c = 0, max = editors.data.length; c < max; c++) {\r\n if (id === editors.data[c].id) {\r\n wide.curEditor = editors.data[c].editor;\r\n break;\r\n }\r\n } \r\n },\r\n _initWS: function () {\r\n // Used for session retention, server will release all resources of the session if this channel closed\r\n var sessionWS = new ReconnectingWebSocket(config.channel + '/session/ws?sid=' + config.wideSessionId);\r\n\r\n sessionWS.onopen = function () {\r\n console.log('[session onopen] connected');\r\n\r\n var dateFormat = function (time, fmt) {\r\n var date = new Date(time);\r\n var dateObj = {\r\n \"M+\": date.getMonth() + 1,\r\n \"d+\": date.getDate(),\r\n \"h+\": date.getHours(),\r\n \"m+\": date.getMinutes(),\r\n \"s+\": date.getSeconds(),\r\n \"q+\": Math.floor((date.getMonth() + 3) / 3),\r\n \"S\": date.getMilliseconds()\r\n };\r\n if (/(y+)/.test(fmt))\r\n fmt = fmt.replace(RegExp.$1, (date.getFullYear() + \"\").substr(4 - RegExp.$1.length));\r\n for (var k in dateObj)\r\n if (new RegExp(\"(\" + k + \")\").test(fmt)) {\r\n fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1)\r\n ? (dateObj[k]) : ((\"00\" + dateObj[k]).substr((\"\" + dateObj[k]).length)));\r\n }\r\n return fmt;\r\n };\r\n\r\n var data = {type: \"Network\", severity: \"INFO\",\r\n message: \"Connected to server [sid=\" + config.wideSessionId + \"], \" + dateFormat(new Date().getTime(), 'yyyy-MM-dd hh:mm:ss')},\r\n $notification = $('.bottom-window-group .notification > table'),\r\n notificationHTML = '';\r\n\r\n notificationHTML += '
' + data.output + '');\r\n } else {\r\n bottomGroup.fillOutput(content.replace(/<\\/pre>$/g, data.output + ''));\r\n }\r\n\r\n wide.curProcessId = data.pid;\r\n\r\n break;\r\n case 'run-done':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html().replace(/<\\/pre>$/g, data.output + ''));\r\n\r\n wide.curProcessId = undefined;\r\n $(\"#buildRun\").removeClass(\"ico-stop\")\r\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\r\n\r\n break;\r\n case 'start-build':\r\n case 'start-test':\r\n case 'start-vet':\r\n case 'start-install':\r\n bottomGroup.fillOutput(data.output);\r\n\r\n break;\r\n case 'go test':\r\n case 'go vet':\r\n case 'go install':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\r\n\r\n break;\r\n case 'git clone':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\r\n tree.fileTree.reAsyncChildNodes(wide.curNode, \"refresh\", false);\r\n\r\n break;\r\n case 'build':\r\n case 'cross-build':\r\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\r\n\r\n if (data.lints) { // has build error\r\n var files = {};\r\n\r\n for (var i = 0; i < data.lints.length; i++) {\r\n var lint = data.lints[i];\r\n\r\n goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0),\r\n to: CodeMirror.Pos(lint.lineNo, 0),\r\n message: lint.msg, severity: lint.severity});\r\n\r\n files[lint.file] = lint.file;\r\n }\r\n\r\n $(\"#buildRun\").removeClass(\"ico-stop\")\r\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\r\n\r\n // trigger gutter lint\r\n for (var path in files) {\r\n var editor = editors.getEditorByPath(path);\r\n CodeMirror.signal(editor, \"change\", editor);\r\n }\r\n } else {\r\n if ('cross-build' === data.cmd) {\r\n var request = newWideRequest(),\r\n path = null;\r\n request.path = data.executable;\r\n request.name = data.name;\r\n\r\n $.ajax({\r\n async: false,\r\n type: 'POST',\r\n url: '/file/zip/new',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n if (0 != result.code) {\r\n $(\"#dialogAlert\").dialog(\"open\", result.msg);\r\n\r\n return false;\r\n }\r\n\r\n path = result.data;\r\n }\r\n });\r\n\r\n if (path) {\r\n window.open('/file/zip?path=' + path + \".zip\");\r\n }\r\n }\r\n }\r\n\r\n break;\r\n }\r\n };\r\n outputWS.onclose = function (e) {\r\n console.log('[output onclose] disconnected (' + e.code + ')');\r\n };\r\n outputWS.onerror = function (e) {\r\n console.log('[output onerror]');\r\n };\r\n },\r\n _initFooter: function () {\r\n $(\".footer .cursor\").dblclick(function () {\r\n $(\"#dialogGoLinePrompt\").dialog(\"open\");\r\n });\r\n },\r\n init: function () {\r\n this._initFooter();\r\n\r\n this._initWS();\r\n\r\n // 点击隐藏弹出层\r\n $(\"body\").bind(\"mouseup\", function (event) {\r\n // MAC 右键文件树失效\r\n if (event.which === 3) {\r\n return false;\r\n }\r\n\r\n $(\".frame\").hide();\r\n\r\n if (!($(event.target).closest(\".frame\").length === 1 || event.target.className === \"frame\")) {\r\n $(\".menu > ul > li\").unbind().removeClass(\"selected\");\r\n menu.subMenu();\r\n }\r\n });\r\n\r\n // 刷新提示\r\n window.onbeforeunload = function () {\r\n if (editors.data.length > 0) {\r\n return config.label.confirm_save;\r\n }\r\n };\r\n\r\n // 禁止鼠标右键菜单\r\n document.oncontextmenu = function () {\r\n return false;\r\n };\r\n\r\n this._initDialog();\r\n },\r\n _save: function (path, editor) {\r\n if (!path) {\r\n return false;\r\n }\r\n\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: '/file/save',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n // reset the save state\r\n editor.doc.markClean();\r\n $(\".edit-panel .tabs > div\").each(function () {\r\n var $span = $(this).find(\"span:eq(0)\");\r\n if ($span.attr(\"title\") === path) {\r\n $span.removeClass(\"changed\");\r\n }\r\n });\r\n }\r\n });\r\n },\r\n saveFile: function () {\r\n var path = editors.getCurrentPath();\r\n if (!path) {\r\n return false;\r\n }\r\n\r\n var editor = wide.curEditor;\r\n if (editor.doc.isClean()) { // no modification\r\n return false;\r\n }\r\n\r\n if (\"text/x-go\" === editor.getOption(\"mode\")) {\r\n wide.gofmt(path, wide.curEditor); // go fmt will save\r\n\r\n // build the file at once\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n request.nextCmd = \"\"; // build only, no following operation\r\n $.ajax({\r\n type: 'POST',\r\n url: '/build',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n beforeSend: function () {\r\n bottomGroup.resetOutput();\r\n },\r\n success: function (result) {\r\n }\r\n });\r\n\r\n // refresh outline\r\n wide.refreshOutline();\r\n\r\n return;\r\n }\r\n\r\n wide._save(path, wide.curEditor);\r\n },\r\n stop: function () {\r\n if ($(\"#buildRun\").hasClass(\"ico-buildrun\")) {\r\n menu.run();\r\n return false;\r\n }\r\n\r\n if (!wide.curProcessId) {\r\n return false;\r\n }\r\n\r\n var request = newWideRequest();\r\n request.pid = wide.curProcessId;\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: '/stop',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n $(\"#buildRun\").removeClass(\"ico-stop\")\r\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\r\n }\r\n });\r\n },\r\n gofmt: function (path, editor) {\r\n var cursor = editor.getCursor();\r\n var scrollInfo = editor.getScrollInfo();\r\n\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n request.cursorLine = cursor.line;\r\n request.cursorCh = cursor.ch;\r\n\r\n $.ajax({\r\n async: false, // sync\r\n type: 'POST',\r\n url: '/go/fmt',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n if (0 == result.code) {\r\n editor.setValue(result.data.code);\r\n editor.setCursor(cursor);\r\n editor.scrollTo(null, scrollInfo.top);\r\n\r\n wide._save(path, editor);\r\n }\r\n }\r\n });\r\n },\r\n fmt: function (path, editor) {\r\n var mode = editor.getOption(\"mode\");\r\n\r\n var cursor = editor.getCursor();\r\n var scrollInfo = editor.getScrollInfo();\r\n\r\n var request = newWideRequest();\r\n request.file = path;\r\n request.code = editor.getValue();\r\n request.cursorLine = cursor.line;\r\n request.cursorCh = cursor.ch;\r\n\r\n var formatted = null;\r\n\r\n switch (mode) {\r\n case \"text/x-go\":\r\n $.ajax({\r\n async: false, // sync\r\n type: 'POST',\r\n url: '/go/fmt',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n if (0 == result.code) {\r\n formatted = result.data.code;\r\n }\r\n }\r\n });\r\n\r\n break;\r\n case \"text/html\":\r\n formatted = html_beautify(editor.getValue());\r\n break;\r\n case \"text/javascript\":\r\n case \"application/json\":\r\n formatted = js_beautify(editor.getValue());\r\n break;\r\n case \"text/css\":\r\n formatted = css_beautify(editor.getValue());\r\n break;\r\n default :\r\n break;\r\n }\r\n\r\n if (formatted) {\r\n editor.setValue(formatted);\r\n editor.setCursor(cursor);\r\n editor.scrollTo(null, scrollInfo.top);\r\n\r\n wide._save(path, editor);\r\n }\r\n },\r\n getClassBySuffix: function (suffix) {\r\n var iconSkin = \"ico-ztree-other \";\r\n switch (suffix) {\r\n case \"html\":\r\n case \"htm\":\r\n iconSkin = \"ico-ztree-html \";\r\n break;\r\n case \"go\":\r\n iconSkin = \"ico-ztree-go \";\r\n break;\r\n case \"css\":\r\n iconSkin = \"ico-ztree-css \";\r\n break;\r\n case \"txt\":\r\n iconSkin = \"ico-ztree-text \";\r\n break;\r\n case \"sql\":\r\n iconSkin = \"ico-ztree-sql \";\r\n break;\r\n case \"properties\":\r\n iconSkin = \"ico-ztree-pro \";\r\n break;\r\n case \"md\":\r\n iconSkin = \"ico-ztree-md \";\r\n break;\r\n case \"js\", \"json\":\r\n iconSkin = \"ico-ztree-js \";\r\n break;\r\n case \"xml\":\r\n iconSkin = \"ico-ztree-xml \";\r\n break;\r\n case \"jpg\":\r\n case \"jpeg\":\r\n case \"bmp\":\r\n case \"gif\":\r\n case \"png\":\r\n case \"svg\":\r\n case \"ico\":\r\n iconSkin = \"ico-ztree-img \";\r\n break;\r\n }\r\n\r\n return iconSkin;\r\n }\r\n};\r\n\r\n$(document).ready(function () {\r\n wide.init();\r\n tree.init();\r\n menu.init();\r\n hotkeys.init();\r\n session.init();\r\n notification.init();\r\n editors.init();\r\n windows.init();\r\n bottomGroup.init();\r\n});\r\n","/*\r\n * Copyright (c) 2014-present, b3log.org\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * https://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\n/*\r\n * @file session.js\r\n *\r\n * @author Liyuan Li\r\n * @version 1.1.0.1, Dec 8, 2015\r\n */\r\nvar session = {\r\n init: function () {\r\n this._initWS();\r\n\r\n var getLayoutState = function (paneState) {\r\n var state = 'normal';\r\n if (paneState.isClosed) {\r\n state = 'min';\r\n } else if (paneState.size >= $('body').width()) {\r\n state = 'max';\r\n }\r\n\r\n return state;\r\n };\r\n\r\n // save session content every 30 seconds\r\n setInterval(function () {\r\n var request = newWideRequest(),\r\n filse = [],\r\n fileTree = [],\r\n currentId = editors.getCurrentId(),\r\n currentFile = currentId ? editors.getCurrentPath() : \"\";\r\n\r\n editors.tabs.obj._$tabs.find(\"div\").each(function () {\r\n var $it = $(this);\r\n if ($it.find(\"span:eq(0)\").attr(\"title\") !== config.label.start_page) {\r\n filse.push($it.find(\"span:eq(0)\").attr(\"title\"));\r\n }\r\n });\r\n\r\n fileTree = tree.getOpenPaths();\r\n\r\n request.currentFile = currentFile; // current editor file\r\n request.fileTree = fileTree; // file tree expansion state\r\n request.files = filse; // editor tabs\r\n\r\n\r\n request.layout = {\r\n \"side\": {\r\n \"size\": windows.outerLayout.west.state.size,\r\n \"state\": getLayoutState(windows.outerLayout.west.state)\r\n },\r\n \"sideRight\": {\r\n \"size\": windows.innerLayout.east.state.size,\r\n \"state\": getLayoutState(windows.innerLayout.east.state)\r\n },\r\n \"bottom\": {\r\n \"size\": windows.innerLayout.south.state.size,\r\n \"state\": getLayoutState(windows.innerLayout.south.state)\r\n }\r\n };\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: '/session/save',\r\n data: JSON.stringify(request),\r\n dataType: \"json\",\r\n success: function (result) {\r\n }\r\n });\r\n }, 30000);\r\n },\r\n restore: function () {\r\n if (!config.latestSessionContent) {\r\n return;\r\n }\r\n\r\n var fileTree = config.latestSessionContent.fileTree,\r\n files = config.latestSessionContent.files,\r\n currentFile = config.latestSessionContent.currentFile,\r\n id = \"\",\r\n nodesToOpen = [];\r\n\r\n var nodes = tree.fileTree.transformToArray(tree.fileTree.getNodes());\r\n\r\n for (var i = 0, ii = nodes.length; i < ii; i++) {\r\n // expand tree\r\n for (var j = 0, jj = fileTree.length; j < jj; j++) {\r\n if (nodes[i].path === fileTree[j]) {\r\n // expand this node only if its parents are open\r\n var parents = tree.getAllParents(tree.fileTree.getNodeByTId(nodes[i].tId)),\r\n isOpen = true;\r\n for (var l = 0, max = parents.length; l < max; l++) {\r\n if (parents[l].open === false) {\r\n isOpen = false;\r\n }\r\n }\r\n if (isOpen) {\r\n tree.fileTree.expandNode(nodes[i], true, false, true);\r\n } else {\r\n // flag it is open\r\n nodes[i].open = true;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n // open editors\r\n for (var k = 0, kk = files.length; k < kk; k++) {\r\n if (nodes[i].path === files[k]) {\r\n nodesToOpen.push(nodes[i]);\r\n break;\r\n }\r\n }\r\n\r\n if (nodes[i].path === currentFile) {\r\n id = nodes[i].path;\r\n\r\n // FIXME: 上面的展开是异步进行的,所以执行到这里的时候可能还没有展开完,导致定位不了可视区域\r\n tree.fileTree.selectNode(nodes[i]);\r\n wide.curNode = nodes[i];\r\n }\r\n }\r\n\r\n // handle the open sequence of editors\r\n for (var m = 0, mm = files.length; m < mm; m++) {\r\n for (var n = 0, nn = nodesToOpen.length; n < nn; n++) {\r\n if (nodesToOpen[n].path === files[m]) {\r\n tree.openFile(nodesToOpen[n]);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // set the current editor\r\n editors.tabs.setCurrent(id);\r\n for (var c = 0, max = editors.data.length; c < max; c++) {\r\n if (id === editors.data[c].id) {\r\n wide.curEditor = editors.data[c].editor;\r\n break;\r\n }\r\n } \r\n },\r\n _initWS: function () {\r\n // Used for session retention, server will release all resources of the session if this channel closed\r\n var sessionWS = new ReconnectingWebSocket(config.channel + '/session/ws?sid=' + config.wideSessionId);\r\n\r\n sessionWS.onopen = function () {\r\n console.log('[session onopen] connected');\r\n\r\n var dateFormat = function (time, fmt) {\r\n var date = new Date(time);\r\n var dateObj = {\r\n \"M+\": date.getMonth() + 1,\r\n \"d+\": date.getDate(),\r\n \"h+\": date.getHours(),\r\n \"m+\": date.getMinutes(),\r\n \"s+\": date.getSeconds(),\r\n \"q+\": Math.floor((date.getMonth() + 3) / 3),\r\n \"S\": date.getMilliseconds()\r\n };\r\n if (/(y+)/.test(fmt))\r\n fmt = fmt.replace(RegExp.$1, (date.getFullYear() + \"\").substr(4 - RegExp.$1.length));\r\n for (var k in dateObj)\r\n if (new RegExp(\"(\" + k + \")\").test(fmt)) {\r\n fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1)\r\n ? (dateObj[k]) : ((\"00\" + dateObj[k]).substr((\"\" + dateObj[k]).length)));\r\n }\r\n return fmt;\r\n };\r\n\r\n var data = {type: \"Network\", severity: \"INFO\",\r\n message: \"Connected to server [sid=\" + config.wideSessionId + \"], \" + dateFormat(new Date().getTime(), 'yyyy-MM-dd hh:mm:ss')},\r\n $notification = $('.bottom-window-group .notification > table'),\r\n notificationHTML = '';\r\n\r\n notificationHTML += '