Finder refactoring
This commit is contained in:
parent
9c0cc8d709
commit
4426d30342
@ -8,6 +8,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//TODO Use this to get json from back
|
||||
type Cat struct {
|
||||
fs *webfilesystem.WebFileSystem
|
||||
}
|
||||
|
@ -63,42 +63,7 @@ class Finder{
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DragEvent} event
|
||||
* @param {HTMLElement} draggedElem
|
||||
*/
|
||||
async DropEvent(event){
|
||||
// console.log(event.dataTransfer.getData("dropType"))
|
||||
if (event.dataTransfer.getData("dropType") == "move"){
|
||||
let params = new URLSearchParams({
|
||||
sourcePath: event.dataTransfer.getData("filePath"),
|
||||
targetPath: this.path + "/" + event.dataTransfer.getData("fileName"),
|
||||
})
|
||||
let response = await fetch('/fs/move/?' + params)
|
||||
console.log(response.status)
|
||||
} else {
|
||||
let formData = new FormData()
|
||||
console.log(this.path)
|
||||
for (let i = 0; i < event.length; i++) {
|
||||
const element = event[i];
|
||||
formData.append("file", element.getAsFile())
|
||||
// console.log(formData)
|
||||
}
|
||||
// console.log(formData)
|
||||
// formData.append("photo", photo);
|
||||
fetch('/fs/upload/?' + new URLSearchParams({
|
||||
parentPath: this.path,
|
||||
}),
|
||||
{
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
.catch((error) => {
|
||||
WebDesktopEnvironment.Alert(error);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string[]} args
|
||||
*/
|
||||
@ -166,46 +131,6 @@ class Finder{
|
||||
WebDesktopEnvironment.CloseWindow(newWindow)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static async DeleteFile(path){
|
||||
const params = new URLSearchParams({
|
||||
path: path
|
||||
})
|
||||
const response = await fetch(`/fs/delete?` + params)
|
||||
if (response.status != 200){
|
||||
WebDesktopEnvironment.Alert("DELETE ERROR") //TODO
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static async CreateDirectory(path){
|
||||
if (path == undefined){
|
||||
WebDesktopEnvironment.Alert("Path is undefined")
|
||||
return false
|
||||
}
|
||||
const params = new URLSearchParams({
|
||||
path: `${path}/New Directory`
|
||||
})
|
||||
const response = await fetch(`/fs/createDir?` + params)
|
||||
if (response.status != 200){
|
||||
WebDesktopEnvironment.Alert("DIRCTORY CREATION ERROR") //TODO
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -226,11 +151,14 @@ class FinderWindow{
|
||||
let newWindow = WebDesktopEnvironment.CreateNewWindow(Finder.appId, 500, 350 )
|
||||
newWindow.innerHTML = html
|
||||
|
||||
this.fileView = new FileView(newWindow.querySelector(".FileTileView"),
|
||||
(event) =>{ this.Click(event) },
|
||||
(event) =>{ this.RightClick(event) },
|
||||
(event, draggedElem) =>{ this.DropEvent(event, draggedElem)
|
||||
})
|
||||
// console.log(this.ReRenderDir)
|
||||
this.fileView = new FileView(
|
||||
newWindow.querySelector(".FileTileView"),
|
||||
(event) => { this.Click(event) },
|
||||
(event) => { this.RightClick(event) },
|
||||
(event, draggedElem) => { this.DropEvent(event, draggedElem)},
|
||||
() => { this.ReRenderDir() }
|
||||
)
|
||||
|
||||
newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
|
||||
|
||||
@ -262,6 +190,48 @@ class FinderWindow{
|
||||
this.RenderDir(this.CurPath)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DragEvent} event
|
||||
* @param {HTMLElement} draggedElem
|
||||
*/
|
||||
async DropEvent(event){
|
||||
// console.log(event.dataTransfer.getData("dropType"))
|
||||
if (event.dataTransfer.getData("dropType") == "move"){
|
||||
const sourcePath= event.dataTransfer.getData("filePath")
|
||||
const targetPath = this.CurPath + "/" + event.dataTransfer.getData("fileName")
|
||||
const res = await WebFS.MoveFile(sourcePath, targetPath)
|
||||
if (res){
|
||||
this.ReRenderDir()
|
||||
} else {
|
||||
WebDesktopEnvironment.Alert("UWAGA TODO MOVE FILE ERROR") //TODO
|
||||
}
|
||||
} else {
|
||||
WebDesktopEnvironment.Alert("Not fixed yet")
|
||||
return
|
||||
let formData = new FormData()
|
||||
let files = event.dataTransfer.files
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const element = files[i];
|
||||
console.log(element)
|
||||
formData.append("file", element) //FIXME Conn reset
|
||||
}
|
||||
const params = new URLSearchParams({
|
||||
parentPath: this.CurPath,
|
||||
})
|
||||
const response = await fetch('/fs/upload/?' + params,
|
||||
{
|
||||
method: "POST", //TODO Change to PUT?
|
||||
body: formData
|
||||
})
|
||||
if (response.status != 200){
|
||||
WebDesktopEnvironment.Alert("ERROR IN UPLOADING FILE")//TODO
|
||||
} else {
|
||||
this.ReRenderDir()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
@ -351,14 +321,14 @@ class FinderWindow{
|
||||
let res = false
|
||||
switch (event.target.children[0].getAttribute("action")) {
|
||||
case "createDir":
|
||||
res = await Finder.CreateDirectory(`${this.CurPath}`)
|
||||
res = await WebFS.CreateDirectory(`${this.CurPath}`)
|
||||
console.log(res)
|
||||
if (res){
|
||||
this.ReRenderDir()
|
||||
}
|
||||
break
|
||||
case "deleteFile":
|
||||
res = await Finder.DeleteFile(`${this.CurPath}/${fileName}`)
|
||||
res = await WebFS.DeleteFile(`${this.CurPath}/${fileName}`)
|
||||
console.log(res)
|
||||
if (res){
|
||||
this.ReRenderDir()
|
||||
@ -366,26 +336,6 @@ class FinderWindow{
|
||||
break
|
||||
case "getInfo":
|
||||
res = await Finder.RenderProperites(`${this.CurPath}/${fileName}`)
|
||||
// fetch(`/application/${Finder.appId}/renderProps?` + new URLSearchParams({
|
||||
// path: `${this.CurPath}/${fileName}`
|
||||
// }))
|
||||
// .then((response) => {
|
||||
// console.log(response)
|
||||
// if (response.status == 200){
|
||||
// console.log("Success")
|
||||
// return response.text();
|
||||
// }
|
||||
// })
|
||||
// .then((html) =>{
|
||||
// let newWindow = WebDesktopEnvironment.CreateNewWindow(Finder.appId, 350, 500 )
|
||||
// newWindow.innerHTML = html
|
||||
// newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
|
||||
// WebDesktopEnvironment.CloseWindow(newWindow)
|
||||
// })
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// WebDesktopEnvironment.Alert(error);
|
||||
// })
|
||||
break
|
||||
case "openAsDir":
|
||||
WebDesktopEnvironment.Open(`/Applications/${Finder.appId}.app`,[`${this.CurPath}/${fileName}`])
|
||||
|
0
resources/sys/libs/fs.js
Normal file
0
resources/sys/libs/fs.js
Normal file
@ -6,8 +6,9 @@ class FileView{
|
||||
* @param {HTMLElement} fileViewElem
|
||||
* @param {Function} doubleClickCallback
|
||||
* @param {Function} rightClickCallback
|
||||
* @param {Function} updateFileViewCallback
|
||||
*/
|
||||
constructor(fileViewElem, doubleClickCallback, rightClickCallback, fileUploadCallback){
|
||||
constructor(fileViewElem, doubleClickCallback, rightClickCallback, fileUploadCallback, updateFileViewCallback){
|
||||
//TODO check all params
|
||||
this.parentElem = fileViewElem
|
||||
|
||||
@ -46,6 +47,8 @@ class FileView{
|
||||
event.dataTransfer.setData("fileName", event.target.getAttribute("name"))
|
||||
event.dataTransfer.setData("filePath", this.path + "/" + event.target.getAttribute("name"))
|
||||
event.dataTransfer.setData("dropType", "move")
|
||||
// console.log(updateFileViewCallback)
|
||||
// event.dataTransfer.setData("updateCallback", updateFileViewCallback)
|
||||
// event.dataTransfer.setData("fileName", )
|
||||
// console.log(draggedElem)
|
||||
})
|
||||
@ -54,8 +57,6 @@ class FileView{
|
||||
event.preventDefault();
|
||||
counter++
|
||||
fileViewElem.classList.add("DragDropBorder")
|
||||
// draggedElem = event.relatedTarget
|
||||
|
||||
})
|
||||
|
||||
fileViewElem.addEventListener('dragend', function(event) {
|
||||
@ -65,6 +66,7 @@ class FileView{
|
||||
if (counter === 0){
|
||||
fileViewElem.classList.remove("DragDropBorder")
|
||||
}
|
||||
// updateFileViewCallback()
|
||||
// draggedElem = undefined
|
||||
})
|
||||
|
||||
@ -84,9 +86,10 @@ class FileView{
|
||||
|
||||
fileViewElem.addEventListener("drop", (event) => {
|
||||
event.preventDefault();
|
||||
// console.log(event.dataTransfer.getData("dropType"))
|
||||
fileUploadCallback(event)
|
||||
fileViewElem.classList.remove("DragDropBorder")
|
||||
// updateFileViewCallback()
|
||||
// this.OpenFolder(this.path)
|
||||
// draggedElem = undefined
|
||||
})
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class WebDesktopEnvironment{
|
||||
document.body.style.setProperty('--zoom', 1)
|
||||
this.wc = new WindowsCompositor()
|
||||
this.loadWDE()
|
||||
let kek = new WebFS()
|
||||
return
|
||||
|
||||
// let applications = document.createElement("div")
|
||||
@ -343,3 +344,62 @@ class WindowsCompositor{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class WebFS{
|
||||
constructor(){
|
||||
console.log("fs loaded")
|
||||
}
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static async CreateDirectory(path){
|
||||
if (path == undefined){
|
||||
WebDesktopEnvironment.Alert("Path is undefined")
|
||||
return false
|
||||
}
|
||||
const params = new URLSearchParams({
|
||||
path: `${path}/New Directory`
|
||||
})
|
||||
const response = await fetch(`/fs/createDir?` + params)
|
||||
if (response.status != 200){
|
||||
WebDesktopEnvironment.Alert("DIRCTORY CREATION ERROR") //TODO
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static async DeleteFile(path){
|
||||
const params = new URLSearchParams({
|
||||
path: path
|
||||
})
|
||||
const response = await fetch(`/fs/delete?` + params)
|
||||
if (response.status != 200){
|
||||
WebDesktopEnvironment.Alert("DELETE ERROR") //TODO
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static async MoveFile(sourcePath, targetPath){
|
||||
const params = new URLSearchParams({
|
||||
sourcePath: sourcePath,
|
||||
targetPath: targetPath
|
||||
})
|
||||
const response = await fetch(`/fs/move?` + params)
|
||||
if (response.status != 200){
|
||||
// WebDesktopEnvironment.Alert("Move ERROR") //TODO
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="res/sys/wde/wde-scrollbar.css">
|
||||
<link rel="stylesheet" type="text/css" href="res/sys/wde/basic-widgets.css">
|
||||
<link rel="stylesheet" type="text/css" href="res/sys/wde/file-view.css">
|
||||
<link rel="stylesheet" type="text/css" href="res/sys/libs/fs.js">
|
||||
<link rel="stylesheet" type="text/css" href="res/mobile-wdeUI.css">
|
||||
<link rel="stylesheet" href="/res/sys/wde/simple-scrollbar.css">
|
||||
<link rel="stylesheet" type="text/css" href="res/sys/finder/finder.css">
|
||||
|
Loading…
Reference in New Issue
Block a user