unify sync components
This commit is contained in:
parent
55b5cebda5
commit
db403c3cd4
21 changed files with 447 additions and 279 deletions
|
@ -16,12 +16,12 @@
|
|||
},
|
||||
"devDependencies": {},
|
||||
"ignore": [],
|
||||
"version": "1.1.105",
|
||||
"_release": "1.1.105",
|
||||
"version": "1.1.106",
|
||||
"_release": "1.1.106",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "1.1.105",
|
||||
"commit": "d46515271d43d1b0f7dd19bb1834cfd457fb3326"
|
||||
"tag": "1.1.106",
|
||||
"commit": "2bed46ebe6ee1e213b5f89476ca8c285937ba343"
|
||||
},
|
||||
"_source": "https://github.com/MediaBrowser/Emby.ApiClient.Javascript.git",
|
||||
"_target": "^1.1.51",
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
function getLocalMediaSource(serverId, itemId) {
|
||||
return Promise.resolve(null);
|
||||
function getLocalItem(serverId, itemId) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function getLocalItemById(id) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function saveOfflineUser(user) {
|
||||
|
@ -30,7 +34,6 @@
|
|||
}
|
||||
|
||||
function deleteUserActions(actions) {
|
||||
//TODO:
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
@ -38,11 +41,19 @@
|
|||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
function removeLocalItem(localItem) {
|
||||
return Promise.resolve();
|
||||
function getServerItems(serverId) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
function getLocalItem(itemId, serverId) {
|
||||
function getViews(serverId, userId) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
function getViewItems(serverId, userId, parentId) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
function removeLocalItem(localItem) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
@ -51,45 +62,51 @@
|
|||
}
|
||||
|
||||
function createLocalItem(libraryItem, serverInfo, jobItem) {
|
||||
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
function downloadFile(url, localPath) {
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function downloadSubtitles(url, localItem, subtitleStreamh) {
|
||||
|
||||
return Promise.resolve('');
|
||||
function getSubtitleSaveFileName(localItem, mediaPath, language, isForced, format) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function hasImage(serverId, itemId, imageTag) {
|
||||
return Promise.resolve(false);
|
||||
function getItemFileSize(path) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function downloadImage(url, serverId, itemId, imageTag) {
|
||||
return Promise.resolve(false);
|
||||
function downloadFile(url, localItem) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function fileExists(path) {
|
||||
return Promise.resolve(false);
|
||||
function downloadSubtitles(url, fileName) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function getImageUrl(serverId, itemId, imageType, index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function hasImage(serverId, itemId, imageType, index) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function downloadImage(localItem, url, serverId, itemId, imageType, index) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function isDownloadFileInQueue(path) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function translateFilePath(path) {
|
||||
return Promise.resolve(path);
|
||||
}
|
||||
|
||||
function getLocalFilePath(path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getLocalItemById(id) {
|
||||
return null;
|
||||
function resyncTransfers() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
getLocalItem: getLocalItem,
|
||||
saveOfflineUser: saveOfflineUser,
|
||||
deleteOfflineUser: deleteOfflineUser,
|
||||
|
@ -106,9 +123,15 @@
|
|||
downloadSubtitles: downloadSubtitles,
|
||||
hasImage: hasImage,
|
||||
downloadImage: downloadImage,
|
||||
fileExists: fileExists,
|
||||
getImageUrl: getImageUrl,
|
||||
translateFilePath: translateFilePath,
|
||||
getLocalFilePath: getLocalFilePath,
|
||||
getLocalItemById: getLocalItemById
|
||||
getSubtitleSaveFileName: getSubtitleSaveFileName,
|
||||
getLocalItemById: getLocalItemById,
|
||||
getServerItems: getServerItems,
|
||||
getItemFileSize: getItemFileSize,
|
||||
isDownloadFileInQueue: isDownloadFileInQueue,
|
||||
getViews: getViews,
|
||||
getViewItems: getViewItems,
|
||||
resyncTransfers: resyncTransfers
|
||||
};
|
||||
});
|
|
@ -15,6 +15,13 @@
|
|||
|
||||
}
|
||||
|
||||
function getPathFromArray(pathArray) {
|
||||
|
||||
// TODO
|
||||
return pathArray.join('/');
|
||||
|
||||
}
|
||||
|
||||
function deleteFile(path) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
@ -34,6 +41,7 @@
|
|||
return {
|
||||
getValidFileName: getValidFileName,
|
||||
getFullLocalPath: getFullLocalPath,
|
||||
getPathFromArray: getPathFromArray,
|
||||
deleteFile: deleteFile,
|
||||
deleteDirectory: deleteDirectory,
|
||||
fileExists: fileExists,
|
||||
|
|
|
@ -35,6 +35,18 @@
|
|||
});
|
||||
}
|
||||
|
||||
function getServerItemTypes(serverId, userId) {
|
||||
return dbPromise.then(function (db) {
|
||||
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000).then(function (all) {
|
||||
return all.filter(function (item) {
|
||||
return item.ServerId === serverId && (item.UserIdsWithAccess == null || item.UserIdsWithAccess.contains(userId));
|
||||
}).map(function (item2) {
|
||||
return (item2.Item.Type || '').toLowerCase();
|
||||
}).filter(filterDistinct);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getServerIds(serverId) {
|
||||
return dbPromise.then(function (db) {
|
||||
return db.transaction(dbName).objectStore(dbName).getAll(null, 10000).then(function (all) {
|
||||
|
@ -83,6 +95,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
function filterDistinct(value, index, self) {
|
||||
return self.indexOf(value) === index;
|
||||
}
|
||||
|
||||
setup();
|
||||
|
||||
return {
|
||||
|
@ -92,6 +108,7 @@
|
|||
clear: clear,
|
||||
getAll: getAll,
|
||||
getServerItemIds: getServerItemIds,
|
||||
getServerIds: getServerIds
|
||||
getServerIds: getServerIds,
|
||||
getServerItemTypes: getServerItemTypes
|
||||
};
|
||||
});
|
|
@ -5,27 +5,30 @@
|
|||
|
||||
console.log('[mediasync] Begin processDownloadStatus');
|
||||
|
||||
return localassetmanager.getServerItems(serverInfo.Id).then(function (items) {
|
||||
return localassetmanager.resyncTransfers().then(function () {
|
||||
|
||||
console.log('[mediasync] Begin processDownloadStatus getServerItems completed');
|
||||
return localassetmanager.getServerItems(serverInfo.Id).then(function (items) {
|
||||
|
||||
var progressItems = items.filter(function (item) {
|
||||
return item.SyncStatus === 'transferring' || item.SyncStatus === 'queued';
|
||||
});
|
||||
console.log('[mediasync] Begin processDownloadStatus getServerItems completed');
|
||||
|
||||
var p = Promise.resolve();
|
||||
var cnt = 0;
|
||||
|
||||
progressItems.forEach(function (item) {
|
||||
p = p.then(function () {
|
||||
return reportTransfer(apiClient, item);
|
||||
var progressItems = items.filter(function (item) {
|
||||
return item.SyncStatus === 'transferring' || item.SyncStatus === 'queued';
|
||||
});
|
||||
cnt++;
|
||||
});
|
||||
|
||||
return p.then(function () {
|
||||
console.log('[mediasync] Exit processDownloadStatus. Items reported: ' + cnt.toString());
|
||||
return Promise.resolve();
|
||||
var p = Promise.resolve();
|
||||
var cnt = 0;
|
||||
|
||||
progressItems.forEach(function (item) {
|
||||
p = p.then(function () {
|
||||
return reportTransfer(apiClient, item);
|
||||
});
|
||||
cnt++;
|
||||
});
|
||||
|
||||
return p.then(function () {
|
||||
console.log('[mediasync] Exit processDownloadStatus. Items reported: ' + cnt.toString());
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -40,23 +43,23 @@
|
|||
item.SyncStatus = 'synced';
|
||||
return localassetmanager.addOrUpdateLocalItem(item);
|
||||
}, function (error) {
|
||||
console.error("[mediasync] Mediasync error on reportSyncJobItemTransferred", error);
|
||||
console.error('[mediasync] Mediasync error on reportSyncJobItemTransferred', error);
|
||||
item.SyncStatus = 'error';
|
||||
return localassetmanager.addOrUpdateLocalItem(item);
|
||||
});
|
||||
} else {
|
||||
return localassetmanager.isDownloadInQueue(item.SyncJobItemId).then(function (result) {
|
||||
return localassetmanager.isDownloadFileInQueue(item.LocalPath).then(function (result) {
|
||||
if (result) {
|
||||
// just wait for completion
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
console.log("[mediasync] reportTransfer: Size is 0 and download no longer in queue. Deleting item.");
|
||||
console.log('[mediasync] reportTransfer: Size is 0 and download no longer in queue. Deleting item.');
|
||||
return localassetmanager.removeLocalItem(item).then(function () {
|
||||
console.log('[mediasync] reportTransfer: Item deleted.');
|
||||
return Promise.resolve();
|
||||
}, function (err2) {
|
||||
console.log('[mediasync] reportTransfer: Failed to delete item.', error);
|
||||
console.log('[mediasync] reportTransfer: Failed to delete item.', err2);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
@ -123,8 +126,10 @@
|
|||
return apiClient.syncData(request).then(function (result) {
|
||||
|
||||
return afterSyncData(apiClient, serverInfo, syncUserItemAccess, result).then(function () {
|
||||
console.log('[mediasync] Exit syncData');
|
||||
return Promise.resolve();
|
||||
}, function () {
|
||||
}, function (err) {
|
||||
console.error('[mediasync] Error in syncData: ' + err.toString());
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
|
@ -202,20 +207,21 @@
|
|||
|
||||
return localassetmanager.getLocalItem(serverInfo.Id, libraryItem.Id).then(function (existingItem) {
|
||||
|
||||
console.log('[mediasync] getNewItem.getLocalItem completed');
|
||||
|
||||
if (existingItem) {
|
||||
if (existingItem.SyncStatus === 'queued' || existingItem.SyncStatus === 'transferring' || existingItem.SyncStatus === 'synced') {
|
||||
console.log('[mediasync] getNewItem.getLocalItem found existing item');
|
||||
console.log('[mediasync] getNewItem: getLocalItem found existing item');
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[mediasync] getNewItem.getLocalItem no existing item found');
|
||||
libraryItem.CanDelete = false;
|
||||
libraryItem.CanDownload = false;
|
||||
libraryItem.People = [];
|
||||
libraryItem.SpecialFeatureCount = null;
|
||||
|
||||
return localassetmanager.createLocalItem(libraryItem, serverInfo, jobItem).then(function (localItem) {
|
||||
|
||||
console.log('[mediasync] getNewItem.createLocalItem completed');
|
||||
console.log('[mediasync] getNewItem: createLocalItem completed');
|
||||
|
||||
localItem.SyncStatus = 'queued';
|
||||
|
||||
|
@ -233,9 +239,7 @@
|
|||
|
||||
function downloadMedia(apiClient, jobItem, localItem, options) {
|
||||
|
||||
console.log('[mediasync] Begin downloadMedia');
|
||||
|
||||
var url = apiClient.getUrl("Sync/JobItems/" + jobItem.SyncJobItemId + "/File", {
|
||||
var url = apiClient.getUrl('Sync/JobItems/' + jobItem.SyncJobItemId + '/File', {
|
||||
api_key: apiClient.accessToken()
|
||||
});
|
||||
|
||||
|
@ -256,88 +260,117 @@
|
|||
|
||||
console.log('[mediasync] Begin getImages');
|
||||
|
||||
return getNextImage(0, apiClient, localItem);
|
||||
var p = Promise.resolve();
|
||||
|
||||
var libraryItem = localItem.Item;
|
||||
|
||||
var serverId = libraryItem.ServerId;
|
||||
|
||||
// case 0
|
||||
var mainImageTag = (libraryItem.ImageTags || {})['Primary'];
|
||||
|
||||
if (libraryItem.Id && mainImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.Id, mainImageTag, 'Primary');
|
||||
});
|
||||
}
|
||||
|
||||
// case 0a
|
||||
var logoImageTag = (libraryItem.ImageTags || {})['Logo'];
|
||||
if (libraryItem.Id && logoImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.Id, logoImageTag, 'Logo');
|
||||
});
|
||||
}
|
||||
|
||||
// case 0b
|
||||
var artImageTag = (libraryItem.ImageTags || {})['Art'];
|
||||
if (libraryItem.Id && artImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.Id, artImageTag, 'Art');
|
||||
});
|
||||
}
|
||||
|
||||
// case 0c
|
||||
var bannerImageTag = (libraryItem.ImageTags || {})['Banner'];
|
||||
if (libraryItem.Id && bannerImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.Id, bannerImageTag, 'Banner');
|
||||
});
|
||||
}
|
||||
|
||||
// case 0d
|
||||
var thumbImageTag = (libraryItem.ImageTags || {})['Thumb'];
|
||||
if (libraryItem.Id && thumbImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.Id, thumbImageTag, 'Thumb');
|
||||
});
|
||||
}
|
||||
|
||||
// Backdrops
|
||||
if (libraryItem.Id && libraryItem.BackdropImageTags) {
|
||||
for (var i = 0; i < libraryItem.BackdropImageTags.length; i++) {
|
||||
|
||||
var backdropImageTag = libraryItem.BackdropImageTags[i];
|
||||
|
||||
// use self-invoking function to simulate block-level variable scope
|
||||
(function (index, tag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.Id, tag, 'backdrop', index);
|
||||
});
|
||||
})(i, backdropImageTag);
|
||||
}
|
||||
}
|
||||
|
||||
// case 1/2:
|
||||
if (libraryItem.SeriesId && libraryItem.SeriesPrimaryImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.SeriesId, libraryItem.SeriesPrimaryImageTag, 'Primary');
|
||||
});
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.SeriesId, libraryItem.SeriesPrimaryImageTag, 'Thumb');
|
||||
});
|
||||
}
|
||||
|
||||
// case 3:
|
||||
if (libraryItem.AlbumId && libraryItem.AlbumPrimaryImageTag) {
|
||||
p = p.then(function () {
|
||||
return downloadImage(localItem, apiClient, serverId, libraryItem.AlbumId, libraryItem.AlbumPrimaryImageTag, 'Primary');
|
||||
});
|
||||
}
|
||||
|
||||
return p.then(function () {
|
||||
console.log('[mediasync] Finished getImages');
|
||||
return localassetmanager.addOrUpdateLocalItem(localItem);
|
||||
}, function (err) {
|
||||
console.log('[mediasync] Error getImages: ' + err.toString());
|
||||
});
|
||||
}
|
||||
|
||||
function getNextImage(index, apiClient, localItem) {
|
||||
function downloadImage(localItem, apiClient, serverId, itemId, imageTag, imageType, index) {
|
||||
|
||||
console.log('[mediasync] Begin getNextImage');
|
||||
|
||||
//if (index >= 4) {
|
||||
index = index || 0;
|
||||
|
||||
// deferred.resolve();
|
||||
// return;
|
||||
//}
|
||||
|
||||
// Just for now while media syncing gets worked out
|
||||
return Promise.resolve();
|
||||
|
||||
//var libraryItem = localItem.Item;
|
||||
|
||||
//var serverId = libraryItem.ServerId;
|
||||
//var itemId = null;
|
||||
//var imageTag = null;
|
||||
//var imageType = "Primary";
|
||||
|
||||
//switch (index) {
|
||||
|
||||
// case 0:
|
||||
// itemId = libraryItem.Id;
|
||||
// imageType = "Primary";
|
||||
// imageTag = (libraryItem.ImageTags || {})["Primary"];
|
||||
// break;
|
||||
// case 1:
|
||||
// itemId = libraryItem.SeriesId;
|
||||
// imageType = "Primary";
|
||||
// imageTag = libraryItem.SeriesPrimaryImageTag;
|
||||
// break;
|
||||
// case 2:
|
||||
// itemId = libraryItem.SeriesId;
|
||||
// imageType = "Thumb";
|
||||
// imageTag = libraryItem.SeriesPrimaryImageTag;
|
||||
// break;
|
||||
// case 3:
|
||||
// itemId = libraryItem.AlbumId;
|
||||
// imageType = "Primary";
|
||||
// imageTag = libraryItem.AlbumPrimaryImageTag;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
//}
|
||||
|
||||
//if (!itemId || !imageTag) {
|
||||
// getNextImage(index + 1, apiClient, localItem, deferred);
|
||||
// return;
|
||||
//}
|
||||
|
||||
//downloadImage(apiClient, serverId, itemId, imageTag, imageType).then(function () {
|
||||
|
||||
// // For the sake of simplicity, limit to one image
|
||||
// deferred.resolve();
|
||||
// return;
|
||||
|
||||
// getNextImage(index + 1, apiClient, localItem, deferred);
|
||||
|
||||
//}, getOnFail(deferred));
|
||||
}
|
||||
|
||||
function downloadImage(apiClient, serverId, itemId, imageTag, imageType) {
|
||||
|
||||
console.log('[mediasync] Begin downloadImage');
|
||||
|
||||
return localassetmanager.hasImage(serverId, itemId, imageTag).then(function (hasImage) {
|
||||
return localassetmanager.hasImage(serverId, itemId, imageType, index).then(function (hasImage) {
|
||||
|
||||
if (hasImage) {
|
||||
console.log('[mediasync] downloadImage - skip existing: ' + itemId + ' ' + imageType + '_' + index.toString());
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
var imageUrl = apiClient.getImageUrl(itemId, {
|
||||
tag: imageTag,
|
||||
type: imageType,
|
||||
format: 'png',
|
||||
api_key: apiClient.accessToken()
|
||||
});
|
||||
|
||||
return localassetmanager.downloadImage(imageUrl, serverId, itemId, imageTag);
|
||||
console.log('[mediasync] downloadImage ' + itemId + ' ' + imageType + '_' + index.toString());
|
||||
|
||||
return localassetmanager.downloadImage(localItem, imageUrl, serverId, itemId, imageType, index);
|
||||
}, function (err) {
|
||||
console.log('[mediasync] Error downloadImage: ' + err.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -346,7 +379,7 @@
|
|||
console.log('[mediasync] Begin getSubtitles');
|
||||
|
||||
if (!jobItem.Item.MediaSources.length) {
|
||||
console.log("[mediasync] Cannot download subtitles because video has no media source info.");
|
||||
console.log('[mediasync] Cannot download subtitles because video has no media source info.');
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
@ -381,19 +414,26 @@
|
|||
if (!subtitleStream) {
|
||||
|
||||
// We shouldn't get in here, but let's just be safe anyway
|
||||
console.log("[mediasync] Cannot download subtitles because matching stream info wasn't found.");
|
||||
console.log('[mediasync] Cannot download subtitles because matching stream info was not found.');
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
var url = apiClient.getUrl("Sync/JobItems/" + jobItem.SyncJobItemId + "/AdditionalFiles", {
|
||||
var url = apiClient.getUrl('Sync/JobItems/' + jobItem.SyncJobItemId + '/AdditionalFiles', {
|
||||
Name: file.Name,
|
||||
api_key: apiClient.accessToken()
|
||||
});
|
||||
|
||||
var fileName = localassetmanager.getSubtitleSaveFileName(jobItem.OriginalFileName, subtitleStream.Language, subtitleStream.IsForced, subtitleStream.Codec);
|
||||
var localFilePath = localassetmanager.getLocalFilePath(localItem, fileName);
|
||||
var fileName = localassetmanager.getSubtitleSaveFileName(localItem, jobItem.OriginalFileName, subtitleStream.Language, subtitleStream.IsForced, subtitleStream.Codec);
|
||||
|
||||
return localassetmanager.downloadSubtitles(url, localFilePath).then(function (subtitlePath) {
|
||||
return localassetmanager.downloadSubtitles(url, fileName).then(function (subtitlePath) {
|
||||
|
||||
if (localItem.AdditionalFiles) {
|
||||
localItem.AdditionalFiles.forEach(function (item) {
|
||||
if (item.Name === file.Name) {
|
||||
item.Path = subtitlePath;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
subtitleStream.Path = subtitlePath;
|
||||
return localassetmanager.addOrUpdateLocalItem(localItem);
|
||||
|
@ -406,10 +446,14 @@
|
|||
|
||||
self.sync = function (apiClient, serverInfo, options) {
|
||||
|
||||
console.log("[mediasync]************************************* Start sync");
|
||||
console.log('[mediasync]************************************* Start sync');
|
||||
|
||||
return processDownloadStatus(apiClient, serverInfo, options).then(function () {
|
||||
|
||||
if (options.syncCheckProgressOnly === true) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return reportOfflineActions(apiClient, serverInfo).then(function () {
|
||||
|
||||
//// Do the first data sync
|
||||
|
@ -420,7 +464,8 @@
|
|||
|
||||
// Do the second data sync
|
||||
return syncData(apiClient, serverInfo, false).then(function () {
|
||||
console.log("[mediasync]************************************* Exit sync");
|
||||
console.log('[mediasync]************************************* Exit sync');
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
//});
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
},
|
||||
"devDependencies": {},
|
||||
"ignore": [],
|
||||
"version": "1.4.397",
|
||||
"_release": "1.4.397",
|
||||
"version": "1.4.399",
|
||||
"_release": "1.4.399",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "1.4.397",
|
||||
"commit": "9adcc0001dbf032595448070447de469a8f24130"
|
||||
"tag": "1.4.399",
|
||||
"commit": "b926b582df014a7b2b54e93dca167db73d59bbcb"
|
||||
},
|
||||
"_source": "https://github.com/MediaBrowser/emby-webcomponents.git",
|
||||
"_target": "^1.2.1",
|
||||
|
|
|
@ -16,6 +16,11 @@ define(['apphost', 'globalize', 'connectionManager', 'itemHelper', 'embyRouter',
|
|||
|
||||
var commands = [];
|
||||
|
||||
if (itemHelper.isLocalItem(item)) {
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
if (itemHelper.supportsAddingToCollection(item)) {
|
||||
commands.push({
|
||||
name: globalize.translate('sharedcomponents#AddToCollection'),
|
||||
|
|
|
@ -111,10 +111,20 @@ define(['apphost'], function (appHost) {
|
|||
return user.Policy.IsAdministrator;
|
||||
}
|
||||
|
||||
function isLocalItem(item) {
|
||||
|
||||
if (item && item.Id && item.Id.indexOf('local') === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
getDisplayName: getDisplayName,
|
||||
supportsAddingToCollection: supportsAddingToCollection,
|
||||
supportsAddingToPlaylist: supportsAddingToPlaylist,
|
||||
isLocalItem: isLocalItem,
|
||||
|
||||
canIdentify: function (user, itemType) {
|
||||
|
||||
|
|
|
@ -353,6 +353,6 @@
|
|||
"HeaderPlayMyMedia": "\u041c\u0435\u043d\u0456\u04a3 \u0442\u0430\u0441\u044b\u0493\u044b\u0448\u0434\u0435\u0440\u0435\u043a\u0442\u0435\u0440\u0456\u043c\u0434\u0456 \u043e\u0439\u043d\u0430\u0442\u0443",
|
||||
"HeaderDiscoverEmbyPremiere": "Emby Premiere \u0430\u0448\u044b\u04a3\u044b\u0437",
|
||||
"OneChannel": "\u0411\u0456\u0440 \u0430\u0440\u043d\u0430\u0434\u0430\u043d",
|
||||
"ConfirmRemoveDownload": "Remove download?",
|
||||
"ConfirmRemoveDownload": "\u0416\u04af\u043a\u0442\u0435\u0443\u0434\u0456 \u0430\u043b\u0430\u0441\u0442\u0430\u0439\u043c\u044b\u0437 \u0431\u0430?",
|
||||
"AddedOnValue": "\u04ae\u0441\u0442\u0435\u043b\u0433\u0435\u043d\u0456 {0}"
|
||||
}
|
|
@ -353,6 +353,6 @@
|
|||
"HeaderPlayMyMedia": "Reproduzir minha M\u00eddia",
|
||||
"HeaderDiscoverEmbyPremiere": "Descobrir o Emby Premiere",
|
||||
"OneChannel": "Um canal",
|
||||
"ConfirmRemoveDownload": "Remove download?",
|
||||
"AddedOnValue": "Adicionado em {0}"
|
||||
"ConfirmRemoveDownload": "Remover download?",
|
||||
"AddedOnValue": "Adicionado {0}"
|
||||
}
|
|
@ -353,6 +353,6 @@
|
|||
"HeaderPlayMyMedia": "\u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043c\u043e\u0438 \u043c\u0435\u0434\u0438\u0430\u0434\u0430\u043d\u043d\u044b\u0435",
|
||||
"HeaderDiscoverEmbyPremiere": "\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 Emby Premiere",
|
||||
"OneChannel": "\u041e\u0434\u0438\u043d \u043a\u0430\u043d\u0430\u043b",
|
||||
"ConfirmRemoveDownload": "Remove download?",
|
||||
"ConfirmRemoveDownload": "\u0418\u0437\u044a\u044f\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443?",
|
||||
"AddedOnValue": "\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e {0}"
|
||||
}
|
|
@ -68,8 +68,8 @@
|
|||
"ConfirmDeleteItem": "Deleting this item will delete it from both the file system and your media library. Are you sure you wish to continue?",
|
||||
"Refresh": "\u5237\u65b0",
|
||||
"RefreshQueued": "\u5217\u961f\u5df2\u5237\u65b0\u3002",
|
||||
"AddToCollection": "Add to collection",
|
||||
"HeaderAddToCollection": "Add to Collection",
|
||||
"AddToCollection": "\u52a0\u5165\u5408\u96c6",
|
||||
"HeaderAddToCollection": "\u52a0\u5165\u5408\u96c6",
|
||||
"NewCollection": "\u65b0\u5408\u96c6",
|
||||
"LabelCollection": "Collection:",
|
||||
"Help": "\u5e2e\u52a9",
|
||||
|
@ -114,7 +114,7 @@
|
|||
"Open": "\u6253\u5f00",
|
||||
"Play": "\u64ad\u653e",
|
||||
"Queue": "\u52a0\u5165\u961f\u5217",
|
||||
"Shuffle": "\u6401\u7f6e",
|
||||
"Shuffle": "\u968f\u673a\u64ad\u653e",
|
||||
"Identify": "\u8bc6\u522b",
|
||||
"EditImages": "\u4fee\u6539\u56fe\u7247",
|
||||
"EditInfo": "\u7f16\u8f91\u4fe1\u606f",
|
||||
|
@ -162,7 +162,7 @@
|
|||
"LabelOverview": "\u5185\u5bb9\u6982\u8ff0\uff1a",
|
||||
"LabelShortOverview": "\u7b80\u4ecb\uff1a",
|
||||
"LabelReleaseDate": "\u53d1\u884c\u65e5\u671f\uff1a",
|
||||
"LabelYear": "Year:",
|
||||
"LabelYear": "\u5e74\u4efd\uff1a",
|
||||
"LabelPlaceOfBirth": "\u51fa\u751f\u5730\uff1a",
|
||||
"LabelAirDays": "\u64ad\u51fa\u65e5\u671f\uff1a",
|
||||
"LabelAirTime": "\u64ad\u51fa\u65f6\u95f4\uff1a",
|
||||
|
@ -213,14 +213,14 @@
|
|||
"Continuing": "\u7ee7\u7eed",
|
||||
"Ended": "\u7ed3\u675f",
|
||||
"HeaderEnabledFields": "\u5df2\u542f\u7528\u7684\u680f",
|
||||
"HeaderEnabledFieldsHelp": "Uncheck a field to lock it and prevent it's data from being changed.",
|
||||
"HeaderEnabledFieldsHelp": "\u53cd\u9009\u680f\u4ee5\u9501\u5b9a\u5e76\u4e0d\u8ba9\u5176\u6570\u636e\u88ab\u66f4\u6539\u3002",
|
||||
"Backdrops": "\u80cc\u666f",
|
||||
"Images": "\u56fe\u7247",
|
||||
"Keywords": "\u5173\u952e\u8bcd",
|
||||
"Runtime": "\u64ad\u653e\u65f6\u95f4",
|
||||
"Runtime": "\u64ad\u653e\u65f6\u957f",
|
||||
"ProductionLocations": "Production locations",
|
||||
"BirthLocation": "\u51fa\u751f\u5730",
|
||||
"ParentalRating": "Parental Rating",
|
||||
"ParentalRating": "\u5bb6\u957f\u5206\u7ea7",
|
||||
"Name": "\u540d\u79f0",
|
||||
"Overview": "\u6982\u8ff0",
|
||||
"LabelType": "\u7c7b\u578b\uff1a",
|
||||
|
@ -256,7 +256,7 @@
|
|||
"PleaseEnterNameOrId": "\u8bf7\u8f93\u5165\u4e00\u4e2a\u540d\u79f0\u6216\u4e00\u4e2a\u5916\u90e8ID\u3002",
|
||||
"MessageItemSaved": "\u9879\u76ee\u5df2\u4fdd\u5b58\u3002",
|
||||
"SearchResults": "\u641c\u7d22\u7ed3\u679c",
|
||||
"SyncToOtherDevice": "Sync to other device",
|
||||
"SyncToOtherDevice": "\u540c\u6b65\u5230\u5176\u4ed6\u8bbe\u5907",
|
||||
"MakeAvailableOffline": "Make available offline",
|
||||
"ServerNameIsRestarting": "Emby Server - {0} is restarting.",
|
||||
"ServerNameIsShuttingDown": "Emby Server - {0} is shutting down.",
|
||||
|
@ -264,7 +264,7 @@
|
|||
"ConfirmDeleteItems": "Deleting these items will delete them from both the file system and your media library. Are you sure you wish to continue?",
|
||||
"PleaseRestartServerName": "Please restart Emby Server - {0}.",
|
||||
"SyncJobCreated": "Sync job created.",
|
||||
"LabelSyncTo": "Sync to:",
|
||||
"LabelSyncTo": "\u540c\u6b65\u5230\uff1a",
|
||||
"LabelSyncJobName": "Sync job name:",
|
||||
"LabelQuality": "Quality:",
|
||||
"LabelSyncNoTargetsHelp": "It looks like you don't currently have any apps that support sync.",
|
||||
|
@ -278,7 +278,7 @@
|
|||
"AutomaticallySyncNewContentHelp": "New content added to this folder will be automatically synced to the device.",
|
||||
"LabelItemLimit": "Item limit:",
|
||||
"LabelItemLimitHelp": "Optional. Set a limit to the number of items that will be synced.",
|
||||
"PleaseSelectDeviceToSyncTo": "Please select a device to sync to.",
|
||||
"PleaseSelectDeviceToSyncTo": "\u8bf7\u9009\u62e9\u60a8\u60f3\u8981\u540c\u6b65\u5230\u7684\u8bbe\u5907\u3002",
|
||||
"Screenshots": "Screenshots",
|
||||
"MoveRight": "Move right",
|
||||
"MoveLeft": "Move left",
|
||||
|
|
|
@ -455,6 +455,10 @@
|
|||
});
|
||||
|
||||
return promise.then(function () {
|
||||
if (layoutManager.tv) {
|
||||
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
|
||||
}
|
||||
|
||||
if (submitted) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
512
dashboard-ui/bower_components/emby-webcomponents/sync/syncjobeditor.js
vendored
Normal file
512
dashboard-ui/bower_components/emby-webcomponents/sync/syncjobeditor.js
vendored
Normal file
|
@ -0,0 +1,512 @@
|
|||
define(['connectionManager', 'serverNotifications', 'events', 'datetime', 'dom', 'imageLoader', 'loading', 'globalize', 'apphost', 'layoutManager', 'scrollHelper', 'dialogHelper', 'shell', 'listViewStyle', 'paper-icon-button-light', 'emby-button', 'formDialogStyle'], function (connectionManager, serverNotifications, events, datetime, dom, imageLoader, loading, globalize, appHost, layoutManager, scrollHelper, dialogHelper, shell) {
|
||||
'use strict';
|
||||
|
||||
function renderJob(context, job, dialogOptions) {
|
||||
|
||||
require(['syncDialog'], function (syncDialog) {
|
||||
syncDialog.renderForm({
|
||||
elem: context.querySelector('.syncJobFormContent'),
|
||||
dialogOptions: dialogOptions,
|
||||
dialogOptionsFn: getTargetDialogOptionsFn(dialogOptions),
|
||||
showName: true,
|
||||
readOnlySyncTarget: true
|
||||
}).then(function () {
|
||||
fillJobValues(context, job, dialogOptions);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getTargetDialogOptionsFn(dialogOptions) {
|
||||
|
||||
return function (targetId) {
|
||||
|
||||
return Promise.resolve(dialogOptions);
|
||||
};
|
||||
}
|
||||
|
||||
function getJobItemHtml(jobItem, apiClient, index) {
|
||||
|
||||
var html = '';
|
||||
|
||||
html += '<div class="listItem" data-itemid="' + jobItem.Id + '" data-status="' + jobItem.Status + '" data-remove="' + jobItem.IsMarkedForRemoval + '">';
|
||||
|
||||
var hasActions = ['Queued', 'Cancelled', 'Failed', 'ReadyToTransfer', 'Transferring', 'Converting', 'Synced'].indexOf(jobItem.Status) != -1;
|
||||
|
||||
var imgUrl;
|
||||
|
||||
if (jobItem.PrimaryImageItemId) {
|
||||
|
||||
imgUrl = apiClient.getImageUrl(jobItem.PrimaryImageItemId, {
|
||||
type: "Primary",
|
||||
width: 80,
|
||||
tag: jobItem.PrimaryImageTag,
|
||||
minScale: 1.5
|
||||
});
|
||||
}
|
||||
|
||||
if (imgUrl) {
|
||||
html += '<button type="button" is="emby-button" class="blue mini fab autoSize" icon="sync" style="background-image:url(\'' + imgUrl + '\');background-repeat:no-repeat;background-position:center center;background-size: cover;"><i style="visibility:hidden;" class="md-icon">sync</i></button>';
|
||||
}
|
||||
else {
|
||||
html += '<button type="button" is="emby-button" class="blue mini fab autoSize" icon="sync"><i class="md-icon">sync</i></button>';
|
||||
}
|
||||
|
||||
html += '<div class="listItemBody three-line">';
|
||||
|
||||
html += '<div>';
|
||||
html += jobItem.ItemName;
|
||||
html += '</div>';
|
||||
|
||||
if (jobItem.Status == 'Failed') {
|
||||
html += '<div class="secondary" style="color:red;">';
|
||||
} else {
|
||||
html += '<div class="secondary">';
|
||||
}
|
||||
html += globalize.translate('SyncJobItemStatus' + jobItem.Status);
|
||||
if (jobItem.Status == 'Synced' && jobItem.IsMarkedForRemoval) {
|
||||
html += '<br/>';
|
||||
html += globalize.translate('SyncJobItemStatusSyncedMarkForRemoval');
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
html += '<div class="secondary" style="padding-top:5px;">';
|
||||
html += '<div style="background:#e0e0e0;height:4px;"><div style="background:#52B54B;width:' + (jobItem.Progress || 0) + '%;height:100%;"></div></div>';
|
||||
html += '</div>';
|
||||
|
||||
html += '</div>';
|
||||
|
||||
var moreIcon = appHost.moreIcon === 'dots-horiz' ? '' : '';
|
||||
|
||||
if (hasActions) {
|
||||
|
||||
html += '<button type="button" is="paper-icon-button-light" class="btnJobItemMenu autoSize"><i class="md-icon">' + moreIcon + '</i></button>';
|
||||
} else {
|
||||
html += '<button type="button" is="paper-icon-button-light" class="btnJobItemMenu autoSize" disabled><i class="md-icon">' + moreIcon + '</i></button>';
|
||||
}
|
||||
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
|
||||
function renderJobItems(context, items, apiClient) {
|
||||
|
||||
var html = '';
|
||||
|
||||
html += '<h1>' + globalize.translate('HeaderItems') + '</h1>';
|
||||
|
||||
html += '<div class="paperList">';
|
||||
|
||||
var index = 0;
|
||||
html += items.map(function (i) {
|
||||
|
||||
return getJobItemHtml(i, apiClient, index++);
|
||||
|
||||
}).join('');
|
||||
|
||||
html += '</div>';
|
||||
|
||||
var elem = context.querySelector('.jobItems');
|
||||
elem.innerHTML = html;
|
||||
imageLoader.lazyChildren(elem);
|
||||
}
|
||||
|
||||
function parentWithClass(elem, className) {
|
||||
|
||||
while (!elem.classList || !elem.classList.contains(className)) {
|
||||
elem = elem.parentNode;
|
||||
|
||||
if (!elem) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return elem;
|
||||
}
|
||||
|
||||
function showJobItemMenu(elem, jobId, apiClient) {
|
||||
|
||||
var context = parentWithClass(elem, 'page');
|
||||
var listItem = parentWithClass(elem, 'listItem');
|
||||
var jobItemId = listItem.getAttribute('data-itemid');
|
||||
var status = listItem.getAttribute('data-status');
|
||||
var remove = listItem.getAttribute('data-remove').toLowerCase() == 'true';
|
||||
|
||||
var menuItems = [];
|
||||
|
||||
if (status == 'Failed') {
|
||||
menuItems.push({
|
||||
name: globalize.translate('ButtonQueueForRetry'),
|
||||
id: 'retry'
|
||||
});
|
||||
}
|
||||
else if (status == 'Cancelled') {
|
||||
menuItems.push({
|
||||
name: globalize.translate('ButtonReenable'),
|
||||
id: 'retry'
|
||||
});
|
||||
}
|
||||
else if (status == 'Queued' || status == 'Transferring' || status == 'Converting' || status == 'ReadyToTransfer') {
|
||||
menuItems.push({
|
||||
name: globalize.translate('ButtonCancelItem'),
|
||||
id: 'cancel'
|
||||
});
|
||||
}
|
||||
else if (status == 'Synced' && remove) {
|
||||
menuItems.push({
|
||||
name: globalize.translate('ButtonUnmarkForRemoval'),
|
||||
id: 'unmarkforremoval'
|
||||
});
|
||||
}
|
||||
else if (status == 'Synced') {
|
||||
menuItems.push({
|
||||
name: globalize.translate('ButtonMarkForRemoval'),
|
||||
id: 'markforremoval'
|
||||
});
|
||||
}
|
||||
|
||||
require(['actionsheet'], function (actionsheet) {
|
||||
|
||||
actionsheet.show({
|
||||
items: menuItems,
|
||||
positionTo: elem,
|
||||
callback: function (id) {
|
||||
|
||||
switch (id) {
|
||||
|
||||
case 'cancel':
|
||||
cancelJobItem(context, jobId, jobItemId, apiClient);
|
||||
break;
|
||||
case 'retry':
|
||||
retryJobItem(context, jobId, jobItemId, apiClient);
|
||||
break;
|
||||
case 'markforremoval':
|
||||
markForRemoval(context, jobId, jobItemId, apiClient);
|
||||
break;
|
||||
case 'unmarkforremoval':
|
||||
unMarkForRemoval(context, jobId, jobItemId, apiClient);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function cancelJobItem(context, jobId, jobItemId, apiClient) {
|
||||
|
||||
// Need a timeout because jquery mobile will not show a popup while another is in the act of closing
|
||||
|
||||
loading.show();
|
||||
|
||||
apiClient.ajax({
|
||||
|
||||
type: "DELETE",
|
||||
url: apiClient.getUrl('Sync/JobItems/' + jobItemId)
|
||||
|
||||
}).then(function () {
|
||||
|
||||
loadJob(context, jobId, apiClient);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function markForRemoval(context, jobId, jobItemId, apiClient) {
|
||||
|
||||
apiClient.ajax({
|
||||
|
||||
type: "POST",
|
||||
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/MarkForRemoval')
|
||||
|
||||
}).then(function () {
|
||||
|
||||
loadJob(context, jobId, apiClient);
|
||||
});
|
||||
}
|
||||
|
||||
function unMarkForRemoval(context, jobId, jobItemId, apiClient) {
|
||||
|
||||
apiClient.ajax({
|
||||
|
||||
type: "POST",
|
||||
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/UnmarkForRemoval')
|
||||
|
||||
}).then(function () {
|
||||
|
||||
loadJob(context, jobId, apiClient);
|
||||
});
|
||||
}
|
||||
|
||||
function retryJobItem(context, jobId, jobItemId, apiClient) {
|
||||
|
||||
apiClient.ajax({
|
||||
|
||||
type: "POST",
|
||||
url: apiClient.getUrl('Sync/JobItems/' + jobItemId + '/Enable')
|
||||
|
||||
}).then(function () {
|
||||
|
||||
loadJob(context, jobId, apiClient);
|
||||
});
|
||||
}
|
||||
|
||||
function fillJobValues(context, job, editOptions) {
|
||||
|
||||
var txtSyncJobName = context.querySelector('#txtSyncJobName');
|
||||
if (txtSyncJobName) {
|
||||
txtSyncJobName.value = job.Name;
|
||||
}
|
||||
|
||||
var selectProfile = context.querySelector('#selectProfile');
|
||||
if (selectProfile) {
|
||||
selectProfile.value = job.Profile || '';
|
||||
}
|
||||
|
||||
var selectQuality = context.querySelector('#selectQuality');
|
||||
if (selectQuality) {
|
||||
selectQuality.value = job.Quality || '';
|
||||
}
|
||||
|
||||
var chkUnwatchedOnly = context.querySelector('#chkUnwatchedOnly');
|
||||
if (chkUnwatchedOnly) {
|
||||
chkUnwatchedOnly.checked = job.UnwatchedOnly;
|
||||
}
|
||||
|
||||
var chkSyncNewContent = context.querySelector('#chkSyncNewContent');
|
||||
if (chkSyncNewContent) {
|
||||
chkSyncNewContent.checked = job.SyncNewContent;
|
||||
}
|
||||
|
||||
var txtItemLimit = context.querySelector('#txtItemLimit');
|
||||
if (txtItemLimit) {
|
||||
txtItemLimit.value = job.ItemLimit;
|
||||
}
|
||||
|
||||
var txtBitrate = context.querySelector('#txtBitrate');
|
||||
if (job.Bitrate) {
|
||||
txtBitrate.value = job.Bitrate / 1000000;
|
||||
} else {
|
||||
txtBitrate.value = '';
|
||||
}
|
||||
|
||||
var target = editOptions.Targets.filter(function (t) {
|
||||
return t.Id == job.TargetId;
|
||||
})[0];
|
||||
var targetName = target ? target.Name : '';
|
||||
|
||||
var selectSyncTarget = context.querySelector('#selectSyncTarget');
|
||||
if (selectSyncTarget) {
|
||||
selectSyncTarget.value = targetName;
|
||||
}
|
||||
}
|
||||
|
||||
var _jobOptions;
|
||||
function loadJob(context, id, apiClient) {
|
||||
|
||||
loading.show();
|
||||
|
||||
apiClient.getJSON(apiClient.getUrl('Sync/Jobs/' + id)).then(function (job) {
|
||||
|
||||
apiClient.getJSON(apiClient.getUrl('Sync/Options', {
|
||||
|
||||
UserId: job.UserId,
|
||||
ItemIds: (job.RequestedItemIds && job.RequestedItemIds.length ? job.RequestedItemIds.join('') : null),
|
||||
|
||||
ParentId: job.ParentId,
|
||||
Category: job.Category,
|
||||
TargetId: job.TargetId
|
||||
|
||||
})).then(function (options) {
|
||||
|
||||
_jobOptions = options;
|
||||
renderJob(context, job, options);
|
||||
loading.hide();
|
||||
});
|
||||
});
|
||||
|
||||
apiClient.getJSON(apiClient.getUrl('Sync/JobItems', {
|
||||
|
||||
JobId: id,
|
||||
AddMetadata: true
|
||||
|
||||
})).then(function (result) {
|
||||
|
||||
renderJobItems(context, result.Items, apiClient);
|
||||
loading.hide();
|
||||
});
|
||||
}
|
||||
|
||||
function loadJobInfo(context, job, jobItems, apiClient) {
|
||||
|
||||
//renderJob(page, job, _jobOptions);
|
||||
renderJobItems(context, jobItems, apiClient);
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
function saveJob(context, id, apiClient) {
|
||||
|
||||
loading.show();
|
||||
|
||||
apiClient.getJSON(apiClient.getUrl('Sync/Jobs/' + id)).then(function (job) {
|
||||
|
||||
require(['syncDialog'], function (syncDialog) {
|
||||
syncDialog.setJobValues(job, context);
|
||||
|
||||
apiClient.ajax({
|
||||
|
||||
url: apiClient.getUrl('Sync/Jobs/' + id),
|
||||
type: 'POST',
|
||||
data: JSON.stringify(job),
|
||||
contentType: "application/json"
|
||||
|
||||
}).then(function () {
|
||||
|
||||
loading.hide();
|
||||
dialogHelper.close(context);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function onHelpLinkClick(e) {
|
||||
|
||||
shell.openUrl(this.href);
|
||||
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
function startListening(apiClient, jobId) {
|
||||
|
||||
var startParams = "0,1500";
|
||||
|
||||
startParams += "," + jobId;
|
||||
|
||||
if (apiClient.isWebSocketOpen()) {
|
||||
apiClient.sendWebSocketMessage("SyncJobStart", startParams);
|
||||
}
|
||||
}
|
||||
|
||||
function stopListening(apiClient) {
|
||||
|
||||
if (apiClient.isWebSocketOpen()) {
|
||||
apiClient.sendWebSocketMessage("SyncJobStop", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function bindEvents(context, jobId, apiClient) {
|
||||
context.querySelector('.jobItems').addEventListener('click', function (e) {
|
||||
var btnJobItemMenu = dom.parentWithClass(e.target, 'btnJobItemMenu');
|
||||
if (btnJobItemMenu) {
|
||||
showJobItemMenu(btnJobItemMenu, jobId, apiClient);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showEditor(options) {
|
||||
|
||||
var apiClient = connectionManager.getApiClient(options.serverId);
|
||||
var id = options.jobId;
|
||||
|
||||
var dlgElementOptions = {
|
||||
removeOnClose: true,
|
||||
scrollY: false,
|
||||
autoFocus: false
|
||||
};
|
||||
|
||||
if (layoutManager.tv) {
|
||||
dlgElementOptions.size = 'fullscreen';
|
||||
} else {
|
||||
dlgElementOptions.size = 'medium';
|
||||
}
|
||||
|
||||
var dlg = dialogHelper.createDialog(dlgElementOptions);
|
||||
|
||||
dlg.classList.add('formDialog');
|
||||
|
||||
var html = '';
|
||||
html += '<div class="formDialogHeader">';
|
||||
html += '<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="md-icon"></i></button>';
|
||||
html += '<h3 class="formDialogHeaderTitle">';
|
||||
html += globalize.translate('sharedcomponents#Sync');
|
||||
html += '</h3>';
|
||||
|
||||
html += '<a href="https://github.com/MediaBrowser/Wiki/wiki/Sync" target="_blank" class="clearLink lnkHelp" style="margin-top:0;display:inline-block;vertical-align:middle;margin-left:auto;"><button is="emby-button" type="button" class="button-accent-flat button-flat"><i class="md-icon">info</i><span>' + globalize.translate('sharedcomponents#Help') + '</span></button></a>';
|
||||
|
||||
html += '</div>';
|
||||
|
||||
html += '<div class="formDialogContent smoothScrollY" style="padding-top:2em;">';
|
||||
html += '<div class="dialogContentInner dialog-content-centered">';
|
||||
|
||||
html += '<form class="syncJobForm" style="margin: auto;">';
|
||||
|
||||
html += '<div class="syncJobFormContent"></div>';
|
||||
|
||||
html += '<div class="jobItems"></div>';
|
||||
|
||||
html += '<div class="formDialogFooter">';
|
||||
html += '<button is="emby-button" type="submit" class="raised button-submit block formDialogFooterItem"><span>' + globalize.translate('sharedcomponents#Save') + '</span></button>';
|
||||
html += '</div>';
|
||||
|
||||
html += '</form>';
|
||||
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
|
||||
dlg.innerHTML = html;
|
||||
|
||||
dlg.querySelector('.lnkHelp').addEventListener('click', onHelpLinkClick);
|
||||
|
||||
var submitted = false;
|
||||
|
||||
dlg.querySelector('form').addEventListener('submit', function (e) {
|
||||
|
||||
saveJob(dlg, id, apiClient);
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
dlg.querySelector('.btnCancel').addEventListener('click', function () {
|
||||
dialogHelper.close(dlg);
|
||||
});
|
||||
|
||||
if (layoutManager.tv) {
|
||||
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
|
||||
}
|
||||
|
||||
function onSyncJobMessage(e, apiClient, msg) {
|
||||
loadJobInfo(dlg, msg.Job, msg.JobItems, apiClient);
|
||||
}
|
||||
|
||||
loadJob(dlg, id, apiClient);
|
||||
bindEvents(dlg, id, apiClient);
|
||||
|
||||
var promise = dialogHelper.open(dlg);
|
||||
|
||||
startListening(apiClient, id);
|
||||
events.on(serverNotifications, "SyncJob", onSyncJobMessage);
|
||||
|
||||
return promise.then(function () {
|
||||
|
||||
stopListening(apiClient);
|
||||
events.off(serverNotifications, "SyncJob", onSyncJobMessage);
|
||||
|
||||
if (layoutManager.tv) {
|
||||
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
|
||||
}
|
||||
|
||||
if (submitted) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
show: showEditor
|
||||
};
|
||||
|
||||
});
|
350
dashboard-ui/bower_components/emby-webcomponents/sync/syncjoblist.js
vendored
Normal file
350
dashboard-ui/bower_components/emby-webcomponents/sync/syncjoblist.js
vendored
Normal file
|
@ -0,0 +1,350 @@
|
|||
define(['serverNotifications', 'events', 'loading', 'connectionManager', 'imageLoader', 'dom', 'globalize', 'listViewStyle'], function (serverNotifications, events, loading, connectionManager, imageLoader, dom, globalize) {
|
||||
'use strict';
|
||||
|
||||
function onSyncJobsUpdated(e, apiClient, data) {
|
||||
|
||||
var listInstance = this;
|
||||
renderList(listInstance, data);
|
||||
}
|
||||
|
||||
function refreshList(listInstance, jobs) {
|
||||
for (var i = 0, length = jobs.length; i < length; i++) {
|
||||
|
||||
var job = jobs[i];
|
||||
refreshJob(listInstance, job);
|
||||
}
|
||||
}
|
||||
|
||||
function cancelJob(listInstance, id) {
|
||||
|
||||
require(['confirm'], function (confirm) {
|
||||
|
||||
var msg = listInstance.options.isLocalSync ?
|
||||
globalize.translate('ConfirmRemoveDownload') :
|
||||
globalize.translate('CancelSyncJobConfirmation');
|
||||
|
||||
confirm(msg).then(function () {
|
||||
|
||||
loading.show();
|
||||
var apiClient = getApiClient(listInstance);
|
||||
|
||||
apiClient.ajax({
|
||||
|
||||
url: apiClient.getUrl('Sync/Jobs/' + id),
|
||||
type: 'DELETE'
|
||||
|
||||
}).then(function () {
|
||||
|
||||
fetchData(listInstance);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refreshJob(listInstance, job) {
|
||||
|
||||
var listItem = listInstance.options.element.querySelector('.listItem[data-id=\'' + job.Id + '\']');
|
||||
|
||||
if (!listItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
var progress = job.Progress || 0;
|
||||
var statusIcon = listItem.querySelector('.statusIcon');
|
||||
|
||||
if (progress === 0) {
|
||||
statusIcon.innerHTML = 'file_download';
|
||||
statusIcon.classList.add('md-icon');
|
||||
statusIcon.classList.remove('status-text-icon');
|
||||
statusIcon.classList.add('zeroProgressStatus');
|
||||
} else if (progress >= 100) {
|
||||
statusIcon.innerHTML = 'check';
|
||||
statusIcon.classList.add('md-icon');
|
||||
statusIcon.classList.remove('status-text-icon');
|
||||
statusIcon.classList.remove('zeroProgressStatus');
|
||||
} else {
|
||||
statusIcon.classList.remove('md-icon');
|
||||
statusIcon.classList.remove('zeroProgressStatus');
|
||||
statusIcon.classList.add('status-text-icon');
|
||||
statusIcon.innerHTML = (Math.round(progress)) + '%';
|
||||
}
|
||||
}
|
||||
|
||||
function getSyncJobHtml(listInstance, job) {
|
||||
|
||||
var html = '';
|
||||
|
||||
html += '<div class="listItem" data-id="' + job.Id + '" data-status="' + job.Status + '">';
|
||||
|
||||
var progress = job.Progress || 0;
|
||||
|
||||
if (progress === 0) {
|
||||
html += '<i class="md-icon listItemIcon statusIcon zeroProgressStatus">file_download</i>';
|
||||
} else if (progress >= 100) {
|
||||
html += '<i class="md-icon listItemIcon statusIcon">check</i>';
|
||||
} else {
|
||||
html += '<i class="listItemIcon statusIcon status-text-icon">' + (Math.round(progress)) + '%</i>';
|
||||
}
|
||||
|
||||
var textLines = [];
|
||||
|
||||
if (job.ParentName) {
|
||||
textLines.push(job.ParentName);
|
||||
}
|
||||
|
||||
textLines.push(job.Name);
|
||||
|
||||
if (job.ItemCount == 1) {
|
||||
textLines.push(globalize.translate('ValueItemCount', job.ItemCount));
|
||||
} else {
|
||||
textLines.push(globalize.translate('ValueItemCountPlural', job.ItemCount));
|
||||
}
|
||||
|
||||
if (textLines >= 3) {
|
||||
html += '<div class="listItemBody three-line">';
|
||||
} else {
|
||||
html += '<div class="listItemBody two-line">';
|
||||
}
|
||||
|
||||
for (var i = 0, length = textLines.length; i < length; i++) {
|
||||
|
||||
if (i == 0) {
|
||||
html += '<h3 class="listItemBodyText">';
|
||||
html += textLines[i];
|
||||
html += '</h3>';
|
||||
} else {
|
||||
html += '<div class="listItemBodyText secondary">';
|
||||
html += textLines[i];
|
||||
html += '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
html += '</div>';
|
||||
|
||||
html += '<button type="button" is="paper-icon-button-light" class="btnJobMenu listItemButton"><i class="md-icon">more_vert</i></button>';
|
||||
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function renderList(listInstance, jobs) {
|
||||
|
||||
if ((new Date().getTime() - listInstance.lastDataLoad) < 60000) {
|
||||
refreshList(listInstance, jobs);
|
||||
return;
|
||||
}
|
||||
|
||||
listInstance.lastDataLoad = new Date().getTime();
|
||||
|
||||
var html = '';
|
||||
var lastTargetName = '';
|
||||
|
||||
var isLocalSync = listInstance.options.isLocalSync;
|
||||
var showTargetName = !isLocalSync;
|
||||
|
||||
var hasOpenSection = false;
|
||||
|
||||
for (var i = 0, length = jobs.length; i < length; i++) {
|
||||
|
||||
var job = jobs[i];
|
||||
if (showTargetName) {
|
||||
var targetName = job.TargetName || 'Unknown';
|
||||
|
||||
if (targetName != lastTargetName) {
|
||||
|
||||
if (lastTargetName) {
|
||||
html += '</div>';
|
||||
html += '<br/>';
|
||||
html += '<br/>';
|
||||
html += '<br/>';
|
||||
hasOpenSection = false;
|
||||
}
|
||||
|
||||
lastTargetName = targetName;
|
||||
|
||||
html += '<div class="detailSectionHeader">';
|
||||
|
||||
html += '<div>' + targetName + '</div>';
|
||||
|
||||
html += '</div>';
|
||||
html += '<div class="itemsContainer vertical-list">';
|
||||
hasOpenSection = true;
|
||||
}
|
||||
}
|
||||
|
||||
html += getSyncJobHtml(listInstance, job);
|
||||
}
|
||||
|
||||
if (hasOpenSection) {
|
||||
html += '</div>';
|
||||
}
|
||||
|
||||
var elem = listInstance.options.element;
|
||||
|
||||
if (!html) {
|
||||
if (isLocalSync) {
|
||||
html = '<div style="padding:1em .25em;">' + globalize.translate('MessageDownloadsFound') + '</div>';
|
||||
} else {
|
||||
html = '<div style="padding:1em .25em;">' + globalize.translate('MessageNoSyncJobsFound') + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
elem.innerHTML = html;
|
||||
|
||||
imageLoader.lazyChildren(elem);
|
||||
}
|
||||
|
||||
function fetchData(listInstance) {
|
||||
|
||||
listInstance.lastDataLoad = 0;
|
||||
loading.show();
|
||||
|
||||
var options = {};
|
||||
var apiClient = getApiClient(listInstance);
|
||||
|
||||
if (listInstance.options.userId) {
|
||||
options.UserId = listInstance.options.userId;
|
||||
}
|
||||
|
||||
if (listInstance.options.isLocalSync) {
|
||||
options.TargetId = apiClient.deviceId();
|
||||
} else {
|
||||
options.ExcludeTargetIds = apiClient.deviceId();
|
||||
}
|
||||
|
||||
return apiClient.getJSON(ApiClient.getUrl('Sync/Jobs', options)).then(function (response) {
|
||||
|
||||
renderList(listInstance, response.Items);
|
||||
loading.hide();
|
||||
});
|
||||
}
|
||||
|
||||
function startListening(listInstance) {
|
||||
|
||||
var startParams = "0,1500";
|
||||
|
||||
var apiClient = getApiClient(listInstance);
|
||||
|
||||
if (listInstance.options.userId) {
|
||||
startParams += "," + listInstance.options.userId;
|
||||
}
|
||||
if (listInstance.options.isLocalSync) {
|
||||
startParams += "," + apiClient.deviceId();
|
||||
}
|
||||
|
||||
if (apiClient.isWebSocketOpen()) {
|
||||
apiClient.sendWebSocketMessage("SyncJobsStart", startParams);
|
||||
}
|
||||
}
|
||||
|
||||
function stopListening(listInstance) {
|
||||
|
||||
var apiClient = getApiClient(listInstance);
|
||||
if (apiClient.isWebSocketOpen()) {
|
||||
apiClient.sendWebSocketMessage("SyncJobsStop", "");
|
||||
}
|
||||
}
|
||||
|
||||
function getApiClient(listInstance) {
|
||||
return connectionManager.getApiClient(listInstance.options.serverId);
|
||||
}
|
||||
|
||||
function showJobMenu(listInstance, elem) {
|
||||
|
||||
var item = dom.parentWithClass(elem, 'listItem');
|
||||
var jobId = item.getAttribute('data-id');
|
||||
var status = item.getAttribute('data-status');
|
||||
|
||||
var menuItems = [];
|
||||
|
||||
if (status == 'Cancelled') {
|
||||
menuItems.push({
|
||||
name: globalize.translate('ButtonDelete'),
|
||||
id: 'delete'
|
||||
});
|
||||
} else {
|
||||
var txt = listInstance.options.isLocalSync ?
|
||||
globalize.translate('RemoveDownload') :
|
||||
globalize.translate('ButtonCancelSyncJob');
|
||||
|
||||
menuItems.push({
|
||||
name: globalize.translate(txt),
|
||||
id: 'cancel'
|
||||
});
|
||||
}
|
||||
|
||||
require(['actionsheet'], function (actionsheet) {
|
||||
|
||||
actionsheet.show({
|
||||
items: menuItems,
|
||||
positionTo: elem,
|
||||
callback: function (id) {
|
||||
|
||||
switch (id) {
|
||||
|
||||
case 'delete':
|
||||
cancelJob(listInstance, jobId);
|
||||
break;
|
||||
case 'cancel':
|
||||
cancelJob(listInstance, jobId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function onElementClick(e) {
|
||||
|
||||
var listInstance = this;
|
||||
|
||||
var btnJobMenu = dom.parentWithClass(e.target, 'btnJobMenu');
|
||||
if (btnJobMenu) {
|
||||
showJobMenu(this, btnJobMenu);
|
||||
return;
|
||||
}
|
||||
|
||||
var listItem = dom.parentWithClass(e.target, 'listItem');
|
||||
if (listItem) {
|
||||
var jobId = listItem.getAttribute('data-id');
|
||||
// edit job
|
||||
events.trigger(listInstance, 'jobedit', [jobId, listInstance.options.serverId]);
|
||||
}
|
||||
}
|
||||
|
||||
function syncJobList(options) {
|
||||
this.options = options;
|
||||
|
||||
var onSyncJobsUpdatedHandler = onSyncJobsUpdated.bind(this);
|
||||
this.onSyncJobsUpdatedHandler = onSyncJobsUpdatedHandler;
|
||||
events.on(serverNotifications, 'SyncJobs', onSyncJobsUpdatedHandler);
|
||||
|
||||
var onClickHandler = onElementClick.bind(this);
|
||||
options.element.addEventListener('click', onClickHandler);
|
||||
this.onClickHandler = onClickHandler;
|
||||
|
||||
fetchData(this);
|
||||
startListening(this);
|
||||
}
|
||||
|
||||
syncJobList.prototype.destroy = function () {
|
||||
|
||||
stopListening(this);
|
||||
|
||||
var onSyncJobsUpdatedHandler = this.onSyncJobsUpdatedHandler;
|
||||
this.onSyncJobsUpdatedHandler = null;
|
||||
events.off(serverNotifications, 'SyncJobs', onSyncJobsUpdatedHandler);
|
||||
|
||||
var onClickHandler = this.onClickHandler;
|
||||
this.onClickHandler = null;
|
||||
this.options.element.removeEventListener('click', onClickHandler);
|
||||
|
||||
this.options = null;
|
||||
};
|
||||
|
||||
return syncJobList;
|
||||
});
|
|
@ -69,8 +69,10 @@
|
|||
|
||||
syncToggle.prototype.refresh = function(item) {
|
||||
|
||||
this.options.item = item;
|
||||
updateSyncStatus(this.options.container, item);
|
||||
if (this.options) {
|
||||
this.options.item = item;
|
||||
updateSyncStatus(this.options.container, item);
|
||||
}
|
||||
};
|
||||
|
||||
syncToggle.prototype.destroy = function () {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
define(['connectionManager', 'globalize', 'dom', 'paper-icon-button-light', 'material-icons', 'emby-button', 'css!./userdatabuttons'], function (connectionManager, globalize, dom) {
|
||||
define(['connectionManager', 'globalize', 'dom', 'itemHelper', 'paper-icon-button-light', 'material-icons', 'emby-button', 'css!./userdatabuttons'], function (connectionManager, globalize, dom, itemHelper) {
|
||||
'use strict';
|
||||
|
||||
var userDataMethods = {
|
||||
|
@ -86,6 +86,10 @@ define(['connectionManager', 'globalize', 'dom', 'paper-icon-button-light', 'mat
|
|||
|
||||
var itemId = item.Id;
|
||||
|
||||
if (itemHelper.isLocalItem(item)) {
|
||||
return html;
|
||||
}
|
||||
|
||||
var btnCssClass = "btnUserData";
|
||||
|
||||
if (cssClass) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue