diff --git a/main.go b/main.go index 5d4a09b..ade89bc 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "personalwebsite/routewde" + "personalwebsite/wde" "personalwebsite/webfilesystem" "personalwebsite/websiteapp" "personalwebsite/websiteapp/blogviewer" @@ -61,23 +62,25 @@ func main() { }) webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection) + wde := wde.NewWDE(webfs) persPropsApp := personalprops.NewPersPropsApp() - finderApp := finder.FinderApplication{} + // finderApp := finder.FinderApplication{} + finderApp := finder.NewFinderApplication(webfs) imgViewerApp := imgviewer.NewImgViewerApp() blogViewerApp := blogviewer.NewBlogViewerApp(webfs) appsStorage := websiteapp.ApplicationsStorage{ Apps: map[string]websiteapp.WebDEApplication{}, } appsStorage.Apps["personal-properties"] = &persPropsApp - appsStorage.Apps["finder"] = &finderApp + appsStorage.Apps["finder"] = finderApp appsStorage.Apps["img-viewer"] = &imgViewerApp appsStorage.Apps["blog-viewer"] = blogViewerApp system := router.Group("system") { - wde := system.Group("wde") + wdeGroup := system.Group("wde") { - routewde.Route(wde) + routewde.Route(wdeGroup, wde) } apps := system.Group("applications") { @@ -240,10 +243,16 @@ func main() { } isMobile := isMobileParam == "true" + ginH, err := blogViewerApp.Render(path, isMobile) + if err != nil { + ctx.JSON(http.StatusInternalServerError, "TODO") + return + } + if isMobile { - ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", blogViewerApp.Render(path, isMobile)) + ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", ginH) } else { - ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(path, isMobile)) + ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", ginH) } }) diff --git a/resources/sys/blog-viewer/blog-viewer.js b/resources/sys/blog-viewer/blog-viewer.js index b905557..9469aef 100644 --- a/resources/sys/blog-viewer/blog-viewer.js +++ b/resources/sys/blog-viewer/blog-viewer.js @@ -4,12 +4,12 @@ class BlogViewer{ } /** - * @param {string} path + * @param {string[]} args */ - NewWindow(path){ + NewWindow(args){ fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ isMobile: WebDesktopEnvironment.isMobile, - path: path, + path: args[0], })) .then((response) => response.text()) .then((html) => { diff --git a/resources/sys/finder/finder.js b/resources/sys/finder/finder.js index 5b904c9..ec993f0 100644 --- a/resources/sys/finder/finder.js +++ b/resources/sys/finder/finder.js @@ -1,5 +1,10 @@ class Finder{ appId = "finder" + fileView = undefined + path = "/" + homePath = "/home/user" + // previousPath = "/" + pathHistory = [] //FIXME Fixed length constructor(){ // this.appElem = appElem } @@ -7,9 +12,11 @@ class Finder{ /** * @param {string} path */ - NewWindow(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()) @@ -17,7 +24,19 @@ class Finder{ let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 ) newWindow.innerHTML = html - let fileView = new FileView("/kek", newWindow.querySelector(".FileTileView"), Finder.Click) + 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 newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) { @@ -30,23 +49,65 @@ class Finder{ }) } + 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 {MouseEvent} event * @param {string} path */ - static Click(event, 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 "app": - //TODO get real id - WebDesktopEnvironment.Open("personal-properties", []) - break; - case "img": - WebDesktopEnvironment.Open("img-viewer", ["pizda"]) - break; + 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; 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); + // }) + // } } diff --git a/resources/sys/wde/file-view.js b/resources/sys/wde/file-view.js index c004ba2..150f41f 100644 --- a/resources/sys/wde/file-view.js +++ b/resources/sys/wde/file-view.js @@ -1,15 +1,14 @@ class FileView{ - path = "" + parentElem = undefined /** - * @param {string} path * @param {HTMLElement} fileViewElem * @param {Function} clickCallback */ - constructor(path, fileViewElem, clickCallback){ + constructor(fileViewElem, clickCallback){ //TODO check all params - this.path = path + this.parentElem = fileViewElem - this.openFolder(path, fileViewElem) + // this.OpenFolder(path) // let scrollDiv = fileViewElem.children[1] // console.log(scrollDiv) @@ -22,14 +21,17 @@ class FileView{ /** Get html of folder by path * @param {string} path - * @param {HTMLElement} parentElem */ - openFolder(path, parentElem){ - // console.log(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`) + OpenFolder(path){ fetch(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`) //TODO Move to wde func. Or Not? .then((response) => response.text()) .then((html) => { - parentElem.innerHTML = html + //TODO + // console.log(responseStatus) + // if (responseStatus != 200) { + // WebDesktopEnvironment.Alert("Error") + // } + this.parentElem.innerHTML = html }).catch((error) => { WebDesktopEnvironment.Alert(error); }) diff --git a/resources/wde.js b/resources/wde.js index 817408d..aa7da97 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -2,7 +2,8 @@ document.addEventListener('DOMContentLoaded', function() { // console.log(window.screen.width) wde = new WebDesktopEnvironment if (!WebDesktopEnvironment.isMobile){ - WebDesktopEnvironment.Open("finder", ["/home/user/"]) + WebDesktopEnvironment.Open("finder", ["/home/user"]) + // WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) // WebDesktopEnvironment.Open("personal-properties", ["kek"]) } else { WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) @@ -210,7 +211,8 @@ class WindowsCompositor{ //TODO refactor this to dynamic add/remove listeners constructor(){ this.windowLayer = document.body.querySelector('#windows-layer') - if (!WebDesktopEnvironment.isMobile) { + // if (!WebDesktopEnvironment.isMobile) { + if (false) { //FIXME addEventListener("mousedown", (event) => { this.xPosInit = event.offsetX this.yPosInit = event.offsetY diff --git a/resources/wdeUI.css b/resources/wdeUI.css index db0dc11..3970f0b 100644 --- a/resources/wdeUI.css +++ b/resources/wdeUI.css @@ -326,5 +326,5 @@ } .FileTileTitle{ - + white-space: nowrap; } \ No newline at end of file diff --git a/routewde/wde.go b/routewde/wde.go index 118fcac..0e7a20b 100644 --- a/routewde/wde.go +++ b/routewde/wde.go @@ -2,12 +2,12 @@ package routewde import ( "net/http" - "personalwebsite/webfilesystem" + "personalwebsite/wde" "github.com/gin-gonic/gin" ) -func Route(route *gin.RouterGroup) { +func Route(route *gin.RouterGroup, wde *wde.WDE) { route.GET("/getbasicwindow", func(ctx *gin.Context) { ctx.HTML(http.StatusOK, "basic-window.html", nil) }) @@ -19,12 +19,17 @@ func Route(route *gin.RouterGroup) { widgets := route.Group("widgets") { widgets.GET("/file-tile-view", func(ctx *gin.Context) { - fs := webfilesystem.WebFileSystem{} - list, _ := fs.List("/") //TODO check errors - ctx.HTML(http.StatusOK, "wde-widgets/file-tile-view.tmpl", gin.H{ - "Name": "Greg Brzezinski", - "Files": list, - }) + path := ctx.Query("path") + if path == "" { + ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct + return + } + ginH, err := wde.Render(path) + if err != nil { + ctx.JSON(http.StatusInternalServerError, "TODO") //TODO + return + } + ctx.HTML(http.StatusOK, "wde-widgets/file-tile-view.tmpl", ginH) }) } } diff --git a/templates/blog-viewer/app.tmpl b/templates/blog-viewer/app.tmpl index 7dbd113..77cd13f 100644 --- a/templates/blog-viewer/app.tmpl +++ b/templates/blog-viewer/app.tmpl @@ -3,13 +3,21 @@