Skip to content

Commit

Permalink
feat(webui): autofill series and number from metadata during book import
Browse files Browse the repository at this point in the history
Closes: #998
  • Loading branch information
gotson committed Dec 14, 2023
1 parent 3843f77 commit 5b75345
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 28 additions & 7 deletions komga-webui/src/components/FileImportRow.vue
Expand Up @@ -27,11 +27,11 @@

<!-- Series picker -->
<td @click="modalSeriesPicker = true" style="cursor: pointer">
<template v-if="selectedSeries">{{ selectedSeries.metadata.title }}</template>
<template v-if="selectedSeries">{{ selectedSeries.title }}</template>
<template v-else>
<div style="height: 2em" class="missing"></div>
</template>
<series-picker-dialog v-model="modalSeriesPicker" :series.sync="selectedSeries" :include-oneshots="false"/>
<series-picker-dialog v-model="modalSeriesPicker" @update:series="pickedSeries" :include-oneshots="false"/>
</td>

<!-- Book number chooser -->
Expand Down Expand Up @@ -129,6 +129,7 @@ import TransientBookViewerDialog from '@/components/dialogs/TransientBookViewerD
import {bookPageUrl, transientBookPageUrl} from '@/functions/urls'
import {convertErrorCodes} from '@/functions/error-codes'
import FileNameChooserDialog from '@/components/dialogs/FileNameChooserDialog.vue'
import {ReadListRequestBookMatchSeriesDto} from '@/types/komga-readlists'
export default Vue.extend({
name: 'FileImportRow',
Expand Down Expand Up @@ -163,7 +164,10 @@ export default Vue.extend({
},
series: {
handler(val) {
if (val) this.selectedSeries = this.$_.cloneDeep(val)
if (val) this.selectedSeries = {
seriesId: val.id,
title: val.metadata.title,
}
},
immediate: true,
},
Expand All @@ -185,7 +189,7 @@ export default Vue.extend({
convertErrorCodes,
innerSelect: false,
bookAnalyzed: undefined as unknown as TransientBookDto,
selectedSeries: undefined as SeriesDto | undefined,
selectedSeries: undefined as ReadListRequestBookMatchSeriesDto | undefined,
seriesBooks: [] as BookDto[],
bookToUpgrade: undefined as BookDto | undefined,
bookToUpgradePages: [] as PageDto[],
Expand Down Expand Up @@ -230,7 +234,7 @@ export default Vue.extend({
importPayload(): BookImportDto | undefined {
if (this.error || !this.selectedSeries) return undefined
return {
seriesId: this.selectedSeries?.id,
seriesId: this.selectedSeries?.seriesId,
sourceFile: this.book.url,
upgradeBookId: this.bookToUpgrade?.id,
destinationName: this.destinationName,
Expand All @@ -240,10 +244,21 @@ export default Vue.extend({
methods: {
async analyze(book: TransientBookDto) {
this.bookAnalyzed = await this.$komgaTransientBooks.analyze(book.id)
this.getSeries(this.bookAnalyzed.seriesId)
this.bookNumber = this.bookAnalyzed.number
},
async getSeriesBooks(series: SeriesDto) {
async getSeries(seriesId?: string) {
if (seriesId) {
const seriesDto = await this.$komgaSeries.getOneSeries(seriesId)
this.selectedSeries = {
seriesId: seriesDto.id,
title: seriesDto.metadata.title,
}
}
},
async getSeriesBooks(series: ReadListRequestBookMatchSeriesDto) {
if (series) {
this.seriesBooks = (await this.$komgaSeries.getBooks(series.id, {unpaged: true})).content
this.seriesBooks = (await this.$komgaSeries.getBooks(series.seriesId, {unpaged: true})).content
this.checkForUpgrade(this.bookNumber)
}
},
Expand All @@ -252,6 +267,12 @@ export default Vue.extend({
if (this.bookToUpgrade) this.bookToUpgradePages = await this.$komgaBooks.getBookPages(this.bookToUpgrade.id)
else this.bookToUpgradePages = []
},
pickedSeries(series: SeriesDto) {
this.selectedSeries = {
seriesId: series.id,
title: series.metadata.title,
}
},
},
})
</script>
Expand Down
2 changes: 2 additions & 0 deletions komga-webui/src/types/komga-transientbooks.ts
Expand Up @@ -12,4 +12,6 @@ export interface TransientBookDto {
pages: PageDto[],
files: string[],
comment: string,
number?: number,
seriesId?: string,
}

0 comments on commit 5b75345

Please sign in to comment.