Skip to content

Commit

Permalink
albums: add sort by update
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Mar 24, 2024
1 parent b1a7f2b commit d88f8d2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

- A Docker Compose example using the community Nextcloud image is now available in the repo.
- **Feature**: Manual upload to folder is now available in the Android app.
- **Feature**: Allow sorting albums by most recently updated.
- **Feature**: Allow sorting albums in ascending and descending direction.
- **Feature**: Manual upload to folder is now available in the Android app.

## [v7.0.2] - 2024-03-19

Expand Down
2 changes: 2 additions & 0 deletions lib/Db/AlbumsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function getList(

// SELECT everything from albums
$count = $query->func()->count($query->createFunction('DISTINCT m.fileid'), 'count');
$maxPafId = $query->createFunction('MAX(paf.album_file_id) AS update_id');
$query->select(
'pa.album_id',
'pa.name',
Expand All @@ -37,6 +38,7 @@ public function getList(
'pa.created',
'pa.location',
'pa.last_added_photo',
$maxPafId,
$count,
)->from('photos_albums', 'pa');

Expand Down
39 changes: 30 additions & 9 deletions src/components/top-matter/AlbumTopMatter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<SortIcon :size="20" />
</template>

<NcActionRadio
name="sort"
:aria-label="t('memories', 'Last updated')"
:checked="!!(config.album_list_sort & c.ALBUM_SORT_FLAGS.LAST_UPDATE)"
@change="changeSort(c.ALBUM_SORT_FLAGS.LAST_UPDATE)"
close-after-click
>
{{ t('memories', 'Last updated') }}
</NcActionRadio>

<NcActionRadio
name="sort"
:aria-label="t('memories', 'Creation date')"
Expand All @@ -40,12 +50,12 @@

<NcActions :forceMenu="true">
<template #icon>
<template v-if="config.album_list_sort & c.ALBUM_SORT_FLAGS.CREATED">
<SortDateDIcon v-if="config.album_list_sort & c.ALBUM_SORT_FLAGS.DESCENDING" :size="20" />
<template v-if="isDateSort">
<SortDateDIcon v-if="isDescending" :size="20" />
<SortDateAIcon v-else :size="20" />
</template>
<template v-else-if="config.album_list_sort & c.ALBUM_SORT_FLAGS.NAME">
<SlotAlphabeticalDIcon v-if="config.album_list_sort & c.ALBUM_SORT_FLAGS.DESCENDING" :size="20" />
<SlotAlphabeticalDIcon v-if="isDescending" :size="20" />
<SlotAlphabeticalAIcon v-else :size="20" />
</template>
<template v-else>
Expand All @@ -55,22 +65,22 @@

<NcActionRadio
name="sort-dir"
:aria-label="t('memories', 'Ascending')"
:checked="!(config.album_list_sort & c.ALBUM_SORT_FLAGS.DESCENDING)"
:aria-label="isDateSort ? t('memories', 'Oldest first') : t('memories', 'Ascending')"
:checked="!isDescending"
@change="setDescending(false)"
close-after-click
>
{{ t('memories', 'Ascending') }}
{{ isDateSort ? t('memories', 'Oldest first') : t('memories', 'Ascending') }}
</NcActionRadio>

<NcActionRadio
name="sort-dir"
:aria-label="t('memories', 'Descending')"
:checked="!!(config.album_list_sort & c.ALBUM_SORT_FLAGS.DESCENDING)"
:aria-label="isDateSort ? t('memories', 'Newest first') : t('memories', 'Descending')"
:checked="isDescending"
@change="setDescending(true)"
close-after-click
>
{{ t('memories', 'Descending') }}
{{ isDateSort ? t('memories', 'Newest first') : t('memories', 'Descending') }}
</NcActionRadio>
</NcActions>
</template>
Expand Down Expand Up @@ -209,6 +219,17 @@ export default defineComponent({
isMobile(): boolean {
return utils.isMobile();
},
isDateSort(): boolean {
return (
!!(this.config.album_list_sort & this.c.ALBUM_SORT_FLAGS.CREATED) ||
!!(this.config.album_list_sort & this.c.ALBUM_SORT_FLAGS.LAST_UPDATE)
);
},
isDescending(): boolean {
return !!(this.config.album_list_sort & this.c.ALBUM_SORT_FLAGS.DESCENDING);
},
},
methods: {
Expand Down
2 changes: 2 additions & 0 deletions src/services/dav/albums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export async function getAlbums(fileid?: number) {
const sort = await staticConfig.get('album_list_sort');
if (sort & utils.constants.ALBUM_SORT_FLAGS.NAME) {
data.sort((a, b) => a.name.localeCompare(b.name, getLanguage(), { numeric: true }));
} else if (sort & utils.constants.ALBUM_SORT_FLAGS.LAST_UPDATE) {
data.sort((a, b) => (a.update_id ?? Number.MAX_SAFE_INTEGER) - (b.update_id ?? Number.MAX_SAFE_INTEGER));
} else {
// fall back to created date
data.sort((a, b) => a.created - b.created);
Expand Down
7 changes: 4 additions & 3 deletions src/services/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export const constants = Object.freeze({
FORBIDDEN_EDIT_MIMES: ['image/bmp', 'image/x-dcraw', 'video/MP2T'], // Exif.php

ALBUM_SORT_FLAGS: {
DESCENDING: 1 << 0,
CREATED: 1 << 1,
NAME: 1 << 2,
DESCENDING: 1 << 0, // default true
LAST_UPDATE: 1 << 1, // default
CREATED: 1 << 2,
NAME: 1 << 3,
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/typings/cluster.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ declare module '@typings' {
last_added_photo: number;
/** Etag of last added photo */
last_added_photo_etag: string;
/** Record ID of the latest update */
update_id: number;
}

export interface IFace extends ICluster {
Expand Down

0 comments on commit d88f8d2

Please sign in to comment.