2021-12-01 03:02:40 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
import LazyBookCard from '@/components/cards/LazyBookCard'
|
|
|
|
import LazySeriesCard from '@/components/cards/LazySeriesCard'
|
|
|
|
import LazyCollectionCard from '@/components/cards/LazyCollectionCard'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
cardsHelpers: {
|
|
|
|
mountEntityCard: this.mountEntityCard
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getComponentClass() {
|
|
|
|
if (this.entityName === 'series') return Vue.extend(LazySeriesCard)
|
|
|
|
if (this.entityName === 'collections') return Vue.extend(LazyCollectionCard)
|
|
|
|
return Vue.extend(LazyBookCard)
|
|
|
|
},
|
|
|
|
async mountEntityCard(index) {
|
|
|
|
var shelf = Math.floor(index / this.entitiesPerShelf)
|
|
|
|
var shelfEl = document.getElementById(`shelf-${shelf}`)
|
|
|
|
if (!shelfEl) {
|
|
|
|
console.error('invalid shelf', shelf, 'book index', index)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.entityIndexesMounted.push(index)
|
|
|
|
if (this.entityComponentRefs[index]) {
|
|
|
|
var bookComponent = this.entityComponentRefs[index]
|
|
|
|
shelfEl.appendChild(bookComponent.$el)
|
|
|
|
if (this.isSelectionMode) {
|
|
|
|
bookComponent.setSelectionMode(true)
|
2022-03-13 23:10:48 +01:00
|
|
|
if (this.selectedLibraryItems.includes(bookComponent.libraryItemId) || this.isSelectAll) {
|
2021-12-01 03:02:40 +01:00
|
|
|
bookComponent.selected = true
|
|
|
|
} else {
|
|
|
|
bookComponent.selected = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bookComponent.setSelectionMode(false)
|
|
|
|
}
|
|
|
|
bookComponent.isHovering = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var shelfOffsetY = 16
|
|
|
|
var row = index % this.entitiesPerShelf
|
|
|
|
var shelfOffsetX = row * this.totalEntityCardWidth + this.bookshelfMarginLeft
|
|
|
|
|
|
|
|
var ComponentClass = this.getComponentClass()
|
|
|
|
|
2021-12-02 22:49:03 +01:00
|
|
|
var props = {
|
|
|
|
index,
|
|
|
|
width: this.entityWidth,
|
|
|
|
height: this.entityHeight,
|
2021-12-28 22:50:17 +01:00
|
|
|
bookCoverAspectRatio: this.bookCoverAspectRatio,
|
|
|
|
bookshelfView: this.bookshelfView
|
2021-12-02 22:49:03 +01:00
|
|
|
}
|
|
|
|
if (this.entityName === 'series-books') props.showVolumeNumber = true
|
2022-02-14 23:01:53 +01:00
|
|
|
if (this.entityName === 'books') {
|
|
|
|
props.filterBy = this.filterBy
|
|
|
|
props.orderBy = this.orderBy
|
|
|
|
props.sortingIgnorePrefix = !!this.sortingIgnorePrefix
|
|
|
|
}
|
2021-12-02 22:49:03 +01:00
|
|
|
|
2021-12-01 03:02:40 +01:00
|
|
|
var _this = this
|
|
|
|
var instance = new ComponentClass({
|
2021-12-02 22:49:03 +01:00
|
|
|
propsData: props,
|
2021-12-01 03:02:40 +01:00
|
|
|
created() {
|
|
|
|
this.$on('edit', (entity) => {
|
|
|
|
if (_this.editEntity) _this.editEntity(entity)
|
|
|
|
})
|
|
|
|
this.$on('select', (entity) => {
|
|
|
|
if (_this.selectEntity) _this.selectEntity(entity)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.entityComponentRefs[index] = instance
|
|
|
|
|
|
|
|
instance.$mount()
|
|
|
|
instance.$el.style.transform = `translate3d(${shelfOffsetX}px, ${shelfOffsetY}px, 0px)`
|
2021-12-18 03:52:11 +01:00
|
|
|
instance.$el.classList.add('absolute', 'top-0', 'left-0')
|
2021-12-01 03:02:40 +01:00
|
|
|
shelfEl.appendChild(instance.$el)
|
|
|
|
|
|
|
|
if (this.entities[index]) {
|
|
|
|
instance.setEntity(this.entities[index])
|
|
|
|
}
|
|
|
|
if (this.isSelectionMode) {
|
|
|
|
instance.setSelectionMode(true)
|
2022-03-13 23:10:48 +01:00
|
|
|
if (instance.libraryItemId && this.selectedLibraryItems.includes(instance.libraryItemId) || this.isSelectAll) {
|
2021-12-01 03:02:40 +01:00
|
|
|
instance.selected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|