From c3591d04490d10b7a05e1aefff903430fecc2ba8 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 20 Sep 2012 14:47:20 +0200 Subject: clean uploading --- formats.go | 7 ++++-- serve.go | 12 ++++++---- templates/base.html | 14 ++++++++---- templates/bom_upload.html | 52 +++++++++++++++++++++++++++++++++++--------- templates/home.html | 17 +++++++++++++++ templates/static/default.css | 2 +- templates/user.html | 13 +++++++++++ 7 files changed, 96 insertions(+), 21 deletions(-) diff --git a/formats.go b/formats.go index 57caa0f..3afe788 100644 --- a/formats.go +++ b/formats.go @@ -100,7 +100,8 @@ func LoadBomFromCSV(input io.Reader) (*Bom, error) { header, err := reader.Read() if err != nil { - log.Fatal(err) + log.Printf("error parsing .csv: %s", err) + return nil, err } var li *LineItem var el_count int @@ -150,7 +151,9 @@ func LoadBomFromCSV(input io.Reader) (*Bom, error) { el_count = len(li.Elements) // XXX: kludge if n > 99999 || el_count > 99999 { - log.Fatal("too large a quantity of elements passed, crashing") + err = Error("too large a quantity of elements passed") + log.Printf("error parsing .csv: %s", err) + return nil, err } else if el_count > n { if *verbose { log.Println("more symbols than qty, taking all symbols") diff --git a/serve.go b/serve.go index d1d035d..d47a60e 100644 --- a/serve.go +++ b/serve.go @@ -51,8 +51,8 @@ func baseHandler(w http.ResponseWriter, r *http.Request) { } if err != nil { // this could cause multiple responses? - http.Error(w, "Internal error (check logs)", 500) log.Println("error, 500: " + err.Error()) + http.Error(w, "Internal error (check logs)", 500) } } @@ -124,6 +124,9 @@ func userController(w http.ResponseWriter, r *http.Request, user, extra string) } context := make(map[string]interface{}) context["BomList"], err = bomstore.ListBoms(ShortName(user)) + if user == "common" { + context["IsCommon"] = true + } context["UserName"] = user context["Session"] = session.Values if err != nil { @@ -173,8 +176,6 @@ func bomUploadController(w http.ResponseWriter, r *http.Request, user, name stri switch r.Method { case "POST": - - err := r.ParseMultipartForm(1024*1024*2) if err != nil { log.Println(err) @@ -218,7 +219,7 @@ func bomUploadController(w http.ResponseWriter, r *http.Request, user, name stri b, err = LoadBomFromCSV(file) bm = &BomMeta{} if err != nil { - context["error"] = "Problem loading XML file" + context["error"] = "Problem loading CSV file: " + err.Error() err = tmplBomUpload.Execute(w, context) return err } @@ -231,6 +232,7 @@ func bomUploadController(w http.ResponseWriter, r *http.Request, user, name stri } default: context["error"] = "Unknown file type: " + string(fileheader.Filename) + log.Fatal(context["error"]) err = tmplBomUpload.Execute(w, context) return err } @@ -244,8 +246,10 @@ func bomUploadController(w http.ResponseWriter, r *http.Request, user, name stri err = tmplBomUpload.Execute(w, context) } http.Redirect(w, r, "//" + user + "/" + name + "/", 302) + return err case "GET": err = tmplBomUpload.Execute(w, context) + return err default: http.Error(w, "bad method", 405) return nil diff --git a/templates/base.html b/templates/base.html index 4fe66ad..ee8a54c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,6 +2,7 @@ bommom + + @@ -24,14 +26,18 @@ function login() { bommom.com {{ range .BreadCrumbs }} / {{.}} {{end}} diff --git a/templates/bom_upload.html b/templates/bom_upload.html index 8cc15c8..04126c3 100644 --- a/templates/bom_upload.html +++ b/templates/bom_upload.html @@ -4,21 +4,53 @@

{{ .BomMeta.Name }} is a bom.

{{ template "BOM_INFO" . }}
- {{ else }}

{{ .name }} could be a bom.

-Owner: {{ .user }}
-
- {{ end }} -{{ if .error }}

{{ .error }}

{{ end }} -
-Version:
-Created: now!
-
- + + {{ if .error }} +
+ Error! {{ .error }} +
+ {{ end }} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + .json, .xml, or .csv +
+
+
+
+ +
+
{{ template "FOOTER" . }} diff --git a/templates/home.html b/templates/home.html index 40e8f6c..41db698 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,5 +1,22 @@ {{ template "HEADER" . }}

this is bomom.

+
+

+bommom is a tool for publishing and analysing electronics "bill of materials", +which are lists of components required to assemble a device like a digital +watch or a space telescope control module. +

+

+this is an open source project; get the code at git.bnewbold.net/bommom or github.com/bnewbold/bommom. the +project includes a command line tool for managing and converting repositories +of BOMs. it is written in golang (the "go" +programming language). +

+
+ +

all BOMs from all users

{{ range .BomList }} diff --git a/templates/static/default.css b/templates/static/default.css index 7ea7b81..045486a 100644 --- a/templates/static/default.css +++ b/templates/static/default.css @@ -1147,7 +1147,7 @@ input[type="tel"], input[type="color"], .uneditable-input { display: inline-block; - height: 20px; + /* height: 20px; */ padding: 4px 6px; margin-bottom: 9px; font-size: 14px; diff --git a/templates/user.html b/templates/user.html index 995819c..7367bc1 100644 --- a/templates/user.html +++ b/templates/user.html @@ -1,5 +1,18 @@ {{ template "HEADER" . }} +{{ if .IsCommon }} +

publicly mirrored BOMs

+
+here BOMs from the "commons" of publicly available open hardware designs are +collected. any logged in bommom user can submit +or edit BOMs here. +
+ +

all BOMs in the commons

+{{ else }}

{{ .UserName }} is a bommom user.

+

all of {{ .UserName }}'s BOMs

+{{ end }} +
{{ range .BomList }} -- cgit v1.2.3