2022-08-20 01:41:58 +02:00
< template >
< div class = "w-full h-full relative" >
2022-08-20 21:21:58 +02:00
< div id = "scheduleWrapper" class = "w-full overflow-y-auto px-2 py-4 md:px-6 md:py-6" >
< template v-if ="!feedUrl" >
< widgets -alert type = "warning" class = "text-base mb-4" > No RSS feed URL is set for this podcast < / w i d g e t s - a l e r t >
< / template >
< template v-if ="feedUrl || autoDownloadEpisodes" >
< div class = "flex items-center justify-between mb-4" >
2022-08-20 21:32:38 +02:00
< p class = "text-base md:text-xl font-semibold" > Schedule Automatic Episode Downloads < / p >
< ui -checkbox v -model = " enableAutoDownloadEpisodes " label = "Enable" medium checkbox -bg = " bg " label -class = " pl -2 text -base md : text -lg " / >
2022-08-20 21:21:58 +02:00
< / div >
< div v-if ="enableAutoDownloadEpisodes" class="flex items-center py-2" >
< ui -text -input ref = "maxEpisodesInput" type = "number" v -model = " newMaxEpisodesToKeep " no -spinner :padding-x ="1" text -center class = "w-10 text-base" @change ="updatedMaxEpisodesToKeep" / >
< ui -tooltip text = "Value of 0 sets no max limit. After a new episode is auto-downloaded this will delete the oldest episode if you have more than X episodes. <br>This will only delete 1 episode per new download." >
< p class = "pl-4 text-base" >
Max episodes to keep
2022-11-21 14:18:10 +01:00
< span class = "material-icons icon-text" > info _outlined < / span >
2022-08-20 21:21:58 +02:00
< / p >
< / u i - t o o l t i p >
< / div >
2022-10-26 23:55:16 +02:00
< div v-if ="enableAutoDownloadEpisodes" class="flex items-center py-2" >
2024-02-28 00:17:33 +01:00
< ui -text -input ref = "maxEpisodesToDownloadInput" type = "number" v -model = " newMaxNewEpisodesToDownload " no -spinner :padding-x ="1" text -center class = "w-10 text-base" @change ="updateMaxNewEpisodesToDownload" / >
2022-10-26 23:55:16 +02:00
< ui -tooltip text = "Value of 0 sets no max limit. When checking for new episodes this is the max number of episodes that will be downloaded." >
< p class = "pl-4 text-base" >
Max new episodes to download per check
2022-11-21 14:18:10 +01:00
< span class = "material-icons icon-text" > info _outlined < / span >
2022-10-26 23:55:16 +02:00
< / p >
< / u i - t o o l t i p >
< / div >
2022-08-20 21:21:58 +02:00
< widgets -cron -expression -builder ref = "cronExpressionBuilder" v -if = " enableAutoDownloadEpisodes " v -model = " cronExpression " / >
< / template >
2022-08-20 01:41:58 +02:00
< / div >
2022-08-20 21:21:58 +02:00
< div v-if ="feedUrl || autoDownloadEpisodes" class="absolute bottom-0 left-0 w-full py-2 md:py-4 bg-bg border-t border-white border-opacity-5" >
2022-08-20 01:41:58 +02:00
< div class = "flex items-center px-2 md:px-4" >
< div class = "flex-grow" / >
< ui -btn @click ="save" :disabled ="!isUpdated" : color = "isUpdated ? 'success' : 'primary'" class = "mx-2" > { { isUpdated ? 'Save' : 'No update necessary' } } < / u i - b t n >
< / div >
< / div >
< / div >
< / template >
< script >
export default {
props : {
processing : Boolean ,
libraryItem : {
type : Object ,
default : ( ) => { }
}
} ,
data ( ) {
return {
enableAutoDownloadEpisodes : false ,
2022-08-20 21:21:58 +02:00
cronExpression : null ,
2022-10-26 23:55:16 +02:00
newMaxEpisodesToKeep : 0 ,
newMaxNewEpisodesToDownload : 0
2022-08-20 01:41:58 +02:00
}
} ,
2023-02-21 22:40:15 +01:00
watch : {
libraryItem : {
immediate : true ,
handler ( newVal ) {
if ( newVal ) this . init ( )
}
}
} ,
2022-08-20 01:41:58 +02:00
computed : {
isProcessing : {
get ( ) {
return this . processing
} ,
set ( val ) {
this . $emit ( 'update:processing' , val )
}
} ,
userIsAdminOrUp ( ) {
return this . $store . getters [ 'user/getIsAdminOrUp' ]
} ,
2022-08-20 21:21:58 +02:00
media ( ) {
return this . libraryItem ? this . libraryItem . media || { } : { }
} ,
mediaMetadata ( ) {
return this . media . metadata || { }
} ,
libraryItemId ( ) {
return this . libraryItem ? this . libraryItem . id : null
} ,
feedUrl ( ) {
return this . mediaMetadata . feedUrl
} ,
2022-08-20 01:41:58 +02:00
autoDownloadEpisodes ( ) {
return ! ! this . media . autoDownloadEpisodes
} ,
autoDownloadSchedule ( ) {
return this . media . autoDownloadSchedule
} ,
2022-08-20 21:21:58 +02:00
maxEpisodesToKeep ( ) {
return this . media . maxEpisodesToKeep
2022-08-20 01:41:58 +02:00
} ,
2022-10-26 23:55:16 +02:00
maxNewEpisodesToDownload ( ) {
return this . media . maxNewEpisodesToDownload
} ,
2022-08-20 01:41:58 +02:00
isUpdated ( ) {
2022-10-26 23:55:16 +02:00
return this . autoDownloadSchedule !== this . cronExpression || this . autoDownloadEpisodes !== this . enableAutoDownloadEpisodes || this . maxEpisodesToKeep !== Number ( this . newMaxEpisodesToKeep ) || this . maxNewEpisodesToDownload !== Number ( this . newMaxNewEpisodesToDownload )
2022-08-20 01:41:58 +02:00
}
} ,
methods : {
2022-08-20 21:21:58 +02:00
updatedMaxEpisodesToKeep ( ) {
if ( isNaN ( this . newMaxEpisodesToKeep ) || this . newMaxEpisodesToKeep < 0 ) {
this . newMaxEpisodesToKeep = 0
} else {
this . newMaxEpisodesToKeep = Number ( this . newMaxEpisodesToKeep )
}
2022-08-20 01:41:58 +02:00
} ,
2022-10-26 23:55:16 +02:00
updateMaxNewEpisodesToDownload ( ) {
if ( isNaN ( this . newMaxNewEpisodesToDownload ) || this . newMaxNewEpisodesToDownload < 0 ) {
this . newMaxNewEpisodesToDownload = 0
} else {
this . newMaxNewEpisodesToDownload = Number ( this . newMaxNewEpisodesToDownload )
}
} ,
2022-08-20 01:41:58 +02:00
save ( ) {
// If custom expression input is focused then unfocus it instead of submitting
if ( this . $refs . cronExpressionBuilder && this . $refs . cronExpressionBuilder . checkBlurExpressionInput ) {
if ( this . $refs . cronExpressionBuilder . checkBlurExpressionInput ( ) ) {
return
}
}
2024-02-28 00:17:33 +01:00
if ( this . $refs . maxEpisodesInput ? . isFocused ) {
2022-08-20 21:21:58 +02:00
this . $refs . maxEpisodesInput . blur ( )
2024-02-28 00:17:33 +01:00
}
if ( this . $refs . maxEpisodesToDownloadInput ? . isFocused ) {
this . $refs . maxEpisodesToDownloadInput . blur ( )
2022-08-20 21:21:58 +02:00
}
2022-08-20 01:41:58 +02:00
const updatePayload = {
autoDownloadEpisodes : this . enableAutoDownloadEpisodes
}
if ( this . enableAutoDownloadEpisodes ) {
updatePayload . autoDownloadSchedule = this . cronExpression
}
2024-02-28 00:17:33 +01:00
this . newMaxEpisodesToKeep = Number ( this . newMaxEpisodesToKeep )
2022-08-20 21:21:58 +02:00
if ( this . newMaxEpisodesToKeep !== this . maxEpisodesToKeep ) {
updatePayload . maxEpisodesToKeep = this . newMaxEpisodesToKeep
}
2024-02-28 00:17:33 +01:00
this . newMaxNewEpisodesToDownload = Number ( this . newMaxNewEpisodesToDownload )
2022-10-26 23:55:16 +02:00
if ( this . newMaxNewEpisodesToDownload !== this . maxNewEpisodesToDownload ) {
updatePayload . maxNewEpisodesToDownload = this . newMaxNewEpisodesToDownload
}
2022-08-20 21:21:58 +02:00
2022-08-20 01:41:58 +02:00
this . updateDetails ( updatePayload )
} ,
async updateDetails ( updatePayload ) {
this . isProcessing = true
var updateResult = await this . $axios . $patch ( ` /api/items/ ${ this . libraryItemId } /media ` , updatePayload ) . catch ( ( error ) => {
console . error ( 'Failed to update' , error )
return false
} )
this . isProcessing = false
if ( updateResult ) {
if ( updateResult . updated ) {
this . $toast . success ( 'Item details updated' )
return true
} else {
2022-11-09 00:10:08 +01:00
this . $toast . info ( this . $strings . MessageNoUpdatesWereNecessary )
2022-08-20 01:41:58 +02:00
}
}
return false
2022-08-20 21:21:58 +02:00
} ,
init ( ) {
this . enableAutoDownloadEpisodes = this . autoDownloadEpisodes
this . cronExpression = this . autoDownloadSchedule
this . newMaxEpisodesToKeep = this . maxEpisodesToKeep
2022-10-26 23:55:16 +02:00
this . newMaxNewEpisodesToDownload = this . maxNewEpisodesToDownload
2022-08-20 01:41:58 +02:00
}
} ,
mounted ( ) {
this . init ( )
}
}
< / script >
< style scoped >
# scheduleWrapper {
height : calc ( 100 % - 80 px ) ;
max - height : calc ( 100 % - 80 px ) ;
}
2023-02-21 22:40:15 +01:00
< / style >