feat: add support for series
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import TracksTable from "./tracks_table.mjs"
|
||||
import IntegrityManager from "./integrity_manager.mjs"
|
||||
import { updateObjectFromJoinedKey } from "./utils.mjs"
|
||||
import { loadMetadata, SeriesMetadata } from "./metadata.mjs"
|
||||
|
||||
export default class Editor {
|
||||
constructor() {
|
||||
@ -18,10 +19,11 @@ export default class Editor {
|
||||
subtitle: new TracksTable(this, "subtitle", "subtitle-tracks", "subtitle_tracks")
|
||||
}
|
||||
|
||||
this.metadata = null
|
||||
this.data = {}
|
||||
this.dirty = false
|
||||
|
||||
this.integrity_mgr = new IntegrityManager(this)
|
||||
this.integrityMgr = new IntegrityManager(this)
|
||||
|
||||
document.getElementById("check-integrity").addEventListener("click", () => this.checkIntegrity())
|
||||
document.getElementById("improve-all").addEventListener("click", () => this.improveAllNames())
|
||||
@ -29,6 +31,14 @@ export default class Editor {
|
||||
document.getElementById("reload").addEventListener("click", () => window.location.reload())
|
||||
document.getElementById("toggle-notifs").addEventListener("click", () => this.toggleNotifications())
|
||||
document.getElementById("close-notifs").addEventListener("click", () => this.closeNotifications())
|
||||
document.getElementById("prev-episode").addEventListener("click", () => this.prevEpisode())
|
||||
document.getElementById("next-episode").addEventListener("click", () => this.nextEpisode())
|
||||
|
||||
this.titleInput = document.getElementById("title")
|
||||
this.titleInput.addEventListener("change", () => {
|
||||
this.data.title = this.titleInput.value
|
||||
this.setDirty()
|
||||
})
|
||||
|
||||
this.setup()
|
||||
}
|
||||
@ -46,14 +56,27 @@ export default class Editor {
|
||||
return null
|
||||
}).then(res => {
|
||||
if (res !== null) {
|
||||
this.data = res
|
||||
this.metadata = loadMetadata(res)
|
||||
this.displayData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
displayData() {
|
||||
document.getElementById("title").value = this.data.title
|
||||
const seriesToolbar = document.getElementById("series-toolbar")
|
||||
if (this.metadata instanceof SeriesMetadata) {
|
||||
seriesToolbar.classList.add("show")
|
||||
const cur = this.metadata.episodeIdx + 1
|
||||
const tot = this.metadata.episodes.length
|
||||
const epMeta = this.metadata.getCurrentEpisode()
|
||||
const season = epMeta.season
|
||||
const episode = epMeta.episode
|
||||
seriesToolbar.querySelector("#cur-episode").innerText = `S${season}E${episode} (${cur} / ${tot})`
|
||||
} else {
|
||||
seriesToolbar.classList.remove("show")
|
||||
}
|
||||
this.data = this.metadata.getData()
|
||||
this.titleInput.value = this.data.title
|
||||
this.tables.audio.loadTracks(this.data.audio_tracks)
|
||||
this.tables.subtitle.loadTracks(this.data.subtitle_tracks)
|
||||
}
|
||||
@ -61,7 +84,7 @@ export default class Editor {
|
||||
save() {
|
||||
fetch(`/api/file/${this.filename}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(this.data),
|
||||
body: JSON.stringify(this.metadata.data),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
@ -100,13 +123,13 @@ export default class Editor {
|
||||
}
|
||||
|
||||
checkIntegrity() {
|
||||
if (this.integrity_mgr.checkIntegrity()) {
|
||||
if (this.integrityMgr.checkIntegrity()) {
|
||||
this.notify("No integrity error detected !", "success")
|
||||
}
|
||||
}
|
||||
|
||||
improveAllNames() {
|
||||
this.integrity_mgr.improveAllNames()
|
||||
this.integrityMgr.improveAllNames()
|
||||
this.notify("Improved all names !", "success")
|
||||
}
|
||||
|
||||
@ -128,4 +151,20 @@ export default class Editor {
|
||||
const hist = document.getElementById("notifs-hist")
|
||||
hist.classList.remove("show")
|
||||
}
|
||||
|
||||
prevEpisode() {
|
||||
if (this.metadata instanceof SeriesMetadata) {
|
||||
if (this.metadata.prev()) {
|
||||
this.displayData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nextEpisode() {
|
||||
if (this.metadata instanceof SeriesMetadata) {
|
||||
if (this.metadata.next()) {
|
||||
this.displayData()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user