2020-07-16 10:28:08 +01:00
|
|
|
import layoutManager from 'layoutManager';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import cardBuilder from 'cardBuilder';
|
|
|
|
import appRouter from 'appRouter';
|
|
|
|
import 'emby-scroller';
|
|
|
|
import 'emby-itemscontainer';
|
|
|
|
import 'emby-button';
|
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function loadSuggestions(instance, context, apiClient) {
|
2020-07-16 10:28:08 +01:00
|
|
|
const options = {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
SortBy: 'IsFavoriteOrLiked,Random',
|
|
|
|
IncludeItemTypes: 'Movie,Series,MusicArtist',
|
2018-10-23 01:05:09 +03:00
|
|
|
Limit: 20,
|
2019-01-10 15:39:37 +03:00
|
|
|
Recursive: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
ImageTypeLimit: 0,
|
2019-01-10 15:39:37 +03:00
|
|
|
EnableImages: false,
|
2018-10-23 01:05:09 +03:00
|
|
|
ParentId: instance.options.parentId,
|
2019-01-10 15:39:37 +03:00
|
|
|
EnableTotalRecordCount: false
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
apiClient.getItems(apiClient.getCurrentUserId(), options).then(function (result) {
|
|
|
|
if (instance.mode !== 'suggestions') {
|
|
|
|
result.Items = [];
|
|
|
|
}
|
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
const html = result.Items.map(function (i) {
|
|
|
|
const href = appRouter.getRouteUrl(i);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
let itemHtml = '<div><a is="emby-linkbutton" class="button-link" style="display:inline-block;padding:.5em 1em;" href="' + href + '">';
|
2019-01-10 15:39:37 +03:00
|
|
|
itemHtml += i.Name;
|
|
|
|
itemHtml += '</a></div>';
|
|
|
|
return itemHtml;
|
|
|
|
}).join('');
|
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
const searchSuggestions = context.querySelector('.searchSuggestions');
|
2019-01-10 15:39:37 +03:00
|
|
|
searchSuggestions.querySelector('.searchSuggestionsList').innerHTML = html;
|
|
|
|
|
|
|
|
if (result.Items.length) {
|
|
|
|
searchSuggestions.classList.remove('hide');
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSearchHints(instance, apiClient, query) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!query.searchTerm) {
|
|
|
|
return Promise.resolve({
|
|
|
|
SearchHints: []
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
let allowSearch = true;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
const queryIncludeItemTypes = query.IncludeItemTypes;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (instance.options.collectionType === 'tvshows') {
|
|
|
|
if (query.IncludeArtists) {
|
|
|
|
allowSearch = false;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (queryIncludeItemTypes === 'Movie' ||
|
2019-01-10 15:39:37 +03:00
|
|
|
queryIncludeItemTypes === 'LiveTvProgram' ||
|
|
|
|
queryIncludeItemTypes === 'MusicAlbum' ||
|
|
|
|
queryIncludeItemTypes === 'Audio' ||
|
|
|
|
queryIncludeItemTypes === 'Book' ||
|
|
|
|
queryIncludeItemTypes === 'AudioBook' ||
|
|
|
|
queryIncludeItemTypes === 'Playlist' ||
|
|
|
|
queryIncludeItemTypes === 'PhotoAlbum' ||
|
|
|
|
query.MediaTypes === 'Video' ||
|
|
|
|
query.MediaTypes === 'Photo') {
|
|
|
|
allowSearch = false;
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (instance.options.collectionType === 'movies') {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (query.IncludeArtists) {
|
|
|
|
allowSearch = false;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (queryIncludeItemTypes === 'Series' ||
|
2019-01-10 15:39:37 +03:00
|
|
|
queryIncludeItemTypes === 'Episode' ||
|
|
|
|
queryIncludeItemTypes === 'LiveTvProgram' ||
|
|
|
|
queryIncludeItemTypes === 'MusicAlbum' ||
|
|
|
|
queryIncludeItemTypes === 'Audio' ||
|
|
|
|
queryIncludeItemTypes === 'Book' ||
|
|
|
|
queryIncludeItemTypes === 'AudioBook' ||
|
|
|
|
queryIncludeItemTypes === 'Playlist' ||
|
|
|
|
queryIncludeItemTypes === 'PhotoAlbum' ||
|
|
|
|
query.MediaTypes === 'Video' ||
|
|
|
|
query.MediaTypes === 'Photo') {
|
|
|
|
allowSearch = false;
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (instance.options.collectionType === 'music') {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (query.People) {
|
|
|
|
allowSearch = false;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (queryIncludeItemTypes === 'Series' ||
|
2019-01-10 15:39:37 +03:00
|
|
|
queryIncludeItemTypes === 'Episode' ||
|
|
|
|
queryIncludeItemTypes === 'LiveTvProgram' ||
|
|
|
|
queryIncludeItemTypes === 'Movie') {
|
|
|
|
allowSearch = false;
|
|
|
|
}
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (instance.options.collectionType === 'livetv') {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (query.IncludeArtists || query.IncludePeople) {
|
|
|
|
allowSearch = false;
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (queryIncludeItemTypes === 'Series' ||
|
2019-01-10 15:39:37 +03:00
|
|
|
queryIncludeItemTypes === 'Episode' ||
|
|
|
|
queryIncludeItemTypes === 'MusicAlbum' ||
|
|
|
|
queryIncludeItemTypes === 'Audio' ||
|
|
|
|
queryIncludeItemTypes === 'Book' ||
|
|
|
|
queryIncludeItemTypes === 'AudioBook' ||
|
|
|
|
queryIncludeItemTypes === 'PhotoAlbum' ||
|
|
|
|
queryIncludeItemTypes === 'Movie' ||
|
|
|
|
query.MediaTypes === 'Video' ||
|
|
|
|
query.MediaTypes === 'Photo') {
|
|
|
|
allowSearch = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (queryIncludeItemTypes === 'NullType') {
|
|
|
|
allowSearch = false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!allowSearch) {
|
|
|
|
return Promise.resolve({
|
|
|
|
SearchHints: []
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the search hint query to a regular item query
|
|
|
|
if (apiClient.isMinServerVersion('3.4.1.31')) {
|
|
|
|
query.Fields = 'PrimaryImageAspectRatio,CanDelete,BasicSyncInfo,MediaSourceCount';
|
|
|
|
query.Recursive = true;
|
|
|
|
query.EnableTotalRecordCount = false;
|
|
|
|
query.ImageTypeLimit = 1;
|
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
let methodName = 'getItems';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!query.IncludeMedia) {
|
|
|
|
if (query.IncludePeople) {
|
|
|
|
methodName = 'getPeople';
|
|
|
|
} else if (query.IncludeArtists) {
|
|
|
|
methodName = 'getArtists';
|
2019-11-23 00:29:38 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return apiClient[methodName](apiClient.getCurrentUserId(), query);
|
|
|
|
}
|
|
|
|
|
|
|
|
query.UserId = apiClient.getCurrentUserId();
|
|
|
|
|
|
|
|
return apiClient.getSearchHints(query);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function search(instance, apiClient, context, value) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (value || layoutManager.tv) {
|
|
|
|
instance.mode = 'search';
|
|
|
|
context.querySelector('.searchSuggestions').classList.add('hide');
|
|
|
|
} else {
|
|
|
|
instance.mode = 'suggestions';
|
|
|
|
loadSuggestions(instance, context, apiClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (instance.options.collectionType === 'livetv') {
|
|
|
|
searchType(instance, apiClient, {
|
|
|
|
searchTerm: value,
|
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'LiveTvProgram',
|
2019-01-10 15:39:37 +03:00
|
|
|
IsMovie: true,
|
|
|
|
IsKids: false,
|
|
|
|
IsNews: false
|
|
|
|
|
|
|
|
}, context, '.movieResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
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
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
searchType(instance, apiClient, {
|
|
|
|
searchTerm: value,
|
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'Movie'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.movieResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true,
|
|
|
|
showYear: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'Series'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.seriesResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true,
|
|
|
|
showYear: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (instance.options.collectionType === 'livetv') {
|
|
|
|
searchType(instance, apiClient, {
|
|
|
|
searchTerm: value,
|
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'LiveTvProgram',
|
2019-01-10 15:39:37 +03:00
|
|
|
IsSeries: true,
|
|
|
|
IsSports: false,
|
|
|
|
IsKids: false,
|
|
|
|
IsNews: false
|
|
|
|
|
|
|
|
}, context, '.episodeResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
preferThumb: true,
|
|
|
|
inheritThumb: false,
|
|
|
|
shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
|
|
|
|
showParentTitleOrTitle: true,
|
|
|
|
showTitle: false,
|
|
|
|
centerText: true,
|
|
|
|
coverImage: true,
|
|
|
|
overlayText: false,
|
|
|
|
overlayMoreButton: true,
|
|
|
|
showAirTime: true,
|
|
|
|
showAirDateTime: true,
|
|
|
|
showChannelName: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
searchType(instance, apiClient, {
|
|
|
|
searchTerm: value,
|
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'Episode'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.episodeResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
coverImage: true,
|
|
|
|
showTitle: true,
|
|
|
|
showParentTitle: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
|
|
|
// NullType to hide
|
|
|
|
IncludeItemTypes: instance.options.collectionType === 'livetv' ? 'LiveTvProgram' : 'NullType',
|
|
|
|
IsSports: true
|
|
|
|
|
|
|
|
}, context, '.sportsResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
preferThumb: true,
|
|
|
|
inheritThumb: false,
|
|
|
|
shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
|
|
|
|
showParentTitleOrTitle: true,
|
|
|
|
showTitle: false,
|
|
|
|
centerText: true,
|
|
|
|
coverImage: true,
|
|
|
|
overlayText: false,
|
|
|
|
overlayMoreButton: true,
|
|
|
|
showAirTime: true,
|
|
|
|
showAirDateTime: true,
|
|
|
|
showChannelName: true
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
|
|
|
// NullType to hide
|
|
|
|
IncludeItemTypes: instance.options.collectionType === 'livetv' ? 'LiveTvProgram' : 'NullType',
|
|
|
|
IsKids: true
|
|
|
|
|
|
|
|
}, context, '.kidsResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
preferThumb: true,
|
|
|
|
inheritThumb: false,
|
|
|
|
shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
|
|
|
|
showParentTitleOrTitle: true,
|
|
|
|
showTitle: false,
|
|
|
|
centerText: true,
|
|
|
|
coverImage: true,
|
|
|
|
overlayText: false,
|
|
|
|
overlayMoreButton: true,
|
|
|
|
showAirTime: true,
|
|
|
|
showAirDateTime: true,
|
|
|
|
showChannelName: true
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
|
|
|
// NullType to hide
|
|
|
|
IncludeItemTypes: instance.options.collectionType === 'livetv' ? 'LiveTvProgram' : 'NullType',
|
|
|
|
IsNews: true
|
|
|
|
|
|
|
|
}, context, '.newsResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
preferThumb: true,
|
|
|
|
inheritThumb: false,
|
|
|
|
shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
|
|
|
|
showParentTitleOrTitle: true,
|
|
|
|
showTitle: false,
|
|
|
|
centerText: true,
|
|
|
|
coverImage: true,
|
|
|
|
overlayText: false,
|
|
|
|
overlayMoreButton: true,
|
|
|
|
showAirTime: true,
|
|
|
|
showAirDateTime: true,
|
|
|
|
showChannelName: true
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'LiveTvProgram',
|
2019-01-10 15:39:37 +03:00
|
|
|
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,
|
|
|
|
IsNews: instance.options.collectionType === 'livetv' ? false : null
|
|
|
|
|
|
|
|
}, context, '.programResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
preferThumb: true,
|
|
|
|
inheritThumb: false,
|
|
|
|
shape: (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
|
|
|
|
showParentTitleOrTitle: true,
|
|
|
|
showTitle: false,
|
|
|
|
centerText: true,
|
|
|
|
coverImage: true,
|
|
|
|
overlayText: false,
|
|
|
|
overlayMoreButton: true,
|
|
|
|
showAirTime: true,
|
|
|
|
showAirDateTime: true,
|
|
|
|
showChannelName: true
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
MediaTypes: 'Video',
|
|
|
|
ExcludeItemTypes: 'Movie,Episode'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.videoResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showParentTitle: true,
|
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: true,
|
|
|
|
IncludeMedia: false,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false
|
|
|
|
|
|
|
|
}, context, '.peopleResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
coverImage: true,
|
|
|
|
showTitle: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: false,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: true
|
|
|
|
|
|
|
|
}, context, '.artistResults', {
|
2019-11-23 00:29:38 +09:00
|
|
|
coverImage: true,
|
|
|
|
showTitle: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'MusicAlbum'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.albumResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showParentTitle: true,
|
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'Audio'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.songResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showParentTitle: true,
|
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true,
|
2020-07-16 15:43:41 +02:00
|
|
|
overlayPlayButton: true
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
MediaTypes: 'Photo'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.photoResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showParentTitle: false,
|
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'PhotoAlbum'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.photoAlbumResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'Book'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.bookResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'AudioBook'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.audioBookResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
searchType(instance, apiClient, {
|
2018-10-23 01:05:09 +03:00
|
|
|
searchTerm: value,
|
2019-01-10 15:39:37 +03:00
|
|
|
IncludePeople: false,
|
|
|
|
IncludeMedia: true,
|
|
|
|
IncludeGenres: false,
|
|
|
|
IncludeStudios: false,
|
|
|
|
IncludeArtists: false,
|
2020-05-04 12:44:12 +02:00
|
|
|
IncludeItemTypes: 'Playlist'
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, context, '.playlistResults', {
|
|
|
|
|
2019-11-23 00:29:38 +09:00
|
|
|
showTitle: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function searchType(instance, apiClient, query, context, section, cardOptions) {
|
2019-01-10 15:39:37 +03:00
|
|
|
query.Limit = enableScrollX() ? 24 : 16;
|
|
|
|
query.ParentId = instance.options.parentId;
|
|
|
|
|
|
|
|
getSearchHints(instance, apiClient, query).then(function (result) {
|
|
|
|
populateResults(result, context, section, cardOptions);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function populateResults(result, context, section, cardOptions) {
|
|
|
|
section = context.querySelector(section);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
const items = result.Items || result.SearchHints;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
const itemsContainer = section.querySelector('.itemsContainer');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
cardBuilder.buildCards(items, Object.assign({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
itemsContainer: itemsContainer,
|
|
|
|
parentContainer: section,
|
2019-01-10 15:39:37 +03:00
|
|
|
shape: enableScrollX() ? 'autooverflow' : 'auto',
|
|
|
|
scalable: true,
|
|
|
|
overlayText: false,
|
|
|
|
centerText: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
allowBottomPadding: !enableScrollX()
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}, cardOptions || {}));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableScrollX() {
|
2019-01-10 15:39:37 +03:00
|
|
|
return true;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function replaceAll(originalString, strReplace, strWith) {
|
2020-07-16 10:28:08 +01:00
|
|
|
const reg = new RegExp(strReplace, 'ig');
|
2019-01-10 15:39:37 +03:00
|
|
|
return originalString.replace(reg, strWith);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function embed(elem, instance, options) {
|
2020-07-21 13:25:50 +01:00
|
|
|
import('text!./searchresults.template.html').then(({default: template}) => {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!enableScrollX()) {
|
|
|
|
template = replaceAll(template, 'data-horizontal="true"', 'data-horizontal="false"');
|
|
|
|
template = replaceAll(template, 'itemsContainer scrollSlider', 'itemsContainer scrollSlider vertical-wrap');
|
|
|
|
}
|
|
|
|
|
2020-07-21 14:53:09 +01:00
|
|
|
const html = globalize.translateHtml(template, 'core');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
|
|
|
|
elem.classList.add('searchResults');
|
|
|
|
instance.search('');
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-07-16 10:28:08 +01:00
|
|
|
class SearchResults {
|
|
|
|
constructor(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
this.options = options;
|
|
|
|
embed(options.element, this, options);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-16 10:28:08 +01:00
|
|
|
search(value) {
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(this.options.serverId);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
search(this, apiClient, this.options.element, value);
|
2020-07-16 10:28:08 +01:00
|
|
|
}
|
|
|
|
destroy() {
|
|
|
|
const options = this.options;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (options) {
|
|
|
|
options.element.classList.remove('searchFields');
|
|
|
|
}
|
|
|
|
this.options = null;
|
2020-07-16 10:28:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SearchResults;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-20 13:43:30 +01:00
|
|
|
/* eslint-enable indent */
|