diff --git a/pcinvj/pcinv/.gitattributes b/.gitattributes similarity index 100% rename from pcinvj/pcinv/.gitattributes rename to .gitattributes diff --git a/.gitignore b/.gitignore index a47f9f7..c2065bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,37 @@ -*.db3 -*.db3-* -*.db3.* -*.iml +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### .idea -pcinv +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 752719c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM golang:1.24.1-alpine3.21 - -WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download - -COPY migrations ./migrations -COPY static ./static -COPY templates ./templates -COPY *.go ./ -RUN go build -o /pcinv - -CMD ["/pcinv"] diff --git a/pcinvj/pcinv/build.gradle.kts b/build.gradle.kts similarity index 100% rename from pcinvj/pcinv/build.gradle.kts rename to build.gradle.kts diff --git a/data.go b/data.go deleted file mode 100644 index df94ecd..0000000 --- a/data.go +++ /dev/null @@ -1,124 +0,0 @@ -package main - -import ( - "fmt" - "gitea.seeseepuff.be/seeseemelk/mysqlite" -) - -func (a *App) getAllTypes(column, table string) ([]string, error) { - var types []string - var err error - for row := range a.db.Query(fmt.Sprintf("SELECT %s FROM %s GROUP BY %s ORDER BY %s ASC", column, table, column, column)).Range(&err) { - var name string - err := row.Scan(&name) - if err != nil { - return nil, err - } - types = append(types, name) - } - return types, err -} - -func (a *App) GetAllBrands() ([]string, error) { - return a.getAllTypes("brand", "assets") -} - -func (a *App) GetAllRamTypes() ([]string, error) { - return a.getAllTypes("type", "info_ram") -} - -func (a *App) GetAllHddTypes() ([]string, error) { - return a.getAllTypes("type", "info_hdd") -} - -func (a *App) GetAllHddFormFactors() ([]string, error) { - return a.getAllTypes("form_factor", "info_hdd") -} - -func (a *App) GetAllHddConnections() ([]string, error) { - return a.getAllTypes("connection", "info_hdd") -} - -func (a *App) GetAllHddSpeeds() ([]string, error) { - return a.getAllTypes("rpm", "info_hdd") -} - -func (a *App) GetAllGroups(vm *CreateDeviceVM) error { - var err error - //vm.AssetBrands, err = a.GetAllBrands() - //if err != nil { - // return err - //} - // - //vm.RamTypes, err = a.GetAllRamTypes() - //if err != nil { - // return err - //} - // - //vm.HddTypes, err = a.GetAllHddTypes() - //if err != nil { - // return err - //} - // - //vm.HddFormFactors, err = a.GetAllHddFormFactors() - //if err != nil { - // return err - //} - // - //vm.HddFormFactors, err = a.GetAllHddConnections() - //if err != nil { - // return err - //} - // - //vm.HddRpms, err = a.GetAllHddSpeeds() - if err != nil { - return err - } - return nil -} - -func (a *App) GetAllTypes() ([]string, error) { - var types []string - var err error - for row := range a.db.Query("SELECT type FROM assets GROUP BY type ORDER BY type ASC").Range(&err) { - var name string - err := row.Scan(&name) - if err != nil { - return nil, err - } - types = append(types, name) - } - return types, err -} - -func (a *App) GetAssetCount() (int, error) { - var count int - err := a.db.Query("SELECT COUNT(*) FROM assets").ScanSingle(&count) - return count, err -} - -func (a *App) GetBrandCount() (int, error) { - var count int - err := a.db.Query("SELECT COUNT(DISTINCT brand) FROM assets").ScanSingle(&count) - return count, err -} - -func (a *App) GetTotalRamCapacity() (int, error) { - var capacity int - err := a.db.Query("SELECT SUM(capacity) FROM info_ram").ScanSingle(&capacity) - return capacity, err -} - -func (a *App) DeleteAsset(tx *mysqlite.Tx, qr int) error { - err := tx.Query("DELETE FROM assets WHERE qr=?").Bind(qr).Exec() - if err != nil { - return err - } - - err = tx.Query("DELETE FROM info_ram WHERE asset=?").Bind(qr).Exec() - if err != nil { - return err - } - - return nil -} diff --git a/descriptors.go b/descriptors.go deleted file mode 100644 index 3ab2e1d..0000000 --- a/descriptors.go +++ /dev/null @@ -1,130 +0,0 @@ -package main - -var DescriptorTree = createDescriptorTree(DescriptorRoot{ - AssetTypes: []AssetType{ - { - Id: "asset", - Table: "assets", - Name: "General Information", - Abstract: true, - Fields: []AssetField{ - { - Id: "qr", - Name: "QR Code", - Type: Number, - }, - { - Id: "type", - Name: "Type", - Type: Type, - }, - { - Id: "brand", - Name: "Brand", - Type: Selection, - }, - { - Id: "name", - Name: "Name", - Type: String, - }, - { - Id: "description", - Name: "Description", - Type: String, - }, - }, - }, - { - Id: "ram", - Name: "Random Access Memory", - Table: "info_ram", - Fields: []AssetField{ - { - Id: "type", - Name: "Type", - Type: String, - }, - { - Id: "capacity", - Name: "Capacity", - Type: Capacity, - }, - }, - }, - { - Id: "hdd", - Name: "Hard Disk Drive", - Table: "info_hdd", - Fields: []AssetField{ - { - Id: "type", - Name: "Type", - Type: Selection, - }, - { - Id: "capacity", - Name: "Capacity", - Type: Capacity, - }, - { - Id: "form_factor", - Name: "Form Factor", - Type: Selection, - }, - { - Id: "interface", - Name: "Interface", - Type: Selection, - }, - { - Id: "rpm", - Name: "RPM", - Type: Selection, - }, - }, - }, - }, -}) - -func createDescriptorTree(tree DescriptorRoot) *DescriptorRoot { - return &tree -} - -func getAssetTypeById(id string) *AssetType { - for _, assetType := range DescriptorTree.AssetTypes { - if assetType.Id == id { - return &assetType - } - } - return nil -} - -type DescriptorRoot struct { - AssetTypes []AssetType -} - -type AssetType struct { - Id string - Name string - Table string - Fields []AssetField - Abstract bool -} - -type AssetField struct { - Id string - Name string - Type FieldType -} - -type FieldType string - -const ( - Number FieldType = "number" - String = "string" - Type = "type" - Selection = "selection" - Bool = "bool" - Capacity = "capacity" -) diff --git a/pcinvj/pcinv/docker-compose.yml b/docker-compose.yml similarity index 100% rename from pcinvj/pcinv/docker-compose.yml rename to docker-compose.yml diff --git a/go.mod b/go.mod deleted file mode 100644 index ae21222..0000000 --- a/go.mod +++ /dev/null @@ -1,48 +0,0 @@ -module pcinv - -go 1.24 - -toolchain go1.24.1 - -require ( - gitea.seeseepuff.be/seeseemelk/mysqlite v0.15.0 - github.com/gin-gonic/gin v1.10.1 -) - -require ( - github.com/bytedance/sonic v1.13.2 // indirect - github.com/bytedance/sonic/loader v0.2.4 // indirect - github.com/cloudwego/base64x v0.1.5 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.9 // indirect - github.com/gin-contrib/sse v1.1.0 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.26.0 // indirect - github.com/goccy/go-json v0.10.5 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.10 // indirect - github.com/leodido/go-urn v1.4.0 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/ncruces/go-strftime v0.1.9 // indirect - github.com/pelletier/go-toml/v2 v2.2.4 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect - github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.14 // indirect - golang.org/x/arch v0.17.0 // indirect - golang.org/x/crypto v0.38.0 // indirect - golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b // indirect - golang.org/x/net v0.40.0 // indirect - golang.org/x/sys v0.33.0 // indirect - golang.org/x/text v0.25.0 // indirect - google.golang.org/protobuf v1.36.6 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect - modernc.org/libc v1.65.8 // indirect - modernc.org/mathutil v1.7.1 // indirect - modernc.org/memory v1.11.0 // indirect - modernc.org/sqlite v1.37.1 // indirect - zombiezen.com/go/sqlite v1.4.2 // indirect -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 98e21e1..0000000 --- a/go.sum +++ /dev/null @@ -1,170 +0,0 @@ -gitea.seeseepuff.be/seeseemelk/mysqlite v0.9.0 h1:GaU2DSrgDfZEqST3HdnNgfKSI4sNXvMm8SSfeMvBxA4= -gitea.seeseepuff.be/seeseemelk/mysqlite v0.9.0/go.mod h1:cgswydOxJjMlNwfcBIXnKjr47LwXnMT9BInkiHb0tXE= -gitea.seeseepuff.be/seeseemelk/mysqlite v0.14.0 h1:aRItVfUj48fBmuec7rm/jY9KCfvHW2VzJfItVk4t8sw= -gitea.seeseepuff.be/seeseemelk/mysqlite v0.14.0/go.mod h1:cgswydOxJjMlNwfcBIXnKjr47LwXnMT9BInkiHb0tXE= -gitea.seeseepuff.be/seeseemelk/mysqlite v0.15.0 h1:+k0iBYM/aZJxz7++EKi/G9e66E9u4bPS3DFLrBeDb9Y= -gitea.seeseepuff.be/seeseemelk/mysqlite v0.15.0/go.mod h1:cgswydOxJjMlNwfcBIXnKjr47LwXnMT9BInkiHb0tXE= -github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= -github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= -github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= -github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= -github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= -github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= -github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= -github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= -github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= -github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= -github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY= -github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok= -github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= -github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= -github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= -github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM= -github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= -github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= -github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= -github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= -github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= -github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= -github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= -github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8= -github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= -github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= -github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= -github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= -github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= -github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= -github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= -github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= -github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= -github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= -github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= -github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= -github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= -github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= -github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/ugorji/go/codec v1.2.14 h1:yOQvXCBc3Ij46LRkRoh4Yd5qK6LVOgi0bYOXfb7ifjw= -github.com/ugorji/go/codec v1.2.14/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= -golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= -golang.org/x/arch v0.17.0 h1:4O3dfLzd+lQewptAHqjewQZQDyEdejz3VwgeYwkZneU= -golang.org/x/arch v0.17.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= -golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= -golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= -golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= -golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= -golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI= -golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= -golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b h1:QoALfVG9rhQ/M7vYDScfPdWjGL9dlsVVM5VGh7aKoAA= -golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= -golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= -golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= -golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= -golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= -golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= -golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= -golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= -golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= -golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= -google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= -google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= -google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= -google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ= -modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= -modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y= -modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s= -modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= -modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= -modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= -modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= -modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U= -modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w= -modernc.org/libc v1.65.8 h1:7PXRJai0TXZ8uNA3srsmYzmTyrLoHImV5QxHeni108Q= -modernc.org/libc v1.65.8/go.mod h1:011EQibzzio/VX3ygj1qGFt5kMjP0lHb0qCW5/D/pQU= -modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= -modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= -modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= -modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= -modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= -modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= -modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= -modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= -modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= -modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= -modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= -modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= -modernc.org/sqlite v1.33.1 h1:trb6Z3YYoeM9eDL1O8do81kP+0ejv+YzgyFo+Gwy0nM= -modernc.org/sqlite v1.33.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k= -modernc.org/sqlite v1.37.1 h1:EgHJK/FPoqC+q2YBXg7fUmES37pCHFc97sI7zSayBEs= -modernc.org/sqlite v1.37.1/go.mod h1:XwdRtsE1MpiBcL54+MbKcaDvcuej+IYSMfLN6gSKV8g= -modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= -modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= -modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= -modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -zombiezen.com/go/sqlite v1.4.0 h1:N1s3RIljwtp4541Y8rM880qgGIgq3fTD2yks1xftnKU= -zombiezen.com/go/sqlite v1.4.0/go.mod h1:0w9F1DN9IZj9AcLS9YDKMboubCACkwYCGkzoy3eG5ik= -zombiezen.com/go/sqlite v1.4.2 h1:KZXLrBuJ7tKNEm+VJcApLMeQbhmAUOKA5VWS93DfFRo= -zombiezen.com/go/sqlite v1.4.2/go.mod h1:5Kd4taTAD4MkBzT25mQ9uaAlLjyR0rFhsR6iINO70jc= diff --git a/pcinvj/pcinv/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from pcinvj/pcinv/gradle/wrapper/gradle-wrapper.jar rename to gradle/wrapper/gradle-wrapper.jar diff --git a/pcinvj/pcinv/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from pcinvj/pcinv/gradle/wrapper/gradle-wrapper.properties rename to gradle/wrapper/gradle-wrapper.properties diff --git a/pcinvj/pcinv/gradlew b/gradlew similarity index 100% rename from pcinvj/pcinv/gradlew rename to gradlew diff --git a/pcinvj/pcinv/gradlew.bat b/gradlew.bat similarity index 100% rename from pcinvj/pcinv/gradlew.bat rename to gradlew.bat diff --git a/main.go b/main.go deleted file mode 100644 index 14526ea..0000000 --- a/main.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "embed" - "html/template" - "log" - "net/http" - "os" - - "gitea.seeseepuff.be/seeseemelk/mysqlite" - "github.com/gin-gonic/gin" -) - -//go:embed migrations/*.sql -var migrations embed.FS - -//go:embed templates/*.gohtml -var templateFS embed.FS - -func main() { - log.Println("Starting...") - - // Get database path from environment variable or use default - dbPath := os.Getenv("PCINV_DB") - if dbPath == "" { - dbPath = "pcinv.db3" - } - - db, err := mysqlite.OpenDb(dbPath) - if err != nil { - log.Fatalf("error opening db: %v", err) - } - defer db.MustClose() - - err = db.MigrateDb(migrations, "migrations") - if err != nil { - log.Fatalf("error migrating db: %v", err) - } - - app := &App{ - db: db, - } - - templates, err := template.New("undefined.gohtml"). - Funcs(template.FuncMap{ - "statusText": http.StatusText, - "createDeviceLink": createDeviceLink, - "formatMemorySize": formatMemorySize, - "formatMemoryPlainSize": formatMemoryPlainSize, - "formatType": formatType, - "isRamType": isRamType, - "createSelectMenu": createSelectMenu, - "createSelectMenuDefault": createSelectMenuDefault, - }). - ParseFS(templateFS, "templates/*.gohtml") - - if err != nil { - log.Fatalf("error parsing templates: %v", err) - } - - gin.DebugPrintFunc = log.Printf - gin.SetMode(gin.ReleaseMode) - r := gin.Default() - r.SetHTMLTemplate(templates) - r.StaticFS("/static", staticFiles) - r.Use(errorHandler) - r.GET("/", app.getIndex) - r.GET("/device", app.getDevice) - r.GET("/create", app.getCreateDevice) - r.POST("/create", app.postCreateDevice) - r.GET("/browse", app.getBrowse) - r.GET("/delete", app.getDelete) - r.POST("/delete", app.postDelete) - err = r.Run() - if err != nil { - log.Fatalf("error serving website: %v", err) - } -} - -type ErrorVM struct { - Errors []*gin.Error - StatusCode int -} - -func errorHandler(c *gin.Context) { - c.Next() - if len(c.Errors) != 0 { - vm := ErrorVM{ - Errors: c.Errors, - StatusCode: c.Writer.Status(), - } - c.HTML(vm.StatusCode, "errors", vm) - } -} diff --git a/migrations/1_initial.sql b/migrations/1_initial.sql deleted file mode 100644 index d6a9938..0000000 --- a/migrations/1_initial.sql +++ /dev/null @@ -1,19 +0,0 @@ -create table assets ( - qr integer unique, - type text not null, - brand text, - name text, - description text -) strict; - -create table worklog ( - asset integer not null, - timestamp integer not null, - action text not null -) strict; - -create table info_ram ( - asset integer not null unique, - capacity integer, - type text -) strict; diff --git a/migrations/2_add_harddrives.sql b/migrations/2_add_harddrives.sql deleted file mode 100644 index d2b0225..0000000 --- a/migrations/2_add_harddrives.sql +++ /dev/null @@ -1,8 +0,0 @@ -create table info_hdd ( - asset integer not null unique, - capacity integer, - type text, - form_factor text, - connection text, - rpm integer -); diff --git a/pcinvj/pcinv/.gitignore b/pcinvj/pcinv/.gitignore deleted file mode 100644 index c2065bc..0000000 --- a/pcinvj/pcinv/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -HELP.md -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ diff --git a/pcinvj/pcinv/.gradle/8.14/checksums/checksums.lock b/pcinvj/pcinv/.gradle/8.14/checksums/checksums.lock deleted file mode 100644 index 61a5ef6..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/checksums/checksums.lock and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/checksums/md5-checksums.bin b/pcinvj/pcinv/.gradle/8.14/checksums/md5-checksums.bin deleted file mode 100644 index e589435..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/checksums/md5-checksums.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/checksums/sha1-checksums.bin b/pcinvj/pcinv/.gradle/8.14/checksums/sha1-checksums.bin deleted file mode 100644 index 6198bf2..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/checksums/sha1-checksums.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/executionHistory/executionHistory.bin b/pcinvj/pcinv/.gradle/8.14/executionHistory/executionHistory.bin deleted file mode 100644 index c74e967..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/executionHistory/executionHistory.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/executionHistory/executionHistory.lock b/pcinvj/pcinv/.gradle/8.14/executionHistory/executionHistory.lock deleted file mode 100644 index 1d30d9a..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/executionHistory/executionHistory.lock and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/fileChanges/last-build.bin b/pcinvj/pcinv/.gradle/8.14/fileChanges/last-build.bin deleted file mode 100644 index f76dd23..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/fileChanges/last-build.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/fileHashes/fileHashes.bin b/pcinvj/pcinv/.gradle/8.14/fileHashes/fileHashes.bin deleted file mode 100644 index edab974..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/fileHashes/fileHashes.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/fileHashes/fileHashes.lock b/pcinvj/pcinv/.gradle/8.14/fileHashes/fileHashes.lock deleted file mode 100644 index e213f32..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/fileHashes/fileHashes.lock and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/fileHashes/resourceHashesCache.bin b/pcinvj/pcinv/.gradle/8.14/fileHashes/resourceHashesCache.bin deleted file mode 100644 index cd45c02..0000000 Binary files a/pcinvj/pcinv/.gradle/8.14/fileHashes/resourceHashesCache.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/8.14/gc.properties b/pcinvj/pcinv/.gradle/8.14/gc.properties deleted file mode 100644 index e69de29..0000000 diff --git a/pcinvj/pcinv/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/pcinvj/pcinv/.gradle/buildOutputCleanup/buildOutputCleanup.lock deleted file mode 100644 index 3f0eceb..0000000 Binary files a/pcinvj/pcinv/.gradle/buildOutputCleanup/buildOutputCleanup.lock and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/buildOutputCleanup/cache.properties b/pcinvj/pcinv/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index 04213be..0000000 --- a/pcinvj/pcinv/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Wed Jun 04 05:47:48 CEST 2025 -gradle.version=8.14 diff --git a/pcinvj/pcinv/.gradle/buildOutputCleanup/outputFiles.bin b/pcinvj/pcinv/.gradle/buildOutputCleanup/outputFiles.bin deleted file mode 100644 index 6a60a6c..0000000 Binary files a/pcinvj/pcinv/.gradle/buildOutputCleanup/outputFiles.bin and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/file-system.probe b/pcinvj/pcinv/.gradle/file-system.probe deleted file mode 100644 index 1e664a8..0000000 Binary files a/pcinvj/pcinv/.gradle/file-system.probe and /dev/null differ diff --git a/pcinvj/pcinv/.gradle/vcs-1/gc.properties b/pcinvj/pcinv/.gradle/vcs-1/gc.properties deleted file mode 100644 index e69de29..0000000 diff --git a/pcinvj/pcinv/HELP.md b/pcinvj/pcinv/HELP.md deleted file mode 100644 index 1fdb4b5..0000000 --- a/pcinvj/pcinv/HELP.md +++ /dev/null @@ -1,30 +0,0 @@ -# Getting Started - -### Reference Documentation - -For further reference, please consider the following sections: - -* [Official Gradle documentation](https://docs.gradle.org) -* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.5.0/gradle-plugin) -* [Create an OCI image](https://docs.spring.io/spring-boot/3.5.0/gradle-plugin/packaging-oci-image.html) -* [Spring Configuration Processor](https://docs.spring.io/spring-boot/3.5.0/specification/configuration-metadata/annotation-processor.html) -* [Spring Data JPA](https://docs.spring.io/spring-boot/3.5.0/reference/data/sql.html#data.sql.jpa-and-spring-data) -* [Spring Boot DevTools](https://docs.spring.io/spring-boot/3.5.0/reference/using/devtools.html) -* [Thymeleaf](https://docs.spring.io/spring-boot/3.5.0/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) -* [Spring Web](https://docs.spring.io/spring-boot/3.5.0/reference/web/servlet.html) - -### Guides - -The following guides illustrate how to use some features concretely: - -* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) -* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) -* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) -* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) -* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) - -### Additional Links - -These additional references should also help you: - -* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) diff --git a/pcinvj/pcinv/build/classes/java/main/be/seeseepuff/pcinv/PcinvApplication.class b/pcinvj/pcinv/build/classes/java/main/be/seeseepuff/pcinv/PcinvApplication.class deleted file mode 100644 index 8581ee0..0000000 Binary files a/pcinvj/pcinv/build/classes/java/main/be/seeseepuff/pcinv/PcinvApplication.class and /dev/null differ diff --git a/pcinvj/pcinv/build/classes/java/main/be/seeseepuff/pcinv/controllers/WebController.class b/pcinvj/pcinv/build/classes/java/main/be/seeseepuff/pcinv/controllers/WebController.class deleted file mode 100644 index f869930..0000000 Binary files a/pcinvj/pcinv/build/classes/java/main/be/seeseepuff/pcinv/controllers/WebController.class and /dev/null differ diff --git a/pcinvj/pcinv/build/tmp/compileJava/previous-compilation-data.bin b/pcinvj/pcinv/build/tmp/compileJava/previous-compilation-data.bin deleted file mode 100644 index b1e8211..0000000 Binary files a/pcinvj/pcinv/build/tmp/compileJava/previous-compilation-data.bin and /dev/null differ diff --git a/pcinvj/pcinv/pcinv.iml b/pcinvj/pcinv/pcinv.iml deleted file mode 100644 index 482334b..0000000 --- a/pcinvj/pcinv/pcinv.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/pcinvj/pcinv/src/main/resources/application.properties b/pcinvj/pcinv/src/main/resources/application.properties deleted file mode 100644 index c127059..0000000 --- a/pcinvj/pcinv/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=pcinv diff --git a/pcinvj/pcinv/src/main/resources/templates/index.html b/pcinvj/pcinv/src/main/resources/templates/index.html deleted file mode 100644 index a4ee839..0000000 --- a/pcinvj/pcinv/src/main/resources/templates/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - PC Inventory - - -

