mirror of
https://github.com/gotson/komga.git
synced 2025-12-30 04:12:51 +01:00
refactor(webui): editSeriesDialog.series can take an object or an array
This commit is contained in:
parent
881806ed1c
commit
bfaad53669
4 changed files with 37 additions and 43 deletions
|
|
@ -144,7 +144,7 @@ export default Vue.extend({
|
|||
props: {
|
||||
value: Boolean,
|
||||
series: {
|
||||
type: Array as () => SeriesDto[],
|
||||
type: [Object as () => SeriesDto, Array as () => SeriesDto[]],
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
|
@ -161,32 +161,33 @@ export default Vue.extend({
|
|||
},
|
||||
computed: {
|
||||
multiple (): boolean {
|
||||
return this.series.length > 1
|
||||
return Array.isArray(this.series)
|
||||
},
|
||||
seriesStatus (): string[] {
|
||||
return Object.keys(SeriesStatus).map(x => capitalize(x))
|
||||
},
|
||||
dialogTitle (): string {
|
||||
return this.multiple
|
||||
? `Edit ${this.series.length} series`
|
||||
: `Edit ${this.$_.get(this.series[0], 'metadata.title')}`
|
||||
? `Edit ${(this.series as SeriesDto[]).length} series`
|
||||
: `Edit ${this.$_.get(this.series, 'metadata.title')}`
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
dialogReset (series: SeriesDto[]) {
|
||||
if (series.length === 0) return
|
||||
if (series.length > 1) {
|
||||
dialogReset (series: SeriesDto | SeriesDto[]) {
|
||||
if (Array.isArray(series) && series.length === 0) return
|
||||
if (Array.isArray(series) && series.length > 0) {
|
||||
const status = this.$_.uniq(series.map(x => x.metadata.status))
|
||||
this.form.status = status.length > 1 ? '' : capitalize(status[0])
|
||||
const statusLock = this.$_.uniq(series.map(x => x.metadata.statusLock))
|
||||
this.form.statusLock = statusLock.length > 1 ? false : statusLock[0]
|
||||
} else {
|
||||
this.form.status = capitalize(series[0].metadata.status)
|
||||
this.form.statusLock = series[0].metadata.statusLock
|
||||
this.form.title = series[0].metadata.title
|
||||
this.form.titleLock = series[0].metadata.titleLock
|
||||
this.form.titleSort = series[0].metadata.titleSort
|
||||
this.form.titleSortLock = series[0].metadata.titleSortLock
|
||||
const s = series as SeriesDto
|
||||
this.form.status = capitalize(s.metadata.status)
|
||||
this.form.statusLock = s.metadata.statusLock
|
||||
this.form.title = s.metadata.title
|
||||
this.form.titleLock = s.metadata.titleLock
|
||||
this.form.titleSort = s.metadata.titleSort
|
||||
this.form.titleSortLock = s.metadata.titleSortLock
|
||||
}
|
||||
},
|
||||
dialogCancel () {
|
||||
|
|
@ -203,7 +204,8 @@ export default Vue.extend({
|
|||
},
|
||||
async editSeries () {
|
||||
const updated = [] as SeriesDto[]
|
||||
for (const s of this.series) {
|
||||
const toUpdate = (this.multiple ? this.series : [this.series]) as SeriesDto[]
|
||||
for (const s of toUpdate) {
|
||||
try {
|
||||
if (this.form.status === '') {
|
||||
return
|
||||
|
|
@ -229,7 +231,7 @@ export default Vue.extend({
|
|||
updated.push(s)
|
||||
}
|
||||
}
|
||||
this.$emit('update:series', updated)
|
||||
this.$emit('update:series', this.multiple ? updated : updated[0])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ export default mixins(VisibleElements).extend({
|
|||
library: undefined as LibraryDto | undefined,
|
||||
series: [] as SeriesDto[],
|
||||
selectedSeries: [] as SeriesDto[],
|
||||
editSeriesSingle: [] as SeriesDto[],
|
||||
editSeriesSingle: {} as SeriesDto,
|
||||
pagesState: [] as LoadState[],
|
||||
pageSize: 20,
|
||||
totalElements: null as number | null,
|
||||
|
|
@ -183,17 +183,15 @@ export default mixins(VisibleElements).extend({
|
|||
val.forEach(s => {
|
||||
const index = this.series.findIndex(x => x.id === s.id)
|
||||
if (index !== -1) {
|
||||
this.series[index] = s
|
||||
this.series.splice(index, 1, s)
|
||||
}
|
||||
})
|
||||
},
|
||||
editSeriesSingle (val: SeriesDto[]) {
|
||||
val.forEach(s => {
|
||||
const index = this.series.findIndex(x => x.id === s.id)
|
||||
if (index !== -1) {
|
||||
this.series[index] = s
|
||||
}
|
||||
})
|
||||
editSeriesSingle (val: SeriesDto) {
|
||||
const index = this.series.findIndex(x => x.id === val.id)
|
||||
if (index !== -1) {
|
||||
this.series.splice(index, 1, val)
|
||||
}
|
||||
}
|
||||
},
|
||||
async created () {
|
||||
|
|
@ -321,7 +319,7 @@ export default mixins(VisibleElements).extend({
|
|||
}
|
||||
},
|
||||
singleEdit (series: SeriesDto) {
|
||||
this.editSeriesSingle = [series]
|
||||
this.editSeriesSingle = series
|
||||
this.dialogEditSingle = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
</v-container>
|
||||
|
||||
<edit-series-dialog v-model="dialogEdit"
|
||||
:series.sync="seriesArray"/>
|
||||
:series.sync="series"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -136,14 +136,6 @@ export default mixins(VisibleElements).extend({
|
|||
},
|
||||
thumbnailUrl (): string {
|
||||
return seriesThumbnailUrl(this.seriesId)
|
||||
},
|
||||
seriesArray: {
|
||||
get (): SeriesDto[] {
|
||||
return [this.series]
|
||||
},
|
||||
set (val: SeriesDto[]) {
|
||||
this.series = val[0]
|
||||
}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ export default Vue.extend({
|
|||
updatedSeries: Array(pageSize).fill(null) as SeriesDto[],
|
||||
books: Array(pageSize).fill(null) as BookDto[],
|
||||
pageSize: pageSize,
|
||||
editSeriesSingle: [] as SeriesDto[],
|
||||
editSeriesSingle: {} as SeriesDto,
|
||||
dialogEditSingle: false
|
||||
}
|
||||
},
|
||||
|
|
@ -112,13 +112,15 @@ export default Vue.extend({
|
|||
}
|
||||
},
|
||||
watch: {
|
||||
editSeriesSingle (val: SeriesDto[]) {
|
||||
val.forEach(s => {
|
||||
const index = this.newSeries.findIndex(x => x.id === s.id)
|
||||
if (index !== -1) {
|
||||
this.newSeries[index] = s
|
||||
}
|
||||
})
|
||||
editSeriesSingle (val: SeriesDto) {
|
||||
let index = this.newSeries.findIndex(x => x.id === val.id)
|
||||
if (index !== -1) {
|
||||
this.newSeries.splice(index, 1, val)
|
||||
}
|
||||
index = this.updatedSeries.findIndex(x => x.id === val.id)
|
||||
if (index !== -1) {
|
||||
this.updatedSeries.splice(index, 1, val)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -137,7 +139,7 @@ export default Vue.extend({
|
|||
this.books = (await this.$komgaBooks.getBooks(undefined, pageRequest)).content
|
||||
},
|
||||
singleEdit (series: SeriesDto) {
|
||||
this.editSeriesSingle = [series]
|
||||
this.editSeriesSingle = series
|
||||
this.dialogEditSingle = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue