diff --git a/main.go b/main.go index 32333c3..12deafd 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "net/http" "personalwebsite/routewde" "personalwebsite/websiteapp" + "personalwebsite/websiteapp/blogviewer" "personalwebsite/websiteapp/finder" imgviewer "personalwebsite/websiteapp/img-viewer" "personalwebsite/websiteapp/personalprops" @@ -12,22 +13,6 @@ import ( "github.com/gin-gonic/gin" ) -// func main() { -// router := gin.Default() -// router.LoadHTMLGlob("templates/**/*") -// router.GET("/posts/index", func(c *gin.Context) { -// c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{ -// "title": "Posts", -// }) -// }) -// router.GET("/users/index", func(c *gin.Context) { -// c.HTML(http.StatusOK, "users/index.tmpl", gin.H{ -// "title": "Users", -// }) -// }) -// router.Run(":8080") -// } - func main() { router := gin.New() @@ -41,12 +26,14 @@ func main() { persPropsApp := personalprops.NewPersPropsApp() finderApp := finder.FinerApplication{} imgViewerApp := imgviewer.NewImgViewerApp() + blogViewerApp := blogviewer.NewBlogViewerApp() appsStorage := websiteapp.ApplicationsStorage{ Apps: map[string]websiteapp.WebDEApplication{}, } appsStorage.Apps["personal-properties"] = &persPropsApp appsStorage.Apps["finder"] = &finderApp appsStorage.Apps["img-viewer"] = &imgViewerApp + appsStorage.Apps["blog-viewer"] = blogViewerApp system := router.Group("system") { @@ -124,6 +111,19 @@ func main() { }) } + blogViewerRoute := app.Group("blog-viewer") + { + blogViewerRoute.GET("render", func(ctx *gin.Context) { + isMobileParam := ctx.Query("isMobile") + isMobile := isMobileParam == "true" + if isMobile { + ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", blogViewerApp.Render(isMobile)) + } else { + ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(isMobile)) + } + + }) + } } router.GET("/test", func(ctx *gin.Context) { ctx.HTML(200, "kek/kek.tmpl", gin.H{}) diff --git a/resources/mobile-wdeUI.css b/resources/mobile-wdeUI.css index e941393..ff80a64 100644 --- a/resources/mobile-wdeUI.css +++ b/resources/mobile-wdeUI.css @@ -3,6 +3,7 @@ height: 100%; background: #CCCCCC; + /* background: #9999CC; */ /* Auto layout */ display: flex; diff --git a/resources/sys/blog-viewer/blog-viewer.css b/resources/sys/blog-viewer/blog-viewer.css new file mode 100644 index 0000000..bc2a899 --- /dev/null +++ b/resources/sys/blog-viewer/blog-viewer.css @@ -0,0 +1,25 @@ +.blog-viewer{ + background-color: #DDDDDD; + width: 100%; + height: 100%; + + overflow: scroll; + + /* Auto layout */ + display: flex; + flex-direction: column; + align-items: flex-start; + justify-content: flex-start; + gap: 50px; + row-gap: 20px; +} + +.blog-viewer .header{ + font-size: x-large; + padding: 15px; +} + +.blog-viewer .plain-text{ + padding: 0px 20px 0px 20px; + +} \ No newline at end of file diff --git a/resources/sys/blog-viewer/blog-viewer.js b/resources/sys/blog-viewer/blog-viewer.js new file mode 100644 index 0000000..2f61074 --- /dev/null +++ b/resources/sys/blog-viewer/blog-viewer.js @@ -0,0 +1,50 @@ +class BlogViewer{ + appId = "blog-viewer" + constructor(){ + } + + /** + * @param {string} path + */ + NewWindow(path){ + fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ + isMobile: WebDesktopEnvironment.isMobile, + })) + .then((response) => response.text()) + .then((html) => { + let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 ) + newWindow.innerHTML = html + + // let fileView = new FileView("/kek", newWindow.querySelector(".FileTileView"), Finder.Click) + 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) { + WebDesktopEnvironment.CloseWindow(newWindow) + }) + } + }) + .catch((error) => { + WebDesktopEnvironment.Alert(error); + }) + } + + /** + * @param {MouseEvent} event + * @param {string} path + */ + static Click(event, path){ + let fileType = event.target.getAttribute("fileType") + switch (fileType) { + 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; + } + } +} diff --git a/resources/wde.js b/resources/wde.js index d767a84..39efd43 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -4,6 +4,8 @@ document.addEventListener('DOMContentLoaded', function() { if (!WebDesktopEnvironment.isMobile){ WebDesktopEnvironment.Open("finder", ["kek"]) WebDesktopEnvironment.Open("personal-properties", ["kek"]) + } else { + WebDesktopEnvironment.Open("blog-viewer", ["kek"]) } @@ -38,6 +40,10 @@ class WebDesktopEnvironment{ //TODO Do not allow launch second instance WebDesktopEnvironment.Open("personal-properties", []) }) + mobileDesktop.querySelector('#mobile-desktop-blog').addEventListener('click', (event) => { + //TODO Do not allow launch second instance + WebDesktopEnvironment.Open("blog-viewer", ['main-page']) + }) mobileDesktop.querySelector('#mobile-dekstop-close').addEventListener('click', (event) => { // console.log('close') WebDesktopEnvironment.CloseFocusedWindow() @@ -89,6 +95,11 @@ class WebDesktopEnvironment{ this.Applications[appId] = newImgViewer func() return newImgViewer + case "blog-viewer": + let newBlogViewer = new BlogViewer() + this.Applications[appId] = newBlogViewer + func() + return newBlogViewer default: break; } diff --git a/templates/base/index.tmpl b/templates/base/index.tmpl index 2e38d2f..9017153 100644 --- a/templates/base/index.tmpl +++ b/templates/base/index.tmpl @@ -8,6 +8,7 @@ + diff --git a/templates/base/mobile-desktop.tmpl b/templates/base/mobile-desktop.tmpl index 61cbfe8..6c637df 100644 --- a/templates/base/mobile-desktop.tmpl +++ b/templates/base/mobile-desktop.tmpl @@ -11,9 +11,9 @@
About Me
-
+
-
Home
+
Blog
diff --git a/templates/blog-viewer/app.tmpl b/templates/blog-viewer/app.tmpl new file mode 100644 index 0000000..7dbd113 --- /dev/null +++ b/templates/blog-viewer/app.tmpl @@ -0,0 +1,18 @@ +{{ define "blog-viewer/app.tmpl" }} +
+ +
+
+ Files +
+
+
+
+
+ +
+ {{template "wde-widgets/scrollbar.tmpl" .}} +
+{{ end }} + + \ No newline at end of file diff --git a/templates/blog-viewer/mobile-app.tmpl b/templates/blog-viewer/mobile-app.tmpl new file mode 100644 index 0000000..db5e1d2 --- /dev/null +++ b/templates/blog-viewer/mobile-app.tmpl @@ -0,0 +1,16 @@ +{{ define "blog-viewer/mobile-app.tmpl" }} +
+
+ Test header +
+ {{ range $block := .blocks }} +
+ {{ range $data := $block.Data }} + {{$data}} + {{ end }} +
+ {{ end }} +
+{{ end }} + + \ No newline at end of file diff --git a/websiteapp/blogviewer/blogviewer.go b/websiteapp/blogviewer/blogviewer.go new file mode 100644 index 0000000..295bbc0 --- /dev/null +++ b/websiteapp/blogviewer/blogviewer.go @@ -0,0 +1,57 @@ +package blogviewer + +import ( + "personalwebsite/websiteapp" + + "github.com/gin-gonic/gin" +) + +type BlogViewerApplication struct { + manifest websiteapp.ApplicationManifest +} + +func NewBlogViewerApp() *BlogViewerApplication { + return &BlogViewerApplication{ + manifest: websiteapp.ApplicationManifest{ + AppId: "blog-viewer", + WindowName: "", + }, + } +} + +func (b *BlogViewerApplication) GetManifest() websiteapp.ApplicationManifest { + return b.manifest +} +func (b *BlogViewerApplication) GetId() string { + return b.manifest.AppId +} + +func (b *BlogViewerApplication) Render(isMobile bool) gin.H { + mockBlocks := []Block{ + { + BlockType: "plain-text", + Data: []string{"qwerty qwerty werty", "oiposi sdfsp sdfip"}, + }, + { + BlockType: "plain-text", + Data: []string{"perpoer", "kekekeke"}, + }, + { + BlockType: "plain-text", + Data: []string{"perpoer", "kekekeke"}, + }, + { + BlockType: "plain-text", + Data: []string{"perpoer", "kekekeke"}, + }, + } + return gin.H{ + "header": "AAAAAA Header", + "blocks": mockBlocks, + } +} + +type Block struct { + BlockType string + Data []string +}