Shares: Show all albums on overview page #776

This commit is contained in:
Michael Mayer 2020-12-31 12:34:06 +01:00
parent bbd0af3dd3
commit f439a6d050
10 changed files with 46 additions and 37 deletions

View file

@ -16,7 +16,7 @@ export default [
path: "/s/:token",
component: Albums,
meta: { title: shareTitle, auth: true },
props: { view: "album", staticFilter: { type: "album" } },
props: { view: "album", staticFilter: { type: "" } },
},
{
name: "album",

View file

@ -78,7 +78,7 @@ func GetAlbums(router *gin.RouterGroup) {
// Guest permissions are limited to shared albums.
if s.Guest() {
f.ID = s.Shares.String()
f.ID = s.Shares.Join(query.Or)
}
result, err := query.AlbumSearch(f)

View file

@ -204,7 +204,7 @@ func (m *Moments) Start() (err error) {
} else {
w := txt.Words(f.Label)
w = append(w, mom.Label)
f.Label = strings.Join(txt.UniqueWords(w), query.OrSep)
f.Label = strings.Join(txt.UniqueWords(w), query.Or)
}
if err := a.Update("AlbumFilter", f.Serialize()); err != nil {

View file

@ -117,7 +117,7 @@ func AlbumSearch(f form.AlbumSearch) (results AlbumResults, err error) {
Where("albums.deleted_at IS NULL")
if f.ID != "" {
s = s.Where("albums.album_uid IN (?)", strings.Split(f.ID, OrSep))
s = s.Where("albums.album_uid IN (?)", strings.Split(f.ID, Or))
if result := s.Scan(&results); result.Error != nil {
return results, result.Error
@ -132,15 +132,15 @@ func AlbumSearch(f form.AlbumSearch) (results AlbumResults, err error) {
}
if f.Type != "" {
s = s.Where("albums.album_type IN (?)", strings.Split(f.Type, OrSep))
s = s.Where("albums.album_type IN (?)", strings.Split(f.Type, Or))
}
if f.Category != "" {
s = s.Where("albums.album_category IN (?)", strings.Split(f.Category, OrSep))
s = s.Where("albums.album_category IN (?)", strings.Split(f.Category, Or))
}
if f.Location != "" {
s = s.Where("albums.album_location IN (?)", strings.Split(f.Location, OrSep))
s = s.Where("albums.album_location IN (?)", strings.Split(f.Location, Or))
}
if f.Favorite {

View file

@ -100,7 +100,7 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) {
}
if f.Color != "" {
s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), OrSep))
s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), Or))
}
if f.Favorite {
@ -108,12 +108,12 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) {
}
if f.Country != "" {
s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), OrSep))
s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), Or))
}
// Filter by media type.
if f.Type != "" {
s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), OrSep))
s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), Or))
}
if f.Video {
@ -131,15 +131,15 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) {
if strings.HasSuffix(p, "/") {
s = s.Where("photos.photo_path = ?", p[:len(p)-1])
} else if strings.Contains(p, OrSep) {
s = s.Where("photos.photo_path IN (?)", strings.Split(p, OrSep))
} else if strings.Contains(p, Or) {
s = s.Where("photos.photo_path IN (?)", strings.Split(p, Or))
} else {
s = s.Where("photos.photo_path LIKE ?", strings.ReplaceAll(p, "*", "%"))
}
}
if strings.Contains(f.Name, OrSep) {
s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, OrSep))
if strings.Contains(f.Name, Or) {
s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, Or))
} else if f.Name != "" {
s = s.Where("photos.photo_name LIKE ?", strings.ReplaceAll(fs.StripKnownExt(f.Name), "*", "%"))
}

View file

