1 line
No EOL
5.6 KiB
JavaScript
1 line
No EOL
5.6 KiB
JavaScript
import ItemManager from"./../modules/common/itemmanager/itemmanager.js";import BaseItemController from"./../modules/common/itemmanager/baseitemcontroller.js";import globalize from"./../modules/common/globalize.js";import humanedate from"./../modules/humanedate/humanedate.js";import connectionManager from"./../modules/emby-apiclient/connectionmanager.js";import appRouter from"./../modules/approuter.js";function ScheduledTaskController(){BaseItemController.apply(this,arguments)}function humane_elapsed(ticks){var ticks=ticks/1e4/1e3,numdays=Math.floor(ticks%31536e3/86400),numhours=Math.floor(ticks%31536e3%86400/3600),numminutes=Math.floor(ticks%31536e3%86400%3600/60),ticks=Math.round(ticks%31536e3%86400%3600%60);let elapsedStr="";return elapsedStr=(elapsedStr=(elapsedStr=elapsedStr+(1===numdays?numdays+" day ":"")+(1<numdays?numdays+" days ":""))+(1===numhours?numhours+" hour ":"")+(1<numhours?numhours+" hours ":""))+(1===numminutes?numminutes+" minute ":"")+(1<numminutes?numminutes+" minutes ":""),1===ticks?(elapsedStr&&(elapsedStr+="and "),elapsedStr+=ticks+" second"):0===ticks?elapsedStr||(elapsedStr,elapsedStr+=ticks+" seconds"):(elapsedStr&&(elapsedStr+="and "),elapsedStr+=ticks+" seconds"),elapsedStr.trim()}function humane_elapsedFromDates(firstDateStr,secondDateStr){firstDateStr=new Date(firstDateStr);return humane_elapsed(1e4*(new Date(secondDateStr).getTime()-firstDateStr.getTime()))}function getTaskProgressHtml(task){let html="";return"Idle"===task.State?task.LastExecutionResult&&(html+=globalize.translate("LabelScheduledTaskLastRan").replace("{0}",humanedate(task.LastExecutionResult.EndTimeUtc)).replace("{1}",humane_elapsedFromDates(task.LastExecutionResult.StartTimeUtc,task.LastExecutionResult.EndTimeUtc)),"Failed"===task.LastExecutionResult.Status?html+=" <span style='color:#FF0000;'>("+globalize.translate("Failed")+")</span>":"Cancelled"===task.LastExecutionResult.Status?html+=" <span style='color:#0026FF;'>("+globalize.translate("Cancelled")+")</span>":"Aborted"===task.LastExecutionResult.Status&&(html+=" <span style='color:#FF0000;'>"+globalize.translate("LabelAbortedByServerShutdown")+"</span>")):"Running"===task.State?(task=(task.CurrentProgressPercentage||0).toFixed(1),html=(html=(html=(html+='<div class="flex align-items-center">')+'<div class="itemProgressBar itemProgressBarRound flex-grow" title="'+task+'%"><div class="itemProgressBarForeground itemProgressBarForegroundRound" style="width:'+task+'%;">')+"</div></div>")+'<span class="itemProgressBarText">'+task+"%</span></div>"):html+="<span style='color:#FF0000;'>"+globalize.translate("LabelStopping")+"</span>",html}Object.assign(ScheduledTaskController.prototype,BaseItemController.prototype),ScheduledTaskController.prototype.getTypeNames=function(){return["ScheduledTask"]},ScheduledTaskController.prototype.getDisplayName=function(item,options){return item.Name},ScheduledTaskController.prototype.isSingleItemFetchRequired=function(typeName){return!1},ScheduledTaskController.prototype.getDefaultIcon=function(item){return"calendar_month"},ScheduledTaskController.prototype.canDelete=function(item,user){return!1},ScheduledTaskController.prototype.enableLibraryItemDeleteConfirmation=function(){return!1},ScheduledTaskController.prototype.canRefreshMetadata=function(item,user){return!1},ScheduledTaskController.prototype.getNameSortOption=function(itemType){return null},ScheduledTaskController.prototype.canAddToPlaylist=function(item){return!1},ScheduledTaskController.prototype.canAddToCollection=function(item,user){return!1},ScheduledTaskController.prototype.canConvert=function(item,user){return!1},ScheduledTaskController.prototype.canEdit=function(items,user){return!0},ScheduledTaskController.prototype.getEditCommand=function(items){return{name:globalize.translate("Settings"),id:"edit",icon:"settings"}},ScheduledTaskController.prototype.editItems=function(items,options){items=items[0];return appRouter.showItem(items)},ScheduledTaskController.prototype.canRate=function(item){return!1},ScheduledTaskController.prototype.canMarkPlayed=function(item){return!1},ScheduledTaskController.prototype.canEditImages=function(item,user){return!1},ScheduledTaskController.prototype.canEditSubtitles=function(item,user){return!1},ScheduledTaskController.prototype.isDeletePrimaryCommand=function(itemType){return!1},ScheduledTaskController.prototype.getDeleteMessages=function(){return{}},ScheduledTaskController.prototype.deleteItemsInternal=function(options){return Promise.reject()},ScheduledTaskController.prototype.getCommands=function(options){var commands=BaseItemController.prototype.getCommands.apply(this,arguments),options=options.items;return 1===options.length&&("Idle"===(options=options[0]).State?commands.push({name:globalize.translate("Start"),id:"scheduledtask_start",icon:""}):"Running"===options.State&&commands.push({name:globalize.translate("Stop"),id:"scheduledtask_stop",icon:""})),commands},ScheduledTaskController.prototype.executeCommand=function(command,items,options){var item=items[0];switch(command){case"scheduledtask_start":return connectionManager.getApiClient(item).startScheduledTask(item.Id);case"scheduledtask_stop":return connectionManager.getApiClient(item).stopScheduledTask(item.Id);default:return BaseItemController.prototype.executeCommand.apply(this,arguments)}},ScheduledTaskController.prototype.resolveField=function(item,field){return"ScheduledTaskRunInfo"!==field?BaseItemController.prototype.resolveField.apply(this,arguments):getTaskProgressHtml(item)},ScheduledTaskController.prototype.getDurationDisplay=humane_elapsed;let instance=new ScheduledTaskController;ItemManager.registerItemController(instance);export default instance; |