2 Commits 4b01054a11 ... 3176b39d32

Auteur SHA1 Bericht Datum
  Gildas Chabot 3176b39d32 Add movies to lists 4 jaren geleden
  Gildas Chabot cb217b24e3 Support Markdown in list description 4 jaren geleden
3 gewijzigde bestanden met toevoegingen van 52 en 12 verwijderingen
  1. 21 9
      pages/pages.go
  2. 0 1
      templates/home.html
  3. 31 2
      templates/list.html

+ 21 - 9
pages/pages.go

@@ -9,6 +9,7 @@ import (
9 9
 
10 10
 	"gogs.gildas.ch/gildas/movies"
11 11
 	"gogs.gildas.ch/gildas/movies/omdb"
12
+	"gopkg.in/russross/blackfriday.v2"
12 13
 )
13 14
 
14 15
 func Router(c *movies.Collection) http.HandlerFunc {
@@ -156,14 +157,13 @@ func List(c *movies.Collection) http.HandlerFunc {
156 157
 		}
157 158
 
158 159
 		if r.Method == "POST" {
159
-			updated, err := movies.UnmarshalList([]byte(r.FormValue("list_json")))
160
-			if err != nil {
161
-				errs = append(errs, err)
162
-			} else if listID != updated.ID {
163
-				errs = append(errs, fmt.Errorf("you cannot change the imdb id."))
164
-			} else {
165
-				l = updated
166
-				c.UpdateList(updated)
160
+			if r.FormValue("title") != "" || r.FormValue("description") != "" {
161
+				l.Title = r.FormValue("title")
162
+				l.Description = r.FormValue("description")
163
+				c.UpdateList(l)
164
+			} else if r.FormValue("imdb_id") != "" {
165
+				l.Movies = append(l.Movies, r.FormValue("imdb_id"))
166
+				c.UpdateList(l)
167 167
 			}
168 168
 		}
169 169
 
@@ -172,8 +172,20 @@ func List(c *movies.Collection) http.HandlerFunc {
172 172
 			errs = append(errs, err)
173 173
 		}
174 174
 
175
+		var ms []*movies.Movie
176
+		for _, imdbID := range l.Movies {
177
+			if m, ok := c.Get(imdbID); ok {
178
+				ms = append(ms, m)
179
+			}
180
+		}
181
+
175 182
 		t.Execute(w, map[string]interface{}{
176
-			"List":     l,
183
+			"List": l,
184
+			"Description": template.HTML(
185
+				blackfriday.Run(
186
+					[]byte(strings.ReplaceAll(l.Description, "\r\n", "\n")),
187
+					blackfriday.WithExtensions(blackfriday.CommonExtensions))),
188
+			"Movies":   ms,
177 189
 			"ListJSON": string(b),
178 190
 			"Errors":   errs,
179 191
 		})

+ 0 - 1
templates/home.html

@@ -40,7 +40,6 @@
40 40
             <a href="/l/{{ $l.ID }}">
41 41
                 <li class="list">
42 42
                     <h3>{{ $l.Title }} ({{ $l.ID }})</h3>
43
-                    <p>{{ $l.Description }}</p>
44 43
                 </li>
45 44
             </a>
46 45
             {{ end }}

+ 31 - 2
templates/list.html

@@ -12,11 +12,40 @@
12 12
 
13 13
         <h1>{{ .List.Title }}</h1>
14 14
 
15
-        <p>{{ .List.Description }}</p>
15
+        {{ .Description }}
16
+
17
+        <ul class="movie-list">
18
+            {{ range $m := .Movies }}
19
+            <a href="/{{ $m.IMDBID }}">
20
+                <li class="movie">
21
+                    <div class="poster">
22
+                        <img src="{{ $m.Poster }}" title="{{ $m.Title }}" alt="{{ $m.Title }}" />
23
+                    </div>
24
+                    <div class="title">
25
+                        <h3>{{ $m.Title }}</h3>
26
+                        <div>{{ $m.Director }}</div>
27
+                    </div>
28
+                    <ul class="metadata">
29
+                        <li>{{ $m.Year }}</li>
30
+                        <li style="flex-grow: 2;">{{ $m.Country }}</li>
31
+                        <li>{{ $m.Runtime }}</li>
32
+                    </ul>
33
+                </li>
34
+            </a>
35
+            {{ end }}
36
+        </ul>
37
+
16 38
 
17 39
         <form method="post">
18 40
             <p>Update list: <input type="submit" /><br />
19
-                <textarea name="list_json" style="width:90%;height:500px;">{{ .ListJSON }}</textarea>
41
+                <input type="text" name="title" value="{{ .List.Title }}" /><br />
42
+                <textarea name="description" style="width:90%;height:500px;">{{ .List.Description }}</textarea>
43
+            </p>
44
+        </form>
45
+
46
+        <form method="post">
47
+            <p>Add movie (by id): <input type="submit" /><br />
48
+                <input type="text" name="imdb_id" value="" />
20 49
             </p>
21 50
         </form>
22 51
     </body>