Show star on photos

pull/37/head
Varun Patil 2022-09-11 20:46:31 -07:00
parent ee274ebf7f
commit fa65f1866f
5 changed files with 54 additions and 7 deletions

View File

@ -6,6 +6,7 @@ namespace OCA\Memories\Db;
use OCA\Memories\Exif; use OCA\Memories\Exif;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ITags;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
trait TimelineQueryDay { trait TimelineQueryDay {
@ -22,6 +23,11 @@ trait TimelineQueryDay {
if (!$row["isvideo"]) { if (!$row["isvideo"]) {
unset($row["isvideo"]); unset($row["isvideo"]);
} }
if ($row["category"] === ITags::TAG_FAVORITE) {
$row["favorite"] = 1;
}
unset($row["category"]);
} }
return $day; return $day;
} }
@ -30,10 +36,11 @@ trait TimelineQueryDay {
private function makeQueryDay( private function makeQueryDay(
IQueryBuilder &$query, IQueryBuilder &$query,
int $dayid, int $dayid,
string $user,
$whereFilecache $whereFilecache
) { ) {
// Get all entries also present in filecache // Get all entries also present in filecache
$query->select('m.fileid', 'f.etag', 'm.isvideo') $query->select('m.fileid', 'f.etag', 'm.isvideo', 'vc.category')
->from('memories', 'm') ->from('memories', 'm')
->innerJoin('m', 'filecache', 'f', ->innerJoin('m', 'filecache', 'f',
$query->expr()->andX( $query->expr()->andX(
@ -42,6 +49,9 @@ trait TimelineQueryDay {
)) ))
->andWhere($query->expr()->eq('m.dayid', $query->createNamedParameter($dayid, IQueryBuilder::PARAM_INT))); ->andWhere($query->expr()->eq('m.dayid', $query->createNamedParameter($dayid, IQueryBuilder::PARAM_INT)));
// Add favorite field
$this->addFavoriteTag($query, $user);
// Group and sort by date taken // Group and sort by date taken
$query->orderBy('m.datetaken', 'DESC'); $query->orderBy('m.datetaken', 'DESC');
return $query; return $query;
@ -62,7 +72,7 @@ trait TimelineQueryDay {
// Filter by path starting with timeline path // Filter by path starting with timeline path
$path = "files" . Exif::getPhotosPath($config, $user) . "%"; $path = "files" . Exif::getPhotosPath($config, $user) . "%";
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$this->makeQueryDay($query, $dayId, $query->expr()->like( $this->makeQueryDay($query, $dayId, $user, $query->expr()->like(
'f.path', $query->createNamedParameter($path) 'f.path', $query->createNamedParameter($path)
)); ));
@ -84,11 +94,12 @@ trait TimelineQueryDay {
* @param int $dayId * @param int $dayId
*/ */
public function getDayFolder( public function getDayFolder(
string $user,
int $folderId, int $folderId,
int $dayId int $dayId
): array { ): array {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$this->makeQueryDay($query, $dayId, $query->expr()->orX( $this->makeQueryDay($query, $dayId, $user, $query->expr()->orX(
$query->expr()->eq('f.parent', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT)), $query->expr()->eq('f.parent', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT)),
$query->expr()->eq('f.fileid', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT)), $query->expr()->eq('f.fileid', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT)),
)); ));

View File

@ -9,11 +9,25 @@ use OCP\ITags;
trait TimelineQueryFavorites { trait TimelineQueryFavorites {
public function transformFavoriteFilter(IQueryBuilder $query, string $userId) { public function transformFavoriteFilter(IQueryBuilder $query, string $userId) {
// Inner join will filter only the favorites // Inner join will filter only the favorites
$query->innerJoin('m', 'vcategory_to_object', 'vco', $query->expr()->eq('vco.objid', 'm.fileid')); $query->innerJoin('m', 'vcategory_to_object', 'fvco', $query->expr()->eq('fvco.objid', 'm.fileid'));
// Get the favorites category only // Get the favorites category only
$query->innerJoin('vco', 'vcategory', 'vc', $query->expr()->andX( $query->innerJoin('fvco', 'vcategory', 'fvc', $query->expr()->andX(
$query->expr()->eq('fvc.id', 'fvco.categoryid'),
$query->expr()->eq('fvc.type', $query->createNamedParameter("files")),
$query->expr()->eq('fvc.uid', $query->createNamedParameter($userId)),
$query->expr()->eq('fvc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)),
));
}
public function addFavoriteTag(IQueryBuilder $query, string $userId) {
// Inner join will filter only the favorites
$query->leftJoin('m', 'vcategory_to_object', 'vco', $query->expr()->eq('vco.objid', 'm.fileid'));
// Get the favorites category only
$query->leftJoin('vco', 'vcategory', 'vc', $query->expr()->andX(
$query->expr()->eq('vc.id', 'vco.categoryid'), $query->expr()->eq('vc.id', 'vco.categoryid'),
$query->expr()->eq('vc.type', $query->createNamedParameter("files")),
$query->expr()->eq('vc.uid', $query->createNamedParameter($userId)), $query->expr()->eq('vc.uid', $query->createNamedParameter($userId)),
$query->expr()->eq('vc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)), $query->expr()->eq('vc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)),
)); ));

View File

@ -14,6 +14,8 @@
@click="toggleSelect"></div> @click="toggleSelect"></div>
<div v-if="data.isvideo" class="icon-video-white"></div> <div v-if="data.isvideo" class="icon-video-white"></div>
<div v-if="data.flag & c.FLAG_IS_FAVORITE" class="icon-starred"></div>
<div class="img-outer" :style="{ <div class="img-outer" :style="{
width: rowHeight + 'px', width: rowHeight + 'px',
height: rowHeight + 'px', height: rowHeight + 'px',
@ -232,7 +234,8 @@ export default {
.icon-checkmark { .icon-checkmark {
position: absolute; position: absolute;
top: 8px; left: 8px; top: 10px; left: 10px;
z-index: 100;
background-color: var(--color-main-background); background-color: var(--color-main-background);
border-radius: 50%; border-radius: 50%;
background-size: 80%; background-size: 80%;
@ -247,7 +250,18 @@ export default {
/* Extra icons */ /* Extra icons */
.icon-video-white { .icon-video-white {
position: absolute; position: absolute;
top: 8px; right: 8px; background-size: 100%;
height: 20px; width: 20px;
top: 10px; right: 10px;
z-index: 100;
}
.icon-starred {
position: absolute;
background-size: 100%;
height: 24px; width: 24px;
bottom: 10px; left: 10px;
z-index: 100;
pointer-events: none;
} }
/* Actual image */ /* Actual image */

View File

@ -613,6 +613,13 @@ export default {
photo.flag = 0; // flags photo.flag = 0; // flags
photo.d = day; // backref to day photo.d = day; // backref to day
} }
// Flag conversion
if (photo.favorite) {
photo.flag |= constants.FLAG_IS_FAVORITE;
delete photo.favorite;
}
this.list[rowIdx].photos.push(photo); this.list[rowIdx].photos.push(photo);
dataIdx++; dataIdx++;

View File

@ -6,4 +6,5 @@ export default {
FLAG_LEAVING: 1 << 4, FLAG_LEAVING: 1 << 4,
FLAG_EXIT_LEFT: 1 << 5, FLAG_EXIT_LEFT: 1 << 5,
FLAG_ENTER_RIGHT: 1 << 6, FLAG_ENTER_RIGHT: 1 << 6,
FLAG_IS_FAVORITE: 1 << 7,
}; };