diff --git a/main.go b/main.go index 67624bc..7db1803 100644 --- a/main.go +++ b/main.go @@ -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) } }) } diff --git a/templates/personal-properties/app.tmpl b/templates/personal-properties/app.tmpl index 3390786..f3481aa 100644 --- a/templates/personal-properties/app.tmpl +++ b/templates/personal-properties/app.tmpl @@ -1,6 +1,6 @@ {{ define "personal-properties/app.tmpl" }} -
+
diff --git a/websiteapp/personalprops/personalprops.go b/websiteapp/personalprops/personalprops.go index 25aea9b..62857b9 100644 --- a/websiteapp/personalprops/personalprops.go +++ b/websiteapp/personalprops/personalprops.go @@ -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{} { // }