basic islands from db

This commit is contained in:
cyber-dream 2023-04-29 22:37:08 +03:00
parent 4c0bea4f89
commit f736033ce3
3 changed files with 70 additions and 25 deletions

11
main.go
View File

@ -63,7 +63,8 @@ func main() {
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
wde := wde.NewWDE(webfs)
persPropsApp := personalprops.NewPersPropsApp()
persPropsApp := personalprops.NewPersPropsApp(webfs)
persPropsApp.WriteToDb()
// finderApp := finder.FinderApplication{}
finderApp := finder.NewFinderApplication(webfs)
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
@ -186,10 +187,14 @@ func main() {
persPropApp.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
ginH, err := persPropsApp.Render()
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO
}
if isMobile {
ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", persPropsApp.Render())
ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", ginH)
} else {
ctx.HTML(http.StatusOK, "personal-properties/app.tmpl", persPropsApp.Render())
ctx.HTML(http.StatusOK, "personal-properties/app.tmpl", ginH)
}
})
}

View File

@ -1,6 +1,6 @@
{{ define "personal-properties/app.tmpl" }}
<!-- <div id="WindowBorder" class="PersonalPropertiesFrame"> -->
<div id="TestWindowHeader" class="WindowFrameTopBar">
<div id="TestWindowHeader" class="WindowFrameTopBar DragArea">
<button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button>
<div id="Drag" class="WindowDragArea"></div>
<div class="WindowFrameTitle">

View File

@ -1,17 +1,21 @@
package personalprops
import (
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type PersonalPropertiesApp struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest
}
func NewPersPropsApp() PersonalPropertiesApp {
func NewPersPropsApp(webFs *webfilesystem.WebFileSystem) PersonalPropertiesApp {
newApp := PersonalPropertiesApp{
fs: webFs,
manifest: websiteapp.ApplicationManifest{
AppId: "personal-properties",
WindowName: "About me",
@ -27,16 +31,7 @@ func (p *PersonalPropertiesApp) GetId() string {
return p.manifest.AppId
}
func (p *PersonalPropertiesApp) Render() gin.H {
// books := make([]Book, 0)
// books = append(books, Book{
// Title: "Title 1",
// Author: "Author 1",
// })
// books = append(books, Book{
// Title: "Title 2",
// Author: "Author 2",
// })
func (p *PersonalPropertiesApp) WriteToDb() {
allProps := make([]PropIsland, 0)
// careerProps := make([]Prop, 0)
@ -123,21 +118,62 @@ func (p *PersonalPropertiesApp) Render() gin.H {
},
},
}
// testKeys := PropIsland{
// Header: "Test",
// Props: []PropElement{{
// Key: "Urtt",
// Values: []string{"BakaBaka"},
// }},
// }
allProps = append(allProps, expertiseIsland, careerProps, eduIsland, volunteerProps)
file := webfilesystem.WebFSFile{
MongoId: primitive.NewObjectID(),
Name: "personal.props",
Type: "props",
Data: PropertiesFile{
Props: allProps,
},
}
err := p.fs.CreateFile(&file, "/home/user/")
if err != nil {
println(err.Error())
} else {
println("Ok")
}
}
func (p *PersonalPropertiesApp) Render() (gin.H, error) {
props, err := p.fs.Read("/home/user/personal.props")
if err != nil {
return nil, err
}
_ = props
allProps := make([]PropIsland, 0)
for _, v := range props.Data.(primitive.D).Map()["props"].(primitive.A) {
island := PropIsland{}
island.Header = v.(primitive.D).Map()["header"].(string)
for _, prop := range v.(primitive.D).Map()["props"].(primitive.A) {
elem := PropElement{
Key: prop.(primitive.D).Map()["key"].(string),
// KeyComments: prop.(primitive.D).Map()["keycomments"].([]string),
}
if prop.(primitive.D).Map()["keycomments"] != nil {
for _, keyComments := range prop.(primitive.D).Map()["keycomments"].(primitive.A) {
elem.KeyComments = append(elem.KeyComments, keyComments.(string))
}
}
for _, elemValues := range prop.(primitive.D).Map()["values"].(primitive.A) {
elem.Values = append(elem.Values, elemValues.(string))
}
island.Props = append(island.Props, elem)
}
allProps = append(allProps, island)
}
// allProps = append(allProps)
return gin.H{
"Name": "Greg Brzezinski",
"BasicBio": "Born 27.09.1998 at Saint-Petersburg",
// "Name": "Greg Brzezinski",
// "BasicBio": "Born 27.09.1998 at Saint-Petersburg",
// "BasicInfo": basicInfo,
// "career": careerProps,
"allprops": allProps,
}
}, nil
}
type Book struct {
@ -156,6 +192,10 @@ type PropIsland struct {
Props []PropElement
}
type PropertiesFile struct {
Props []PropIsland `bson:"props"`
}
// func (p *PersonalPropertiesApp) GetContent(ctx *gin.Context) interface{} {
// }