Compare commits

..

No commits in common. "471350ead128f2c995f0854ad2c56b17bfe47665" and "21b201fd9d131c633e15826445d6e115f57e71fc" have entirely different histories.

14 changed files with 72 additions and 246 deletions

21
main.go
View File

@ -7,7 +7,6 @@ import (
"net/http" "net/http"
"os" "os"
"personalwebsite/routewde" "personalwebsite/routewde"
"personalwebsite/wde"
"personalwebsite/webfilesystem" "personalwebsite/webfilesystem"
"personalwebsite/websiteapp" "personalwebsite/websiteapp"
"personalwebsite/websiteapp/blogviewer" "personalwebsite/websiteapp/blogviewer"
@ -62,25 +61,23 @@ func main() {
}) })
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection) webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
wde := wde.NewWDE(webfs)
persPropsApp := personalprops.NewPersPropsApp() persPropsApp := personalprops.NewPersPropsApp()
// finderApp := finder.FinderApplication{} finderApp := finder.FinerApplication{}
finderApp := finder.NewFinderApplication(webfs)
imgViewerApp := imgviewer.NewImgViewerApp() imgViewerApp := imgviewer.NewImgViewerApp()
blogViewerApp := blogviewer.NewBlogViewerApp(webfs) blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
appsStorage := websiteapp.ApplicationsStorage{ appsStorage := websiteapp.ApplicationsStorage{
Apps: map[string]websiteapp.WebDEApplication{}, Apps: map[string]websiteapp.WebDEApplication{},
} }
appsStorage.Apps["personal-properties"] = &persPropsApp appsStorage.Apps["personal-properties"] = &persPropsApp
appsStorage.Apps["finder"] = finderApp appsStorage.Apps["finder"] = &finderApp
appsStorage.Apps["img-viewer"] = &imgViewerApp appsStorage.Apps["img-viewer"] = &imgViewerApp
appsStorage.Apps["blog-viewer"] = blogViewerApp appsStorage.Apps["blog-viewer"] = blogViewerApp
system := router.Group("system") system := router.Group("system")
{ {
wdeGroup := system.Group("wde") wde := system.Group("wde")
{ {
routewde.Route(wdeGroup, wde) routewde.Route(wde)
} }
apps := system.Group("applications") apps := system.Group("applications")
{ {
@ -243,16 +240,10 @@ func main() {
} }
isMobile := isMobileParam == "true" isMobile := isMobileParam == "true"
ginH, err := blogViewerApp.Render(path, isMobile)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO")
return
}
if isMobile { if isMobile {
ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", ginH) ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", blogViewerApp.Render(path, isMobile))
} else { } else {
ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", ginH) ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(path, isMobile))
} }
}) })

View File

