-
Notifications
You must be signed in to change notification settings - Fork 5
/
editable.go
48 lines (44 loc) · 1.04 KB
/
editable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/andrewarrow/feedback/router"
)
func editable(path, name string) {
asBytes, _ := ioutil.ReadFile(path + "/app/feedback.json")
var site router.FeedbackSite
json.Unmarshal(asBytes, &site)
m := site.FindModel(name)
fmt.Println(`<table class="inline-block whitespace-nowrap">`)
fmt.Println(`{{$row := index . "item"}}`)
for _, field := range m.Fields {
fmt.Println("<tr>")
fmt.Println(`{{$value := index $row "` + field.Name + `"}}`)
if field.Flavor == "photo" {
t := `
<td class="px-3 py-2">
%s<br/>
{{ if eq $value ""}}
<img src="https://i.imgur.com/OY8fov3.png" width="160"/>
{{ else }}
<img src="/bucket/{{$value}}" width="160"/>
{{ end }}
<br/>
<input type="file" name="file" accept="image/jpeg, image/png, image/gif"/>
</td>
`
fmt.Printf(t, field.Name)
} else {
t := `
<td class="px-3 py-2">
%s<br/>
{{ textfield "%s" $value}}
</td>
`
fmt.Printf(t, field.Name, field.Name)
}
fmt.Println("</tr>")
}
fmt.Println("</table>")
}