class Finder{ appId = "finder" fileView = undefined path = "/" homePath = "/home/user" // previousPath = "/" pathHistory = [] //FIXME Fixed length constructor(){ // this.appElem = appElem } /** * @param {string} path */ NewWindow(args){ this.path = args[0] fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ isMobile: WebDesktopEnvironment.isMobile, // path: this.path, // bar: true, })) //TODO Move to wde func. Or Not? .then((response) => response.text()) .then((html) => { let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 ) newWindow.innerHTML = html 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) }) if (!WebDesktopEnvironment.isMobile){ // let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector console.log(newWindow.querySelector("#closeWindowButton")) newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) { WebDesktopEnvironment.CloseWindow(newWindow) }) } }) .catch((error) => { WebDesktopEnvironment.Alert(error); }) } 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) } } /** * @param {string} path */ OpenDir(path){ console.log() this.pathHistory += this.path this.path = path this.fileView.OpenFolder(this.path) } /** * @param {MouseEvent} event */ Click(event){ let fileType = event.target.getAttribute("fileType") let fileName = event.target.getAttribute("name") switch (fileType) { 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 "base64img": WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName]) break; default: console.log("Unsupported file type") break; } } // /** // * @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); // }) // } }