Browse Source

Added share icon display on desktop

TC pushbot 5 4 years ago
parent
commit
cfe6f566f8

+ 4 - 1
desktop.go

@@ -61,7 +61,6 @@ func DesktopInit() {
 	})
 }
 
-/////////////////////////////////////////////////////////////////////////////////////
 /*
 	FUNCTIONS RELATED TO PARSING DESKTOP FILE ICONS
 
@@ -203,6 +202,7 @@ func desktop_listFiles(w http.ResponseWriter, r *http.Request) {
 		IsDir         bool
 		IsEmptyDir    bool
 		IsShortcut    bool
+		IsShared      bool
 		ShortcutImage string
 		ShortcutType  string
 		ShortcutName  string
@@ -259,6 +259,9 @@ func desktop_listFiles(w http.ResponseWriter, r *http.Request) {
 
 		}
 		thisFileObject.IsShortcut = isShortcut
+
+		//Check if this file is shared
+		thisFileObject.IsShared = shareManager.FileIsShared(this)
 		//Check the file location
 		username, _ := authAgent.GetUserName(w, r)
 		x, y, _ := getDesktopLocatioFromPath(thisFileObject.Filename, username)

+ 24 - 0
web/SystemAO/file_system/file_share.html

@@ -128,9 +128,12 @@
                     $("#sharingRemoveBtn").addClass("disabled");
                     return
                 }
+
+
                 //Make sure one file is choicen each time
                 inputFile = inputFile[0]; 
                 shareingFileData = inputFile;
+
                 initFileDetails(shareingFileData, function(shareUUID){
                     //Set the mode of share if it is defined
                     if (shareingFileData.shareMode !== undefined && shareingFileData.shareMode == "remove"){
@@ -187,6 +190,17 @@
                                
                             });
 
+                            //If the file is from desktop, set share icon
+                            if (ao_module_virtualDesktop == true){
+                                var fileDir = shareingFileData.filepath.split("/");
+                                fileDir.pop();
+                                fileDir = fileDir.join("/");
+                                if (fileDir == "user:/Desktop"){
+                                    //Remove share icon
+                                    parent.setFileShareIndicator(shareingFileData.filename);
+                                }
+                            }
+
                             if (callback != undefined){
                                 callback(data.UUID)
                             }
@@ -215,6 +229,16 @@
                             $("#sharelink").attr("href", "#");
                             $("#qrcode").html(`<br><br><h1><i class="green checkmark icon"></i> Share Removed</h1>`);
 
+                            //If the file is located on desktop and it is web desktop mode
+                            if (ao_module_virtualDesktop == true){
+                                var fileDir = shareingFileData.filepath.split("/");
+                                fileDir.pop();
+                                fileDir = fileDir.join("/");
+                                if (fileDir == "user:/Desktop"){
+                                    //Remove share icon
+                                    parent.removeFileShareIndicator(shareingFileData.filename);
+                                }
+                            }
                         }
                     }
                 });

+ 85 - 3
web/desktop.system

@@ -682,6 +682,34 @@
             background-color:#f5f5f5 !important;
         }
 
+        .fileShareIndicator.small{
+            position: absolute;
+            top: calc(50% - 8px);
+            left: 8px;
+            height: 10px;
+            width: 10px;
+        }
+
+        .fileShareIndicator.medium{
+            position: absolute;
+            top: calc(50% - 8px);
+            left: 10px;
+            height: 16px;
+            width: 16px;
+        }
+
+        .fileShareIndicator.big{
+            position: absolute;
+            top: calc(50% - 8px);
+            left: 12px;
+            height: 18px;
+            width: 18px;
+        }
+
+        .fileShareIndicator img{
+            width: 100%;
+        }
+
          /* Offline blinking warning css */
          @-moz-keyframes blink {
                 0% {
@@ -2850,6 +2878,7 @@
             var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
             var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
             var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
+            var isShared = JSON.parse(JSON.stringify(filedata.IsShared));
             var maxlength = 12;
             var type = "file";
             let shortenedName = filename;
@@ -2933,6 +2962,7 @@
                         size: size,
                         imagePath: imagePath,
                         shortenedName: shortenedName,
+                        isShared: isShared,
                     });
                 }
 
@@ -2950,6 +2980,7 @@
                     size: size,
                     imagePath: imagePath,
                     shortenedName: shortenedName,
+                    isShared: isShared,
                 });
             }
            
@@ -2981,6 +3012,7 @@
             if (properties.type == "file" && isChrome){
                 htmlType = "a";
             }
+           
             var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon" 
                     type="${properties.type}" 
                     draggable="true" 
@@ -2994,11 +3026,18 @@
                     filepath="${properties.filepath}" 
                     filedata="${properties.compressedFiledata}" 
                     style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
-                    <span class="launchIconWrapper"><img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
-                        <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p></span>
+                    <span class="launchIconWrapper">
+                        <img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
+                        <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p>
+                    </span>
                     </${htmlType}>`);
 
             $(target).append(thisIcon);
+
+            //Updates 20 May 2021: Check if this file is shared. If yes, append the share icon
+            if (typeof(properties.isShared) != "undefined" && properties.isShared == true){
+                setFileShareIndicator(properties.filename);
+            }
             
             if (properties.type == "file" && isChrome){
                 console.log(isChrome);
@@ -3024,6 +3063,50 @@
             }
         }
 
+        /*
+            Share indicator settings
+            This append or remove share from a particular file
+
+            Only require filename as all files here are on desktop
+        */
+
+        function getFileObjectByFilename(filename){
+            var result = null;
+            $(".launchIcon").each(function(){
+                var thisFilename = $(this).attr("filename");
+                if (thisFilename == filename){
+                    result = $(this);
+                }
+            });
+
+            return result;
+        }
+
+        function setFileShareIndicator(filename){
+            var targetFileObject = getFileObjectByFilename(filename);
+            if (targetFileObject == null){
+                return;
+            }
+            var sharedIcon = `<div class="fileShareIndicator ${desktopIconSize}">
+                <img src="img/desktop/system_icon/shared.png">
+            </div>`;
+
+            $(targetFileObject).find(".launchIconWrapper").append(sharedIcon);
+
+        }
+
+        function removeFileShareIndicator(filename){
+            var targetFileObject = getFileObjectByFilename(filename);
+            if (targetFileObject == null){
+                return;
+            }
+
+            var indicator = $(targetFileObject).find(".fileShareIndicator");
+            if (indicator.length > 0){
+                indicator.remove();
+            }
+        }
+
         // ========================== LAUNCH ICON OPERATIONS ================
 
         //This function start all the launchicon related events
@@ -4268,7 +4351,6 @@
                         }else{
                             addContextMenuTitle($("#subcontextmenu"), `<i class="share alternate icon"></i> Share this File`);
                         }
-                        console.log(data);
 
                         var checkmarkStyle = `style="color: #71ba68;"`;
                         var anyoneClass = "";

BIN
web/img/desktop/system_icon/shared.png


BIN
web/img/desktop/system_icon/shared.psd