From 732b273c5aebdb6428a39de3ebd783badb690ef6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 6 May 2017 14:34:38 -0400 Subject: [PATCH] update search --- search/searchresults.js | 267 ++++++++++++++++++++++++++--- search/searchresults.template.html | 32 +++- 2 files changed, 268 insertions(+), 31 deletions(-) diff --git a/search/searchresults.js b/search/searchresults.js index bf28ad34..6fbdc071 100644 --- a/search/searchresults.js +++ b/search/searchresults.js @@ -33,7 +33,7 @@ }); } - function getSearchHints(apiClient, query) { + function getSearchHints(instance, apiClient, query) { if (!query.searchTerm) { return Promise.resolve({ @@ -41,6 +41,72 @@ }); } + var allowSearch = true; + + var queryIncludeItemTypes = query.IncludeItemTypes; + + if (instance.options.collectionType === 'tvshows') { + if (query.IncludeArtists) { + allowSearch = false; + } + else if (queryIncludeItemTypes === 'Movie' || + queryIncludeItemTypes === 'LiveTvProgram' || + queryIncludeItemTypes === 'MusicAlbum' || + queryIncludeItemTypes === 'Audio' || + queryIncludeItemTypes === 'Book' || + queryIncludeItemTypes === 'AudioBook') { + allowSearch = false; + } + } + else if (instance.options.collectionType === 'movies') { + if (query.IncludeArtists) { + allowSearch = false; + } + else if (queryIncludeItemTypes === 'Series' || + queryIncludeItemTypes === 'Episode' || + queryIncludeItemTypes === 'LiveTvProgram' || + queryIncludeItemTypes === 'MusicAlbum' || + queryIncludeItemTypes === 'Audio' || + queryIncludeItemTypes === 'Book' || + queryIncludeItemTypes === 'AudioBook') { + allowSearch = false; + } + } + else if (instance.options.collectionType === 'music') { + if (query.People) { + allowSearch = false; + } + else if (queryIncludeItemTypes === 'Series' || + queryIncludeItemTypes === 'Episode' || + queryIncludeItemTypes === 'LiveTvProgram' || + queryIncludeItemTypes === 'Movie') { + allowSearch = false; + } + } + else if (instance.options.collectionType === 'livetv') { + if (query.IncludeArtists || query.IncludePeople) { + allowSearch = false; + } + else if (queryIncludeItemTypes === 'Series' || + queryIncludeItemTypes === 'Episode' || + queryIncludeItemTypes === 'MusicAlbum' || + queryIncludeItemTypes === 'Audio' || + queryIncludeItemTypes === 'Book' || + queryIncludeItemTypes === 'AudioBook' || + queryIncludeItemTypes === 'Movie') { + allowSearch = false; + } + } + if (queryIncludeItemTypes === 'NullType') { + allowSearch = false; + } + + if (!allowSearch) { + return Promise.resolve({ + SearchHints: [] + }); + } + return apiClient.getSearchHints(query); } @@ -52,6 +118,54 @@ loadSuggestions(instance, context, apiClient); } + if (instance.options.collectionType === 'livetv') { + + searchType(instance, apiClient, { + searchTerm: value, + IncludePeople: false, + IncludeMedia: true, + IncludeGenres: false, + IncludeStudios: false, + IncludeArtists: false, + IncludeItemTypes: "LiveTvProgram", + IsMovie: true, + IsKids: false + + }, context, '.movieResults', { + + preferThumb: true, + inheritThumb: false, + shape: (enableScrollX() ? 'overflowPortrait' : 'portrait'), + showParentTitleOrTitle: true, + showTitle: false, + centerText: true, + coverImage: true, + overlayText: false, + overlayMoreButton: true, + showAirTime: true, + showAirDateTime: true, + showChannelName: true + }); + } else { + + searchType(instance, apiClient, { + searchTerm: value, + IncludePeople: false, + IncludeMedia: true, + IncludeGenres: false, + IncludeStudios: false, + IncludeArtists: false, + IncludeItemTypes: "Movie" + + }, context, '.movieResults', { + + showTitle: true, + overlayText: false, + centerText: true, + showYear: true + }); + } + searchType(instance, apiClient, { searchTerm: value, IncludePeople: false, @@ -59,9 +173,9 @@ IncludeGenres: false, IncludeStudios: false, IncludeArtists: false, - IncludeItemTypes: "Movie" + IncludeItemTypes: "Series" - }, context, '.movieResults', { + }, context, '.seriesResults', { showTitle: true, overlayText: false, @@ -69,6 +183,57 @@ showYear: true }); + if (instance.options.collectionType === 'livetv') { + + searchType(instance, apiClient, { + searchTerm: value, + IncludePeople: false, + IncludeMedia: true, + IncludeGenres: false, + IncludeStudios: false, + IncludeArtists: false, + IncludeItemTypes: "LiveTvProgram", + IsSeries: true, + IsSports: false, + IsKids: false, + IsNews: false + + }, context, '.episodeResults', { + + preferThumb: true, + inheritThumb: false, + shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'), + preferThumb: true, + showParentTitleOrTitle: true, + showTitle: false, + centerText: true, + coverImage: true, + overlayText: false, + overlayMoreButton: true, + showAirTime: true, + showAirDateTime: true, + showChannelName: true + }); + + } else { + + searchType(instance, apiClient, { + searchTerm: value, + IncludePeople: false, + IncludeMedia: true, + IncludeGenres: false, + IncludeStudios: false, + IncludeArtists: false, + IncludeItemTypes: "Episode" + + }, context, '.episodeResults', { + + coverImage: true, + showTitle: true, + showParentTitle: true + }); + } + searchType(instance, apiClient, { searchTerm: value, IncludePeople: false, @@ -76,14 +241,25 @@ IncludeGenres: false, IncludeStudios: false, IncludeArtists: false, - IncludeItemTypes: "LiveTvProgram" - - }, context, '.programResults', { - - showTitle: true, - showParentTitle: true, + // NullType to hide + IncludeItemTypes: instance.options.collectionType === 'livetv' ? 'LiveTvProgram' : 'NullType', + IsSports: true + + }, context, '.sportsResults', { + + preferThumb: true, + inheritThumb: false, + shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'), + preferThumb: true, + showParentTitleOrTitle: true, + showTitle: false, + centerText: true, + coverImage: true, overlayText: false, - centerText: true + overlayMoreButton: true, + showAirTime: true, + showAirDateTime: true, + showChannelName: true }); @@ -94,14 +270,26 @@ IncludeGenres: false, IncludeStudios: false, IncludeArtists: false, - IncludeItemTypes: "Series" - - }, context, '.seriesResults', { - - showTitle: true, - overlayText: false, + // NullType to hide + IncludeItemTypes: instance.options.collectionType === 'livetv' ? 'LiveTvProgram' : 'NullType', + IsKids: true + + }, context, '.kidsResults', { + + preferThumb: true, + inheritThumb: false, + shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'), + preferThumb: true, + showParentTitleOrTitle: true, + showTitle: false, centerText: true, - showYear: true + coverImage: true, + overlayText: false, + overlayMoreButton: true, + showAirTime: true, + showAirDateTime: true, + showChannelName: true + }); searchType(instance, apiClient, { @@ -111,13 +299,28 @@ IncludeGenres: false, IncludeStudios: false, IncludeArtists: false, - IncludeItemTypes: "Episode" + IncludeItemTypes: "LiveTvProgram", + IsMovie: instance.options.collectionType === 'livetv' ? false : null, + IsSeries: instance.options.collectionType === 'livetv' ? false : null, + IsSports: instance.options.collectionType === 'livetv' ? false : null, + IsKids: instance.options.collectionType === 'livetv' ? false : null - }, context, '.episodeResults', { + }, context, '.programResults', { + preferThumb: true, + inheritThumb: false, + shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'), + preferThumb: true, + showParentTitleOrTitle: true, + showTitle: false, + centerText: true, coverImage: true, - showTitle: true, - showParentTitle: true + overlayText: false, + overlayMoreButton: true, + showAirTime: true, + showAirDateTime: true, + showChannelName: true + }); searchType(instance, apiClient, { @@ -220,10 +423,10 @@ function searchType(instance, apiClient, query, context, section, cardOptions) { query.UserId = apiClient.getCurrentUserId(); - query.Limit = 24; + query.Limit = enableScrollX() ? 24 : 16; query.ParentId = instance.options.parentId; - getSearchHints(apiClient, query).then(function (result) { + getSearchHints(instance, apiClient, query).then(function (result) { populateResults(result, context, section, cardOptions); }); @@ -241,21 +444,35 @@ itemsContainer: itemsContainer, parentContainer: section, - shape: 'autooverflow', + shape: enableScrollX() ? 'autooverflow' : 'auto', scalable: true, overlayText: false, centerText: true, - allowBottomPadding: false + allowBottomPadding: !enableScrollX() }, cardOptions || {})); section.querySelector('.emby-scroller').scrollToBeginning(true); } + function enableScrollX() { + return !layoutManager.desktop; + } + + function replaceAll(originalString, strReplace, strWith) { + var reg = new RegExp(strReplace, 'ig'); + return originalString.replace(reg, strWith); + } + function embed(elem, instance, options) { require(['text!./searchresults.template.html'], function (template) { + if (!enableScrollX()) { + template = replaceAll(template, 'data-horizontal="true"', 'data-horizontal="false"'); + template = replaceAll(template, 'itemsContainer scrollSlider', 'itemsContainer scrollSlider vertical-wrap'); + } + var html = globalize.translateDocument(template, 'sharedcomponents'); elem.innerHTML = html; diff --git a/search/searchresults.template.html b/search/searchresults.template.html index 1f840d77..2d717a1f 100644 --- a/search/searchresults.template.html +++ b/search/searchresults.template.html @@ -19,9 +19,9 @@

+
-

${Programs}

+

${Shows}

@@ -29,9 +29,9 @@

+
-

${Shows}

+

${Episodes}

@@ -39,9 +39,29 @@

+
-

${Episodes}

+

${Sports}

+
+ +
+
+
+
+ +
+
+

${Kids}

+
+ +
+
+
+
+ +
+
+

${Programs}