Hello, world!

- - diff --git a/pcinvj/pcinv/settings.gradle.kts b/settings.gradle.kts similarity index 100% rename from pcinvj/pcinv/settings.gradle.kts rename to settings.gradle.kts diff --git a/pcinvj/pcinv/src/main/java/be/seeseepuff/pcinv/PcinvApplication.java b/src/main/java/be/seeseepuff/pcinv/PcinvApplication.java similarity index 100% rename from pcinvj/pcinv/src/main/java/be/seeseepuff/pcinv/PcinvApplication.java rename to src/main/java/be/seeseepuff/pcinv/PcinvApplication.java diff --git a/pcinvj/pcinv/src/main/java/be/seeseepuff/pcinv/controllers/WebController.java b/src/main/java/be/seeseepuff/pcinv/controllers/WebController.java similarity index 100% rename from pcinvj/pcinv/src/main/java/be/seeseepuff/pcinv/controllers/WebController.java rename to src/main/java/be/seeseepuff/pcinv/controllers/WebController.java diff --git a/pcinvj/pcinv/build/resources/main/application.properties b/src/main/resources/application.properties similarity index 100% rename from pcinvj/pcinv/build/resources/main/application.properties rename to src/main/resources/application.properties diff --git a/pcinvj/pcinv/build/resources/main/templates/index.html b/src/main/resources/templates/index.html similarity index 100% rename from pcinvj/pcinv/build/resources/main/templates/index.html rename to src/main/resources/templates/index.html diff --git a/pcinvj/pcinv/src/test/java/be/seeseepuff/pcinv/PcinvApplicationTests.java b/src/test/java/be/seeseepuff/pcinv/PcinvApplicationTests.java similarity index 100% rename from pcinvj/pcinv/src/test/java/be/seeseepuff/pcinv/PcinvApplicationTests.java rename to src/test/java/be/seeseepuff/pcinv/PcinvApplicationTests.java diff --git a/static/scripts.js b/static/scripts.js deleted file mode 100644 index 82f2c03..0000000 --- a/static/scripts.js +++ /dev/null @@ -1,23 +0,0 @@ -function newOption(elementId, name) { - var el = document.getElementById(elementId) - if (el.value !== "New...") { - return - } - - var newValue = window.prompt("Enter " + name + " Name") - if (newValue === null) { - return; - } - var child = document.createElement("option") - child.value = newValue - child.innerText = newValue - el.prepend(child) - el.value = newValue -} - -window.onload = function() { - var elements = document.getElementsByClassName("to-delete") - while (elements.length > 0) { - elements[0].remove() - } -} diff --git a/template_debug.go b/template_debug.go deleted file mode 100644 index f73461b..0000000 --- a/template_debug.go +++ /dev/null @@ -1,8 +0,0 @@ -// / +build !release -package main - -import ( - "net/http" -) - -const staticFiles = http.Dir("./static") diff --git a/template_funcs.go b/template_funcs.go deleted file mode 100644 index ac65f39..0000000 --- a/template_funcs.go +++ /dev/null @@ -1,119 +0,0 @@ -package main - -import ( - "fmt" -) - -func createDeviceLink(deviceType, name string, qr *int) CreateDeviceLink { - return CreateDeviceLink{ - Type: deviceType, - Name: name, - Qr: qr, - } -} - -type CreateDeviceLink struct { - Type string - Name string - Qr *int -} - -func formatMemoryUnit(size int) string { - const ( - KB = 1024 - MB = KB * 1024 - GB = MB * 1024 - ) - - switch { - case size >= GB: - return "GB" - case size >= MB: - return "MB" - case size >= KB: - return "KB" - default: - return "B" - } -} - -func formatMemorySize(size int) string { - const ( - KB = 1024 - MB = KB * 1024 - GB = MB * 1024 - ) - - switch formatMemoryUnit(size) { - case "GB": - return fmt.Sprintf("%.2f GB", float64(size)/GB) - case "MB": - return fmt.Sprintf("%.2f MB", float64(size)/MB) - case "KB": - return fmt.Sprintf("%.2f KB", float64(size)/KB) - case "B": - return fmt.Sprintf("%d B", size) - default: - panic("invalid memory size") - } -} - -func formatMemoryPlainSize(size int) int { - const ( - KB = 1024 - MB = KB * 1024 - GB = MB * 1024 - ) - - switch formatMemoryUnit(size) { - case "GB": - return size / GB - case "MB": - return size / MB - case "KB": - return size / KB - case "B": - return size - default: - panic("invalid memory size") - } -} - -func isRamType(size int, unit string) bool { - if size == 0 && unit == "MB" { - return true - } - actualUnit := formatMemoryUnit(size) - return unit == actualUnit -} - -func formatType(t string) string { - for _, assetType := range DescriptorTree.AssetTypes { - if assetType.Id == t { - return assetType.Name - } - } - panic("unknown type") -} - -type SelectMenu struct { - Name string - Label string - Selected string - Options []string - DefaultValue string -} - -func createSelectMenu(name, label, selected string, options []string) SelectMenu { - return createSelectMenuDefault(name, label, selected, options, "Unknown") -} - -func createSelectMenuDefault(name, label, selected string, options []string, defaultValue string) SelectMenu { - return SelectMenu{ - Name: name, - Label: label, - Selected: selected, - Options: options, - DefaultValue: defaultValue, - } -} diff --git a/templates/browse.gohtml b/templates/browse.gohtml deleted file mode 100644 index c24bd45..0000000 --- a/templates/browse.gohtml +++ /dev/null @@ -1,31 +0,0 @@ -{{- /*gotype: main.BrowseVM */}} -{{define "browse"}} -{{template "header" "Search Results"}} - - - - - - - - {{if .HasRam}} - - - {{end}} - - {{range .Assets}} - - - - - - - {{if $.HasRam}} - - - {{end}} - - {{end}} -
QRTypeNameBrandDescriptionRAM TypeRAM Capacity
{{.Qr}}{{.Type | formatType}}{{.Name}}{{.Brand}}{{.Description}}{{.RamType}}{{.RamCapacity | formatMemorySize}}
-{{template "footer"}} -{{end}} diff --git a/templates/create_device.gohtml b/templates/create_device.gohtml deleted file mode 100644 index 3825755..0000000 --- a/templates/create_device.gohtml +++ /dev/null @@ -1,8 +0,0 @@ -{{- /*gotype: main.CreateDeviceVM */}} -{{define "create_device"}} - {{if .Type}} - {{template "create_device_step2" .}} - {{else}} - {{template "create_device_step1" .}} - {{end}} -{{end}} diff --git a/templates/create_device_step1.gohtml b/templates/create_device_step1.gohtml deleted file mode 100644 index c4a20ba..0000000 --- a/templates/create_device_step1.gohtml +++ /dev/null @@ -1,20 +0,0 @@ -{{- /*gotype: pcinv.CreateDeviceVM*/ -}} -{{define "create_device_step1"}} -{{template "header" "Create Device - Choose Device Type"}} - -{{template "footer"}} -{{end}} diff --git a/templates/create_device_step2.gohtml b/templates/create_device_step2.gohtml deleted file mode 100644 index 518a2f5..0000000 --- a/templates/create_device_step2.gohtml +++ /dev/null @@ -1,188 +0,0 @@ -{{- /*gotype: pcinv.CreateDeviceVM*/}} -{{define "create_device_step2"}} -{{template "header" "Create Device - Enter Device Data"}} -
- - {{range .DescriptorTree.AssetTypes}} - {{if $.IsPartOf .Id}} -