@ -58,7 +58,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
// Shortcut for known photo ids.
if f.ID != "" {
s = s.Where("photos.photo_uid IN (?)", strings.Split(f.ID, OrSep))
s = s.Where("photos.photo_uid IN (?)", strings.Split(f.ID, Or))
s = s.Order("files.file_primary DESC")
if result := s.Scan(&results); result.Error != nil {
@ -80,7 +80,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
var labelIds []uint
if f.Label != "" {
if err := Db().Where(AnySlug("label_slug", f.Label, OrSep)).Or(AnySlug("custom_slug", f.Label, OrSep)).Find(&labels).Error; len(labels) == 0 || err != nil {
if err := Db().Where(AnySlug("label_slug", f.Label, Or)).Or(AnySlug("custom_slug", f.Label, Or)).Find(&labels).Error; len(labels) == 0 || err != nil {
log.Errorf("search: labels %s not found", txt.Quote(f.Label))
return results, 0, fmt.Errorf("%s not found", txt.Quote(f.Label))
} else {
@ -182,7 +182,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
}
if f.Color != "" {
s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), OrSep))
s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), Or))
}
if f.Favorite {
@ -204,21 +204,21 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
}
if f.Country != "" {
s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), OrSep))
s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), Or))
}
if f.State != "" {
s = s.Where("places.place_state IN (?)", strings.Split(f.State, OrSep))
s = s.Where("places.place_state IN (?)", strings.Split(f.State, Or))
}
if f.Category != "" {
s = s.Joins("JOIN cells ON photos.cell_id = cells.id").
Where("cells.cell_category IN (?)", strings.Split(strings.ToLower(f.Category), OrSep))
Where("cells.cell_category IN (?)", strings.Split(strings.ToLower(f.Category), Or))
}
// Filter by media type.
if f.Type != "" {
s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), OrSep))
s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), Or))
}
if f.Video {
@ -236,41 +236,41 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
if strings.HasSuffix(p, "/") {
s = s.Where("photos.photo_path = ?", p[:len(p)-1])
} else if strings.Contains(p, OrSep) {
s = s.Where("photos.photo_path IN (?)", strings.Split(p, OrSep))
} else if strings.Contains(p, Or) {
s = s.Where("photos.photo_path IN (?)", strings.Split(p, Or))
} else {
s = s.Where("photos.photo_path LIKE ?", strings.ReplaceAll(p, "*", "%"))
}
}
if strings.Contains(f.Name, OrSep) {
s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, OrSep))
if strings.Contains(f.Name, Or) {
s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, Or))
} else if f.Name != "" {
s = s.Where("photos.photo_name LIKE ?", strings.ReplaceAll(fs.StripKnownExt(f.Name), "*", "%"))
}
if strings.Contains(f.Filename, OrSep) {
s = s.Where("files.file_name IN (?)", strings.Split(f.Filename, OrSep))
if strings.Contains(f.Filename, Or) {
s = s.Where("files.file_name IN (?)", strings.Split(f.Filename, Or))
} else if f.Filename != "" {
s = s.Where("files.file_name LIKE ?", strings.ReplaceAll(f.Filename, "*", "%"))
}
if strings.Contains(f.Original, OrSep) {
s = s.Where("photos.original_name IN (?)", strings.Split(f.Original, OrSep))
if strings.Contains(f.Original, Or) {
s = s.Where("photos.original_name IN (?)", strings.Split(f.Original, Or))
} else if f.Original != "" {
s = s.Where("photos.original_name LIKE ?", strings.ReplaceAll(f.Original, "*", "%"))
}
if strings.Contains(f.Title, OrSep) {
s = s.Where("photos.photo_title IN (?)", strings.Split(strings.ToLower(f.Title), OrSep))
if strings.Contains(f.Title, Or) {
s = s.Where("photos.photo_title IN (?)", strings.Split(strings.ToLower(f.Title), Or))
} else if f.Title != "" {
s = s.Where("photos.photo_title LIKE ?", strings.ReplaceAll(strings.ToLower(f.Title), "*", "%"))
}
if strings.Contains(f.Hash, OrSep) {
s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), OrSep))
if strings.Contains(f.Hash, Or) {
s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), Or))
} else if f.Hash != "" {
s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), OrSep))
s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), Or))
}
if f.Portrait {

View file

@ -49,7 +49,7 @@ var log = event.Log
const (
MySQL = "mysql"
SQLite = "sqlite3"
OrSep = "|"
Or = "|"
)
// Max result limit for queries.

View file

@ -89,7 +89,7 @@ func TestAnySlug(t *testing.T) {
})
t.Run("comma separated", func(t *testing.T) {
where := AnySlug("custom_slug", "botanical-garden|landscape|bay", OrSep)
where := AnySlug("custom_slug", "botanical-garden|landscape|bay", Or)
assert.Equal(t, "custom_slug = 'botanical-garden' OR custom_slug = 'landscape' OR custom_slug = 'bay'", where)
})

View file

@ -15,7 +15,11 @@ type Saved struct {
type UIDs []string
func (list UIDs) String() string {
return strings.Join(list, ",")
return list.Join(",")
}
func (list UIDs) Join(s string) string {
return strings.Join(list, s)
}
type Data struct {

View file

@ -11,6 +11,11 @@ func TestUIDs_String(t *testing.T) {
assert.Equal(t, "dghjkfd,dfgehrih", uid.String())
}
func TestUIDs_Join(t *testing.T) {
uid := UIDs{"dghjkfd", "dfgehrih"}
assert.Equal(t, "dghjkfd|dfgehrih", uid.Join("|"))
}
func TestData_HasShare(t *testing.T) {
data := Data{Shares: []string{"abc123", "def444"}}
assert.True(t, data.HasShare("def444"))