2019-11-06 13:43:39 +03:00
|
|
|
define(["browser", "layoutManager", "userSettings", "inputManager", "loading", "cardBuilder", "dom", "apphost", "imageLoader", "libraryMenu", "playbackManager", "mainTabsManager", "scrollStyles", "emby-itemscontainer", "emby-tabs", "emby-button", "flexStyles"], function (browser, layoutManager, userSettings, inputManager, loading, cardBuilder, dom, appHost, imageLoader, libraryMenu, playbackManager, mainTabsManager) {
|
2018-10-23 01:05:09 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function itemsPerRow() {
|
|
|
|
var screenWidth = dom.getWindowSize().innerWidth;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (screenWidth >= 1920) {
|
|
|
|
return 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screenWidth >= 1200) {
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screenWidth >= 1000) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 8;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableScrollX() {
|
2019-11-06 13:43:39 +03:00
|
|
|
return !layoutManager.desktop;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSquareShape() {
|
2019-11-06 13:43:39 +03:00
|
|
|
return enableScrollX() ? "overflowSquare" : "square";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadLatest(page, parentId) {
|
|
|
|
loading.show();
|
2019-11-06 13:43:39 +03:00
|
|
|
var userId = ApiClient.getCurrentUserId();
|
|
|
|
var options = {
|
|
|
|
IncludeItemTypes: "Audio",
|
|
|
|
Limit: enableScrollX() ? 3 * itemsPerRow() : 2 * itemsPerRow(),
|
|
|
|
Fields: "PrimaryImageAspectRatio,BasicSyncInfo",
|
|
|
|
ParentId: parentId,
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
EnableTotalRecordCount: false
|
|
|
|
};
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Users/" + userId + "/Items/Latest", options)).then(function (items) {
|
|
|
|
var elem = page.querySelector("#recentlyAddedSongs");
|
|
|
|
var supportsImageAnalysis = appHost.supports("imageanalysis");
|
|
|
|
supportsImageAnalysis = false;
|
|
|
|
elem.innerHTML = cardBuilder.getCardsHtml({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: items,
|
2019-11-06 13:43:39 +03:00
|
|
|
showUnplayedIndicator: false,
|
|
|
|
showLatestItemsPopup: false,
|
2018-10-23 01:05:09 +03:00
|
|
|
shape: getSquareShape(),
|
2019-11-06 13:43:39 +03:00
|
|
|
showTitle: true,
|
|
|
|
showParentTitle: true,
|
|
|
|
lazy: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
centerText: !supportsImageAnalysis,
|
|
|
|
overlayPlayButton: !supportsImageAnalysis,
|
|
|
|
allowBottomPadding: !enableScrollX(),
|
|
|
|
cardLayout: supportsImageAnalysis,
|
2019-11-06 13:43:39 +03:00
|
|
|
coverImage: true
|
|
|
|
});
|
|
|
|
imageLoader.lazyChildren(elem);
|
|
|
|
loading.hide();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadRecentlyPlayed(page, parentId) {
|
|
|
|
var options = {
|
|
|
|
SortBy: "DatePlayed",
|
|
|
|
SortOrder: "Descending",
|
|
|
|
IncludeItemTypes: "Audio",
|
|
|
|
Limit: itemsPerRow(),
|
2019-11-06 13:43:39 +03:00
|
|
|
Recursive: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
Fields: "PrimaryImageAspectRatio,AudioInfo",
|
|
|
|
Filters: "IsPlayed",
|
|
|
|
ParentId: parentId,
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
2019-11-06 13:43:39 +03:00
|
|
|
EnableTotalRecordCount: false
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.getItems(ApiClient.getCurrentUserId(), options).then(function (result) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var elem = page.querySelector("#recentlyPlayed");
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (result.Items.length) {
|
|
|
|
elem.classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
elem.classList.add("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
var itemsContainer = elem.querySelector(".itemsContainer");
|
|
|
|
var supportsImageAnalysis = appHost.supports("imageanalysis");
|
|
|
|
supportsImageAnalysis = false;
|
|
|
|
itemsContainer.innerHTML = cardBuilder.getCardsHtml({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: result.Items,
|
2019-11-06 13:43:39 +03:00
|
|
|
showUnplayedIndicator: false,
|
2018-10-23 01:05:09 +03:00
|
|
|
shape: getSquareShape(),
|
2019-11-06 13:43:39 +03:00
|
|
|
showTitle: true,
|
|
|
|
showParentTitle: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
action: "instantmix",
|
2019-11-06 13:43:39 +03:00
|
|
|
lazy: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
centerText: !supportsImageAnalysis,
|
|
|
|
overlayMoreButton: !supportsImageAnalysis,
|
|
|
|
allowBottomPadding: !enableScrollX(),
|
|
|
|
cardLayout: supportsImageAnalysis,
|
2019-11-06 13:43:39 +03:00
|
|
|
coverImage: true
|
|
|
|
});
|
|
|
|
imageLoader.lazyChildren(itemsContainer);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadFrequentlyPlayed(page, parentId) {
|
|
|
|
var options = {
|
|
|
|
SortBy: "PlayCount",
|
|
|
|
SortOrder: "Descending",
|
|
|
|
IncludeItemTypes: "Audio",
|
|
|
|
Limit: itemsPerRow(),
|
2019-11-06 13:43:39 +03:00
|
|
|
Recursive: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
Fields: "PrimaryImageAspectRatio,AudioInfo",
|
|
|
|
Filters: "IsPlayed",
|
|
|
|
ParentId: parentId,
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
2019-11-06 13:43:39 +03:00
|
|
|
EnableTotalRecordCount: false
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.getItems(ApiClient.getCurrentUserId(), options).then(function (result) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var elem = page.querySelector("#topPlayed");
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (result.Items.length) {
|
|
|
|
elem.classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
elem.classList.add("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
var itemsContainer = elem.querySelector(".itemsContainer");
|
|
|
|
var supportsImageAnalysis = appHost.supports("imageanalysis");
|
|
|
|
supportsImageAnalysis = false;
|
|
|
|
itemsContainer.innerHTML = cardBuilder.getCardsHtml({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: result.Items,
|
2019-11-06 13:43:39 +03:00
|
|
|
showUnplayedIndicator: false,
|
2018-10-23 01:05:09 +03:00
|
|
|
shape: getSquareShape(),
|
2019-11-06 13:43:39 +03:00
|
|
|
showTitle: true,
|
|
|
|
showParentTitle: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
action: "instantmix",
|
2019-11-06 13:43:39 +03:00
|
|
|
lazy: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
centerText: !supportsImageAnalysis,
|
|
|
|
overlayMoreButton: !supportsImageAnalysis,
|
|
|
|
allowBottomPadding: !enableScrollX(),
|
|
|
|
cardLayout: supportsImageAnalysis,
|
2019-11-06 13:43:39 +03:00
|
|
|
coverImage: true
|
|
|
|
});
|
|
|
|
imageLoader.lazyChildren(itemsContainer);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadSuggestionsTab(page, tabContent, parentId) {
|
2019-11-06 13:43:39 +03:00
|
|
|
console.log("loadSuggestionsTab");
|
|
|
|
loadLatest(tabContent, parentId);
|
|
|
|
loadRecentlyPlayed(tabContent, parentId);
|
|
|
|
loadFrequentlyPlayed(tabContent, parentId);
|
|
|
|
|
|
|
|
require(["components/favoriteitems"], function (favoriteItems) {
|
|
|
|
favoriteItems.render(tabContent, ApiClient.getCurrentUserId(), parentId, ["favoriteArtists", "favoriteAlbums", "favoriteSongs"]);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTabs() {
|
|
|
|
return [{
|
|
|
|
name: Globalize.translate("TabSuggestions")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("TabAlbums")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("TabAlbumArtists")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("TabArtists")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("TabPlaylists")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("TabSongs")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("TabGenres")
|
|
|
|
}, {
|
|
|
|
name: Globalize.translate("ButtonSearch"),
|
|
|
|
cssClass: "searchTabButton"
|
2019-11-06 13:43:39 +03:00
|
|
|
}];
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDefaultTabIndex(folderId) {
|
|
|
|
switch (userSettings.get("landing-" + folderId)) {
|
|
|
|
case "albums":
|
|
|
|
return 1;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "albumartists":
|
|
|
|
return 2;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "artists":
|
|
|
|
return 3;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "playlists":
|
|
|
|
return 4;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "songs":
|
|
|
|
return 5;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "genres":
|
|
|
|
return 6;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
default:
|
2019-11-06 13:43:39 +03:00
|
|
|
return 0;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
return function (view, params) {
|
2018-10-23 01:05:09 +03:00
|
|
|
function reload() {
|
|
|
|
loading.show();
|
|
|
|
var tabContent = view.querySelector(".pageTabContent[data-index='0']");
|
2019-11-06 13:43:39 +03:00
|
|
|
loadSuggestionsTab(view, tabContent, params.topParentId);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableScrollX() {
|
2019-11-06 13:43:39 +03:00
|
|
|
return browser.mobile;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setScrollClasses(elem, scrollX) {
|
2019-11-06 13:43:39 +03:00
|
|
|
if (scrollX) {
|
|
|
|
elem.classList.add("hiddenScrollX");
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
elem.classList.add("smoothScrollX");
|
|
|
|
}
|
|
|
|
|
|
|
|
elem.classList.add("scrollX");
|
|
|
|
elem.classList.remove("vertical-wrap");
|
|
|
|
} else {
|
|
|
|
elem.classList.remove("hiddenScrollX");
|
|
|
|
elem.classList.remove("smoothScrollX");
|
|
|
|
elem.classList.remove("scrollX");
|
|
|
|
elem.classList.add("vertical-wrap");
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onBeforeTabChange(e) {
|
2019-11-06 13:43:39 +03:00
|
|
|
preLoadTab(view, parseInt(e.detail.selectedTabIndex));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTabChange(e) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loadTab(view, parseInt(e.detail.selectedTabIndex));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTabContainers() {
|
2019-11-06 13:43:39 +03:00
|
|
|
return view.querySelectorAll(".pageTabContent");
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function initTabs() {
|
2019-11-06 13:43:39 +03:00
|
|
|
mainTabsManager.setTabs(view, currentTabIndex, getTabs, getTabContainers, onBeforeTabChange, onTabChange);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTabController(page, index, callback) {
|
|
|
|
var depends = [];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case 1:
|
2019-08-15 21:25:43 -07:00
|
|
|
depends.push("controllers/music/musicalbums");
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2019-08-15 21:25:43 -07:00
|
|
|
depends.push("controllers/music/musicartists");
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case 4:
|
2019-08-15 21:25:43 -07:00
|
|
|
depends.push("controllers/music/musicplaylists");
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case 5:
|
2019-08-15 21:25:43 -07:00
|
|
|
depends.push("controllers/music/songs");
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case 6:
|
2019-08-15 21:25:43 -07:00
|
|
|
depends.push("controllers/music/musicgenres");
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case 7:
|
2019-11-06 13:43:39 +03:00
|
|
|
depends.push("scripts/searchtab");
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
require(depends, function (controllerFactory) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var tabContent;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (0 == index) {
|
|
|
|
tabContent = view.querySelector(".pageTabContent[data-index='" + index + "']");
|
|
|
|
self.tabContent = tabContent;
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var controller = tabControllers[index];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (!controller) {
|
|
|
|
tabContent = view.querySelector(".pageTabContent[data-index='" + index + "']");
|
|
|
|
|
|
|
|
if (index === 0) {
|
|
|
|
controller = self;
|
|
|
|
} else if (index === 7) {
|
|
|
|
controller = new controllerFactory(view, tabContent, {
|
|
|
|
collectionType: "music",
|
|
|
|
parentId: params.topParentId
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
controller = new controllerFactory(view, params, tabContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == 2) {
|
|
|
|
controller.mode = "albumartists";
|
|
|
|
} else if (index == 3) {
|
|
|
|
controller.mode = "artists";
|
|
|
|
}
|
|
|
|
|
|
|
|
tabControllers[index] = controller;
|
|
|
|
if (controller.initTab) {
|
|
|
|
controller.initTab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(controller);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function preLoadTab(page, index) {
|
2019-11-06 13:43:39 +03:00
|
|
|
getTabController(page, index, function (controller) {
|
|
|
|
if (renderedTabs.indexOf(index) == -1 && controller.preRender) {
|
|
|
|
controller.preRender();
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadTab(page, index) {
|
2019-11-06 13:43:39 +03:00
|
|
|
currentTabIndex = index;
|
|
|
|
getTabController(page, index, function (controller) {
|
|
|
|
initialTabIndex = null;
|
|
|
|
|
|
|
|
if (renderedTabs.indexOf(index) == -1) {
|
|
|
|
renderedTabs.push(index);
|
|
|
|
controller.renderTab();
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onInputCommand(e) {
|
|
|
|
switch (e.detail.command) {
|
|
|
|
case "search":
|
2019-11-06 13:43:39 +03:00
|
|
|
e.preventDefault();
|
|
|
|
Dashboard.navigate("search.html?collectionType=music&parentId=" + params.topParentId);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
var isViewRestored;
|
|
|
|
var self = this;
|
|
|
|
var currentTabIndex = parseInt(params.tab || getDefaultTabIndex(params.topParentId));
|
|
|
|
var initialTabIndex = currentTabIndex;
|
|
|
|
|
|
|
|
self.initTab = function () {
|
|
|
|
var tabContent = view.querySelector(".pageTabContent[data-index='0']");
|
|
|
|
var containers = tabContent.querySelectorAll(".itemsContainer");
|
|
|
|
|
|
|
|
for (var i = 0, length = containers.length; i < length; i++) {
|
|
|
|
setScrollClasses(containers[i], enableScrollX());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.renderTab = function () {
|
|
|
|
reload();
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
var tabControllers = [];
|
|
|
|
var renderedTabs = [];
|
|
|
|
view.addEventListener("viewshow", function (e) {
|
|
|
|
isViewRestored = e.detail.isRestored;
|
|
|
|
initTabs();
|
|
|
|
if (!view.getAttribute("data-title")) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var parentId = params.topParentId;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (parentId) {
|
|
|
|
ApiClient.getItem(ApiClient.getCurrentUserId(), parentId).then(function (item) {
|
|
|
|
view.setAttribute("data-title", item.Name);
|
|
|
|
libraryMenu.setTitle(item.Name);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
view.setAttribute("data-title", Globalize.translate("TabMusic"));
|
|
|
|
libraryMenu.setTitle(Globalize.translate("TabMusic"));
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
inputManager.on(window, onInputCommand);
|
|
|
|
});
|
|
|
|
view.addEventListener("viewbeforehide", function (e) {
|
|
|
|
inputManager.off(window, onInputCommand);
|
|
|
|
});
|
|
|
|
view.addEventListener("viewdestroy", function (e) {
|
|
|
|
tabControllers.forEach(function (t) {
|
|
|
|
if (t.destroy) {
|
|
|
|
t.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|