Explorar el Código

Fixed file operation bug and move desktop files to desktop folder

TC pushbot 5 hace 4 años
padre
commit
1cdfdd5ec8

+ 1 - 1
file_system.go

@@ -676,7 +676,7 @@ func system_fs_validateFileOpr(w http.ResponseWriter, r *http.Request) {
 	}
 	vsrcFiles, _ := mv(r, "src", true)
 	vdestFile, _ := mv(r, "dest", true)
-	var duplicateFiles []string
+	var duplicateFiles []string = []string{}
 
 	//Loop through all files are see if there are duplication during copy and paste
 	sourceFiles := []string{}

+ 6 - 1
mod/subservice/subservice.go

@@ -261,7 +261,12 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
 			absolutePath, _ = filepath.Abs(initPath)
 		}
 
-		cmd := exec.Command(absolutePath, "-port", ":"+intToString(thisServicePort), "-rpt", "http://localhost:"+intToString(sr.listenPort)+"/api/ajgi/interface")
+		servicePort := ":" + intToString(thisServicePort)
+		if fileExists(filepath.Join(servicePath, "/.intport")) {
+			servicePort = intToString(thisServicePort)
+		}
+
+		cmd := exec.Command(absolutePath, "-port", servicePort, "-rpt", "http://localhost:"+intToString(sr.listenPort)+"/api/ajgi/interface")
 		cmd.Stdout = os.Stdout
 		cmd.Stderr = os.Stderr
 		cmd.Dir = filepath.ToSlash(servicePath + "/")

+ 2 - 14
web/SystemAO/file_system/file_explorer.html

@@ -373,17 +373,6 @@
                 overflow:auto;
             }
 
-            /*
-            .popupheader.whiteTheme{
-                background-color:#eee;
-                color: #232322;
-            }
-            .popupheader.darkTheme{
-                background-color:#111017 !important;
-                color: white;
-            }
-            */
-
             .popupcloser{
                 position:absolute;
                 top:5px;
@@ -1822,7 +1811,6 @@
                           
                         });
                     }