{{.Name}}

- {{$asset := .}} - - {{range .Fields}} - - - - - {{end}} -
- {{if eq .Type "type"}} - {{$.NiceType}} - - {{else if eq .Type "number"}} - - {{else if eq .Type "string"}} - - {{else if eq .Type "selection"}} - - - {{else if eq .Type "capacity"}} - - - {{end}} -
- {{end}} - {{end}} - -{{/* */}} -{{/* */}} -{{/* */}} -{{/* {{if .Qr}}*/}} -{{/* */}} -{{/* {{else}}*/}} -{{/* */}} -{{/* {{end}}*/}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/*
*/}} -{{/* */}} -{{/*
*/}} - -{{/* {{if eq .Type "ram"}}*/}} -{{/*

Memory Information

*/}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/*
*/}} -{{/* */}} -{{/*
*/}} -{{/* */}} -{{/* */}} -{{/*
*/}} -{{/* {{end}}*/}} - -{{/* {{if eq .Type "hdd"}}*/}} -{{/*

Hard Drive Information

*/}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/* */}} -{{/*
*/}} -{{/* */}} -{{/* */}} -{{/*
{{template "create_device_select" createSelectMenu "hdd_type" "HDD Type" .HddType .HddTypes}}
{{template "create_device_select" createSelectMenu "hdd_form_factor" "HDD Form Factor" .HddFormFactor .HddFormFactors}}
{{template "create_device_select" createSelectMenu "hdd_connection" "HDD Connection" .HddConnection .HddConnections}}
{{template "create_device_select" createSelectMenuDefault "hdd_rpm" "HDD RPM" .HddRpm .HddRpms "Not Applicable"}}
*/}} -{{/* {{end}}*/}} - - {{if .IsEdit}} - - {{else}} - - {{end}} -
-{{template "footer"}} -{{end}} - -{{/*{{define "create_device_select"}}*/}} -{{/* */}} -{{/*{{end}}*/}} diff --git a/templates/delete.gohtml b/templates/delete.gohtml deleted file mode 100644 index 2f955c5..0000000 --- a/templates/delete.gohtml +++ /dev/null @@ -1,9 +0,0 @@ -{{- /*gotype: pcinv.DeleteVM*/ -}} -{{define "delete"}} -{{template "header" "Delete Device"}} -

