From c95501dbb738c73d85d3d57d04bb9be77e9f33c1 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Fri, 5 May 2023 23:31:42 +0300 Subject: [PATCH] Working img viewer --- apps/finder/finder.go | 81 +++++++++------------------------- apps/img-viewer/imgviewer.go | 29 +++++++----- resources/sys/finder/finder.js | 14 +++++- resources/wde.js | 2 +- routewde/wde.go | 2 +- templates/img-viewer/app.tmpl | 2 +- 6 files changed, 53 insertions(+), 77 deletions(-) diff --git a/apps/finder/finder.go b/apps/finder/finder.go index 6399b67..1dac72d 100644 --- a/apps/finder/finder.go +++ b/apps/finder/finder.go @@ -4,7 +4,6 @@ import ( "personalwebsite/apps" "personalwebsite/wde" "personalwebsite/webfilesystem" - "strings" "github.com/gin-gonic/gin" ) @@ -36,72 +35,32 @@ func (f *FinderApplication) Render(isMobile bool) gin.H { } func (f *FinderApplication) RenderContextMenu(context string, data string) gin.H { - islands := [][]wde.ContexMenuRow{} //FIXME - switch context { - case "FileTileView": - islands = [][]wde.ContexMenuRow{ - { - { - Label: "Get Info", - Action: strings.Join([]string{"getInfo"}[:], ","), - }, - }, - { - { - Label: "New Directory", - Action: strings.Join([]string{"createDir"}[:], ","), - }, - }, - } - case "directory": - islands = [][]wde.ContexMenuRow{ - { - { - Label: "Test", - Action: strings.Join([]string{""}[:], ","), - }, - { - Label: "Delete", - Action: strings.Join([]string{""}[:], ","), - }, - }, - { - { - Label: "Get Info", - Action: strings.Join([]string{""}[:], ","), - }, - }, - } - default: - islands = [][]wde.ContexMenuRow{ - { - { - Label: "temp Menu 1", - Action: strings.Join([]string{""}[:], ","), - }, - { - Label: "temp Menu 2", - Action: strings.Join([]string{""}[:], ","), - }, - { - Label: "temp Menu 3", - Action: strings.Join([]string{""}[:], ","), - }, - { - Label: "temp Menu 4", - Action: strings.Join([]string{""}[:], ","), - }, - }, + islands := [][]wde.ContexMenuRow{} + + islands = append(islands, []wde.ContexMenuRow{ + {Label: "Get Info", Action: "getInfo"}, + }) + if context == "FileTileView" { + return gin.H{ + "Islands": islands, } } islands = append(islands, []wde.ContexMenuRow{ - { - Label: "Delete File", - Action: strings.Join([]string{"deleteFile"}[:], ";"), - }, + {Label: "Delete File", Action: "deleteFile"}, + // {Label: "Get Info", Action: "getInfo"}, }) + switch context { + case "directory": + + default: + islands = append(islands, []wde.ContexMenuRow{ + {Label: "temp Menu 1", Action: ""}, + {Label: "temp Menu 2", Action: ""}, + }) + } + return gin.H{ "Islands": islands, } diff --git a/apps/img-viewer/imgviewer.go b/apps/img-viewer/imgviewer.go index 60e91a4..f2c0486 100644 --- a/apps/img-viewer/imgviewer.go +++ b/apps/img-viewer/imgviewer.go @@ -3,7 +3,6 @@ package imgviewer import ( "net/http" websiteapp "personalwebsite/apps" - "personalwebsite/libs" "personalwebsite/webfilesystem" "github.com/gin-gonic/gin" @@ -54,17 +53,25 @@ func (p *ImgViewerApp) GetId() string { return p.manifest.AppId } -func (p *ImgViewerApp) Render(path string, isMobile bool) (gin.H, error) { - img, err := p.fs.NewRead(path) - if err != nil { - return nil, err - } - data, err := libs.ReadImage(img) - if err != nil { - return nil, err - } +func (p *ImgViewerApp) Render(filePath string, isMobile bool) (gin.H, error) { + // file, err := p.fs.NewRead(filePath) + // if err != nil { + // return nil, err + // } + // println(file.Data.(primitive.Binary).Data) + + // img, err := p.fs.NewRead(path) + // if err != nil { + // return nil, err + // } + // data, err := libs.ReadImage(img) + // if err != nil { + // return nil, err + // } + // url := location.Get(ctx) return gin.H{ - "header": data.Header, + "imgUrl": "/system/libs/img/get?path=" + filePath, + // "header": data.Header, // "base64": data.Base64, }, nil } diff --git a/resources/sys/finder/finder.js b/resources/sys/finder/finder.js index e8d7a60..da6b607 100644 --- a/resources/sys/finder/finder.js +++ b/resources/sys/finder/finder.js @@ -160,7 +160,8 @@ class Finder{ // //TODO get real id // WebDesktopEnvironment.Open("personal-properties", []) // break; - case "base64img": + case "jpeg": + case "png": WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName]) break; default: @@ -204,6 +205,7 @@ class Finder{ overlay.addEventListener('click',(event) => { if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks?? let fileType = target.getAttribute("fileType") + let fileName = target.getAttribute("name") switch (event.target.children[0].getAttribute("action")) { case "createDir": fetch(`/fs/createDir?` + new URLSearchParams({ @@ -211,13 +213,15 @@ class Finder{ })) .then((response) => { console.log(response.status) + if (response.status == 200){ + this.OpenDir(this.path) + } }) .catch((error) => { WebDesktopEnvironment.Alert(error); }) break case "deleteFile": - let fileName = target.getAttribute("name") console.log(fileName) // break fetch(`/fs/delete?` + new URLSearchParams({ @@ -225,11 +229,17 @@ class Finder{ })) .then((response) => { console.log(response.status) + if (response.status == 200){ + this.OpenDir(this.path) + } }) .catch((error) => { WebDesktopEnvironment.Alert(error); }) break + case "getInfo": + // console.log("Open Properties") + WebDesktopEnvironment.Open("props-viewer", `${this.path}/${fileName}`) default: break; } diff --git a/resources/wde.js b/resources/wde.js index d3b228b..7759217 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -193,7 +193,7 @@ class WebDesktopEnvironment{ * @param {string} alertText */ static CreateAlertWindow(alertText){ - console.log("alertWinfdo") + // console.log("alertWinfdo") let newWindow = document.createElement("div") newWindow.setAttribute("class", "WindowFrameless") newWindow.setAttribute("windowId", "SuperUniqUUID") //TODO: diff --git a/routewde/wde.go b/routewde/wde.go index d57b296..9076988 100644 --- a/routewde/wde.go +++ b/routewde/wde.go @@ -21,7 +21,7 @@ func Route(route *gin.RouterGroup, wde *wde.WDE) { { widgets.GET("/file-tile-view", func(ctx *gin.Context) { url := location.Get(ctx) - _ = url + // _ = url path := ctx.Query("path") if path == "" { ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct diff --git a/templates/img-viewer/app.tmpl b/templates/img-viewer/app.tmpl index 01a3f49..acbaf52 100644 --- a/templates/img-viewer/app.tmpl +++ b/templates/img-viewer/app.tmpl @@ -12,7 +12,7 @@ Toolbar --> - + {{ end }}