jellyfin-web/dashboard-ui/scripts/autoorganizelog.js

355 lines
9.8 KiB
JavaScript
Raw Normal View History

2016-05-07 23:31:08 -07:00
define(['jQuery', 'datetime', 'paper-icon-button-light'], function ($, datetime) {
2014-01-20 23:10:58 -07:00
var query = {
StartIndex: 0,
2016-02-08 19:15:26 -07:00
Limit: 50
2014-01-20 23:10:58 -07:00
};
var currentResult;
function showStatusMessage(id) {
var item = currentResult.Items.filter(function (i) {
2016-04-22 09:27:17 -07:00
return i.Id == id;
2014-01-20 23:10:58 -07:00
})[0];
Dashboard.alert({
title: getStatusText(item, false),
message: item.StatusMessage
});
}
function deleteOriginalFile(page, id) {
var item = currentResult.Items.filter(function (i) {
2016-04-22 09:27:17 -07:00
return i.Id == id;
2014-01-20 23:10:58 -07:00
})[0];
var message = Globalize.translate('MessageFileWillBeDeleted') + '<br/><br/>' + item.OriginalPath + '<br/><br/>' + Globalize.translate('MessageSureYouWishToProceed');
2014-01-20 23:10:58 -07:00
2016-02-22 12:12:06 -07:00
require(['confirm'], function (confirm) {
2014-01-20 23:10:58 -07:00
2016-02-22 12:12:06 -07:00
confirm(message, Globalize.translate('HeaderDeleteFile')).then(function () {
2014-01-20 23:10:58 -07:00
Dashboard.showLoadingMsg();
2014-01-22 10:05:06 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.deleteOriginalFileFromOrganizationResult(id).then(function () {
2014-01-20 23:10:58 -07:00
Dashboard.hideLoadingMsg();
reloadItems(page);
2015-12-14 08:43:03 -07:00
}, onApiFailure);
2016-02-22 12:12:06 -07:00
});
2014-01-20 23:10:58 -07:00
});
}
2016-03-10 13:06:47 -07:00
function organizeFileWithCorrections(page, item) {
2014-01-22 10:05:06 -07:00
2016-03-10 13:06:47 -07:00
showCorrectionPopup(page, item);
}
2016-03-10 13:06:47 -07:00
function showCorrectionPopup(page, item) {
2014-01-22 10:05:06 -07:00
2016-02-12 21:34:47 -07:00
require(['components/fileorganizer/fileorganizer'], function (fileorganizer) {
2014-01-22 10:05:06 -07:00
2016-02-12 21:34:47 -07:00
fileorganizer.show(item).then(function () {
reloadItems(page);
});
});
2014-01-22 10:05:06 -07:00
}
2014-01-20 23:10:58 -07:00
function organizeFile(page, id) {
var item = currentResult.Items.filter(function (i) {
2016-04-22 09:27:17 -07:00
return i.Id == id;
2014-01-20 23:10:58 -07:00
})[0];
2014-01-22 10:05:06 -07:00
if (!item.TargetPath) {
if (item.Type == "Episode") {
2016-03-10 13:06:47 -07:00
organizeFileWithCorrections(page, item);
2014-01-22 10:05:06 -07:00
}
return;
}
var message = Globalize.translate('MessageFollowingFileWillBeMovedFrom') + '<br/><br/>' + item.OriginalPath + '<br/><br/>' + Globalize.translate('MessageDestinationTo') + '<br/><br/>' + item.TargetPath;
if (item.DuplicatePaths.length) {
message += '<br/><br/>' + Globalize.translate('MessageDuplicatesWillBeDeleted');
message += '<br/><br/>' + item.DuplicatePaths.join('<br/>');
}
message += '<br/><br/>' + Globalize.translate('MessageSureYouWishToProceed');
2014-01-20 23:10:58 -07:00
2016-02-22 12:12:06 -07:00
require(['confirm'], function (confirm) {
2014-01-20 23:10:58 -07:00
2016-02-22 12:12:06 -07:00
confirm(message, Globalize.translate('HeaderOrganizeFile')).then(function () {
2014-01-20 23:10:58 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.performOrganization(id).then(function () {
2014-01-20 23:10:58 -07:00
Dashboard.hideLoadingMsg();
reloadItems(page);
2015-12-14 08:43:03 -07:00
}, onApiFailure);
2016-02-22 12:12:06 -07:00
});
2014-01-20 23:10:58 -07:00
});
2014-01-22 10:05:06 -07:00
}
2014-01-20 23:10:58 -07:00
function reloadItems(page) {
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getFileOrganizationResults(query).then(function (result) {
2014-01-20 23:10:58 -07:00
currentResult = result;
renderResults(page, result);
Dashboard.hideLoadingMsg();
2015-12-14 08:43:03 -07:00
}, onApiFailure);
2014-01-20 23:10:58 -07:00
}
function getStatusText(item, enhance) {
var status = item.Status;
var color = null;
2014-01-21 09:24:12 -07:00
if (status == 'SkippedExisting') {
status = Globalize.translate('StatusSkipped');
2014-01-20 23:10:58 -07:00
}
else if (status == 'Failure') {
color = '#cc0000';
status = Globalize.translate('StatusFailed');
2014-01-20 23:10:58 -07:00
}
if (status == 'Success') {
color = 'green';
status = Globalize.translate('StatusSuccess');
2014-01-20 23:10:58 -07:00
}
2015-08-07 07:21:29 -07:00
if (enhance) {
2014-01-20 23:10:58 -07:00
if (item.StatusMessage) {
return '<a style="color:' + color + ';" data-resultid="' + item.Id + '" href="#" class="btnShowStatusMessage">' + status + '</a>';
} else {
return '<span data-resultid="' + item.Id + '" style="color:' + color + ';">' + status + '</span>';
}
}
return status;
}
function renderResults(page, result) {
var rows = result.Items.map(function (item) {
var html = '';
html += '<tr>';
html += '<td>';
2016-05-05 21:50:06 -07:00
var date = datetime.parseISO8601Date(item.Date, true);
2014-01-22 10:05:06 -07:00
html += date.toLocaleDateString();
2014-01-20 23:10:58 -07:00
2014-01-22 10:05:06 -07:00
html += '</td>';
2014-01-20 23:10:58 -07:00
2014-01-22 10:05:06 -07:00
html += '<td>';
var status = item.Status;
2014-01-20 23:10:58 -07:00
2014-01-22 10:05:06 -07:00
if (status == 'SkippedExisting') {
html += '<a data-resultid="' + item.Id + '" style="color:blue;" href="#" class="btnShowStatusMessage">';
2014-01-22 10:05:06 -07:00
html += item.OriginalFileName;
html += '</a>';
2014-01-20 23:10:58 -07:00
}
2014-01-22 10:05:06 -07:00
else if (status == 'Failure') {
html += '<a data-resultid="' + item.Id + '" style="color:red;" href="#" class="btnShowStatusMessage">';
html += item.OriginalFileName;
html += '</a>';
} else {
html += '<div style="color:green;">';
html += item.OriginalFileName;
html += '</div>';
2014-01-20 23:10:58 -07:00
}
2014-01-22 10:05:06 -07:00
html += '</td>';
2014-01-20 23:10:58 -07:00
2014-01-22 10:05:06 -07:00
html += '<td>';
html += item.TargetPath || '';
2014-01-20 23:10:58 -07:00
html += '</td>';
2015-09-06 12:09:36 -07:00
html += '<td class="organizerButtonCell">';
if (item.Status != 'Success') {
2016-05-07 23:31:08 -07:00
html += '<button type="button" is="paper-icon-button-light" data-resultid="' + item.Id + '" class="btnProcessResult organizerButton" title="' + Globalize.translate('ButtonOrganizeFile') + '"><iron-icon icon="folder"></iron-icon></button>';
2016-05-09 08:41:45 -07:00
html += '<button type="button" is="paper-icon-button-light" data-resultid="' + item.Id + '" class="btnDeleteResult organizerButton" title="' + Globalize.translate('ButtonDeleteFile') + '"><iron-icon icon="delete"></iron-icon></button>';
2015-09-06 12:09:36 -07:00
}
html += '</td>';
2014-01-20 23:10:58 -07:00
html += '</tr>';
return html;
}).join('');
2016-04-22 09:27:17 -07:00
var elem = $('.resultBody', page).html(rows).parents('.tblOrganizationResults').table('refresh').trigger('create');
2014-01-20 23:10:58 -07:00
$('.btnShowStatusMessage', elem).on('click', function () {
var id = this.getAttribute('data-resultid');
showStatusMessage(id);
});
$('.btnProcessResult', elem).on('click', function () {
var id = this.getAttribute('data-resultid');
organizeFile(page, id);
});
$('.btnDeleteResult', elem).on('click', function () {
var id = this.getAttribute('data-resultid');
deleteOriginalFile(page, id);
});
2015-06-18 11:29:44 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false
});
2015-08-07 07:21:29 -07:00
$(page)[0].querySelector('.listTopPaging').innerHTML = pagingHtml;
2014-01-20 23:10:58 -07:00
if (result.TotalRecordCount > query.Limit && result.TotalRecordCount > 50) {
2016-04-22 09:27:17 -07:00
2014-01-20 23:10:58 -07:00
$('.listBottomPaging', page).html(pagingHtml).trigger('create');
} else {
2016-04-22 09:27:17 -07:00
2014-01-20 23:10:58 -07:00
$('.listBottomPaging', page).empty();
}
$('.btnNextPage', page).on('click', function () {
2016-04-22 09:27:17 -07:00
2014-01-20 23:10:58 -07:00
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
2016-04-22 09:27:17 -07:00
2014-01-20 23:10:58 -07:00
query.StartIndex -= query.Limit;
reloadItems(page);
});
2014-01-22 10:05:06 -07:00
if (result.TotalRecordCount) {
$('.btnClearLog', page).show();
} else {
$('.btnClearLog', page).hide();
}
2014-01-20 23:10:58 -07:00
}
2015-02-14 12:36:40 -07:00
function onWebSocketMessage(e, msg) {
var page = $.mobile.activePage;
if ((msg.MessageType == 'ScheduledTaskEnded' && msg.Data.Key == 'AutoOrganize') || msg.MessageType == 'AutoOrganizeUpdate') {
2015-02-14 12:36:40 -07:00
reloadItems(page);
2015-02-14 12:36:40 -07:00
}
}
function onApiFailure(e) {
Dashboard.hideLoadingMsg();
if (e.status == 0) {
2016-04-22 09:27:17 -07:00
Dashboard.alert({
title: 'Auto-Organize',
message: 'The operation is going to take a little longer. The view will be updated on completion.'
});
}
else {
2016-04-22 09:27:17 -07:00
Dashboard.alert({
title: Globalize.translate('AutoOrganizeError'),
2016-04-22 09:27:17 -07:00
message: Globalize.translate('ErrorOrganizingFileWithErrorCode', e.headers.get('X-Application-Error-Code'))
});
}
2015-06-08 14:32:20 -07:00
}
2016-04-12 22:28:45 -07:00
function getTabs() {
return [
{
href: 'autoorganizelog.html',
name: Globalize.translate('TabActivityLog')
},
{
href: 'autoorganizetv.html',
name: Globalize.translate('TabTV')
},
{
href: 'autoorganizesmart.html',
name: Globalize.translate('TabSmartMatches')
}];
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#libraryFileOrganizerLogPage", function () {
2014-01-22 10:05:06 -07:00
var page = this;
$('.btnClearLog', page).on('click', function () {
2015-12-14 08:43:03 -07:00
ApiClient.clearOrganizationLog().then(function () {
2014-01-22 10:05:06 -07:00
reloadItems(page);
2015-12-14 08:43:03 -07:00
}, onApiFailure);
2014-01-22 10:05:06 -07:00
});
2016-04-22 09:27:17 -07:00
}).on('pageshow', '#libraryFileOrganizerLogPage', function () {
2014-01-20 23:10:58 -07:00
2016-04-12 22:28:45 -07:00
LibraryMenu.setTabs('autoorganize', 0, getTabs);
2014-01-20 23:10:58 -07:00
var page = this;
reloadItems(page);
2015-01-20 13:19:54 -07:00
// on here
$('.btnOrganize', page).taskButton({
mode: 'on',
2015-09-12 09:39:24 -07:00
progressElem: page.querySelector('.organizeProgress'),
2015-01-20 14:32:48 -07:00
panel: $('.organizeTaskPanel', page),
2015-01-20 13:19:54 -07:00
taskKey: 'AutoOrganize'
});
2016-04-22 09:27:17 -07:00
Events.on(ApiClient, 'websocketmessage', onWebSocketMessage);
2015-02-14 12:36:40 -07:00
2016-04-22 09:27:17 -07:00
}).on('pagebeforehide', '#libraryFileOrganizerLogPage', function () {
2014-01-20 23:10:58 -07:00
2015-01-20 14:32:48 -07:00
var page = this;
2014-01-20 23:10:58 -07:00
currentResult = null;
2015-01-20 13:19:54 -07:00
// off here
$('.btnOrganize', page).taskButton({
mode: 'off'
});
2015-02-14 12:36:40 -07:00
2016-04-22 09:27:17 -07:00
Events.off(ApiClient, 'websocketmessage', onWebSocketMessage);
2014-01-20 23:10:58 -07:00
});
2016-04-22 09:27:17 -07:00
});