Compare commits
2 Commits
21b201fd9d
...
471350ead1
Author | SHA1 | Date | |
---|---|---|---|
471350ead1 | |||
b6b3cf9ca1 |
21
main.go
21
main.go
@ -7,6 +7,7 @@ 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"
|
||||||
@ -61,23 +62,25 @@ 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.FinerApplication{}
|
// finderApp := finder.FinderApplication{}
|
||||||
|
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")
|
||||||
{
|
{
|
||||||
|
|
||||||
wde := system.Group("wde")
|
wdeGroup := system.Group("wde")
|
||||||
{
|
{
|
||||||
routewde.Route(wde)
|
routewde.Route(wdeGroup, wde)
|
||||||
}
|
}
|
||||||
apps := system.Group("applications")
|
apps := system.Group("applications")
|
||||||
{
|
{
|
||||||
@ -240,10 +243,16 @@ 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", blogViewerApp.Render(path, isMobile))
|
ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", ginH)
|
||||||
} else {
|
} else {
|
||||||
ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(path, isMobile))
|
ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", ginH)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -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({
|
fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
|
||||||
isMobile: WebDesktopEnvironment.isMobile,
|
isMobile: WebDesktopEnvironment.isMobile,
|
||||||
path: path,
|
path: args[0],
|
||||||
}))
|
}))
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((html) => {
|
.then((html) => {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
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
|
||||||
}
|
}
|
||||||
@ -7,9 +12,11 @@ class Finder{
|
|||||||
/**
|
/**
|
||||||
* @param {string} path
|
* @param {string} path
|
||||||
*/
|
*/
|
||||||
NewWindow(path){
|
NewWindow(args){
|
||||||
|
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())
|
||||||
@ -17,7 +24,19 @@ class Finder{
|
|||||||
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
|
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
|
||||||
newWindow.innerHTML = html
|
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){
|
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) {
|
||||||
@ -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
|
* @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 fileType = event.target.getAttribute("fileType")
|
||||||
|
let fileName = event.target.getAttribute("name")
|
||||||
switch (fileType) {
|
switch (fileType) {
|
||||||
case "app":
|
case "directory":
|
||||||
//TODO get real id
|
this.OpenDir(this.path +"/" + fileName)
|
||||||
WebDesktopEnvironment.Open("personal-properties", [])
|
break
|
||||||
break;
|
case "blog-page":
|
||||||
case "img":
|
WebDesktopEnvironment.Open("blog-viewer", [this.path + "/" + fileName])
|
||||||
WebDesktopEnvironment.Open("img-viewer", ["pizda"])
|
break
|
||||||
break;
|
// case "app":
|
||||||
|
// //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);
|
||||||
|
// })
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
class FileView{
|
class FileView{
|
||||||
path = ""
|
parentElem = undefined
|
||||||
/**
|
/**
|
||||||
* @param {string} path
|
|
||||||
* @param {HTMLElement} fileViewElem
|
* @param {HTMLElement} fileViewElem
|
||||||
* @param {Function} clickCallback
|
* @param {Function} clickCallback
|
||||||
*/
|
*/
|
||||||
constructor(path, fileViewElem, clickCallback){
|
constructor(fileViewElem, clickCallback){
|
||||||
//TODO check all params
|
//TODO check all params
|
||||||
this.path = path
|
this.parentElem = fileViewElem
|
||||||
|
|
||||||
this.openFolder(path, fileViewElem)
|
// this.OpenFolder(path)
|
||||||
|
|
||||||
// let scrollDiv = fileViewElem.children[1]
|
// let scrollDiv = fileViewElem.children[1]
|
||||||
// console.log(scrollDiv)
|
// console.log(scrollDiv)
|
||||||
@ -22,14 +21,17 @@ 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, parentElem){
|
OpenFolder(path){
|
||||||
// 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) => {
|
||||||
parentElem.innerHTML = html
|
//TODO
|
||||||
|
// console.log(responseStatus)
|
||||||
|
// if (responseStatus != 200) {
|
||||||
|
// WebDesktopEnvironment.Alert("Error")
|
||||||
|
// }
|
||||||
|
this.parentElem.innerHTML = html
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
WebDesktopEnvironment.Alert(error);
|
WebDesktopEnvironment.Alert(error);
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,8 @@ 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"])
|
||||||
@ -210,7 +211,8 @@ 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
|
||||||
|
@ -326,5 +326,5 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.FileTileTitle{
|
.FileTileTitle{
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
@ -2,12 +2,12 @@ package routewde
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/wde"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"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) {
|
route.GET("/getbasicwindow", func(ctx *gin.Context) {
|
||||||
ctx.HTML(http.StatusOK, "basic-window.html", nil)
|
ctx.HTML(http.StatusOK, "basic-window.html", nil)
|
||||||
})
|
})
|
||||||
@ -19,12 +19,17 @@ func Route(route *gin.RouterGroup) {
|
|||||||
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) {
|
||||||
fs := webfilesystem.WebFileSystem{}
|
path := ctx.Query("path")
|
||||||
list, _ := fs.List("/") //TODO check errors
|
if path == "" {
|
||||||
ctx.HTML(http.StatusOK, "wde-widgets/file-tile-view.tmpl", gin.H{
|
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||||
"Name": "Greg Brzezinski",
|
return
|
||||||
"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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,21 @@
|
|||||||
<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">
|
||||||
Files
|
{{.header}}
|
||||||
</div>
|
</div>
|
||||||
<div id="Drag" class="WindowDragArea"></div>
|
<div id="Drag" class="WindowDragArea"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ContentBorder">
|
<div class="ContentBorder">
|
||||||
<div class="FileTileView">
|
<div class="blog-viewer">
|
||||||
|
{{ 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>
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
</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">
|
||||||
|
|
||||||
|
@ -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 id="{{ $fileTile.Id }}" fileType="{{ $fileTile.Type }}" class="FileTile" fileName="{{$fileTile.FileName}}">
|
<div fileType="{{ $fileTile.Type }}" class="FileTile" name="{{$fileTile.Name}}">
|
||||||
<div class="FileTileIcon NoClick"></div>
|
<div class="FileTileIcon NoClick"></div>
|
||||||
<div class="FileTileTitle NoClick">{{ $fileTile.FileName }}</div>
|
<div class="FileTileTitle NoClick">{{ $fileTile.Name }}</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
32
wde/wde.go
Normal file
32
wde/wde.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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
|
||||||
|
}
|
6
websiteapp/blogviewer/blogfile.go
Normal file
6
websiteapp/blogviewer/blogfile.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package blogviewer
|
||||||
|
|
||||||
|
type BlogFileData struct {
|
||||||
|
Header string `bson:"header"`
|
||||||
|
Blocks []Block `bson:"blocks"`
|
||||||
|
}
|
@ -1,17 +1,21 @@
|
|||||||
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() *BlogViewerApplication {
|
func NewBlogViewerApp(webFs *webfilesystem.WebFileSystem) *BlogViewerApplication {
|
||||||
return &BlogViewerApplication{
|
return &BlogViewerApplication{
|
||||||
|
fs: webFs,
|
||||||
manifest: websiteapp.ApplicationManifest{
|
manifest: websiteapp.ApplicationManifest{
|
||||||
AppId: "blog-viewer",
|
AppId: "blog-viewer",
|
||||||
WindowName: "",
|
WindowName: "",
|
||||||
@ -22,36 +26,65 @@ func NewBlogViewerApp() *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) Render(isMobile bool) gin.H {
|
func (b *BlogViewerApplication) WriteMock(path string) {
|
||||||
mockBlocks := []Block{
|
blogFile := webfilesystem.WebFSFile{
|
||||||
|
MongoId: primitive.NewObjectID(),
|
||||||
|
Name: "test-1.blog",
|
||||||
|
Type: "blog-page",
|
||||||
|
Data: BlogFileData{
|
||||||
|
Header: "OMG THIS IS BLOG",
|
||||||
|
Blocks: []Block{
|
||||||
{
|
{
|
||||||
BlockType: "plain-text",
|
Type: "plain-text",
|
||||||
Data: []string{"qwerty qwerty werty", "oiposi sdfsp sdfip"},
|
Data: []string{
|
||||||
|
"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"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return gin.H{
|
err := b.fs.CreateFile(&blogFile, path)
|
||||||
"header": "AAAAAA Header",
|
if err != nil {
|
||||||
"blocks": mockBlocks,
|
println(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Block struct {
|
func (b *BlogViewerApplication) Render(path string, isMobile bool) (gin.H, error) {
|
||||||
BlockType string
|
file, err := b.fs.Read(path)
|
||||||
Data []string
|
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{
|
||||||
|
"header": header,
|
||||||
|
"blocks": blocks,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Block struct {
|
||||||
|
Type string `bson:"type"`
|
||||||
|
Data []string `bson:"data"`
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,34 @@
|
|||||||
package finder
|
package finder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"personalwebsite/webfilesystem"
|
||||||
"personalwebsite/websiteapp"
|
"personalwebsite/websiteapp"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FinerApplication struct {
|
type FinderApplication struct {
|
||||||
|
fs *webfilesystem.WebFileSystem
|
||||||
manifest websiteapp.ApplicationManifest
|
manifest websiteapp.ApplicationManifest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FinerApplication) GetManifest() websiteapp.ApplicationManifest {
|
func NewFinderApplication(webFs *webfilesystem.WebFileSystem) *FinderApplication {
|
||||||
|
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 *FinerApplication) GetId() string {
|
func (f *FinderApplication) GetId() string {
|
||||||
return f.manifest.AppId
|
return f.manifest.AppId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FinerApplication) Render(isMobile bool) gin.H {
|
func (f *FinderApplication) Render(isMobile bool) gin.H {
|
||||||
|
|
||||||
return gin.H{}
|
return gin.H{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user