2023-03-19 10:41:59 +01:00
|
|
|
Vue.createApp({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: false,
|
|
|
|
moreFilters: false,
|
|
|
|
items: [],
|
|
|
|
total: 0,
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
page: query.page || 1,
|
|
|
|
totalPages: 1,
|
|
|
|
limit: 16,
|
|
|
|
artist: "",
|
|
|
|
format: "",
|
|
|
|
year: "",
|
|
|
|
genre: "",
|
|
|
|
style: "",
|
|
|
|
sortOrder: "artists_sort-asc",
|
|
|
|
sort: "artists_sort",
|
|
|
|
order: "asc",
|
|
|
|
itemId: null,
|
|
|
|
showModalDelete: false,
|
|
|
|
showModalShare: false,
|
|
|
|
// eslint-disable-next-line no-undef
|
2023-03-23 14:34:18 +01:00
|
|
|
shareLink: `/collection/${userId}`,
|
2023-03-19 10:41:59 +01:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
isPublicCollection,
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
query,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
methods: {
|
2023-03-22 15:01:27 +01:00
|
|
|
formatParams(param) {
|
|
|
|
return param.replace("&", "%26").replace("+", "%2B");
|
|
|
|
},
|
2023-03-19 10:41:59 +01:00
|
|
|
fetch() {
|
|
|
|
this.loading = true;
|
|
|
|
this.total = 0;
|
|
|
|
|
|
|
|
const queryString = window.location.search;
|
|
|
|
const urlParams = new URLSearchParams(queryString);
|
|
|
|
const entries = urlParams.entries();
|
|
|
|
|
|
|
|
const sortOrder = {
|
2022-10-30 21:48:49 +01:00
|
|
|
sort: "artists_sort",
|
|
|
|
order: "asc",
|
|
|
|
};
|
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
for (const entry of entries) {
|
|
|
|
const [key, value] = entry;
|
|
|
|
switch (key) {
|
|
|
|
case "artists_sort":
|
|
|
|
this.artist = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (["order", "sort"].indexOf(key) !== -1) {
|
|
|
|
sortOrder[key] = value;
|
|
|
|
}
|
|
|
|
this[key] = value;
|
2022-10-30 21:48:49 +01:00
|
|
|
}
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
this.sortOrder = `${sortOrder.sort}-${sortOrder.order}`;
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
let url = `/api/v1/albums?page=${this.page}&limit=${this.limit}&sort=${this.sort}&order=${this.order}`;
|
|
|
|
if (this.artist) {
|
2023-03-23 14:34:18 +01:00
|
|
|
url += `&artist=${this.formatParams(this.artist)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
|
|
|
if (this.format) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&format=${this.formatParams(this.format)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
|
|
|
if (this.year) {
|
|
|
|
url += `&year=${this.year}`;
|
|
|
|
}
|
|
|
|
if (this.genre) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&genre=${this.formatParams(this.genre)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
|
|
|
if (this.style) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&style=${this.formatParams(this.style)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
axios
|
|
|
|
.get(url)
|
|
|
|
.then((response) => {
|
|
|
|
this.items = response.data.rows;
|
|
|
|
this.total = response.data.count || 0;
|
|
|
|
this.totalPages =
|
|
|
|
parseInt(response.data.count / this.limit, 10) +
|
|
|
|
(response.data.count % this.limit > 0 ? 1 : 0);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
showToastr(
|
|
|
|
err.response?.data?.message ||
|
|
|
|
"Impossible de charger votre collection"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
changeUrl() {
|
|
|
|
let url = `?page=${this.page}&limit=${this.limit}&sort=${this.sort}&order=${this.order}`;
|
|
|
|
if (this.artist) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&artists_sort=${this.formatParams(this.artist)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
|
|
|
if (this.format) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&format=${this.formatParams(this.format)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
|
|
|
if (this.year) {
|
|
|
|
url += `&year=${this.year}`;
|
|
|
|
}
|
|
|
|
if (this.genre) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&genre=${this.formatParams(this.genre)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
|
|
|
if (this.style) {
|
2023-03-22 15:01:27 +01:00
|
|
|
url += `&style=${this.formatParams(this.style)}`;
|
2023-03-19 10:41:59 +01:00
|
|
|
}
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
window.location.href = url;
|
|
|
|
},
|
|
|
|
next(event) {
|
|
|
|
event.preventDefault();
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
this.page += 1;
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
this.changeUrl();
|
|
|
|
},
|
|
|
|
previous(event) {
|
|
|
|
event.preventDefault();
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
this.page -= 1;
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
this.changeUrl();
|
|
|
|
},
|
|
|
|
goTo(page) {
|
|
|
|
this.page = page;
|
|
|
|
|
|
|
|
this.changeUrl();
|
|
|
|
},
|
|
|
|
changeSort() {
|
|
|
|
const [sort, order] = this.sortOrder.split("-");
|
|
|
|
this.sort = sort;
|
|
|
|
this.order = order;
|
|
|
|
this.page = 1;
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
this.changeUrl();
|
|
|
|
},
|
|
|
|
changeFilter() {
|
|
|
|
this.page = 1;
|
|
|
|
|
|
|
|
this.changeUrl();
|
|
|
|
},
|
|
|
|
showMoreFilters() {
|
|
|
|
this.moreFilters = !this.moreFilters;
|
|
|
|
},
|
|
|
|
toggleModal() {
|
|
|
|
this.showModalDelete = !this.showModalDelete;
|
|
|
|
},
|
|
|
|
toggleModalShare() {
|
|
|
|
this.showModalShare = !this.showModalShare;
|
|
|
|
},
|
|
|
|
showConfirmDelete(itemId) {
|
|
|
|
this.itemId = itemId;
|
|
|
|
this.toggleModal();
|
|
|
|
},
|
|
|
|
deleteItem() {
|
2023-09-22 08:46:43 +02:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
if (vueType !== "private") {
|
2023-03-19 10:41:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-09-22 08:46:43 +02:00
|
|
|
return axios
|
2023-03-19 10:41:59 +01:00
|
|
|
.delete(`/api/v1/albums/${this.itemId}`)
|
|
|
|
.then(() => {
|
|
|
|
this.fetch();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
showToastr(
|
|
|
|
err.response?.data?.message ||
|
|
|
|
"Impossible de supprimer cet album"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.toggleModal();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
shareCollection() {
|
2023-09-22 08:46:43 +02:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
if (vueType !== "private") {
|
2023-03-19 10:41:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-09-22 08:46:43 +02:00
|
|
|
return axios
|
2023-03-19 10:41:59 +01:00
|
|
|
.patch(`/api/v1/me`, {
|
|
|
|
isPublicCollection: !this.isPublicCollection,
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
this.isPublicCollection = res.data.isPublicCollection;
|
2022-10-30 21:48:49 +01:00
|
|
|
|
2023-03-19 10:41:59 +01:00
|
|
|
if (this.isPublicCollection) {
|
|
|
|
showToastr(
|
|
|
|
"Votre collection est désormais publique",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
showToastr(
|
|
|
|
"Votre collection n'est plus partagée",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
showToastr(
|
|
|
|
err.response?.data?.message ||
|
|
|
|
"Impossible de supprimer cet album"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.toggleModalShare();
|
|
|
|
});
|
2022-10-30 21:48:49 +01:00
|
|
|
},
|
2023-03-23 14:34:18 +01:00
|
|
|
renderAlbumTitle(item) {
|
2023-09-22 08:46:43 +02:00
|
|
|
let render = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < item.artists.length; i += 1) {
|
|
|
|
const { name, join } = item.artists[i];
|
|
|
|
render += `${name} ${join ? `${join} ` : ""}`;
|
2023-03-23 14:34:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render += `- ${item.title}`;
|
|
|
|
|
|
|
|
return render;
|
2023-09-22 08:46:43 +02:00
|
|
|
},
|
2023-03-19 10:41:59 +01:00
|
|
|
},
|
2023-09-22 08:46:43 +02:00
|
|
|
}).mount("#collection");
|