Skip to content

Commit 5ffa6f7

Browse files
upload-view: Display user's uploaded plugs
Display a user's uploaded plugs on the /upload page so they know what has already been uploaded/approved. This resolves an issue where users may not realize that they have already uploaded a plug. This also serves as partial work towards the completion of: liam-middlebrook#11
1 parent d909aea commit 5ffa6f7

File tree

3 files changed

+77
-21
lines changed

3 files changed

+77
-21
lines changed

db.go

+23
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,29 @@ func (c DBConnection) GetPendingPlugs() []Plug {
178178
return plugs
179179
}
180180

181+
func (c DBConnection) GetUserPlugs(user string) []Plug {
182+
rows, err := c.con.Query(SQL_RETRIEVE_PENDING_PLUGS)
183+
184+
if err != nil {
185+
log.Fatal(err)
186+
}
187+
188+
var plugs []Plug
189+
for rows.Next() {
190+
var obj Plug
191+
err = rows.Scan(&obj.ID, &obj.S3ID, &obj.Owner, &obj.ViewsRemaining, &obj.Approved)
192+
193+
if err != nil {
194+
log.Error(err)
195+
}
196+
if obj.Owner == user {
197+
plugs = append(plugs, obj)
198+
}
199+
}
200+
201+
return plugs
202+
}
203+
181204
func (c DBConnection) SetPendingPlugs(approvedList []string) {
182205
_, err := c.con.Exec("UPDATE plugs SET approved = false;")
183206
if err != nil {

routes.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,23 @@ func (r PlugRoutes) upload(c *gin.Context) {
123123
}
124124

125125
func (r PlugRoutes) upload_view(c *gin.Context) {
126-
c.HTML(http.StatusOK, "upload.tmpl", gin.H{})
126+
claims, ok := c.Value(csh_auth.AuthKey).(csh_auth.CSHClaims)
127+
if !ok {
128+
log.Fatal("error finding claims")
129+
return
130+
}
131+
132+
plugs := r.app.db.GetUserPlugs(claims.UserInfo.Username)
133+
var out_plugs []Plug
134+
135+
for _, plug := range plugs {
136+
new := plug
137+
new.PresignedURL = r.app.s3.PresignPlug(plug).String()
138+
out_plugs = append(out_plugs, new)
139+
}
140+
c.HTML(http.StatusOK, "upload.tmpl", gin.H{
141+
"plugs": out_plugs,
142+
})
127143
}
128144

129145
func (r PlugRoutes) get_pending_plugs(c *gin.Context) {

templates/upload.tmpl

+37-20
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,47 @@
2121
</div>
2222
</nav>
2323

24+
<div class="container">
25+
<h2>My Plugs:</h2>
26+
<p>Plugs displayed below without color have not been approved for viewing yet.</p>
27+
{{ range $element := .plugs }}
28+
<div class="row justify-content-center">
29+
<div class="col-lg-7">
30+
<div class="card mb-3">
31+
<!-- Make plugs which haven't been approved yet grayscale -->
32+
<img style="width: 100%; display: block;
33+
{{ if !$element.Approved }} filter: grayscale(100%); {{ end }}
34+
" src="{{$element.PresignedURL}}" alt="Plug by {{$element.Owner}}">
35+
<div class="card-footer text-muted">
36+
<p>{{$element.ViewsRemaining}} View(s) Remaining</p>
37+
</div>
38+
</div>
39+
</div>
40+
</div>
41+
{{ end }}
42+
</div>
2443
<div class="jumbotron">
2544
<div class="row justify-content-center">
2645
<div class="col-lg-7">
27-
<div class="jumbotron" style="max-width: 800px">
28-
<h1 class="display-3">Upload a Plug!</h1>
29-
<p class="lead">You will lose 1 drink credit in exchange for a 100 view-limit of your plug.<br> Plugs must be 728x200 pixels and in PNG, or JPG format</p>
30-
<hr class="my-4">
46+
<h2>Upload a Plug!</h2>
47+
<p class="lead">You will lose 1 drink credit in exchange for a 100 view-limit of your plug.<br> Plugs must be 728x200 pixels and in PNG, or JPG format</p>
48+
<hr class="my-4">
3149

32-
<form action="/upload" method="post" enctype="multipart/form-data">
33-
<div class="form-group">
34-
<input class="form-control-number" id="numCredits"
35-
name="numCredits" aria-describedby="numHelp"
36-
type="number" value="1">
37-
<small id="numHelp" class="form-text
38-
text-muted">Increase the number of credits to pay
39-
for extended-air-time.</small>
40-
<input class="form-control-file" id="fileUpload" name="fileUpload" aria-describedby="fileHelp" type="file">
41-
<small id="fileHelp" class="form-text text-muted">Your Plug must be approved before it will appear for viewing. Any member of the following groups (drink, eboard, rtp) can do so via the admin page.</small>
42-
</div>
43-
<div class="float-right">
44-
<input class="btn btn-primary btn-lg" href="/upload" role="button" value="Upload" name="submit" type="submit">
45-
</div>
46-
</form>
47-
</div>
50+
<form action="/upload" method="post" enctype="multipart/form-data">
51+
<div class="form-group">
52+
<input class="form-control-number" id="numCredits"
53+
name="numCredits" aria-describedby="numHelp"
54+
type="number" value="1">
55+
<small id="numHelp" class="form-text
56+
text-muted">Increase the number of credits to pay
57+
for extended-air-time.</small>
58+
<input class="form-control-file" id="fileUpload" name="fileUpload" aria-describedby="fileHelp" type="file">
59+
<small id="fileHelp" class="form-text text-muted">Your Plug must be approved before it will appear for viewing. Any member of the following groups (drink, eboard, rtp) can do so via the admin page.</small>
60+
</div>
61+
<div class="float-right">
62+
<input class="btn btn-primary btn-lg" href="/upload" role="button" value="Upload" name="submit" type="submit">
63+
</div>
64+
</form>
4865
</div>
4966
</div>
5067
</div>

0 commit comments

Comments
 (0)