Are you sure you want to delete this device?

-
- - -{{template "footer"}} -{{end}} diff --git a/templates/device.gohtml b/templates/device.gohtml deleted file mode 100644 index f47de45..0000000 --- a/templates/device.gohtml +++ /dev/null @@ -1,57 +0,0 @@ -{{- /*gotype: main.DeviceVM */}} -{{define "device"}} -{{template "header" "Device Details"}} - - - - - - - - - - - - - - - - - - {{if eq .Type "ram"}} - - - - - - - - - {{end}} - {{if eq .Type "hdd"}} - - - - - - - - - - - - - - - - - - - - - {{end}} -
Name:{{.Name}}
Brand:{{.Brand}}
Type:{{.Type}}
Description:{{.Description}}
RAM Type:{{.RamType}}
RAM Capacity:{{.RamCapacity | formatMemorySize}}
HDD Capacity:{{.HddCapacity}}
HDD Type:{{.HddType}}
Form Factor:{{.HddFormFactor}}
Connection:{{.HddConnection}}
RPM:{{.HddRpm}}
- - -{{template "footer"}} -{{end}} diff --git a/templates/errors.gohtml b/templates/errors.gohtml deleted file mode 100644 index 45e7b65..0000000 --- a/templates/errors.gohtml +++ /dev/null @@ -1,12 +0,0 @@ -{{- /*gotype: main.ErrorVM*/}} -{{define "errors"}} -{{template "header" .StatusCode | statusText}} - - - -{{template "footer"}} -{{end}} diff --git a/templates/footer.gohtml b/templates/footer.gohtml deleted file mode 100644 index 634a10f..0000000 --- a/templates/footer.gohtml +++ /dev/null @@ -1,4 +0,0 @@ -{{define "footer"}} - - -{{end}} diff --git a/templates/header.gohtml b/templates/header.gohtml deleted file mode 100644 index be6b2af..0000000 --- a/templates/header.gohtml +++ /dev/null @@ -1,16 +0,0 @@ -{{define "header"}} - - - PC Inventory{{if .}} - {{.}}{{end}} - - - -

