diff --git a/conf/wide.go b/conf/wide.go index a3ffffb..d0861e1 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -102,7 +102,7 @@ func Load(confPath, confData, confServer, confLogLevel string) { } func initUsers() { - os.MkdirAll(Wide.Data + PathSeparator + "users", 0755) + os.MkdirAll(Wide.Data+PathSeparator+"users", 0755) f, err := os.Open(Wide.Data + PathSeparator + "users") if nil != err { @@ -325,7 +325,7 @@ func initCustomizedConfs() { // UpdateCustomizedConf creates (if not exists) or updates user customized configuration files. // -// 1. /static/user/{userId}/style.css +// 1. /static/users/{userId}/style.css func UpdateCustomizedConf(userId string) { var u *User for _, user := range Users { // maybe it is a beauty of the trade-off of the another world between design and implementation @@ -347,7 +347,7 @@ func UpdateCustomizedConf(userId string) { os.Exit(-1) } - dir := filepath.Clean(Wide.Data + "/static/" + userId) + dir := filepath.Clean(Wide.Data + "/static/users/" + userId) if err := os.MkdirAll(dir, 0755); nil != err { logger.Error(err) diff --git a/main.go b/main.go index ab8ecf3..386fbba 100644 --- a/main.go +++ b/main.go @@ -95,18 +95,13 @@ func main() { // static resources http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + http.Handle("/static/users/", http.StripPrefix("/static/", http.FileServer(http.Dir("C:\\Users\\DL882\\wide\\static\\")))) serveSingle("/favicon.ico", "./static/favicon.ico") // oauth http.HandleFunc("/oauth/github", session.RedirectGitHubHandler) http.HandleFunc("/oauth/github/callback", session.GithubCallbackHandler) - // workspaces - for _, user := range conf.Users { - http.Handle("/workspace/"+user.Id+"/", http.StripPrefix("/workspace/"+user.Id+"/", http.FileServer(http.Dir(user.WorkspacePath())))) - http.Handle("/static/user/", http.StripPrefix("/workspace/"+user.Id+"/", http.FileServer(http.Dir(conf.Wide.Data + conf.PathSeparator + "static")))) - } - // session http.HandleFunc("/session/ws", handlerWrapper(session.WSHandler)) http.HandleFunc("/session/save", handlerWrapper(session.SaveContentHandler)) diff --git a/session/oauthctl.go b/session/oauthctl.go index f72ec26..9e4bad3 100644 --- a/session/oauthctl.go +++ b/session/oauthctl.go @@ -185,9 +185,6 @@ func addUser(userId, userName, userAvatar string) string { helloWorld(workspace) conf.UpdateCustomizedConf(userId) - http.Handle("/workspace/"+userId+"/", - http.StripPrefix("/workspace/"+userId+"/", http.FileServer(http.Dir(newUser.WorkspacePath())))) - logger.Infof("Created a user [%s]", userId) return userCreated diff --git a/static/js/editors.js b/static/js/editors.js index 6383e05..83762c5 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -246,7 +246,7 @@ var editors = { + '"> ' + config.label.start_page + '', content: '
', after: function () { - $("#startPage").load(config.context + '/start?sid=' + config.wideSessionId); + $("#startPage").load('/start?sid=' + config.wideSessionId); $.ajax({ url: "https://hacpai.com/apis/articles?tags=wide,golang&p=1&size=20", type: "GET", @@ -329,7 +329,7 @@ var editors = { $.ajax({ async: false, // 同步执行 type: 'POST', - url: config.context + '/autocomplete', + url: '/autocomplete', data: JSON.stringify(request), dataType: "json", success: function (data) { @@ -435,7 +435,7 @@ var editors = { $.ajax({ type: 'POST', - url: config.context + '/exprinfo', + url: '/exprinfo', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -583,7 +583,7 @@ var editors = { $.ajax({ type: 'POST', - url: config.context + '/find/decl', + url: '/find/decl', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -613,7 +613,7 @@ var editors = { $.ajax({ type: 'POST', - url: config.context + '/find/usages', + url: '/find/usages', data: JSON.stringify(request), dataType: "json", success: function (result) { diff --git a/static/js/menu.js b/static/js/menu.js index cc461da..422a52c 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -61,7 +61,7 @@ var menu = { }); }, _initAbout: function () { - $("#dialogAbout").load(config.context + '/about', function () { + $("#dialogAbout").load('/about', function () { $("#dialogAbout").dialog({ "modal": true, "title": config.label.about, @@ -159,12 +159,12 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/logout', + url: '/logout', data: JSON.stringify(request), dataType: "json", success: function (result) { if (result.succ) { - window.location.href = config.context + "/login"; + window.location.href = "/login"; } } }); @@ -189,7 +189,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/go/get', + url: '/go/get', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -216,7 +216,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/go/install', + url: '/go/install', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -244,7 +244,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/go/test', + url: '/go/test', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -272,7 +272,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/go/vet', + url: '/go/vet', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -307,7 +307,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/build', + url: '/build', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -340,7 +340,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/build', + url: '/build', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -351,7 +351,7 @@ var menu = { }); }, _initPreference: function () { - $("#dialogPreference").load(config.context + '/preference', function () { + $("#dialogPreference").load('/preference', function () { $("#dialogPreference input").keyup(function () { var isChange = false, emptys = [], @@ -465,7 +465,7 @@ var menu = { $.ajax({ type: 'POST', - url: config.context + '/preference', + url: '/preference', data: JSON.stringify(request), success: function (result, textStatus, jqXHR) { if (!result.succ) { @@ -496,7 +496,7 @@ var menu = { var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); $okBtn.prop("disabled", true); - $("#themesLink").attr("href", config.staticServer + '/static/css/themes/' + $theme.val() + '.css'); + $("#themesLink").attr("href", '/static/css/themes/' + $theme.val() + '.css'); config.editorTheme = $editorTheme.val(); for (var i = 0, ii = editors.data.length; i < ii; i++) { diff --git a/static/js/playground.js b/static/js/playground.js index bbf73e6..ae6a253 100644 --- a/static/js/playground.js +++ b/static/js/playground.js @@ -91,7 +91,7 @@ var playground = { $.ajax({ async: false, // 同步执行 type: 'POST', - url: config.context + '/playground/autocomplete', + url: '/playground/autocomplete', data: JSON.stringify(request), dataType: "json", success: function (data) { @@ -356,7 +356,7 @@ var playground = { $.ajax({ type: 'POST', - url: config.context + '/playground/save', + url: '/playground/save', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -375,7 +375,7 @@ var playground = { request.url = url; $.ajax({ type: 'POST', - url: config.context + '/playground/short-url', + url: '/playground/short-url', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -420,7 +420,7 @@ var playground = { $.ajax({ type: 'POST', - url: config.context + '/playground/stop', + url: '/playground/stop', data: JSON.stringify(request), dataType: "json" }); @@ -443,7 +443,7 @@ var playground = { $.ajax({ type: 'POST', - url: config.context + '/playground/save', + url: '/playground/save', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -462,7 +462,7 @@ var playground = { $.ajax({ type: 'POST', - url: config.context + '/playground/build', + url: '/playground/build', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -482,7 +482,7 @@ var playground = { $.ajax({ type: 'POST', - url: config.context + '/playground/run', + url: '/playground/run', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -509,7 +509,7 @@ var playground = { $.ajax({ type: 'POST', - url: config.context + '/playground/save', + url: '/playground/save', data: JSON.stringify(request), dataType: "json", success: function (result) { diff --git a/static/js/session.js b/static/js/session.js index 85adb1a..d93915c 100644 --- a/static/js/session.js +++ b/static/js/session.js @@ -74,7 +74,7 @@ var session = { $.ajax({ type: 'POST', - url: config.context + '/session/save', + url: '/session/save', data: JSON.stringify(request), dataType: "json", success: function (result) { diff --git a/static/js/shell.js b/static/js/shell.js deleted file mode 100644 index 61ccd3f..0000000 --- a/static/js/shell.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2014-2019, b3log.org & hacpai.com - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * @file shell.js - * - * @author Liang Ding - * @version 1.0.0.1, Dec 8, 2015 - */ -var shell = { - _shellWS: undefined, - _initWS: function () { - shell.shellWS = new ReconnectingWebSocket(config.channel + '/shell/ws?sid=' + config.wideSessionId); - shell.shellWS.onopen = function () { - console.log('[shell onopen] connected'); - }; - shell.shellWS.onmessage = function (e) { - console.log('[shell onmessage]' + e.data); - var data = JSON.parse(e.data); - if ('init-shell' !== data.cmd) { - $('#shellOutput').val(data.output); - } - }; - shell.shellWS.onclose = function (e) { - console.log('[shell onclose] disconnected (' + e.code + ')'); - }; - shell.shellWS.onerror = function (e) { - console.log('[shell onerror] ' + e); - }; - }, - init: function () { - this._initWS(); - - $('#shellInput').keydown(function (event) { - if (13 === event.which) { - var input = { - cmd: $('#shellInput').val() - }; - shell.shellWS.send(JSON.stringify(input)); - $('#shellInput').val(''); - } - }); - } -}; - -$(document).ready(function () { - shell.init(); -}); \ No newline at end of file diff --git a/static/js/tree.js b/static/js/tree.js index c86ae10..c048266 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -160,7 +160,7 @@ var tree = { $.ajax({ async: false, type: 'POST', - url: config.context + '/file/zip/new', + url: '/file/zip/new', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -175,7 +175,7 @@ var tree = { }); if (isSucc) { - window.open(config.context + '/file/zip?path=' + wide.curNode.path + ".zip"); + window.open('/file/zip?path=' + wide.curNode.path + ".zip"); } }, crossCompile: function (platform) { @@ -186,7 +186,7 @@ var tree = { $.ajax({ async: false, type: 'POST', - url: config.context + '/cross', + url: '/cross', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -198,28 +198,6 @@ var tree = { } }); }, - decompress: function () { - var request = newWideRequest(); - request.path = wide.curNode.path; - - $.ajax({ - async: false, - type: 'POST', - url: config.context + '/file/decompress', - data: JSON.stringify(request), - dataType: "json", - success: function (result) { - if (!result.succ) { - $("#dialogAlert").dialog("open", result.msg); - - return false; - } - - var dir = wide.curNode.getParentNode(); - tree.fileTree.reAsyncChildNodes(dir, "refresh"); - } - }); - }, refresh: function (it) { if (it) { if ($(it).hasClass("disabled")) { @@ -238,7 +216,7 @@ var tree = { $.ajax({ type: 'POST', - url: config.context + '/files', + url: '/files', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -257,7 +235,7 @@ var tree = { }, async: { enable: true, - url: config.context + "/file/refresh", + url: "/file/refresh", autoParam: ["path"] }, callback: { @@ -392,7 +370,7 @@ var tree = { $.ajax({ async: false, type: 'POST', - url: config.context + '/file', + url: '/file', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -419,7 +397,7 @@ var tree = { if ("img" === data.mode) { // 是图片文件的话新建 tab 打开 // 最好是开 tab,但这个最终取决于浏览器设置 - var w = window.open(config.context + data.path); + var w = window.open(data.path); return false; } @@ -481,7 +459,7 @@ var tree = { $.ajax({ type: 'POST', - url: config.context + '/file/search/text', + url: '/file/search/text', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -517,7 +495,7 @@ var tree = { $.ajax({ type: 'POST', - url: config.context + '/file/rename', + url: '/file/rename', data: JSON.stringify(request), dataType: "json", success: function (result) { diff --git a/static/js/wide.js b/static/js/wide.js index 2d5d691..3825780 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -38,7 +38,7 @@ var wide = { $.ajax({ type: 'POST', async: false, - url: config.context + '/outline', + url: '/outline', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -121,7 +121,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/file/remove', + url: '/file/remove', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -159,7 +159,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/file/new', + url: '/file/new', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -203,7 +203,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/file/new', + url: '/file/new', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -264,7 +264,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/file/find/name', + url: '/file/find/name', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -360,7 +360,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/run', + url: '/run', data: JSON.stringify(request), dataType: "json" }); @@ -441,7 +441,7 @@ var wide = { $.ajax({ async: false, type: 'POST', - url: config.context + '/file/zip/new', + url: '/file/zip/new', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -456,7 +456,7 @@ var wide = { }); if (path) { - window.open(config.context + '/file/zip?path=' + path + ".zip"); + window.open('/file/zip?path=' + path + ".zip"); } } } @@ -521,7 +521,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/file/save', + url: '/file/save', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -557,7 +557,7 @@ var wide = { request.nextCmd = ""; // build only, no following operation $.ajax({ type: 'POST', - url: config.context + '/build', + url: '/build', data: JSON.stringify(request), dataType: "json", beforeSend: function () { @@ -590,7 +590,7 @@ var wide = { $.ajax({ type: 'POST', - url: config.context + '/stop', + url: '/stop', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -612,7 +612,7 @@ var wide = { $.ajax({ async: false, // sync type: 'POST', - url: config.context + '/go/fmt', + url: '/go/fmt', data: JSON.stringify(request), dataType: "json", success: function (result) { @@ -645,7 +645,7 @@ var wide = { $.ajax({ async: false, // sync type: 'POST', - url: config.context + '/go/fmt', + url: '/go/fmt', data: JSON.stringify(request), dataType: "json", success: function (result) { diff --git a/static/js/wide.min.js b/static/js/wide.min.js index 91f63e0..0bb316b 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":case"start-get":bottomGroup.fillOutput(t.output);break;case"go test":case"go vet":case"go install":case"go get":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":case"start-get":bottomGroup.fillOutput(t.output);break;case"go test":case"go vet":case"go install":case"go get":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 case 'start-get':\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 case 'go get':\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: config.context + '/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(config.context + '/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: config.context + '/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: config.context + '/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: config.context + '/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: config.context + '/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: config.context + '/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-2019, b3log.org & hacpai.com\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: config.context + '/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 case 'start-get':\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 case 'go get':\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-2019, b3log.org & hacpai.com\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 += '