2021-10-05 05:11:42 +02:00
< template >
2021-10-13 03:07:42 +02:00
< div class = "w-full px-4 h-12 border border-white border-opacity-10 flex items-center relative -mt-px" : class = "selected ? 'bg-primary bg-opacity-50' : 'hover:bg-primary hover:bg-opacity-25'" @ mouseover = "mouseover = true" @ mouseleave = "mouseover = false" >
2021-10-05 05:11:42 +02:00
< div v -show = " selected " class = "absolute top-0 left-0 h-full w-0.5 bg-warning z-10" / >
2022-03-04 02:03:34 +01:00
< widgets -library -icon v -if = " ! libraryScan " :icon ="library.icon" :size ="6" class = "text-white" : class = "isHovering ? 'text-opacity-90' : 'text-opacity-50'" / >
2021-10-05 05:11:42 +02:00
< svg v -else viewBox = "0 0 24 24" class = "h-6 w-6 text-white text-opacity-50 animate-spin" >
< path fill = "currentColor" d = "M12,4V2A10,10 0 0,0 2,12H4A8,8 0 0,1 12,4Z" / >
< / svg >
2021-10-13 03:07:42 +02:00
< p class = "text-xl font-book pl-4 hover:underline cursor-pointer" @ click.stop = " $ emit ( ' click ' , library ) " > { { library . name } } < / p >
2021-10-05 05:11:42 +02:00
< div class = "flex-grow" / >
2022-04-12 02:42:09 +02:00
< ui -btn v-show ="isHovering && !libraryScan" small color="success" @click.stop="scan" > Scan < / ui -btn >
< ui -btn v-show ="isHovering && !libraryScan" small color="bg" class="ml-2" @click.stop="forceScan" > Force Re -Scan < / ui -btn >
2022-02-16 01:33:33 +01:00
2022-04-21 01:05:09 +02:00
< ui -btn v-show ="isHovering && !libraryScan && isBookLibrary" small color="bg" class="ml-2" @click.stop="matchAll" > Match Books < / ui -btn >
2022-02-16 01:33:33 +01:00
2022-04-12 02:42:09 +02:00
< span v-show ="isHovering && !libraryScan && showEdit" class="material-icons text-xl text-gray-300 hover:text-gray-50 ml-4 cursor-pointer" @click.stop="editClick" > edit < / span >
< span v-show ="!libraryScan && isHovering && showEdit && !isDeleting" class="material-icons text-xl text-gray-300 ml-3" :class="isMain ? 'text-opacity-5 cursor-not-allowed' : 'hover:text-gray-50 cursor-pointer'" @click.stop="deleteClick" > delete < / span >
2021-10-13 03:07:42 +02:00
< div v-show ="isDeleting" class="text-xl text-gray-300 ml-3 animate-spin" >
2021-10-10 23:36:21 +02:00
< svg viewBox = "0 0 24 24" class = "w-6 h-6" >
< path fill = "currentColor" d = "M12,4V2A10,10 0 0,0 2,12H4A8,8 0 0,1 12,4Z" / >
< / svg >
< / div >
2022-06-19 11:03:05 +02:00
< span class = "material-icons text-xxl text-gray-300 hover:text-gray-50 ml-4 cursor-pointer" > reorder < / span >
2021-10-05 05:11:42 +02:00
< / div >
< / template >
< script >
export default {
props : {
library : {
type : Object ,
default : ( ) => { }
} ,
selected : Boolean ,
2021-10-13 03:07:42 +02:00
showEdit : Boolean ,
dragging : Boolean
2021-10-05 05:11:42 +02:00
} ,
data ( ) {
return {
2021-10-10 23:36:21 +02:00
mouseover : false ,
isDeleting : false
2021-10-05 05:11:42 +02:00
}
} ,
computed : {
2021-10-13 03:07:42 +02:00
isHovering ( ) {
return this . mouseover && ! this . dragging
} ,
2021-10-05 05:11:42 +02:00
isMain ( ) {
return this . library . id === 'main'
} ,
libraryScan ( ) {
return this . $store . getters [ 'scanners/getLibraryScan' ] ( this . library . id )
2022-04-21 01:05:09 +02:00
} ,
mediaType ( ) {
return this . library . mediaType
} ,
isBookLibrary ( ) {
return this . mediaType === 'book'
2021-10-05 05:11:42 +02:00
}
} ,
methods : {
2022-02-16 01:33:33 +01:00
matchAll ( ) {
this . $axios
2022-04-21 01:05:09 +02:00
. $post ( ` /api/libraries/ ${ this . library . id } /matchall ` )
2022-02-16 01:33:33 +01:00
. then ( ( ) => {
console . log ( 'Starting scan for matches' )
} )
. catch ( ( error ) => {
console . error ( 'Failed' , error )
var errorMsg = err . response ? err . response . data : ''
this . $toast . error ( errorMsg || 'Match all failed' )
} )
} ,
2021-10-05 05:11:42 +02:00
editClick ( ) {
this . $emit ( 'edit' , this . library )
} ,
scan ( ) {
2022-05-18 23:33:24 +02:00
this . $store
. dispatch ( 'libraries/requestLibraryScan' , { libraryId : this . library . id } )
. then ( ( ) => {
this . $toast . success ( 'Library scan started' )
} )
. catch ( ( error ) => {
console . error ( 'Failed to start scan' , error )
this . $toast . error ( 'Failed to start scan' )
} )
2021-10-10 23:36:21 +02:00
} ,
2021-12-05 00:57:47 +01:00
forceScan ( ) {
2022-05-18 23:36:54 +02:00
if ( confirm ( ` Force Re-Scan will scan all files again like a fresh scan. Audio file ID3 tags, OPF files, and text files will be probed/parsed to be used for the library item. \ n \ nAre you sure you want to force re-scan? ` ) ) {
this . $store
. dispatch ( 'libraries/requestLibraryScan' , { libraryId : this . library . id , force : 1 } )
. then ( ( ) => {
this . $toast . success ( 'Library scan started' )
} )
. catch ( ( error ) => {
console . error ( 'Failed to start scan' , error )
this . $toast . error ( 'Failed to start scan' )
} )
}
2021-12-05 00:57:47 +01:00
} ,
2021-10-10 23:36:21 +02:00
deleteClick ( ) {
if ( this . isMain ) return
if ( confirm ( ` Are you sure you want to permanently delete library " ${ this . library . name } "? ` ) ) {
this . isDeleting = true
this . $axios
2021-11-22 03:00:40 +01:00
. $delete ( ` /api/libraries/ ${ this . library . id } ` )
2021-10-10 23:36:21 +02:00
. then ( ( data ) => {
this . isDeleting = false
if ( data . error ) {
this . $toast . error ( data . error )
} else {
this . $toast . success ( 'Library deleted' )
}
} )
. catch ( ( error ) => {
console . error ( 'Failed to delete library' , error )
this . $toast . error ( 'Failed to delete library' )
this . isDeleting = false
} )
}
2021-10-05 05:11:42 +02:00
}
} ,
mounted ( ) { }
}
< / script >