Working img viewer
This commit is contained in:
parent
5736b8de31
commit
c95501dbb7
@ -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,
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -12,7 +12,7 @@
|
||||
Toolbar
|
||||
</div> -->
|
||||
|
||||
<img class="Img-Viewer-Picture-Container"src="data:{{.header}},{{.base64}}">
|
||||
<img class="Img-Viewer-Picture-Container"src="{{.imgUrl}}">
|
||||
|
||||
</div>
|
||||
{{ end }}
|
||||
|
Loading…
Reference in New Issue
Block a user