2022-10-28 22:56:04 +02:00
|
|
|
if (typeof item !== "undefined") {
|
2022-10-28 22:40:02 +02:00
|
|
|
Vue.createApp({
|
|
|
|
data() {
|
|
|
|
return {
|
2022-10-28 22:56:04 +02:00
|
|
|
// eslint-disable-next-line no-undef
|
2022-10-28 22:40:02 +02:00
|
|
|
item,
|
|
|
|
tracklist: [],
|
|
|
|
identifiers: [],
|
|
|
|
modalIsVisible: false,
|
2022-10-28 22:56:04 +02:00
|
|
|
identifiersMode: "preview",
|
2022-10-28 22:40:02 +02:00
|
|
|
identifiersPreviewLength: 16,
|
|
|
|
preview: null,
|
|
|
|
index: null,
|
|
|
|
showModalDelete: false,
|
2022-10-28 22:56:04 +02:00
|
|
|
};
|
2022-10-28 22:40:02 +02:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.setTrackList();
|
|
|
|
this.setIdentifiers();
|
|
|
|
|
|
|
|
window.addEventListener("keydown", this.changeImage);
|
|
|
|
},
|
|
|
|
destroyed() {
|
2022-10-28 22:56:04 +02:00
|
|
|
window.removeEventListener("keydown", this.changeImage);
|
2022-10-28 22:40:02 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setIdentifiers() {
|
|
|
|
this.identifiers = [];
|
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
const max =
|
|
|
|
this.identifiersMode === "preview" &&
|
|
|
|
this.item.identifiers.length > this.identifiersPreviewLength
|
|
|
|
? this.identifiersPreviewLength
|
|
|
|
: this.item.identifiers.length;
|
2022-10-28 22:40:02 +02:00
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
for (let i = 0; i < max; i += 1) {
|
2022-10-28 22:40:02 +02:00
|
|
|
this.identifiers.push(this.item.identifiers[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setTrackList() {
|
|
|
|
let subTrack = {
|
2022-10-28 22:56:04 +02:00
|
|
|
type: null,
|
|
|
|
title: null,
|
|
|
|
tracks: [],
|
|
|
|
};
|
|
|
|
for (let i = 0; i < this.item.tracklist.length; i += 1) {
|
|
|
|
const { type_, title, position, duration, extraartists } =
|
|
|
|
this.item.tracklist[i];
|
2022-10-28 22:40:02 +02:00
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
if (type_ === "heading") {
|
|
|
|
if (subTrack.type) {
|
|
|
|
this.tracklist.push(subTrack);
|
|
|
|
subTrack = {
|
|
|
|
type: null,
|
|
|
|
title: null,
|
|
|
|
tracks: [],
|
|
|
|
};
|
|
|
|
}
|
2022-10-28 22:40:02 +02:00
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
subTrack.type = type_;
|
|
|
|
subTrack.title = title;
|
|
|
|
} else {
|
|
|
|
subTrack.tracks.push({
|
|
|
|
title,
|
|
|
|
position,
|
|
|
|
duration,
|
|
|
|
extraartists,
|
|
|
|
});
|
|
|
|
}
|
2022-10-28 22:40:02 +02:00
|
|
|
}
|
2022-10-28 22:56:04 +02:00
|
|
|
this.tracklist.push(subTrack);
|
2022-10-28 22:40:02 +02:00
|
|
|
},
|
|
|
|
setImage() {
|
|
|
|
this.preview = this.item.images[this.index].uri;
|
|
|
|
},
|
|
|
|
showGallery(event) {
|
2022-10-28 22:56:04 +02:00
|
|
|
const item =
|
|
|
|
event.target.tagName === "IMG"
|
|
|
|
? event.target.parentElement
|
|
|
|
: event.target;
|
2022-10-28 22:40:02 +02:00
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
const { index } = item.dataset;
|
2022-10-28 22:40:02 +02:00
|
|
|
|
|
|
|
this.index = Number(index);
|
|
|
|
this.modalIsVisible = true;
|
|
|
|
|
|
|
|
this.setImage();
|
|
|
|
},
|
|
|
|
toggleModal() {
|
|
|
|
this.modalIsVisible = !this.modalIsVisible;
|
|
|
|
},
|
|
|
|
previous() {
|
2022-10-28 22:56:04 +02:00
|
|
|
this.index =
|
|
|
|
this.index > 0
|
|
|
|
? this.index - 1
|
|
|
|
: this.item.images.length - 1;
|
2022-10-28 22:40:02 +02:00
|
|
|
this.setImage();
|
|
|
|
},
|
|
|
|
next() {
|
2022-10-28 22:56:04 +02:00
|
|
|
this.index =
|
|
|
|
this.index + 1 === this.item.images.length
|
|
|
|
? 0
|
|
|
|
: this.index + 1;
|
2022-10-28 22:40:02 +02:00
|
|
|
this.setImage();
|
|
|
|
},
|
|
|
|
changeImage(event) {
|
|
|
|
const direction = event.code;
|
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
if (
|
|
|
|
this.modalIsVisible &&
|
|
|
|
["ArrowRight", "ArrowLeft", "Escape"].indexOf(direction) !==
|
|
|
|
-1
|
|
|
|
) {
|
2022-10-28 22:40:02 +02:00
|
|
|
switch (direction) {
|
2022-10-28 22:56:04 +02:00
|
|
|
case "ArrowRight":
|
2022-10-28 22:40:02 +02:00
|
|
|
return this.next();
|
2022-10-28 22:56:04 +02:00
|
|
|
case "ArrowLeft":
|
2022-10-28 22:40:02 +02:00
|
|
|
return this.previous();
|
|
|
|
default:
|
|
|
|
this.modalIsVisible = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-10-28 22:56:04 +02:00
|
|
|
|
|
|
|
return true;
|
2022-10-28 22:40:02 +02:00
|
|
|
},
|
|
|
|
showAllIdentifiers() {
|
2022-10-28 22:56:04 +02:00
|
|
|
this.identifiersMode = "all";
|
2022-10-28 22:40:02 +02:00
|
|
|
this.setIdentifiers();
|
|
|
|
},
|
|
|
|
showLessIdentifiers() {
|
2022-10-28 22:56:04 +02:00
|
|
|
this.identifiersMode = "preview";
|
2022-10-28 22:40:02 +02:00
|
|
|
this.setIdentifiers();
|
|
|
|
|
2022-10-28 22:56:04 +02:00
|
|
|
document
|
|
|
|
.querySelector("#identifiers")
|
|
|
|
.scrollIntoView({ behavior: "smooth" });
|
2022-10-28 22:40:02 +02:00
|
|
|
},
|
|
|
|
showConfirmDelete() {
|
2022-10-28 22:56:04 +02:00
|
|
|
this.toggleModalDelete();
|
2022-10-28 22:40:02 +02:00
|
|
|
},
|
2022-10-28 22:56:04 +02:00
|
|
|
toggleModalDelete() {
|
2022-10-28 22:40:02 +02:00
|
|
|
this.showModalDelete = !this.showModalDelete;
|
|
|
|
},
|
|
|
|
updateItem() {
|
|
|
|
showToastr("Mise à jour en cours…", true);
|
2022-10-28 22:56:04 +02:00
|
|
|
axios
|
|
|
|
.patch(`/api/v1/albums/${this.item._id}`)
|
|
|
|
.then((res) => {
|
2022-10-28 22:40:02 +02:00
|
|
|
showToastr("Mise à jour réalisée avec succès", true);
|
|
|
|
this.item = res.data;
|
2022-10-28 22:45:38 +02:00
|
|
|
|
|
|
|
this.setTrackList();
|
|
|
|
this.setIdentifiers();
|
|
|
|
this.showLessIdentifiers();
|
2022-10-28 22:40:02 +02:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
2022-10-28 22:56:04 +02:00
|
|
|
showToastr(
|
|
|
|
err.response?.data?.message ||
|
|
|
|
"Impossible de mettre à jour cet album",
|
|
|
|
false
|
|
|
|
);
|
2022-10-28 22:40:02 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteItem() {
|
2022-10-28 22:56:04 +02:00
|
|
|
axios
|
|
|
|
.delete(`/api/v1/albums/${this.item._id}`)
|
|
|
|
.then(() => {
|
2022-10-28 22:40:02 +02:00
|
|
|
window.location.href = "/ma-collection";
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2022-10-28 22:56:04 +02:00
|
|
|
showToastr(
|
|
|
|
err.response?.data?.message ||
|
|
|
|
"Impossible de supprimer cet album"
|
|
|
|
);
|
2022-10-28 22:40:02 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
2022-10-28 22:56:04 +02:00
|
|
|
this.toggleModalDelete();
|
2022-10-28 22:40:02 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
goToArtist() {
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
},
|
2022-10-28 22:56:04 +02:00
|
|
|
}).mount("#ma-collection-details");
|
|
|
|
}
|