diff --git a/assets/templates/index.tmpl b/assets/templates/index.tmpl index 3aab0d0e7..c1123bdb2 100644 --- a/assets/templates/index.tmpl +++ b/assets/templates/index.tmpl @@ -18,7 +18,8 @@ appName: "{{ .title }}", appVersion: "1.0.0", debug: {{ .debug }}, - cameras: {{ .cameras }} + cameras: {{ .cameras }}, + countries: {{ .countries }} }; diff --git a/frontend/src/app/pages/photos.vue b/frontend/src/app/pages/photos.vue index da2a5acf4..e2b57a0b8 100644 --- a/frontend/src/app/pages/photos.vue +++ b/frontend/src/app/pages/photos.vue @@ -40,6 +40,8 @@ label="Country" flat solo color="blue-grey" + item-value="LocCountryCode" + item-text="LocCountry" v-model="query.country" :items="options.countries"> @@ -77,6 +79,7 @@ direction="top" open-on-hover transition="slide-y-reverse-transition" + style="right: 8px; bottom: 8px;" > 0 { - q = q.Where("camera_id = ?", form.CameraID) + q = q.Where("photos.camera_id = ?", form.CameraID) + } + + if form.Country != "" { + q = q.Where("locations.loc_country_code = ?", form.Country) + } + + switch form.Cat { + case "amenity": + q = q.Where("locations.loc_category = 'amenity'") + case "bank": + q = q.Where("locations.loc_type = 'bank'") + case "building": + q = q.Where("locations.loc_category = 'building'") + case "school": + q = q.Where("locations.loc_type = 'school'") + case "supermarket": + q = q.Where("locations.loc_type = 'supermarket'") + case "shop": + q = q.Where("locations.loc_category = 'shop'") + case "hotel": + q = q.Where("locations.loc_type = 'hotel'") + case "bar": + q = q.Where("locations.loc_type = 'bar'") + case "parking": + q = q.Where("locations.loc_type = 'parking'") + case "airport": + q = q.Where("locations.loc_category = 'aeroway'") + case "historic": + q = q.Where("locations.loc_category = 'historic'") + case "tourism": + q = q.Where("locations.loc_category = 'tourism'") + default: } switch form.Order { @@ -118,28 +150,13 @@ func (s *Search) Photos(form PhotoSearchForm) ([]PhotoSearchResult, int, error) q = q.Limit(100).Offset(0) } - results := make([]PhotoSearchResult, 0, form.Count) + var results []PhotoSearchResult - rows, err := q.Rows() - - if err != nil { - return results, 0, err + if result := q.Scan(&results); result.Error != nil { + return results, result.Error } - defer rows.Close() - - for rows.Next() { - var result PhotoSearchResult - s.db.ScanRows(rows, &result) - results = append(results, result) - } - - // TODO: Check if this works properly with concurrent requests and caching - count := &SearchCount{} - s.db.Raw("SELECT FOUND_ROWS() AS total").Scan(&count) - total := count.Total - - return results, total, nil + return results, nil } func (s *Search) FindFiles(count int, offset int) (files []File) { diff --git a/internal/photoprism/search_test.go b/internal/photoprism/search_test.go index c9bc914a6..a50be8b66 100644 --- a/internal/photoprism/search_test.go +++ b/internal/photoprism/search_test.go @@ -20,23 +20,21 @@ func TestSearch_Photos_Query(t *testing.T) { form.Count = 3 form.Offset = 0 - photos, total, err := search.Photos(form) + photos, err := search.Photos(form) if err != nil { t.Fatal(err) } t.Log(photos) - t.Logf("Total Count: %d", total) - photos, total, err = search.Photos(form) + photos, err = search.Photos(form) if err != nil { t.Fatal(err) } t.Log(photos) - t.Logf("Total Count: %d", total) } @@ -56,12 +54,11 @@ func TestSearch_Photos_Camera(t *testing.T) { form.Count = 3 form.Offset = 0 - photos, total, err := search.Photos(form) + photos, err := search.Photos(form) if err != nil { t.Fatal(err) } t.Log(photos) - t.Logf("Total Count: %d", total) } diff --git a/internal/photoprism/thumbnails.go b/internal/photoprism/thumbnails.go index ec387f878..4ce4cdb6a 100644 --- a/internal/photoprism/thumbnails.go +++ b/internal/photoprism/thumbnails.go @@ -25,7 +25,6 @@ func CreateThumbnailsFromOriginals(originalsPath string, thumbnailsPath string, if thumbnail, err := mediaFile.GetSquareThumbnail(thumbnailsPath, size); err != nil { log.Printf("Could not create thumbnail: %s", err.Error()) } else { - thumbnail.GetHeight() log.Printf("Created %dx%d px thumbnail for \"%s\"", thumbnail.GetWidth(), thumbnail.GetHeight(), mediaFile.GetRelativeFilename(originalsPath)) } } else { diff --git a/internal/server/routes.go b/internal/server/routes.go index 8fb58be76..8cfef1d79 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -28,13 +28,12 @@ func ConfigureRoutes(app *gin.Engine, conf *photoprism.Config) { c.MustBindWith(&form, binding.Form) - result, total, err := search.Photos(form) + result, err := search.Photos(form) if err != nil { c.AbortWithStatusJSON(400, gin.H{"error": err.Error()}) } - c.Header("x-result-total", strconv.Itoa(total)) c.Header("x-result-count", strconv.Itoa(form.Count)) c.Header("x-result-offset", strconv.Itoa(form.Offset))