2023-03-20 11:20:37 +00:00
|
|
|
class Finder{
|
|
|
|
appId = "finder"
|
2023-04-29 13:58:39 +00:00
|
|
|
fileView = undefined
|
|
|
|
path = "/"
|
|
|
|
homePath = "/home/user"
|
2023-05-04 00:38:24 +00:00
|
|
|
windowElement
|
2023-04-29 13:58:39 +00:00
|
|
|
// previousPath = "/"
|
|
|
|
pathHistory = [] //FIXME Fixed length
|
2023-04-12 17:04:25 +00:00
|
|
|
constructor(){
|
|
|
|
// this.appElem = appElem
|
2023-03-17 01:16:51 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 21:53:06 +00:00
|
|
|
/**
|
2023-04-29 21:01:23 +00:00
|
|
|
* @param {string[]} args
|
2023-03-22 21:53:06 +00:00
|
|
|
*/
|
2023-04-29 13:58:39 +00:00
|
|
|
NewWindow(args){
|
|
|
|
this.path = args[0]
|
2023-04-29 21:01:23 +00:00
|
|
|
if (args[1] == "desktop"){
|
|
|
|
this.NewDesktop(args)
|
|
|
|
return
|
|
|
|
}
|
2023-04-13 01:09:07 +00:00
|
|
|
fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
|
|
|
|
isMobile: WebDesktopEnvironment.isMobile,
|
2023-04-29 13:58:39 +00:00
|
|
|
// path: this.path,
|
2023-04-13 01:09:07 +00:00
|
|
|
// bar: true,
|
|
|
|
})) //TODO Move to wde func. Or Not?
|
2023-03-17 01:16:51 +00:00
|
|
|
.then((response) => response.text())
|
|
|
|
.then((html) => {
|
2023-04-13 01:09:07 +00:00
|
|
|
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
|
2023-03-22 21:53:06 +00:00
|
|
|
newWindow.innerHTML = html
|
2023-04-13 01:09:07 +00:00
|
|
|
|
2023-05-04 00:38:24 +00:00
|
|
|
this.fileView = new FileView(newWindow.querySelector(".FileTileView"),
|
|
|
|
(event) =>{ this.Open(event, false) },
|
2023-05-04 19:49:22 +00:00
|
|
|
(event) =>{ this.RightClick(event) },
|
|
|
|
(event) =>{ this.FileUploading(event) },
|
|
|
|
)
|
2023-04-29 13:58:39 +00:00
|
|
|
this.OpenDir(this.path)
|
|
|
|
|
|
|
|
newWindow.querySelector("#BackButton").addEventListener('click', () =>{
|
|
|
|
this.OpenPreviousDir()
|
|
|
|
})
|
|
|
|
|
|
|
|
newWindow.querySelector("#HomeButton").addEventListener('click', () =>{
|
|
|
|
this.OpenDir(this.homePath)
|
|
|
|
})
|
|
|
|
|
2023-05-04 00:38:24 +00:00
|
|
|
this.windowElement = newWindow
|
|
|
|
|
2023-04-13 01:09:07 +00:00
|
|
|
if (!WebDesktopEnvironment.isMobile){
|
2023-04-29 15:34:25 +00:00
|
|
|
// let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector
|
2023-04-29 21:01:23 +00:00
|
|
|
// console.log(newWindow.querySelector("#closeWindowButton"))
|
2023-05-04 19:49:22 +00:00
|
|
|
|
2023-04-13 18:28:28 +00:00
|
|
|
newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
|
2023-04-29 15:34:25 +00:00
|
|
|
|
2023-04-13 01:09:07 +00:00
|
|
|
WebDesktopEnvironment.CloseWindow(newWindow)
|
2023-04-29 15:34:25 +00:00
|
|
|
|
2023-04-13 01:09:07 +00:00
|
|
|
})
|
|
|
|
}
|
2023-03-17 01:16:51 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
WebDesktopEnvironment.Alert(error);
|
2023-03-22 21:53:06 +00:00
|
|
|
})
|
2023-04-12 17:04:25 +00:00
|
|
|
}
|
2023-04-13 01:09:07 +00:00
|
|
|
|
2023-05-04 19:49:22 +00:00
|
|
|
/**
|
|
|
|
* @param {DataTransferItemList} filesList
|
|
|
|
*/
|
|
|
|
|
|
|
|
FileUploading(filesList){
|
|
|
|
let formData = new FormData()
|
|
|
|
// console.log(filesList)
|
|
|
|
for (let i = 0; i < filesList.length; i++) {
|
|
|
|
const element = filesList[i];
|
|
|
|
formData.append("file", element.getAsFile())
|
|
|
|
console.log(formData)
|
|
|
|
}
|
|
|
|
// console.log(formData)
|
|
|
|
// formData.append("photo", photo);
|
|
|
|
fetch('/fs/upload/?' + new URLSearchParams({
|
|
|
|
path: '/home/user/',
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
body: formData
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
WebDesktopEnvironment.Alert(error);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-29 21:01:23 +00:00
|
|
|
/**
|
|
|
|
* @param {string[]} args
|
|
|
|
*/
|
|
|
|
NewDesktop(args){
|
|
|
|
fetch(`${window.location.origin}/application/${this.appId}/renderDesktop?` + new URLSearchParams({
|
|
|
|
isMobile: WebDesktopEnvironment.isMobile,
|
|
|
|
path: args[0]
|
|
|
|
}))
|
|
|
|
.then((response) => response.text())
|
|
|
|
.then((html) => {
|
|
|
|
// console.log(args)
|
|
|
|
args[2].innerHTML = html
|
|
|
|
|
|
|
|
this.fileView = new FileView(args[2].querySelector(".FileTileView"), (event) =>{
|
2023-05-02 00:48:12 +00:00
|
|
|
this.Open(event, true)
|
2023-04-29 21:01:23 +00:00
|
|
|
})
|
|
|
|
this.OpenDir(this.path)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
WebDesktopEnvironment.Alert(error);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-29 13:58:39 +00:00
|
|
|
OpenPreviousDir(){
|
|
|
|
if (this.pathHistory.length > 0){
|
|
|
|
// console.log(this.pathHistory)
|
|
|
|
let path = this.pathHistory[this.pathHistory.length - 1]
|
|
|
|
// console.log(typeof( this.pathHistory))
|
|
|
|
this.pathHistory.pop()
|
|
|
|
this.OpenDir(this.path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-12 17:04:25 +00:00
|
|
|
/**
|
|
|
|
* @param {string} path
|
|
|
|
*/
|
2023-04-29 13:58:39 +00:00
|
|
|
OpenDir(path){
|
|
|
|
this.pathHistory += this.path
|
|
|
|
this.path = path
|
|
|
|
this.fileView.OpenFolder(this.path)
|
|
|
|
}
|
|
|
|
|
2023-05-02 00:48:12 +00:00
|
|
|
|
2023-04-29 13:58:39 +00:00
|
|
|
/**
|
|
|
|
* @param {MouseEvent} event
|
2023-04-29 21:01:23 +00:00
|
|
|
* @param {boolean} inNewWindow
|
2023-04-29 13:58:39 +00:00
|
|
|
*/
|
2023-04-29 21:01:23 +00:00
|
|
|
Click(event, inNewWindow){
|
2023-05-02 00:48:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
* @param {boolean} inNewWindow
|
|
|
|
*/
|
|
|
|
Open(event, inNewWindow){
|
2023-04-13 01:09:07 +00:00
|
|
|
let fileType = event.target.getAttribute("fileType")
|
2023-04-29 13:58:39 +00:00
|
|
|
let fileName = event.target.getAttribute("name")
|
2023-04-13 01:09:07 +00:00
|
|
|
switch (fileType) {
|
2023-04-29 13:58:39 +00:00
|
|
|
case "directory":
|
2023-04-29 21:01:23 +00:00
|
|
|
if (inNewWindow){
|
|
|
|
WebDesktopEnvironment.Open("finder", ["/home/user/" + fileName]) //FIXME this.path is shared for all windows
|
|
|
|
break
|
|
|
|
}
|
2023-04-29 13:58:39 +00:00
|
|
|
this.OpenDir(this.path +"/" + fileName)
|
|
|
|
break
|
|
|
|
case "blog-page":
|
|
|
|
WebDesktopEnvironment.Open("blog-viewer", [this.path + "/" + fileName])
|
|
|
|
break
|
2023-05-04 19:49:22 +00:00
|
|
|
case "deleteFile":
|
|
|
|
fetch(`/fs/delete` + new URLSearchParams({
|
|
|
|
path: "/home/user/" + fileName //FIXME
|
|
|
|
}))
|
|
|
|
.then((response) => {
|
|
|
|
console.log(response.status)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
WebDesktopEnvironment.Alert(error);
|
|
|
|
})
|
|
|
|
break
|
2023-04-29 13:58:39 +00:00
|
|
|
// case "app":
|
|
|
|
// //TODO get real id
|
|
|
|
// WebDesktopEnvironment.Open("personal-properties", [])
|
|
|
|
// break;
|
2023-04-29 16:47:12 +00:00
|
|
|
case "base64img":
|
|
|
|
WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName])
|
|
|
|
break;
|
2023-04-12 21:05:23 +00:00
|
|
|
default:
|
2023-05-02 11:32:56 +00:00
|
|
|
// console.log("Unsupported file type")
|
|
|
|
WebDesktopEnvironment.Alert("Unsupported file type")
|
2023-04-12 17:04:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-03-17 01:16:51 +00:00
|
|
|
}
|
2023-05-04 00:38:24 +00:00
|
|
|
|
|
|
|
RightClick(event){
|
2023-05-04 14:58:38 +00:00
|
|
|
this.CreateContextMenu(event.target, [event.clientY, event.clientX])
|
2023-05-04 00:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateContextMenu(target, pos){
|
2023-05-04 19:49:22 +00:00
|
|
|
let context = ""
|
2023-05-04 14:58:38 +00:00
|
|
|
if (target.classList.contains("FileTileView"))
|
|
|
|
{
|
|
|
|
context = "FileTileView"
|
|
|
|
|
|
|
|
}
|
2023-05-04 00:38:24 +00:00
|
|
|
fetch(`${window.location.origin}/application/${this.appId}/contextMenu?` + new URLSearchParams({
|
2023-05-04 14:58:38 +00:00
|
|
|
context: context
|
|
|
|
|
2023-05-04 00:38:24 +00:00
|
|
|
}))
|
|
|
|
.then((response) => response.text())
|
|
|
|
.then((html) => {
|
|
|
|
let overlay = document.createElement("div") //TODO Move to WDE.CreateOverlay()
|
|
|
|
overlay.setAttribute('id', 'finder-context-menu-overlay')
|
|
|
|
overlay.style.position = 'absolute'
|
|
|
|
overlay.style.width = "100%"
|
|
|
|
overlay.style.height = "100%"
|
2023-05-04 14:58:38 +00:00
|
|
|
|
2023-05-04 00:38:24 +00:00
|
|
|
let menu = document.createElement("div")
|
|
|
|
menu.setAttribute('class', 'ContextMenu WindowFrameShadow')
|
|
|
|
menu.style.position = 'absolute';
|
|
|
|
menu.style.top = pos[0] + "px";
|
|
|
|
menu.style.left = pos[1] + "px";
|
|
|
|
|
|
|
|
menu.innerHTML = html
|
2023-05-04 14:58:38 +00:00
|
|
|
menu.children[0].lastElementChild.remove() //FIXME Can't ommit rendering of horLine in end of menu on backend
|
2023-05-04 00:38:24 +00:00
|
|
|
|
|
|
|
overlay.appendChild(menu)
|
|
|
|
document.body.appendChild(overlay)
|
|
|
|
|
|
|
|
overlay.addEventListener('click',(event) => {
|
2023-05-04 14:58:38 +00:00
|
|
|
if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks??
|
2023-05-04 19:49:22 +00:00
|
|
|
switch (event.target.children[0].getAttribute("action")) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-05-04 00:38:24 +00:00
|
|
|
}
|
|
|
|
overlay.remove()
|
|
|
|
})
|
|
|
|
overlay.addEventListener('contextmenu', (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
overlay.remove()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
WebDesktopEnvironment.Alert(error);
|
2023-05-04 14:58:38 +00:00
|
|
|
})
|
2023-05-04 00:38:24 +00:00
|
|
|
}
|
2023-03-17 01:16:51 +00:00
|
|
|
}
|