Переглянути джерело

Fixed more NotepadA shit by rewritting php script in AGI

Toby Chui 3 роки тому
батько
коміт
2dab0d0c0e

+ 1 - 1
web/NotepadA/ace/editor.html

@@ -157,7 +157,7 @@
 	}
 	
 	function getFilepath(){
-		return (filename.replace("../",""));
+		return (filepath);
 	}
 	
 	function openInNewTab(){

+ 38 - 0
web/NotepadA/backend/filesaver.js

@@ -0,0 +1,38 @@
+/*
+    FileSaver.js
+    Author: tobychui
+
+    This file save the NotepadA files to server side
+    Required POST paramters:
+
+    filepath
+    content
+*/
+
+
+function error(message){
+    sendJSONResp(JSON.stringify({
+        "error": message
+    }));
+}
+
+
+function main(){
+    //Require libraries
+    if (!requirelib("filelib")){
+        error("Unable to request filelib");
+        return
+    }
+
+    //Write to the file
+    var succ = filelib.writeFile(filepath, content);
+    if (!succ){
+        error("Unable to save file");
+        return
+    }else{
+        sendResp("OK");
+        return
+    }
+}
+
+main();

+ 28 - 0
web/NotepadA/backend/getDir.js

@@ -0,0 +1,28 @@
+/*
+    getDir.js
+
+    Author: tobychui
+    An implementation in AGI script for getDir.php
+
+*/
+
+function basename(filepath){
+    return filepath.split("/").pop();
+}
+
+
+requirelib("filelib");
+var results = [];
+if (listpath == ""){
+    listpath = "user:/";
+}
+if (listpath.substring(listpath.length - 1, listpath.length) != "/"){
+    listpath = listpath + "/";
+}
+var fileList = filelib.aglob(listpath + "*");
+for (var i = 0; i < fileList.length; i++){
+    if (filelib.isDir(fileList[i]) && basename(fileList[i]).substring(0, 1) != "."){
+        results.push([fileList[i] + "/",basename(fileList[i])])
+    }
+}
+sendJSONResp(JSON.stringify(results));

+ 56 - 11
web/NotepadA/index.html

@@ -280,6 +280,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
 </div>
 <script>
 //Global variables
+var moduleRootPath = "NotepadA/";
 var dragIn = "";
 var theme = 'github';
 var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
@@ -291,7 +292,7 @@ var fontsize = 12;
 var VDI = ao_module_virtualDesktop;
 var openedFilePath = [];
 var previousSavedState = true;
-var currentSaveAsPath = "";
+var currentSaveAsPath = "user:/Desktop";
 var insertTarget;
 var currentTabWidth = 0;
 var mainCodingWindow = true;
@@ -468,7 +469,35 @@ function saveToAOCC(){
 }
 
 function SetSaveAsPath(dirpath){
-     $("#directoryList").html("<tr><th>Loading...</th></tr>");
+    $("#directoryList").html("<tr><th>Loading...</th></tr>");
+	if (dirpath == ""){
+		dirpath = "user:/"
+	}
+	currentSaveAsPath = dirpath;
+	//Make sure there is always an ending / at the end of current savepath
+	if (currentSaveAsPath.substring(currentSaveAsPath.length - 1, currentSaveAsPath.length) != "/"){
+		currentSaveAsPath = currentSaveAsPath + "/";
+	}
+
+	//Listdir
+	ao_module_agirun(moduleRootPath + "backend/getDir.js", {listpath: currentSaveAsPath}, function(result){
+		if (result.error !== undefined){
+			onsole.log(result);
+		}else{
+			$("#directoryList").html("<tr><th>📂 " + currentSaveAsPath + "</th></tr>");
+			if (currentSaveAsPath.split("/").length >= 3){
+				//Not root
+				let parentPath = currentSaveAsPath.substr(0, currentSaveAsPath.length -1).split("/");
+				parentPath.pop();
+				parentPath = parentPath.join("/");
+				$("#directoryList").append(`<tr><td class="selectable" foldername="${parentPath}" onClick="changeSaveAsPath(this);">⏎ ../</td></tr>`);
+			}
+			for (var i = 0; i < result.length; i++){
+					$("#directoryList").append('<tr><td class="selectable" foldername="'+result[i][0]+'"  onClick="changeSaveAsPath(this);"> 📂 '+result[i][1]+'</td></tr>');
+			} 
+		}
+	})
+	 /*
     if (dirpath == "../"){
        currentSaveAsPath = currentSaveAsPath.split("/")
        while (currentSaveAsPath.pop() == ""){
@@ -510,6 +539,7 @@ function SetSaveAsPath(dirpath){
             }
         }});
     }
+	*/
 }
 
 
@@ -761,17 +791,26 @@ function handleFileMenu(itemText){
 				break;
 			}
 			var id = getFocusedTab()[0];
-			var uid = Math.round((new Date()).getTime() / 1000);
-			var url = $("#" + id)[0].contentWindow.getFilepath().replace("../","");
+			//var uid = Math.round((new Date()).getTime() / 1000);
+			var url = "./media?file=" + $("#" + id)[0].contentWindow.getFilepath().replace("../","");
 			var title = "NotepadA Runtime";
 			var icon = "code";
-			if (url.substr(0,14) == "/media/storage"){
-				title += " (External Storage)";
-				url = "SystemAOB/functions/extDiskAccess.php?file=" + url;
-				newfw(url,title,icon,uid,1080,580);
-			}else{
-				newfw(url,title,icon,uid,1080,580);
-			}
+			ao_module_newfw({
+				url: url,
+				width: 1080,
+				height: 580,
+				appicon: "NotepadA/img/small_icon.png",
+			});
+
+			/*
+				if (url.substr(0,14) == "/media/storage"){
+					title += " (External Storage)";
+					url = "SystemAOB/functions/extDiskAccess.php?file=" + url;
+					newfw(url,title,icon,uid,1080,580);
+				}else{
+					newfw(url,title,icon,uid,1080,580);
+				}
+			*/
 			break;
 		case 3:
 			//Open the current folder in explorer
@@ -779,9 +818,12 @@ function handleFileMenu(itemText){
 			if (base == undefined){
 				break;
 			}
+			/*
 			if (base.includes("../../")){
 			    base = base.replace("../../","");
 			}
+
+			
 			var url = "SystemAOB/functions/file_system/index.php?controlLv=2&finishing=embedded&subdir=" + base;
 			if (base.substr(0,14) == "/media/storage"){
 				//This file is located in external storage location. Open file editor in ext mode
@@ -795,6 +837,9 @@ function handleFileMenu(itemText){
 				break;
 			}
 			newfw(url,title,icon,uid,1080,580);
+			*/
+
+			ao_module_openPath(base);
 			break;
 		case 4:
 			//Reload is pressed