aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--formats.go7
-rw-r--r--serve.go12
-rw-r--r--templates/base.html14
-rw-r--r--templates/bom_upload.html52
-rw-r--r--templates/home.html17
-rw-r--r--templates/static/default.css2
-rw-r--r--templates/user.html13
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 @@
<head>
<title>bommom</title>
<link rel="stylesheet" type="text/css" href="/static/default.css"></link>
+<!-- Start Mozilla Persona Code -->
<script src="/static/include.js"></script>
<script>
function login() {
@@ -15,6 +16,7 @@ function login() {
});
}
</script>
+<!-- End Mozilla Persona Code -->
</head>
<body>
@@ -24,14 +26,18 @@ function login() {
<a class="brand" href="/">bommom.com</a>
{{ range .BreadCrumbs }} / {{.}} {{end}}
<div class="nav-collapse collapse">
- <p class="navbar-text pull-right">
{{ if .Session.UserName }}
- {{ .Session.UserName }}
- <a href="/account/logout/"><button class="btn btn-mini" type="button" style="margin-left: 5px;">Log out!</button></a>
+ <p class="navbar-text pull-right">
+ <a href="/account/logout/"><button class="btn btn-mini" type="button" style="margin-left: 15px; margin-top:9px;">Log out!</button></a>
+ </p>
+ <p class="navbar-text pull-right">
+ logged in as {{ .Session.UserName }}
+ </p>
{{ else }}
+ <p class="navbar-text pull-right">
<a href="/account/login/"><button class="btn btn-mini" type="button" style="margin-top: 9px;">Log in!</button></a>
- {{ end }}
</p>
+ {{ end }}
</div><!--/.nav-collapse -->
</div>
</div>
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 @@
<h1>{{ .BomMeta.Name }} is a bom.</h1>
{{ template "BOM_INFO" . }}
<hr>
-
{{ else }}
<h1>{{ .name }} could be a bom.</h1>
-<b>Owner: </b>{{ .user }}<br>
-<hr>
-
{{ end }}
-{{ if .error }}<h3 style="color:red;">{{ .error }}</h3>{{ end }}
-<form enctype="multipart/form-data" method="POST" target=".">
-<b>Version: </b><input name="version" type="text" value="{{ .version }}"></input><br>
-<b>Created: </b>now!<br>
-<input type="file" name="bomfile" accept="application/json,application/xml,text/csv"></input><br>
-<input type="submit" value="Upload"></input>
+<form class="form-horizontal" enctype="multipart/form-data" method="POST" target=".">
+ {{ if .error }}
+ <div class="alert alert-error">
+ <strong>Error!</strong> {{ .error }}
+ </div>
+ {{ end }}
+ <div class="control-group">
+ <label class="control-label" for="owner">Owner</label>
+ <div class="controls">
+ <input type="text" id="created" name="owner" placeholder="{{ .user }}" disabled class="input-large">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="name">Name</label>
+ <div class="controls">
+ <input type="text" id="created" name="name" placeholder="{{ .name }}" disabled class="input-large">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="version">Version</label>
+ <div class="controls">
+ <input type="text" id="version" name="version" value="{{ .version }}" placeholder="eg, Rev5" class="input-large">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="created">Creation Time</label>
+ <div class="controls">
+ <input type="text" id="created" name="created" placeholder="right now!" disabled class="input-large">
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="bomfile">File</label>
+ <div class="controls">
+ <input type="file" name="bomfile" accept="application/json,application/xml,text/csv"></input>
+ <span class="help-inline">.json, .xml, or .csv</span>
+ </div>
+ </div>
+ <div class="control-group">
+ <div class="controls">
+ <button type="submit" name="submit" value="up" class="btn btn-primary">Upload</button>
+ </div>
+ </div>
</form>
{{ 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" . }}
<h1>this is bomom.</h1>
+<div class="well">
+<p>
+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.
+</p>
+<p>
+this is an open source project; get the code at <a
+href="http://git.bnewbold.net/bommom/">git.bnewbold.net/bommom</a> or <a
+href="http://github.com/bnewbold/bommom">github.com/bnewbold/bommom</a>. the
+project includes a command line tool for managing and converting repositories
+of BOMs. it is written in <a href="http://golang.org">golang</a> (the "go"
+programming language).
+</p>
+</div>
+
+<h3>all BOMs from all users</h3>
<table class="table">
{{ range .BomList }}
<tr/>
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 }}
+<h1>publicly mirrored BOMs</h1>
+<div class="well">
+here BOMs from the "commons" of publicly available open hardware designs are
+collected. any <a href="/account/login/">logged in</a> bommom user can submit
+or edit BOMs here.
+</div>
+
+<h3>all BOMs in the commons</h3>
+{{ else }}
<h1>{{ .UserName }} is a bommom user.</h1>
+<h3>all of {{ .UserName }}'s BOMs</h3>
+{{ end }}
+
<table class="table">
{{ range .BomList }}
<tr/>