PC Inventory{{if .}} - {{.}}{{end}}

-
- - - - Create Device -
-
-{{end}} diff --git a/templates/index.gohtml b/templates/index.gohtml deleted file mode 100644 index c6782a3..0000000 --- a/templates/index.gohtml +++ /dev/null @@ -1,34 +0,0 @@ -{{- /*gotype: main.IndexVM*/}} -{{define "index"}} -{{template "header"}} -

Statistics

- The inventory contains: - - -

Filter Devices

-
-

Select Brands:

- {{range .Brands}} -
- {{end}} - -

Select Types:

- {{range .Types}} -
- {{end}} - - -
- -{{template "footer"}} -{{end}} diff --git a/view_createdevice.go b/view_createdevice.go deleted file mode 100644 index 14f7dfc..0000000 --- a/view_createdevice.go +++ /dev/null @@ -1,135 +0,0 @@ -package main - -import ( - "fmt" - "github.com/gin-gonic/gin" - "net/http" - "strconv" - "strings" -) - -type CreateDeviceVM struct { - IsEdit bool - DescriptorTree *DescriptorRoot - - // Assets - Qr *int - Type string - - Values map[string]string -} - -func (vm *CreateDeviceVM) SetValue(assetType string, field string, value string) { - if vm.Values == nil { - vm.Values = make(map[string]string) - } - vm.Values[assetType+"-"+field] = value -} - -func (vm *CreateDeviceVM) GetValue(assetType string, field string) string { - if vm.Values == nil { - return "" - } - return vm.Values[assetType+"-"+field] -} - -func (vm *CreateDeviceVM) NiceType() string { - return getAssetTypeById(vm.Type).Name -} - -func (vm *CreateDeviceVM) IsPartOf(assertType string) bool { - if assertType == "asset" { - return true - } - return assertType == vm.Type -} - -func (a *App) getCreateDevice(c *gin.Context) { - var err error - vm := &CreateDeviceVM{} - vm.DescriptorTree = DescriptorTree - vm.Type = c.Query("type") - - qr := c.Query("id") - if qr != "" { - qrInt, err := strconv.Atoi(qr) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("invalid qr: %v", err)) - return - } - vm.Qr = &qrInt - } - - err = a.GetAllGroups(vm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - if c.Query("edit") != "" && vm.Qr != nil { - vm.IsEdit = true - err := a.pullDataFromDb(*vm.Qr, "asset", vm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to load asset data: %v", err)) - return - } - //// Load the asset data from the database - //err = a.db.Query("SELECT * FROM assets WHERE qr = ?"). - // Bind(*vm.Qr). - // ScanColumns(&columns). - // ScanSingle(&vm.Qr, &vm.Type, &vm.Values) - //if err != nil { - // c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to load asset: %v", err)) - // return - // - //} - - //err = a.db.Query("SELECT name, type, brand, description FROM assets WHERE qr = ?"). - // Bind(*vm.Qr). - // ScanSingle(&vm.AssetName, &vm.Type, &vm.AssetBrand, &vm.AssetDescription) - //if err != nil { - // c.AbortWithError(http.StatusInternalServerError, err) - // return - //} - //if vm.Type == "ram" { - // err = a.db.Query("SELECT type, capacity FROM info_ram WHERE asset = ?"). - // Bind(*vm.Qr). - // ScanSingle(&vm.RamType, &vm.RamCapacity) - // if err != nil { - // c.AbortWithError(http.StatusInternalServerError, err) - // return - // } - //} else if vm.Type == "hdd" { - // err = a.db.Query("SELECT capacity, type, form_factor, connection, rpm FROM info_hdd WHERE asset = ?"). - // Bind(*vm.Qr). - // ScanSingle(&vm.HddCapacity, &vm.HddType, &vm.HddFormFactor, &vm.HddConnection, &vm.HddRpm) - // if err != nil { - // c.AbortWithError(http.StatusInternalServerError, err) - // return - // } - //} - } - - c.HTML(http.StatusOK, "create_device", vm) -} - -func (a *App) pullDataFromDb(qr int, assetType string, vm *CreateDeviceVM) error { - var fields []string - assetDescriptor := getAssetTypeById(assetType) - for _, field := range assetDescriptor.Fields { - fields = append(fields, field.Id) - } - values := make([]any, len(fields)) - - query := fmt.Sprintf("SELECT %s FROM %s WHERE qr = ?", strings.Join(fields, ", "), assetDescriptor.Table) - err := a.db.Query(query).Bind(qr).ScanSingle(values...) - if err != nil { - return fmt.Errorf("failed to load asset data: %v", err) - } - - for i, field := range fields { - vm.SetValue(assetType, field, fmt.Sprintf("%v", values[i])) - } - - return err -} diff --git a/view_device.go b/view_device.go deleted file mode 100644 index 9ac3d6c..0000000 --- a/view_device.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "github.com/gin-gonic/gin" - "net/http" - "strconv" -) - -type DeviceVM struct { - Qr int - Name string - Brand string - Type string - Description string - RamType string - RamCapacity int - HddCapacity int - HddType string - HddFormFactor string - HddConnection string - HddRpm int -} - -func (a *App) getDevice(c *gin.Context) { - qr, err := strconv.Atoi(c.Query("id")) - if err != nil { - c.AbortWithError(http.StatusBadRequest, err) - return - } - - var count int - err = a.db.Query("SELECT COUNT(*) FROM assets WHERE qr = ?"). - Bind(qr). - ScanSingle(&count) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - if count == 0 { - c.Redirect(http.StatusTemporaryRedirect, "/create?id="+strconv.Itoa(qr)) - return - } - - vm := &DeviceVM{Qr: qr} - err = a.db.Query("SELECT name, brand, type, description FROM assets WHERE qr = ?"). - Bind(qr). - ScanSingle(&vm.Name, &vm.Brand, &vm.Type, &vm.Description) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - if vm.Type == "ram" { - err = a.db.Query("SELECT type, capacity FROM info_ram WHERE asset = ?"). - Bind(qr). - ScanSingle(&vm.RamType, &vm.RamCapacity) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } else if vm.Type == "hdd" { - err = a.db.Query("SELECT capacity, type, form_factor, connection, rpm FROM info_hdd WHERE asset = ?"). - Bind(qr). - ScanSingle(&vm.HddCapacity, &vm.HddType, &vm.HddFormFactor, &vm.HddConnection, &vm.HddRpm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } - - c.HTML(http.StatusOK, "device", vm) -} diff --git a/view_index.go b/view_index.go deleted file mode 100644 index da0fd32..0000000 --- a/view_index.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "github.com/gin-gonic/gin" - "net/http" -) - -type IndexVM struct { - AssetCount int - BrandCount int - TotalRamCapacity int - Brands []string - Types []string -} - -func (a *App) getIndex(c *gin.Context) { - vm := &IndexVM{} - var err error - vm.AssetCount, err = a.GetAssetCount() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - vm.BrandCount, err = a.GetBrandCount() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - vm.TotalRamCapacity, err = a.GetTotalRamCapacity() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - vm.Brands, err = a.GetAllBrands() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - vm.Types, err = a.GetAllTypes() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - c.HTML(http.StatusOK, "index", vm) -} diff --git a/views.go b/views.go deleted file mode 100644 index 978dde3..0000000 --- a/views.go +++ /dev/null @@ -1,276 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "gitea.seeseepuff.be/seeseemelk/mysqlite" - "github.com/gin-gonic/gin" - "net/http" - "strconv" - "strings" -) - -type App struct { - db *mysqlite.Db -} - -func (a *App) postCreateDevice(c *gin.Context) { - qr, err := strconv.Atoi(c.PostForm("asset-qr")) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("invalid qr: %v", err)) - } - - tx, err := a.db.Begin() - defer tx.MustRollback() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error beginning tx: %v", err)) - return - } - - err = a.DeleteAsset(tx, qr) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error removing assets: %v", err)) - return - } - - // Insert the asset into the database - var id int - err = a.createAsset("asset", tx, c, &id) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error inserting asset: %v", err)) - return - } - assetType := c.PostForm("asset-type") - err = a.createAsset(assetType, tx, c, &id) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error inserting asset type: %v", err)) - return - } - - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - err = tx.Commit() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - c.Redirect(http.StatusSeeOther, "/") -} - -func (a *App) createAsset(assetType string, tx *mysqlite.Tx, c *gin.Context, assetId *int) error { - for _, assetDescriptor := range DescriptorTree.AssetTypes { - if assetDescriptor.Id != assetType { - continue - } - - var fields []string - var questions []string - var values []string - - for _, field := range assetDescriptor.Fields { - fields = append(fields, field.Id) - questions = append(questions, "?") - values = append(values, c.PostForm(assetType+"-"+field.Id)) - } - - if *assetId != 0 { - fields = append(fields, "asset") - questions = append(questions, "?") - values = append(values, strconv.Itoa(*assetId)) - } - - fieldsStr := strings.Join(fields, ", ") - questionsStr := strings.Join(questions, ", ") - err := tx.Query(fmt.Sprintf("INSERT INTO %s (%s) values (%s)", assetDescriptor.Table, fieldsStr, questionsStr)). - Bind(values). - Exec() - if err != nil { - return err - } - - if *assetId == 0 { - err := tx.Query("SELECT LAST_INSERT_ROWID()").ScanSingle(assetId) - if err != nil { - return fmt.Errorf("error getting last insert id: %v", err) - } - } - - return nil - } - return errors.New("Create Asset not implemented for type: " + assetType) -} - -func (a *App) postCreateDeviceRam(c *gin.Context, qr int, tx *mysqlite.Tx) error { - var err error - capacity := 0 - capacityString := c.PostForm("ram_capacity") - if capacityString != "" { - capacity, err = strconv.Atoi(c.PostForm("ram_capacity")) - if err != nil { - return err - } - } - switch c.PostForm("ram_capacity_unit") { - case "B": - case "KB": - capacity *= 1024 - case "MB": - capacity *= 1024 * 1024 - case "GB": - capacity *= 1024 * 1024 * 1024 - default: - return errors.New("invalid ram_capacity_unit") - } - - err = tx.Query("INSERT INTO info_ram (asset, type, capacity) VALUES (?, ?, ?)"). - Bind(qr, c.PostForm("ram_type"), capacity).Exec() - return err -} - -func (a *App) postCreateDeviceHdd(c *gin.Context, qr int, tx *mysqlite.Tx) error { - var err error - capacity := 0 - capacityString := c.PostForm("hdd_capacity") - if capacityString != "" { - capacity, err = strconv.Atoi(c.PostForm("hdd_capacity")) - if err != nil { - return err - } - } - switch c.PostForm("hdd_capacity_unit") { - case "B": - case "KB": - capacity *= 1024 - case "MB": - capacity *= 1024 * 1024 - case "GB": - capacity *= 1024 * 1024 * 1024 - default: - return errors.New("invalid hdd_capacity_unit") - } - - err = tx.Query("INSERT INTO info_hdd (asset, capacity, type, form_factor, connection, rpm) VALUES (?, ?, ?, ?, ?, ?)"). - Bind(qr, capacity, c.PostForm("hdd_type"), c.PostForm("hdd_form_factor"), c.PostForm("hdd_connection"), c.PostForm("hdd_rpm")). - Exec() - return err -} - -type BrowseVM struct { - Assets []Asset - HasRam bool -} - -type Asset struct { - Qr int - Name string - Brand string - Type string - Description string - RamType string - RamCapacity int - HddCapacity int - HddType string - HddFormFactor string - HddConnection string - HddRpm int -} - -func (a *App) getBrowse(c *gin.Context) { - brands := c.QueryArray("brand") - types := c.QueryArray("type") - - query := `SELECT assets.qr, assets.name, assets.brand, assets.type, assets.description, - info_ram.type, info_ram.capacity, - info_hdd.capacity, info_hdd.type, info_hdd.form_factor, info_hdd.connection, info_hdd.rpm - FROM assets - LEFT JOIN info_ram ON info_ram.asset = assets.qr - LEFT JOIN info_hdd ON info_hdd.asset = assets.qr - WHERE 1=1` - if len(brands) > 0 { - query += " AND assets.brand IN (" + placeholders(len(brands)) + ")" - } - if len(types) > 0 { - query += " AND assets.type IN (" + placeholders(len(types)) + ")" - } - query += "ORDER BY assets.type, assets.brand, assets.name, assets.qr" - - vm := &BrowseVM{} - - var err error - q := a.db.Query(query).Bind(brands, types) - for row := range q.Range(&err) { - var asset Asset - err := row.Scan(&asset.Qr, &asset.Name, &asset.Brand, &asset.Type, &asset.Description, - &asset.RamType, &asset.RamCapacity, - &asset.HddCapacity, &asset.HddType, &asset.HddFormFactor, &asset.HddConnection, &asset.HddRpm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - vm.Assets = append(vm.Assets, asset) - if asset.Type == "ram" { - vm.HasRam = true - } - } - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - c.HTML(http.StatusOK, "browse", vm) -} - -type DeleteVM struct { - Qr int -} - -func (a *App) getDelete(c *gin.Context) { - qr, err := strconv.Atoi(c.Query("id")) - if err != nil { - c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid qr: %v", err)) - return - } - vm := &DeleteVM{Qr: qr} - c.HTML(http.StatusOK, "delete", vm) -} - -func (a *App) postDelete(c *gin.Context) { - qr, err := strconv.Atoi(c.Query("id")) - if err != nil { - c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid qr: %v", err)) - return - } - tx, err := a.db.Begin() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - err = a.DeleteAsset(tx, qr) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - err = tx.Commit() - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - c.Redirect(http.StatusSeeOther, "/") -} - -func placeholders(count int) string { - if count == 0 { - return "" - } - placeholder := "?" - for count > 1 { - placeholder += ", ?" - count-- - } - return placeholder -}