-                    
                 };
 
                 thumbRenderWebSocket.onclose = function(event) {
@@ -2447,7 +2435,7 @@
                         url: `../../system/file_system/validateFileOpr`,
                         data: {src: JSON.stringify(fileList), dest: targetDir},
                         success: function(data){
-                           if (!nocheck && data !== null){
+                           if (!nocheck && data.length > 0){
                                //There are problem with the copy target. Pop up overwrite rule selector
                                 showDuplicateHandler(data);
                            }else{
@@ -2514,7 +2502,7 @@
                         url: `../../system/file_system/validateFileOpr`,
                         data: {src: JSON.stringify(fileList), dest: targetDir},
                         success: function(data){
-                           if (!nocheck && data !== null){
+                           if (!nocheck && data.length > 0){
                                //There are problem with the copy target. Pop up overwrite rule selector
                                 showDuplicateHandler(data);
                            }else{

+ 20 - 11
web/SystemAO/file_system/file_operation.html

@@ -385,9 +385,7 @@ mainloop:
                             $("#progressbar").css("background-color", "#2bba35");
                             $("#progressbar").css("width", "100%");
                             $("#progress").text("100%")
-                            setTimeout(function(){
-                                ao_module_close();
-                            }, 1000);
+                            handleFinish({});
                         }
                     };
 
@@ -464,9 +462,7 @@ mainloop:
                             $("#progressbar").css("background-color", "#2bba35");
                             $("#progressbar").css("width", "100%");
                             $("#progress").text("100%")
-                            setTimeout(function(){
-                                ao_module_close();
-                            }, 1000);
+                            handleFinish({});
                         }
                      
                         
@@ -546,10 +542,8 @@ mainloop:
                         if (!enterErrorMode){
                             $("#progressbar").css("background-color", "#2bba35");
                             $("#progressbar").css("width", "100%");
-                            $("#progress").text("100%")
-                            setTimeout(function(){
-                                ao_module_close();
-                            }, 1000);
+                            $("#progress").text("100%");
+                            handleFinish({});
                         }
                     };
 
@@ -626,12 +620,27 @@ mainloop:
                         //Action completed. close window.
                         setTimeout(function(){
                             //Do callback if exists
-                            if (operationConfig.callbackWindowID !== undefined && operationConfig.callbackFunction !== undefined){
+                            if (operationConfig.callbackWindowID == "desktop"){
+                                //Special call from desktop
+                                parent.eval(operationConfig.callbackFunction);
+                            }else if (operationConfig.callbackWindowID !== undefined && operationConfig.callbackFunction !== undefined){
                                 var callbackWindowObject = parent.getFloatWindowByID(operationConfig.callbackWindowID)
                                 var windowObject = $(callbackWindowObject).find("iframe")[0];
                                 console.log(windowObject.contentWindow, operationConfig.callbackFunction);
                                 windowObject.contentWindow.eval(operationConfig.callbackFunction);
                             }
+
+                            //If the target is desktop, refresh desktop as well
+                            var filteredDest = operationConfig.dest;
+                            if (filteredDest.substr(filteredDest.length - 1) == "/"){
+                                filteredDest = filteredDest.substr(0, filteredDest.length - 1);
+                            }
+                            var dirChunk = filteredDest.split("/");
+                            console.log(dirChunk);
+                            if (dirChunk.length == 2 && dirChunk[0].toLowerCase() == "user:" && dirChunk[1].toLowerCase() == "desktop"){
+                                //This is a direct access desktop file
+                                parent.refresh(undefined, true);
+                            }
                             ao_module_close();
                         }, 1000);
                     }else if (opr == "download"){

+ 74 - 41
web/desktop.system

@@ -3200,8 +3200,6 @@
             if (sourceFilelist !== ""){
                 sourceFilelist = JSON.parse(sourceFilelist);
             }
-            console.log(sourceFilelist);
-
 
             //Drop opererations
             if (target.attr("id") == "bgwrapper") {
@@ -3296,20 +3294,6 @@
                                 title = "Moving "
                             }
 
-                            //Check if any of the files already exists on desktop
-                            /*
-                            var duplicateFound = false;
-                            filelist.forEach(file => {
-                                var thisFilename = file.filename;
-                                desktopFileList.forEach(desktopFile => {
-                                    if (desktopFile == thisFilename){
-                                        //Diplicate
-                                        duplicateFound = true;
-                                    }
-                                });
-                            });
-                            */
-
                             var filepathList = [];
                             filelist.forEach(file => {
                                 filepathList.push(file.filepath)
@@ -3397,14 +3381,6 @@
                             let thisIconObject = getObjectFromPath(filepath);
                             let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
                             let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
-                            //Check for duplication
-                            /*
-                            var duplicateObject = getObjectFromLocation(finalIconLocation[0][0]  + iconOffsetXY[0], finalIconLocation[0][1] + iconOffsetXY[1]);
-                            if (duplicateObject !== undefined) {
-                                //There are already object there. Relocate this object later
-                                relocatePendingObjects.push(duplicateObject)
-                            }
-                            */
                         
                             //Move this icon to designed location
                             $(thisIconObject).css({
@@ -3500,7 +3476,24 @@
                 }
             } else if (target.attr("type") == "folder") {
                 //Move this file or folder into the target folder
-                //WIP
+                var moveSources = [sourceFilepath];
+                if ($(".launchIconWrapper.selected").length > 1){
+                    //Multi move operations
+                    moveSources = [];
+                    $(".launchIconWrapper.selected").each(function(){
+                        var thisFileData = $(this).parent().attr("filedata");
+                        thisFileData = JSON.parse(decodeURIComponent(thisFileData));
+                        moveSources.push(thisFileData.Filepath);
+                    });
+                }
+
+                //Get the move target location
+                var targetFd = $(target).attr("filedata");
+                targetFd = JSON.parse(decodeURIComponent(targetFd));
+
+                //Move it
+                console.log(moveSources, targetFd.Filepath);
+                moveSourceFilesToTarget(moveSources, targetFd.Filepath)
 
             } else if (target.attr("type") == "shortcut") {
                 //Opening with the shortcut
@@ -3539,14 +3532,66 @@
                     openFileWithModule(shortcutModule, openFileList);
                 } else if (shortcutType == "folder") {
                     //Move the source file into this folder
-
+                    alert("wip");
                 }
 
             } else {
-                console.log("Unknown reaction type: ", target.attr("type"));
+                console.log("Unknown action type: ", target.attr("type"));
             }
         }
 
+        
+        //Use move if it is folder on desktop, use copy if it is a shortcut
+        function moveSourceFilesToTarget(sourceList, target, opr="move"){
+            var oprConfig = {
+                opr: opr,
+                src: sourceList,
+                dest: target,
+                callbackWindowID: "desktop",
+                callbackFunction: `refresh(undefined, true)`
+            }
+            var configHash = encodeURIComponent(JSON.stringify(oprConfig));
+            var title = "Copying " + sourceList.length;
+            if (sourceList.length > 1){
+                title += " files";
+            }else{
+                title += " file";
+            }
+
+            //Create FloatWindow to handle the file operations
+            newFloatWindow({
+                url: "SystemAO/file_system/file_operation.html#" + configHash,
+                width: 400,
+                height: 220,
+                appicon: "SystemAO/file_system/img/selector.png",
+                title: title
+            });
+
+            //Delete the file location from db
+            sourceList.forEach(file => {
+                let filename = file.split("/").pop();
+                $.ajax({
+                    url: "system/desktop/files",
+                    data: {del: filename},
+                    success: function(data){
+                        if (data.error !== undefined){
+                            console.log(data.error);
+                        }
+                    }
+                });
+            });
+           
+        }
+
+        function requestCSRFToken(callback){
+            $.ajax({
+                url: "system/csrf/new",
+                success: function(token){
+                    callback(token);
+                }
+            });
+        }
+        
         function getModuleFromShortcutInfo(shortcutInfo) {
             var ShortcutPath = shortcutInfo["ShortcutPath"];
             if (ShortcutPath.includes("/") == false) {
@@ -5161,25 +5206,13 @@
                                     if (data.error == undefined){
                                         let iconSize = 20;
                                         let topOffset = $(imageContainer).height() - iconSize/2 + 2;
-                                        $(imageContainer).parent().append(`<img src="${data.IconPath}" style="position: absolute; right: 0px; top: ${topOffset}px; width: ${iconSize}px; height: ${iconSize}px;"></img>`);
-                                        console.log(filedata.Filename, data);
+                                        $(imageContainer).parent().append(`<img src="${data.IconPath}" style="position: absolute; right: 0px; top: ${topOffset}px; width: ${iconSize}px; height: ${iconSize}px; pointer-events:none;"></img>`);
                                     }
                                 }
                             })
                         }
                     }
                 });
-
-                /*
-                $(".fileObject").each(function(){
-                    if (thumbData[1].length > 0){
-                        if ($(this).attr("filename") == thumbData[0]){
-                            $(this).find("img").attr("src","data:image/jpg;base64," + thumbData[1]);
-                        }
-                    }
-                    
-                });
-                */
             };
 
             thumbRenderWebSocket.onclose = function(event) {
@@ -5420,7 +5453,7 @@
                 socket.onopen = function(e) {
                     if (filesize < uploadFileChunkSize){
                         //This file is smaller than chunk size, set it to somwhere within 10% - 20% so it doesn't look like it is stuck
-                        
+                        $("." + uploadingIconUUID + ".launchIcon").find(".bar").css("width", "15%");
                     }
                     
                     //Send the first chunk