Merge branch 'master' of git.darkou.fr:dbroqua/MusicTopus into develop

This commit is contained in:
Damien Broqua 2023-09-24 14:57:03 +02:00
commit 7b525d3e43
5 changed files with 43 additions and 2 deletions

View file

@ -113,6 +113,7 @@ Vue.createApp({
format, format,
genre, genre,
style, style,
inCollection,
} = results[i]; } = results[i];
items.push({ items.push({
id, id,
@ -123,6 +124,7 @@ Vue.createApp({
format, format,
genre, genre,
style, style,
inCollection,
}); });
} }

View file

@ -7,10 +7,18 @@
.list { .list {
margin-top: 2rem; margin-top: 2rem;
.item{ .item {
img { img {
cursor: pointer; cursor: pointer;
} }
&.in-collection {
opacity: 0.6;
small {
font-style: italic;
}
}
} }
} }
} }

View file

@ -167,6 +167,7 @@ Publié automatiquement via #musictopus`;
genre, genre,
style, style,
userId: collectionUserId, userId: collectionUserId,
discogsIds,
} = this.req.query; } = this.req.query;
let userId = this.req.user?._id; let userId = this.req.user?._id;
@ -216,6 +217,10 @@ Publié automatiquement via #musictopus`;
userId = userIsSharingCollection._id; userId = userIsSharingCollection._id;
} }
if (discogsIds) {
where.discogsId = { $in: discogsIds };
}
const count = await AlbumsModel.count({ const count = await AlbumsModel.count({
User: userId, User: userId,
...where, ...where,

View file

@ -3,6 +3,7 @@ import { ensureLoggedIn } from "connect-ensure-login";
import { sendResponse } from "../../../libs/format"; import { sendResponse } from "../../../libs/format";
import { searchSong, getAlbumDetails } from "../../../helpers"; import { searchSong, getAlbumDetails } from "../../../helpers";
import Albums from "../../../middleware/Albums";
// eslint-disable-next-line new-cap // eslint-disable-next-line new-cap
const router = express.Router(); const router = express.Router();
@ -16,6 +17,30 @@ router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
req.query.country || null req.query.country || null
); );
const discogsIds = [];
const foundIds = [];
for (let i = 0; i < data.results.length; i += 1) {
discogsIds.push(data.results[i].id);
}
req.query.discogsIds = discogsIds;
const albums = new Albums(req);
const myAlbums = await albums.getAll();
if (myAlbums.rows) {
for (let i = 0; i < myAlbums.rows.length; i += 1) {
foundIds.push(myAlbums.rows[i].discogsId);
}
}
for (let i = 0; i < data.results.length; i += 1) {
data.results[i].inCollection = foundIds.includes(
data.results[i].id
);
}
sendResponse(req, res, data); sendResponse(req, res, data);
} catch (err) { } catch (err) {
next(err); next(err);

View file

@ -34,8 +34,9 @@
<div class="grid grid-cols-1 md:grid-cols-2 list hover"> <div class="grid grid-cols-1 md:grid-cols-2 list hover">
<div class="item" v-if="!loading" v-for="item in items"> <div v-if="!loading" v-for="item in items" class="item" :class="{'in-collection': item.inCollection}">
<a @click="loadDetails(item.id)" class="title">{{ item.artists_sort }} {{ item.title }}</a> <a @click="loadDetails(item.id)" class="title">{{ item.artists_sort }} {{ item.title }}</a>
<small v-if="item.inCollection"> (Dans ma collection)</small>
<div class="grid grid-cols-2 md:grid-cols-4"> <div class="grid grid-cols-2 md:grid-cols-4">
<div> <div>
<img :src="item.thumb" :alt="item.title" @click="loadDetails(item.id)"/> <img :src="item.thumb" :alt="item.title" @click="loadDetails(item.id)"/>