Skip to content

Commit

Permalink
update search
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed May 6, 2017
1 parent 9dd41b3 commit 732b273
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 31 deletions.
267 changes: 242 additions & 25 deletions search/searchresults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,80 @@
});
}

function getSearchHints(apiClient, query) {
function getSearchHints(instance, apiClient, query) {

if (!query.searchTerm) {
return Promise.resolve({
SearchHints: []
});
}

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);
}

Expand All @@ -52,38 +118,148 @@
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,
IncludeMedia: true,
IncludeGenres: false,
IncludeStudios: false,
IncludeArtists: false,
IncludeItemTypes: "Movie"
IncludeItemTypes: "Series"

}, context, '.movieResults', {
}, context, '.seriesResults', {

showTitle: true,
overlayText: false,
centerText: true,
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,
IncludeMedia: true,
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

});

Expand All @@ -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, {
Expand All @@ -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, {
Expand Down Expand Up @@ -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);
});
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 732b273

Please sign in to comment.