From 1beba0f0ee298aa4e348961f0749b023bc787839 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sat, 6 May 2023 01:50:57 +0300 Subject: [PATCH] Personal props --- apps/personalprops/personalprops.go | 198 ++++++---------------- resources/sys/blog-viewer/blog-viewer.css | 6 +- resources/sys/finder/finder.js | 8 +- resources/wde.js | 4 +- templates/finder/admin-app.tmpl | 2 +- templates/personal-properties/app.tmpl | 3 +- webfilesystem/mongo.go | 4 +- webfilesystem/newmethods.go | 4 +- 8 files changed, 64 insertions(+), 165 deletions(-) diff --git a/apps/personalprops/personalprops.go b/apps/personalprops/personalprops.go index 9314680..c92ba85 100644 --- a/apps/personalprops/personalprops.go +++ b/apps/personalprops/personalprops.go @@ -4,10 +4,10 @@ import ( "errors" "net/http" websiteapp "personalwebsite/apps" - "personalwebsite/libs" "personalwebsite/webfilesystem" "github.com/gin-gonic/gin" + "github.com/mitchellh/mapstructure" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -34,6 +34,7 @@ func (p *PersonalPropertiesApp) Route(route *gin.RouterGroup) { ginH, err := p.Render() if err != nil { ctx.JSON(http.StatusInternalServerError, "TODO") //TODO + return } if isMobile { ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", ginH) @@ -50,170 +51,62 @@ func (p *PersonalPropertiesApp) GetId() string { return p.manifest.AppId } -// func (p *PersonalPropertiesApp) WriteToDb() { -// allProps := make([]PropIsland, 0) - -// // careerProps := make([]Prop, 0) -// expertiseIsland := PropIsland{ -// Header: "Area Of Expertise", -// Props: []PropElement{{ -// Key: "Programming", -// Values: []string{ -// "Creating tools and plugins for artists", -// "Editor and basic gameplay scripting", -// }, -// }, -// { -// Key: "Game Art", -// Values: []string{ -// "Professional modeling", -// "Complete knowledge in CG render theory", -// }, -// }, -// }, -// } -// eduIsland := PropIsland{ -// Header: "Education", -// Props: []PropElement{ -// { -// Key: "Gymnasium 526", -// KeyComments: []string{"2005-2015"}, -// Values: []string{"Extended natural sciences course", "Additional C++, media production and computer graphics courses", "Winner of conference “The future of a strong Russia is in high technology” in programming section"}, -// }, -// { -// Key: "Lyceum 281", -// KeyComments: []string{"2015-2016"}, -// Values: []string{"Extended IT and Physical sciences course"}, -// }, -// { -// Key: "University", -// KeyComments: []string{"2017-2019"}, -// Values: []string{"Faculty: Info-communication Networks and Systems", "Specialty: Information Security"}, -// }, -// }, -// } -// careerProps := PropIsland{ -// Header: "Career", -// Props: []PropElement{ -// { -// Key: "VR lab assistant", -// KeyComments: []string{"Academy of Digital Technologies", "2019-2020"}, -// Values: []string{"Teaching lessons for students in Unreal Engine 4, Unity and Blender editor courses", "Training students for World Skills Russia"}, -// }, -// { -// Key: "3d artist", -// KeyComments: []string{"Space Time VR", "2020-2020"}, -// Values: []string{"Creating 3d assets for VR game"}, -// }, -// { -// Key: "Jr. Techartist", -// KeyComments: []string{"MP Games"}, -// Values: []string{"Game content integration and production", "Shader coding", "Optimization asset production in artists pipeline"}, -// }, -// { -// Key: "Techartist", -// Values: []string{"Game content optimization and production", "Profiling and debugging render pipeline", "Creating in-house tools for pipeline software", "Working process pipeline integration and maintenance", "Linux servers administration"}, -// }, -// }, -// } -// volunteerProps := PropIsland{ -// Header: "Volunteer Experience", -// Props: []PropElement{ -// { -// Key: "Metrostroi Mod", -// Values: []string{ -// "Help unite fragmented community on one social platform", -// "Worked on social elements of official site, create ranking", -// "Took a part on creating ranking system for players", -// "Creating models and maps for Steam Workshop"}, -// }, -// { -// Key: "Age of Silence", -// Values: []string{ -// "Start as tech-artist, create naming system in big ue4 project", -// "Promoted to chief of 3d Department", -// "Project win Unreal Day 2019", -// }, -// }, -// }, -// } - -// 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.NewRead("/home/user/personal.props") + propsFile, err := p.fs.NewRead("/home/user/About Me.props") if err != nil { + println(err.Error()) return nil, err } - if props.Data == nil || props.Type != "props" { - return nil, errors.New("bad file") - } - headerProps := props.Data.(primitive.D).Map()["headerprops"].(primitive.D).Map() - // file, err := p.fs.Read(headerProps["icon"].(string)) - if err != nil { - //TODO err catch + + if propsFile.Type != "pers-props" { + return nil, errors.New("file is not a directory") } - // data, err := wde.ReadImage(file) + fileData, err := castToPersPropsData(propsFile.Data) + if err != nil { + println(err.Error()) + return nil, err + } + + _ = fileData + + // file := castToFile(fileRaw) + + // return file, nil + + // if propsFile.Data == nil || propsFile.Type != "pers-props" { + // return nil, errors.New("bad file") + // } + + // props, err := castToPersPropsData(propsFileRaw) + // _ = props // if err != nil { // return nil, err // } - hIsland := HeaderIsland{ - Name: headerProps["name"].(string), - // Icon: data, - Info1: "LLL", - Info2: "QQQ", - } - - 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), - } - 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) - } - return gin.H{ - "headerProps": hIsland, - "allprops": allProps, + // "headerProps": props.Header, + // "allprops": props.Props, }, nil } +func castToPersPropsData(fileData interface{}) (*PropertiesFileData, error) { + propsData := PropertiesFileData{ + Header.Name: fileData.(primitive.D).Map()["name"].(string), + } + err := mapstructure.Decode(fileData.(primitive.D).Map(), &propsData) + if err != nil { + return nil, err + } + return &propsData, nil + +} + type HeaderIsland struct { - Name string - Icon *libs.Base64Img - Info1 string - Info2 string + Name string `bson:"name"` + IconPath string `bson:"iconpath"` + Info1 string `bson:"info1"` + Info2 string `bson:"info2"` } type PropElement struct { @@ -230,3 +123,8 @@ type PropIsland struct { type PropertiesFile struct { Props []PropIsland `bson:"props"` } + +type PropertiesFileData struct { + Header HeaderIsland `bson:"header"` + Props []PropIsland `bson:"props"` +} diff --git a/resources/sys/blog-viewer/blog-viewer.css b/resources/sys/blog-viewer/blog-viewer.css index 8bbf70c..1063197 100644 --- a/resources/sys/blog-viewer/blog-viewer.css +++ b/resources/sys/blog-viewer/blog-viewer.css @@ -15,17 +15,17 @@ .blog-viewer .header-h1{ font-size:x-large; - padding: 10px; + padding-bottom: 10px; } .blog-viewer .header-h2{ font-size:large; - padding: 6px; + padding-bottom: 6px; } .blog-viewer .header-h3{ font-size:larger; - padding: 2px; + padding-bottom: 2px; } .blog-viewer .plain-text{ diff --git a/resources/sys/finder/finder.js b/resources/sys/finder/finder.js index ffbe3e8..ec201fd 100644 --- a/resources/sys/finder/finder.js +++ b/resources/sys/finder/finder.js @@ -36,9 +36,9 @@ class Finder{ ) this.OpenDir(this.path) - // newWindow.querySelector("#BackButton").addEventListener('click', () =>{ - // this.OpenPreviousDir() - // }) + newWindow.querySelector("#RootButton").addEventListener('click', () =>{ + this.OpenDir('/') + }) // newWindow.querySelector("#HomeButton").addEventListener('click', () =>{ // this.OpenDir(this.homePath) @@ -125,7 +125,7 @@ class Finder{ * @param {string} path */ OpenDir(path){ - this.fileView.OpenFolder(this.path) + this.fileView.OpenFolder(path) } diff --git a/resources/wde.js b/resources/wde.js index 7759217..662e029 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -4,9 +4,9 @@ document.addEventListener('DOMContentLoaded', function() { // console.log(window.screen.width) wde = new WebDesktopEnvironment 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 { WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) } diff --git a/templates/finder/admin-app.tmpl b/templates/finder/admin-app.tmpl index 1ca2bc2..a245e54 100644 --- a/templates/finder/admin-app.tmpl +++ b/templates/finder/admin-app.tmpl @@ -12,7 +12,7 @@
- +
diff --git a/templates/personal-properties/app.tmpl b/templates/personal-properties/app.tmpl index 2230479..bbc0364 100644 --- a/templates/personal-properties/app.tmpl +++ b/templates/personal-properties/app.tmpl @@ -11,8 +11,9 @@
- My Photo + My Photo
+ {{ .headerProps.IconPath }}
{{ .headerProps.Name }}
{{ .headerProps.Info1 }}
{{ .headerProps.Info2 }}
diff --git a/webfilesystem/mongo.go b/webfilesystem/mongo.go index 84b0074..889156a 100644 --- a/webfilesystem/mongo.go +++ b/webfilesystem/mongo.go @@ -7,12 +7,12 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" ) -type readStruct struct { +type ReadStruct struct { File interface{} Filter interface{} } -func (fs *WebFileSystem) readMongo(read readStruct) (*interface{}, error) { +func (fs *WebFileSystem) ReadMongo(read ReadStruct) (*interface{}, error) { err := fs.webfsCollection.FindOne(fs.ctx, read.Filter).Decode(read.File) if err != nil { return nil, err diff --git a/webfilesystem/newmethods.go b/webfilesystem/newmethods.go index f863082..5d933ef 100644 --- a/webfilesystem/newmethods.go +++ b/webfilesystem/newmethods.go @@ -8,13 +8,13 @@ import ( func (fs *WebFileSystem) NewRead(filePath string) (*WebFSFile, error) { splittedPath := fs.SplitPath(filePath) - read := readStruct{ + read := ReadStruct{ File: &WebFSFile{}, Filter: primitive.M{ "name": splittedPath[len(splittedPath)-1], }, } - fileRaw, err := fs.readMongo(read) + fileRaw, err := fs.ReadMongo(read) if err != nil { return nil, err }