@ -4,12 +4,12 @@ class BlogViewer{
} }
/** /**
* @param {string[]} args * @param {string} path
*/ */
NewWindow(args){ NewWindow(path){
fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
isMobile: WebDesktopEnvironment.isMobile, isMobile: WebDesktopEnvironment.isMobile,
path: args[0], path: path,
})) }))
.then((response) => response.text()) .then((response) => response.text())
.then((html) => { .then((html) => {

View File

@ -1,10 +1,5 @@
class Finder{ class Finder{
appId = "finder" appId = "finder"
fileView = undefined
path = "/"
homePath = "/home/user"
// previousPath = "/"
pathHistory = [] //FIXME Fixed length
constructor(){ constructor(){
// this.appElem = appElem // this.appElem = appElem
} }
@ -12,11 +7,9 @@ class Finder{
/** /**
* @param {string} path * @param {string} path
*/ */
NewWindow(args){ NewWindow(path){
this.path = args[0]
fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
isMobile: WebDesktopEnvironment.isMobile, isMobile: WebDesktopEnvironment.isMobile,
// path: this.path,
// bar: true, // bar: true,
})) //TODO Move to wde func. Or Not? })) //TODO Move to wde func. Or Not?
.then((response) => response.text()) .then((response) => response.text())
@ -24,19 +17,7 @@ class Finder{
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 ) let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
newWindow.innerHTML = html newWindow.innerHTML = html
this.fileView = new FileView(newWindow.querySelector(".FileTileView"), (event) =>{ let fileView = new FileView("/kek", newWindow.querySelector(".FileTileView"), Finder.Click)
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){ if (!WebDesktopEnvironment.isMobile){
let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector 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) { newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
@ -49,65 +30,23 @@ 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 {string} path
*/
OpenDir(path){
console.log()
this.pathHistory += this.path
this.path = path
this.fileView.OpenFolder(this.path)
}
/** /**
* @param {MouseEvent} event * @param {MouseEvent} event
* @param {string} path
*/ */
Click(event){ static Click(event, path){
let fileType = event.target.getAttribute("fileType") let fileType = event.target.getAttribute("fileType")
let fileName = event.target.getAttribute("name")
switch (fileType) { switch (fileType) {
case "directory": case "app":
this.OpenDir(this.path +"/" + fileName) //TODO get real id
break WebDesktopEnvironment.Open("personal-properties", [])
case "blog-page": break;
WebDesktopEnvironment.Open("blog-viewer", [this.path + "/" + fileName]) case "img":
break WebDesktopEnvironment.Open("img-viewer", ["pizda"])
// case "app": break;
// //TODO get real id
// WebDesktopEnvironment.Open("personal-properties", [])
// break;
// case "img":
// WebDesktopEnvironment.Open("img-viewer", ["pizda"])
// break;
default: default:
console.log("Unsupported file type") console.log("Unsupported file type")
break; 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);
// })
// }
} }

View File

@ -1,14 +1,15 @@
class FileView{ class FileView{
parentElem = undefined path = ""
/** /**
* @param {string} path
* @param {HTMLElement} fileViewElem * @param {HTMLElement} fileViewElem
* @param {Function} clickCallback * @param {Function} clickCallback
*/ */
constructor(fileViewElem, clickCallback){ constructor(path, fileViewElem, clickCallback){
//TODO check all params //TODO check all params
this.parentElem = fileViewElem this.path = path
// this.OpenFolder(path) this.openFolder(path, fileViewElem)
// let scrollDiv = fileViewElem.children[1] // let scrollDiv = fileViewElem.children[1]
// console.log(scrollDiv) // console.log(scrollDiv)
@ -21,17 +22,14 @@ class FileView{
/** Get html of folder by path /** Get html of folder by path
* @param {string} path * @param {string} path
* @param {HTMLElement} parentElem
*/ */
OpenFolder(path){ openFolder(path, parentElem){
// console.log(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`)
fetch(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`) //TODO Move to wde func. Or Not? fetch(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`) //TODO Move to wde func. Or Not?
.then((response) => response.text()) .then((response) => response.text())
.then((html) => { .then((html) => {
//TODO parentElem.innerHTML = html
// console.log(responseStatus)
// if (responseStatus != 200) {
// WebDesktopEnvironment.Alert("Error")
// }
this.parentElem.innerHTML = html
}).catch((error) => { }).catch((error) => {
WebDesktopEnvironment.Alert(error); WebDesktopEnvironment.Alert(error);
}) })

View File

@ -2,8 +2,7 @@ document.addEventListener('DOMContentLoaded', function() {
// console.log(window.screen.width) // console.log(window.screen.width)
wde = new WebDesktopEnvironment wde = new WebDesktopEnvironment
if (!WebDesktopEnvironment.isMobile){ 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"]) // WebDesktopEnvironment.Open("personal-properties", ["kek"])
} else { } else {
WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
@ -211,8 +210,7 @@ class WindowsCompositor{
//TODO refactor this to dynamic add/remove listeners //TODO refactor this to dynamic add/remove listeners
constructor(){ constructor(){
this.windowLayer = document.body.querySelector('#windows-layer') this.windowLayer = document.body.querySelector('#windows-layer')
// if (!WebDesktopEnvironment.isMobile) { if (!WebDesktopEnvironment.isMobile) {
if (false) { //FIXME
addEventListener("mousedown", (event) => { addEventListener("mousedown", (event) => {
this.xPosInit = event.offsetX this.xPosInit = event.offsetX
this.yPosInit = event.offsetY this.yPosInit = event.offsetY

View File

@ -326,5 +326,5 @@
} }
.FileTileTitle{ .FileTileTitle{
white-space: nowrap;
} }

View File

@ -2,12 +2,12 @@ package routewde
import ( import (
"net/http" "net/http"
"personalwebsite/wde" "personalwebsite/webfilesystem"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func Route(route *gin.RouterGroup, wde *wde.WDE) { func Route(route *gin.RouterGroup) {
route.GET("/getbasicwindow", func(ctx *gin.Context) { route.GET("/getbasicwindow", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "basic-window.html", nil) ctx.HTML(http.StatusOK, "basic-window.html", nil)
}) })
@ -19,17 +19,12 @@ func Route(route *gin.RouterGroup, wde *wde.WDE) {
widgets := route.Group("widgets") widgets := route.Group("widgets")
{ {
widgets.GET("/file-tile-view", func(ctx *gin.Context) { widgets.GET("/file-tile-view", func(ctx *gin.Context) {
path := ctx.Query("path") fs := webfilesystem.WebFileSystem{}
if path == "" { list, _ := fs.List("/") //TODO check errors
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct ctx.HTML(http.StatusOK, "wde-widgets/file-tile-view.tmpl", gin.H{
return "Name": "Greg Brzezinski",
} "Files": list,
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)
}) })
} }
} }

View File

@ -3,21 +3,13 @@
<button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button> <button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button>
<div id="Drag" class="WindowDragArea"></div> <div id="Drag" class="WindowDragArea"></div>
<div class="WindowFrameTitle"> <div class="WindowFrameTitle">
{{.header}} Files
</div> </div>
<div id="Drag" class="WindowDragArea"></div> <div id="Drag" class="WindowDragArea"></div>
</div> </div>
<div class="ContentBorder"> <div class="ContentBorder">
<div class="blog-viewer"> <div class="FileTileView">
{{ range $block := .blocks }}
<div class="{{$block.Type}}">
{{ range $data := $block.Data }}
<div>
{{$data}}
</div>
{{ end }}
</div>
{{ end }}
</div> </div>
{{template "wde-widgets/scrollbar.tmpl" .}} {{template "wde-widgets/scrollbar.tmpl" .}}
</div> </div>

View File

@ -7,10 +7,6 @@
</div> </div>
<div id="Drag" class="WindowDragArea"></div> <div id="Drag" class="WindowDragArea"></div>
</div> </div>
<div class="ToolBar">
<button id="BackButton">Back</button>
<button id="HomeButton">Home</button>
</div>
<div class="ContentBorder"> <div class="ContentBorder">
<div class="FileTileView"> <div class="FileTileView">

View File

@ -1,8 +1,8 @@
{{ define "wde-widgets/file-tile-view.tmpl" }} {{ define "wde-widgets/file-tile-view.tmpl" }}
{{ range $fileTile := .Files }} {{ range $fileTile := .Files }}
<div fileType="{{ $fileTile.Type }}" class="FileTile" name="{{$fileTile.Name}}"> <div id="{{ $fileTile.Id }}" fileType="{{ $fileTile.Type }}" class="FileTile" fileName="{{$fileTile.FileName}}">
<div class="FileTileIcon NoClick"></div> <div class="FileTileIcon NoClick"></div>
<div class="FileTileTitle NoClick">{{ $fileTile.Name }}</div> <div class="FileTileTitle NoClick">{{ $fileTile.FileName }}</div>
</div> </div>
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -1,32 +0,0 @@
package wde
import (
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
)
type WDE struct {
fs *webfilesystem.WebFileSystem
FilesWidget FilesWidget
}
func NewWDE(webFs *webfilesystem.WebFileSystem) *WDE {
return &WDE{
fs: webFs,
}
}
type FilesWidget struct {
}
func (w *WDE) Render(path string) (gin.H, error) {
list, err := w.fs.List(path)
if err != nil {
return nil, err
}
return gin.H{
"Name": "Greg Brzezinski",
"Files": list,
}, nil
}

View File

@ -1,6 +0,0 @@
package blogviewer
type BlogFileData struct {
Header string `bson:"header"`
Blocks []Block `bson:"blocks"`
}

View File

@ -1,21 +1,17 @@
package blogviewer package blogviewer
import ( import (
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp" "personalwebsite/websiteapp"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
) )
type BlogViewerApplication struct { type BlogViewerApplication struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest manifest websiteapp.ApplicationManifest
} }
func NewBlogViewerApp(webFs *webfilesystem.WebFileSystem) *BlogViewerApplication { func NewBlogViewerApp() *BlogViewerApplication {
return &BlogViewerApplication{ return &BlogViewerApplication{
fs: webFs,
manifest: websiteapp.ApplicationManifest{ manifest: websiteapp.ApplicationManifest{
AppId: "blog-viewer", AppId: "blog-viewer",
WindowName: "", WindowName: "",
@ -26,65 +22,36 @@ func NewBlogViewerApp(webFs *webfilesystem.WebFileSystem) *BlogViewerApplication
func (b *BlogViewerApplication) GetManifest() websiteapp.ApplicationManifest { func (b *BlogViewerApplication) GetManifest() websiteapp.ApplicationManifest {
return b.manifest return b.manifest
} }
func (b *BlogViewerApplication) GetId() string { func (b *BlogViewerApplication) GetId() string {
return b.manifest.AppId return b.manifest.AppId
} }
func (b *BlogViewerApplication) WriteMock(path string) { func (b *BlogViewerApplication) Render(isMobile bool) gin.H {
blogFile := webfilesystem.WebFSFile{ mockBlocks := []Block{
MongoId: primitive.NewObjectID(),
Name: "test-1.blog",
Type: "blog-page",
Data: BlogFileData{
Header: "OMG THIS IS BLOG",
Blocks: []Block{
{ {
Type: "plain-text", BlockType: "plain-text",
Data: []string{ Data: []string{"qwerty qwerty werty", "oiposi sdfsp sdfip"},
"Apoqiwepoqiwepo",
".,mas;dakls;d",
"q[poqwieqpipoi]",
}, },
{
BlockType: "plain-text",
Data: []string{"perpoer", "kekekeke"},
}, },
{
BlockType: "plain-text",
Data: []string{"perpoer", "kekekeke"},
}, },
{
BlockType: "plain-text",
Data: []string{"perpoer", "kekekeke"},
}, },
} }
err := b.fs.CreateFile(&blogFile, path)
if err != nil {
println(err.Error())
}
}
func (b *BlogViewerApplication) Render(path string, isMobile bool) (gin.H, error) {
file, err := b.fs.Read(path)
if err != nil {
println(err.Error())
return nil, err
}
blogDataRaw := file.Data.(primitive.D).Map()
header := blogDataRaw["header"]
blocks := []Block{}
for _, rawBlock := range blogDataRaw["blocks"].(primitive.A) {
lel := rawBlock.(primitive.D).Map()
block := Block{
Type: lel["type"].(string),
Data: []string{},
}
for _, v := range lel["data"].(primitive.A) {
block.Data = append(block.Data, v.(string))
}
blocks = append(blocks, block)
}
return gin.H{ return gin.H{
"header": header, "header": "AAAAAA Header",
"blocks": blocks, "blocks": mockBlocks,
}, nil }
} }
type Block struct { type Block struct {
Type string `bson:"type"` BlockType string
Data []string `bson:"data"` Data []string
} }

View File

@ -1,34 +1,22 @@
package finder package finder
import ( import (
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp" "personalwebsite/websiteapp"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type FinderApplication struct { type FinerApplication struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest manifest websiteapp.ApplicationManifest
} }
func NewFinderApplication(webFs *webfilesystem.WebFileSystem) *FinderApplication { func (f *FinerApplication) GetManifest() websiteapp.ApplicationManifest {
return &FinderApplication{
fs: webFs,
manifest: websiteapp.ApplicationManifest{
AppId: "finder",
WindowName: "TODO DELETE", //TODO DELETE
},
}
}
func (f *FinderApplication) GetManifest() websiteapp.ApplicationManifest {
return f.manifest return f.manifest
} }
func (f *FinderApplication) GetId() string { func (f *FinerApplication) GetId() string {
return f.manifest.AppId return f.manifest.AppId
} }
func (f *FinderApplication) Render(isMobile bool) gin.H { func (f *FinerApplication) Render(isMobile bool) gin.H {
return gin.H{} return gin.H{}
} }