personal-website/resources/sys/finder/finder.js

117 lines
3.6 KiB
JavaScript
Raw Normal View History

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"
// 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
/**
* @param {string} path
*/
2023-04-29 13:58:39 +00:00
NewWindow(args){
this.path = args[0]
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-04-29 13:58:39 +00:00
this.fileView = new FileView(newWindow.querySelector(".FileTileView"), (event) =>{
this.Click(event, this.path)
})
this.OpenDir(this.path)
newWindow.querySelector("#BackButton").addEventListener('click', () =>{
this.OpenPreviousDir()
})
newWindow.querySelector("#HomeButton").addEventListener('click', () =>{
this.OpenDir(this.homePath)
})
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
console.log(newWindow.querySelector("#closeWindowButton"))
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-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){
console.log()
this.pathHistory += this.path
this.path = path
this.fileView.OpenFolder(this.path)
}
/**
* @param {MouseEvent} event
*/
Click(event){
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":
this.OpenDir(this.path +"/" + fileName)
break
case "blog-page":
WebDesktopEnvironment.Open("blog-viewer", [this.path + "/" + fileName])
break
// case "app":
// //TODO get real id
// WebDesktopEnvironment.Open("personal-properties", [])
// break;
// case "img":
// WebDesktopEnvironment.Open("img-viewer", ["pizda"])
// break;
2023-04-12 21:05:23 +00:00
default:
2023-04-12 17:04:25 +00:00
console.log("Unsupported file type")
break;
}
2023-03-17 01:16:51 +00:00
}
2023-04-29 13:58:39 +00:00
// /**
// * @param {path} string
// */
// renderFileView(path){
// fetch(`${window.location.origin}/fs/list?` + new URLSearchParams({
// path: path,
// }))
// .then((response) => response.text())
// .then((html) => {
// this.fileView.innerHTML = html
// })
// .catch((error) => {
// WebDesktopEnvironment.Alert(error);
// })
// }
2023-03-17 01:16:51 +00:00
}