Browse Source

Show metadata on the list page

Gildas Chabot 4 years ago
parent
commit
0fdafaab8a
4 changed files with 44 additions and 11 deletions
  1. 4 2
      collection.go
  2. 12 0
      movies.go
  3. 7 2
      templates/list.html
  4. 21 7
      templates/style.css

+ 4 - 2
collection.go

@@ -56,16 +56,18 @@ func (c *Collection) Add(m *Movie) {
56
 	c.mutex.Lock()
56
 	c.mutex.Lock()
57
 	defer c.mutex.Unlock()
57
 	defer c.mutex.Unlock()
58
 
58
 
59
+	c.hasChanged = true
60
+
59
 	for _, present := range c.Movies {
61
 	for _, present := range c.Movies {
60
 		if m.IMDBID == present.IMDBID {
62
 		if m.IMDBID == present.IMDBID {
63
+			present.OMDB = m.OMDB
64
+			present.FillFromOMDB()
61
 			return
65
 			return
62
 		}
66
 		}
63
 	}
67
 	}
64
 
68
 
65
 	c.Movies = append(c.Movies, m)
69
 	c.Movies = append(c.Movies, m)
66
 	c.movieMap[m.IMDBID] = m
70
 	c.movieMap[m.IMDBID] = m
67
-
68
-	c.hasChanged = true
69
 }
71
 }
70
 
72
 
71
 func (c *Collection) HasChanged() bool {
73
 func (c *Collection) HasChanged() bool {

+ 12 - 0
movies.go

@@ -12,6 +12,9 @@ type Movie struct {
12
 	Poster   string
12
 	Poster   string
13
 	Rating   *Rating
13
 	Rating   *Rating
14
 	IMDBID   string
14
 	IMDBID   string
15
+	Country  string
16
+	Year     string
17
+	Runtime  string
15
 
18
 
16
 	OMDB OMDBMovie
19
 	OMDB OMDBMovie
17
 }
20
 }
@@ -83,6 +86,15 @@ func (m *Movie) FillFromOMDB() error {
83
 	if m.IMDBID == "" {
86
 	if m.IMDBID == "" {
84
 		m.IMDBID = m.OMDB.IMDBID
87
 		m.IMDBID = m.OMDB.IMDBID
85
 	}
88
 	}
89
+	if m.Country == "" {
90
+		m.Country = m.OMDB.Country
91
+	}
92
+	if m.Year == "" {
93
+		m.Year = m.OMDB.Year
94
+	}
95
+	if m.Runtime == "" {
96
+		m.Runtime = m.OMDB.Runtime
97
+	}
86
 
98
 
87
 	if m.Rating == nil {
99
 	if m.Rating == nil {
88
 		m.Rating = &Rating{}
100
 		m.Rating = &Rating{}

+ 7 - 2
templates/list.html

@@ -15,14 +15,19 @@
15
         <ul class="movie-list">
15
         <ul class="movie-list">
16
             {{ range $m := .Collection.Movies }}
16
             {{ range $m := .Collection.Movies }}
17
             <a href="/{{ $m.IMDBID }}">
17
             <a href="/{{ $m.IMDBID }}">
18
-                <li>
18
+                <li class="movie">
19
                     <div class="poster">
19
                     <div class="poster">
20
                         <img src="{{ $m.Poster }}" title="{{ $m.Title }}" alt="{{ $m.Title }}" />
20
                         <img src="{{ $m.Poster }}" title="{{ $m.Title }}" alt="{{ $m.Title }}" />
21
                     </div>
21
                     </div>
22
-                    <div class="metadata">
22
+                    <div class="title">
23
                         <h3>{{ $m.Title }}</h3>
23
                         <h3>{{ $m.Title }}</h3>
24
                         <div>{{ $m.Director }}</div>
24
                         <div>{{ $m.Director }}</div>
25
                     </div>
25
                     </div>
26
+                    <ul class="metadata">
27
+                        <li>{{ $m.Year }}</li>
28
+                        <li style="flex-grow: 2;">{{ $m.Country }}</li>
29
+                        <li>{{ $m.Runtime }}</li>
30
+                    </ul>
26
                 </li>
31
                 </li>
27
             </a>
32
             </a>
28
             {{ end }}
33
             {{ end }}

+ 21 - 7
templates/style.css

@@ -16,26 +16,40 @@ ul.movie-list {
16
     flex-wrap: wrap;
16
     flex-wrap: wrap;
17
     padding: 0;
17
     padding: 0;
18
 }
18
 }
19
-ul.movie-list li {
19
+ul.movie-list li.movie {
20
     width: 240px;
20
     width: 240px;
21
-    height: 400px;
21
+    height: 440px;
22
     display: grid;
22
     display: grid;
23
-    grid-template-rows: 320px 80px;
23
+    grid-template-rows: 320px 80px 40px;
24
     box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
24
     box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
25
     margin: 10px;
25
     margin: 10px;
26
 }
26
 }
27
-ul.movie-list li .poster {
27
+ul.movie-list li.movie .poster {
28
     justify-self: center;
28
     justify-self: center;
29
     align-self: center;
29
     align-self: center;
30
 }
30
 }
31
-ul.movie-list li .metadata {
31
+ul.movie-list li.movie .title {
32
     padding: 10px;
32
     padding: 10px;
33
 }
33
 }
34
-ul.movie-list li img {
34
+ul.movie-list li.movie img {
35
     max-width: 240px;
35
     max-width: 240px;
36
     max-height: 320px;
36
     max-height: 320px;
37
 }
37
 }
38
-ul.movie-list li a {
38
+ul.movie-list li.movie a {
39
     color: black;
39
     color: black;
40
     text-decoration: none;
40
     text-decoration: none;
41
 }
41
 }
42
+ul.movie-list li.movie ul.metadata {
43
+    list-style-type: none;
44
+    padding: 0;
45
+    display: flex;
46
+    flex-wrap: nowrap;
47
+    justify-content: space-between;
48
+    padding-top: 10px;
49
+    padding-bottom: 10px;
50
+}
51
+ul.movie-list li.movie ul.metadata li {
52
+    overflow: hidden;
53
+    padding-left: 10px;
54
+    padding-right: 10px;
55
+}