From 733a391cec3fe8e3d88b0f94e96b4a1a5c660f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tavares=20Andr=C3=A9?= Date: Mon, 27 Jul 2015 20:16:37 +0200 Subject: [PATCH] Reports - Code cleanup, Added user image to Activities log, Export update --- MediaBrowser.Api/MediaBrowser.Api.csproj | 1 + .../Activities/ReportActivitiesBuilder.cs | 30 +- .../Reports/Common/HeaderMetadata.cs | 14 +- .../Reports/Common/ItemViewType.cs | 32 +- .../Reports/Common/ReportBuilderBase.cs | 33 +- .../Reports/Common/ReportDisplayType.cs | 14 + .../Reports/Common/ReportHelper.cs | 16 + .../Reports/Data/ReportBuilder.cs | 122 ++- .../Reports/Model/ReportHeader.cs | 10 + MediaBrowser.Api/Reports/Model/ReportRow.cs | 4 + MediaBrowser.Api/Reports/ReportRequests.cs | 260 +----- MediaBrowser.Api/Reports/ReportsService.cs | 787 +++--------------- .../Localization/Server/server.json | 8 +- 13 files changed, 373 insertions(+), 958 deletions(-) create mode 100644 MediaBrowser.Api/Reports/Common/ReportDisplayType.cs diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index e1235c935..295cc78e9 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -89,6 +89,7 @@ + diff --git a/MediaBrowser.Api/Reports/Activities/ReportActivitiesBuilder.cs b/MediaBrowser.Api/Reports/Activities/ReportActivitiesBuilder.cs index 34115812e..33d36f11b 100644 --- a/MediaBrowser.Api/Reports/Activities/ReportActivitiesBuilder.cs +++ b/MediaBrowser.Api/Reports/Activities/ReportActivitiesBuilder.cs @@ -40,9 +40,10 @@ namespace MediaBrowser.Api.Reports /// The result. public ReportResult GetResult(QueryResult queryResult, IReportsQuery request) { + ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType); List> options = this.GetReportOptions(request, () => this.GetDefaultHeaderMetadata(), - (hm) => this.GetOption(hm)).Where(x => x.Header.Visible == true).ToList(); + (hm) => this.GetOption(hm)).Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).ToList(); var headers = GetHeaders(options); var rows = GetReportRows(queryResult.Items, options); @@ -93,6 +94,7 @@ namespace MediaBrowser.Api.Reports { return new List { + HeaderMetadata.UserPrimaryImage, HeaderMetadata.Date, HeaderMetadata.User, HeaderMetadata.Type, @@ -100,7 +102,7 @@ namespace MediaBrowser.Api.Reports HeaderMetadata.Name, HeaderMetadata.ShortOverview, HeaderMetadata.Overview, - //HeaderMetadata.UserPrimaryImageTag, + //HeaderMetadata.UserId //HeaderMetadata.Item, }; } @@ -126,11 +128,6 @@ namespace MediaBrowser.Api.Reports switch (header) { - case HeaderMetadata.StatusImage: - option.Header.ItemViewType = ItemViewType.StatusImage; - internalHeader = HeaderMetadata.Status; - option.Header.CanGroup = false; - break; case HeaderMetadata.Name: option.Column = (i, r) => i.Name; break; @@ -158,15 +155,23 @@ namespace MediaBrowser.Api.Reports option.Header.Type = ""; break; - case HeaderMetadata.UserPrimaryImageTag: + case HeaderMetadata.UserPrimaryImage: //option.Column = (i, r) => i.UserPrimaryImageTag; + option.Header.DisplayType = ReportDisplayType.Screen; + option.Header.ItemViewType = ItemViewType.UserPrimaryImage; + option.Header.ShowHeaderLabel = false; + internalHeader = HeaderMetadata.User; + option.Header.CanGroup = false; option.Column = (i, r) => { if (!string.IsNullOrEmpty(i.UserId)) { MediaBrowser.Controller.Entities.User user = _userManager.GetUserById(i.UserId); if (user != null) - return user.PrimaryImagePath; + { + var dto = _userManager.GetUserDto(user); + return dto.PrimaryImageTag; + } } return string.Empty; }; @@ -193,7 +198,10 @@ namespace MediaBrowser.Api.Reports }; option.Header.SortField = ""; break; - + case HeaderMetadata.UserId: + option.Column = (i, r) => i.UserId; + option.Header.SortField = ""; + break; } option.Header.Name = GetLocalizedHeader(internalHeader); @@ -239,7 +247,7 @@ namespace MediaBrowser.Api.Reports ReportRow rRow = new ReportRow { Id = item.Id, - + UserId = item.UserId }; return rRow; } diff --git a/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs b/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs index f61331aa7..74fcdd149 100644 --- a/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs +++ b/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs @@ -35,22 +35,28 @@ namespace MediaBrowser.Api.Reports Subtitles, Genres, Countries, - StatusImage, + Status, Tracks, EpisodeSeries, EpisodeSeason, AudioAlbumArtist, MusicArtist, AudioAlbum, - Status, + Locked, + Unidentified, + ImagePrimary, + ImageBackdrop, + ImageLogo, + //Activity logs Overview, ShortOverview, Type, Date, - UserPrimaryImageTag, + UserPrimaryImage, Severity, Item, - User + User, + UserId } } diff --git a/MediaBrowser.Api/Reports/Common/ItemViewType.cs b/MediaBrowser.Api/Reports/Common/ItemViewType.cs index 3e09a290d..5126457cf 100644 --- a/MediaBrowser.Api/Reports/Common/ItemViewType.cs +++ b/MediaBrowser.Api/Reports/Common/ItemViewType.cs @@ -4,17 +4,23 @@ using System.Linq; namespace MediaBrowser.Api.Reports { - public enum ItemViewType - { - None, - Detail, - Edit, - List, - ItemByNameDetails, - StatusImage, - EmbeddedImage, - SubtitleImage, - TrailersImage, - SpecialsImage - } + public enum ItemViewType + { + None, + Detail, + Edit, + List, + ItemByNameDetails, + StatusImage, + EmbeddedImage, + SubtitleImage, + TrailersImage, + SpecialsImage, + LockDataImage, + UnidentifiedImage, + TagsPrimaryImage, + TagsBackdropImage, + TagsLogoImage, + UserPrimaryImage + } } diff --git a/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs b/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs index 939bf280a..81b441a07 100644 --- a/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs +++ b/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs @@ -54,10 +54,10 @@ namespace MediaBrowser.Api.Reports /// Generic type parameter. /// Options for controlling the operation. /// The active headers. - protected List GetActiveHeaders(List> options) + protected List GetActiveHeaders(List> options, ReportDisplayType displayType) { List headers = new List(); - foreach (ReportOptions option in options.Where(x => x.Header.Visible == true)) + foreach (ReportOptions option in options.Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType))) { headers.Add(option.Header); } @@ -221,9 +221,12 @@ namespace MediaBrowser.Api.Reports { List headersMetadata = getHeadersMetadata(); List> options = new List>(); + ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType); foreach (HeaderMetadata header in headersMetadata) { - options.Add(getOptions(header)); + ReportOptions headerOptions = getOptions(header); + if (this.DisplayTypeVisible(headerOptions.Header.DisplayType, displayType)) + options.Add(headerOptions); } if (request != null && !string.IsNullOrEmpty(request.ReportColumns)) @@ -231,10 +234,17 @@ namespace MediaBrowser.Api.Reports List headersMetadataFiltered = ReportHelper.GetFilteredReportHeaderMetadata(request.ReportColumns, () => headersMetadata); foreach (ReportHeader header in options.Select(x => x.Header)) { - if (!headersMetadataFiltered.Contains(header.FieldName)) + + if (this.DisplayTypeVisible(header.DisplayType, displayType)) { - header.Visible = false; + + if (!headersMetadataFiltered.Contains(header.FieldName) && displayType != ReportDisplayType.Export) + { + header.DisplayType = ReportDisplayType.None; + } } + else + header.DisplayType = ReportDisplayType.None; } } @@ -336,6 +346,19 @@ namespace MediaBrowser.Api.Reports return string.Empty; } + /// Displays a type visible. + /// Type of the header display. + /// Type of the display. + /// true if it succeeds, false if it fails. + protected bool DisplayTypeVisible(ReportDisplayType headerDisplayType, ReportDisplayType displayType) + { + if (headerDisplayType == ReportDisplayType.None) + return false; + + bool rval = headerDisplayType == displayType || headerDisplayType == ReportDisplayType.ScreenExport && (displayType == ReportDisplayType.Screen || displayType == ReportDisplayType.Export); + return rval; + } + #endregion } diff --git a/MediaBrowser.Api/Reports/Common/ReportDisplayType.cs b/MediaBrowser.Api/Reports/Common/ReportDisplayType.cs new file mode 100644 index 000000000..69d6d71ee --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportDisplayType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Reports +{ + public enum ReportDisplayType + { + None, + Screen, + Export, + ScreenExport + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportHelper.cs b/MediaBrowser.Api/Reports/Common/ReportHelper.cs index 1de0190cf..94ba40d1c 100644 --- a/MediaBrowser.Api/Reports/Common/ReportHelper.cs +++ b/MediaBrowser.Api/Reports/Common/ReportHelper.cs @@ -127,6 +127,22 @@ namespace MediaBrowser.Api.Reports return rType; } + /// Gets report display type. + /// Type of the display. + /// The report display type. + public static ReportDisplayType GetReportDisplayType(string displayType) + { + if (string.IsNullOrEmpty(displayType)) + return ReportDisplayType.ScreenExport; + + ReportDisplayType rType; + + if (!Enum.TryParse(displayType, out rType)) + return ReportDisplayType.ScreenExport; + + return rType; + } + /// Gets server localized string. /// The phrase. /// The server localized string. diff --git a/MediaBrowser.Api/Reports/Data/ReportBuilder.cs b/MediaBrowser.Api/Reports/Data/ReportBuilder.cs index 6232018f1..512441bd7 100644 --- a/MediaBrowser.Api/Reports/Data/ReportBuilder.cs +++ b/MediaBrowser.Api/Reports/Data/ReportBuilder.cs @@ -43,9 +43,11 @@ namespace MediaBrowser.Api.Reports public ReportResult GetResult(BaseItem[] items, IReportsQuery request) { ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); + ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType); + List> options = this.GetReportOptions(request, () => this.GetDefaultHeaderMetadata(reportRowType), - (hm) => this.GetOption(hm)).Where(x => x.Header.Visible == true).ToList(); + (hm) => this.GetOption(hm)).Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).ToList(); var headers = GetHeaders(options); var rows = GetReportRows(items, options); @@ -100,8 +102,13 @@ namespace MediaBrowser.Api.Reports { case ReportIncludeItemTypes.Season: return new List - { - HeaderMetadata.StatusImage, + { + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Series, HeaderMetadata.Season, HeaderMetadata.SeasonNumber, @@ -112,8 +119,13 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.Series: return new List - { - HeaderMetadata.StatusImage, + { + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.Network, HeaderMetadata.DateAdded, @@ -129,7 +141,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.MusicAlbum: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.AlbumArtist, HeaderMetadata.DateAdded, @@ -142,7 +159,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.MusicArtist: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.MusicArtist, HeaderMetadata.Countries, HeaderMetadata.DateAdded, @@ -153,7 +175,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.Game: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.GameSystem, HeaderMetadata.DateAdded, @@ -169,7 +196,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.Movie: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, @@ -189,7 +221,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.Book: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, @@ -202,7 +239,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.BoxSet: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, @@ -216,7 +258,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.Audio: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.AudioAlbumArtist, HeaderMetadata.AudioAlbum, @@ -235,7 +282,12 @@ namespace MediaBrowser.Api.Reports case ReportIncludeItemTypes.Episode: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.EpisodeSeries, HeaderMetadata.Season, @@ -261,7 +313,16 @@ namespace MediaBrowser.Api.Reports default: return new List { - HeaderMetadata.StatusImage, + HeaderMetadata.Status, + HeaderMetadata.Locked, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, + HeaderMetadata.Unidentified, + HeaderMetadata.ImagePrimary, + HeaderMetadata.ImageBackdrop, + HeaderMetadata.ImageLogo, HeaderMetadata.Name, HeaderMetadata.DateAdded, HeaderMetadata.ReleaseDate, @@ -303,10 +364,41 @@ namespace MediaBrowser.Api.Reports switch (header) { - case HeaderMetadata.StatusImage: + case HeaderMetadata.Status: option.Header.ItemViewType = ItemViewType.StatusImage; internalHeader = HeaderMetadata.Status; option.Header.CanGroup = false; + option.Header.DisplayType = ReportDisplayType.Screen; + break; + case HeaderMetadata.Locked: + option.Column = (i, r) => this.GetBoolString(r.HasLockData); + option.Header.ItemViewType = ItemViewType.LockDataImage; + option.Header.CanGroup = false; + option.Header.DisplayType = ReportDisplayType.Export; + break; + case HeaderMetadata.Unidentified: + option.Column = (i, r) => this.GetBoolString(r.IsUnidentified); + option.Header.ItemViewType = ItemViewType.UnidentifiedImage; + option.Header.CanGroup = false; + option.Header.DisplayType = ReportDisplayType.Export; + break; + case HeaderMetadata.ImagePrimary: + option.Column = (i, r) => this.GetBoolString(r.HasImageTagsPrimary); + option.Header.ItemViewType = ItemViewType.TagsPrimaryImage; + option.Header.CanGroup = false; + option.Header.DisplayType = ReportDisplayType.Export; + break; + case HeaderMetadata.ImageBackdrop: + option.Column = (i, r) => this.GetBoolString(r.HasImageTagsBackdrop); + option.Header.ItemViewType = ItemViewType.TagsBackdropImage; + option.Header.CanGroup = false; + option.Header.DisplayType = ReportDisplayType.Export; + break; + case HeaderMetadata.ImageLogo: + option.Column = (i, r) => this.GetBoolString(r.HasImageTagsLogo); + option.Header.ItemViewType = ItemViewType.TagsLogoImage; + option.Header.CanGroup = false; + option.Header.DisplayType = ReportDisplayType.Export; break; case HeaderMetadata.Name: diff --git a/MediaBrowser.Api/Reports/Model/ReportHeader.cs b/MediaBrowser.Api/Reports/Model/ReportHeader.cs index 81b85954a..6bff9b37e 100644 --- a/MediaBrowser.Api/Reports/Model/ReportHeader.cs +++ b/MediaBrowser.Api/Reports/Model/ReportHeader.cs @@ -16,6 +16,8 @@ namespace MediaBrowser.Api.Reports ItemViewType = ItemViewType.None; Visible = true; CanGroup = true; + ShowHeaderLabel = true; + DisplayType = ReportDisplayType.ScreenExport; } /// Gets or sets the type of the header field. @@ -46,6 +48,14 @@ namespace MediaBrowser.Api.Reports /// true if visible, false if not. public bool Visible { get; set; } + /// Gets or sets the type of the display. + /// The type of the display. + public ReportDisplayType DisplayType { get; set; } + + /// Gets or sets a value indicating whether the header label is shown. + /// true if show header label, false if not. + public bool ShowHeaderLabel { get; set; } + /// Gets or sets a value indicating whether we can group. /// true if we can group, false if not. public bool CanGroup { get; set; } diff --git a/MediaBrowser.Api/Reports/Model/ReportRow.cs b/MediaBrowser.Api/Reports/Model/ReportRow.cs index d9bae8afa..3f66b8479 100644 --- a/MediaBrowser.Api/Reports/Model/ReportRow.cs +++ b/MediaBrowser.Api/Reports/Model/ReportRow.cs @@ -67,5 +67,9 @@ namespace MediaBrowser.Api.Reports /// Gets or sets the type. /// The type. public ReportIncludeItemTypes RowType { get; set; } + + /// Gets or sets the identifier of the user. + /// The identifier of the user. + public string UserId { get; set; } } } diff --git a/MediaBrowser.Api/Reports/ReportRequests.cs b/MediaBrowser.Api/Reports/ReportRequests.cs index 1a7b3284b..9e48a8070 100644 --- a/MediaBrowser.Api/Reports/ReportRequests.cs +++ b/MediaBrowser.Api/Reports/ReportRequests.cs @@ -53,14 +53,23 @@ namespace MediaBrowser.Api.Reports /// A list of types of the include items. string IncludeItemTypes { get; set; } + /// Gets or sets a list of types of the displays. + /// A list of types of the displays. + string DisplayType { get; set; } + } - public class BaseReportRequest : BaseItemsRequest, IReportsQuery + public class BaseReportRequest : GetItems, IReportsQuery { /// Gets or sets the report view. /// The report view. [ApiMember(Name = "ReportView", Description = "The report view. Values (ReportData, ReportStatistics, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string ReportView { get; set; } + + /// Gets or sets the report view. + /// The report view. + [ApiMember(Name = "DisplayType", Description = "The report display type. Values (None, Screen, Export, ScreenExport)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string DisplayType { get; set; } /// /// Gets or sets a value indicating whether this MediaBrowser.Api.Reports.BaseReportRequest has @@ -81,244 +90,7 @@ namespace MediaBrowser.Api.Reports [ApiMember(Name = "ReportColumns", Description = "Optional. The columns to show.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ReportColumns { get; set; } - /// - /// Gets or sets the user id. - /// - /// The user id. - [ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "GET")] - public string UserId { get; set; } - - /// - /// Limit results to items containing a specific person - /// - /// The person. - [ApiMember(Name = "Person", Description = "Optional. If specified, results will be filtered to include only those containing the specified person.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string Person { get; set; } - - [ApiMember(Name = "PersonIds", Description = "Optional. If specified, results will be filtered to include only those containing the specified person.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string PersonIds { get; set; } - - /// - /// If the Person filter is used, this can also be used to restrict to a specific person type - /// - /// The type of the person. - [ApiMember(Name = "PersonTypes", Description = "Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string PersonTypes { get; set; } - - /// - /// Limit results to items containing specific studios - /// - /// The studios. - [ApiMember(Name = "Studios", Description = "Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string Studios { get; set; } - - [ApiMember(Name = "StudioIds", Description = "Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string StudioIds { get; set; } - - /// - /// Gets or sets the studios. - /// - /// The studios. - [ApiMember(Name = "Artists", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string Artists { get; set; } - - [ApiMember(Name = "ArtistIds", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string ArtistIds { get; set; } - - [ApiMember(Name = "Albums", Description = "Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string Albums { get; set; } - - /// - /// Gets or sets the item ids. - /// - /// The item ids. - [ApiMember(Name = "Ids", Description = "Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string Ids { get; set; } - - /// - /// Gets or sets the video types. - /// - /// The video types. - [ApiMember(Name = "VideoTypes", Description = "Optional filter by VideoType (videofile, dvd, bluray, iso). Allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string VideoTypes { get; set; } - - /// - /// Gets or sets the video formats. - /// - /// The video formats. - [ApiMember(Name = "Is3D", Description = "Optional filter by items that are 3D, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? Is3D { get; set; } - - /// - /// Gets or sets the series status. - /// - /// The series status. - [ApiMember(Name = "SeriesStatus", Description = "Optional filter by Series Status. Allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string SeriesStatus { get; set; } - - [ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string NameStartsWithOrGreater { get; set; } - - [ApiMember(Name = "NameStartsWith", Description = "Optional filter by items whose name is sorted equally than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string NameStartsWith { get; set; } - - [ApiMember(Name = "NameLessThan", Description = "Optional filter by items whose name is equally or lesser than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string NameLessThan { get; set; } - - [ApiMember(Name = "AlbumArtistStartsWithOrGreater", Description = "Optional filter by items whose album artist is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string AlbumArtistStartsWithOrGreater { get; set; } - - /// - /// Gets or sets the air days. - /// - /// The air days. - [ApiMember(Name = "AirDays", Description = "Optional filter by Series Air Days. Allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string AirDays { get; set; } - - /// - /// Gets or sets the min offical rating. - /// - /// The min offical rating. - [ApiMember(Name = "MinOfficialRating", Description = "Optional filter by minimum official rating (PG, PG-13, TV-MA, etc).", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string MinOfficialRating { get; set; } - - /// - /// Gets or sets the max offical rating. - /// - /// The max offical rating. - [ApiMember(Name = "MaxOfficialRating", Description = "Optional filter by maximum official rating (PG, PG-13, TV-MA, etc).", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string MaxOfficialRating { get; set; } - - [ApiMember(Name = "HasThemeSong", Description = "Optional filter by items with theme songs.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? HasThemeSong { get; set; } - - [ApiMember(Name = "HasThemeVideo", Description = "Optional filter by items with theme videos.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? HasThemeVideo { get; set; } - - [ApiMember(Name = "HasSubtitles", Description = "Optional filter by items with subtitles.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? HasSubtitles { get; set; } - - [ApiMember(Name = "HasSpecialFeature", Description = "Optional filter by items with special features.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? HasSpecialFeature { get; set; } - - [ApiMember(Name = "HasTrailer", Description = "Optional filter by items with trailers.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? HasTrailer { get; set; } - - [ApiMember(Name = "AdjacentTo", Description = "Optional. Return items that are siblings of a supplied item.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string AdjacentTo { get; set; } - - [ApiMember(Name = "MinIndexNumber", Description = "Optional filter by minimum index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? MinIndexNumber { get; set; } - - [ApiMember(Name = "MinPlayers", Description = "Optional filter by minimum number of game players.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? MinPlayers { get; set; } - - [ApiMember(Name = "MaxPlayers", Description = "Optional filter by maximum number of game players.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? MaxPlayers { get; set; } - - [ApiMember(Name = "ParentIndexNumber", Description = "Optional filter by parent index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? ParentIndexNumber { get; set; } - - [ApiMember(Name = "HasParentalRating", Description = "Optional filter by items that have or do not have a parental rating", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? HasParentalRating { get; set; } - - [ApiMember(Name = "IsHD", Description = "Optional filter by items that are HD or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsHD { get; set; } - - [ApiMember(Name = "LocationTypes", Description = "Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string LocationTypes { get; set; } - - [ApiMember(Name = "ExcludeLocationTypes", Description = "Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string ExcludeLocationTypes { get; set; } - - [ApiMember(Name = "IsMissing", Description = "Optional filter by items that are missing episodes or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsMissing { get; set; } - - [ApiMember(Name = "IsUnaired", Description = "Optional filter by items that are unaired episodes or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsUnaired { get; set; } - - [ApiMember(Name = "IsVirtualUnaired", Description = "Optional filter by items that are virtual unaired episodes or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsVirtualUnaired { get; set; } - - [ApiMember(Name = "MinCommunityRating", Description = "Optional filter by minimum community rating.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public double? MinCommunityRating { get; set; } - - [ApiMember(Name = "MinCriticRating", Description = "Optional filter by minimum critic rating.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public double? MinCriticRating { get; set; } - - [ApiMember(Name = "AiredDuringSeason", Description = "Gets all episodes that aired during a season, including specials.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? AiredDuringSeason { get; set; } - - [ApiMember(Name = "MinPremiereDate", Description = "Optional. The minimum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string MinPremiereDate { get; set; } - - [ApiMember(Name = "MaxPremiereDate", Description = "Optional. The maximum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string MaxPremiereDate { get; set; } - - [ApiMember(Name = "HasOverview", Description = "Optional filter by items that have an overview or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? HasOverview { get; set; } - - [ApiMember(Name = "HasImdbId", Description = "Optional filter by items that have an imdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? HasImdbId { get; set; } - - [ApiMember(Name = "HasTmdbId", Description = "Optional filter by items that have a tmdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? HasTmdbId { get; set; } - - [ApiMember(Name = "HasTvdbId", Description = "Optional filter by items that have a tvdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? HasTvdbId { get; set; } - - [ApiMember(Name = "IsYearMismatched", Description = "Optional filter by items that are potentially misidentified.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsYearMismatched { get; set; } - - [ApiMember(Name = "IsInBoxSet", Description = "Optional filter by items that are in boxsets, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? IsInBoxSet { get; set; } - - [ApiMember(Name = "IsLocked", Description = "Optional filter by items that are locked.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? IsLocked { get; set; } - - [ApiMember(Name = "IsUnidentified", Description = "Optional filter by items that are unidentified by internet metadata providers.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? IsUnidentified { get; set; } - - [ApiMember(Name = "IsPlaceHolder", Description = "Optional filter by items that are placeholders", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? IsPlaceHolder { get; set; } - - [ApiMember(Name = "HasOfficialRating", Description = "Optional filter by items that have official ratings", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? HasOfficialRating { get; set; } - - [ApiMember(Name = "CollapseBoxSetItems", Description = "Whether or not to hide items behind their boxsets.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? CollapseBoxSetItems { get; set; } - - public string[] GetStudios() - { - return (Studios ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); - } - - public string[] GetStudioIds() - { - return (StudioIds ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); - } - - public string[] GetPersonTypes() - { - return (PersonTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - } - - public string[] GetPersonIds() - { - return (PersonIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - } - - public VideoType[] GetVideoTypes() - { - var val = VideoTypes; - - if (string.IsNullOrEmpty(val)) - { - return new VideoType[] { }; - } - - return val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true)).ToArray(); - } + } [Route("/Reports/Items", "GET", Summary = "Gets reports based on library items")] @@ -335,6 +107,11 @@ namespace MediaBrowser.Api.Reports [ApiMember(Name = "ReportView", Description = "The report view. Values (ReportData, ReportStatistics, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string ReportView { get; set; } + /// Gets or sets the report view. + /// The report view. + [ApiMember(Name = "DisplayType", Description = "The report display type. Values (None, Screen, Export, ScreenExport)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string DisplayType { get; set; } + /// Gets or sets a list of types of the include items. /// A list of types of the include items. [ApiMember(Name = "IncludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] @@ -379,6 +156,11 @@ namespace MediaBrowser.Api.Reports [ApiMember(Name = "ReportView", Description = "The report view. Values (ReportData, ReportStatistics, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string ReportView { get; set; } + /// Gets or sets the report view. + /// The report view. + [ApiMember(Name = "DisplayType", Description = "The report display type. Values (None, Screen, Export, ScreenExport)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string DisplayType { get; set; } + /// /// Gets or sets a value indicating whether this MediaBrowser.Api.Reports.GetActivityLogs has /// query limit. diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs index 2c0728719..82e7264f1 100644 --- a/MediaBrowser.Api/Reports/ReportsService.cs +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -71,6 +71,7 @@ namespace MediaBrowser.Api.Reports /// A Task<object> public async Task Get(GetActivityLogs request) { + request.DisplayType = "Screen"; ReportResult result = await GetReportActivities(request).ConfigureAwait(false); return ToOptimizedResult(result); } @@ -83,8 +84,8 @@ namespace MediaBrowser.Api.Reports if (string.IsNullOrEmpty(request.IncludeItemTypes)) return null; + request.DisplayType = "Screen"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); - ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); List result = new List(); switch (reportViewType) @@ -113,6 +114,7 @@ namespace MediaBrowser.Api.Reports if (string.IsNullOrEmpty(request.IncludeItemTypes)) return null; + request.DisplayType = "Screen"; var reportResult = await GetReportResult(request); return ToOptimizedResult(reportResult); @@ -125,6 +127,7 @@ namespace MediaBrowser.Api.Reports { if (string.IsNullOrEmpty(request.IncludeItemTypes)) return null; + request.DisplayType = "Screen"; var reportResult = await GetReportStatistic(request); return ToOptimizedResult(reportResult); @@ -138,6 +141,7 @@ namespace MediaBrowser.Api.Reports if (string.IsNullOrEmpty(request.IncludeItemTypes)) return null; + request.DisplayType = "Export"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); var headers = new Dictionary(); string fileExtension = "csv"; @@ -190,538 +194,126 @@ namespace MediaBrowser.Api.Reports #endregion - #region [Internal Methods] - - /// Applies filtering. - /// The items. - /// The filter. - /// The user. - /// The repository. - /// IEnumerable{BaseItem}. - internal static IEnumerable ApplyFilter(IEnumerable items, ItemFilter filter, User user, IUserDataManager repository) - { - // Avoid implicitly captured closure - var currentUser = user; - - switch (filter) - { - case ItemFilter.IsFavoriteOrLikes: - return items.Where(item => - { - var userdata = repository.GetUserData(user.Id, item.GetUserDataKey()); - - if (userdata == null) - { - return false; - } - - var likes = userdata.Likes ?? false; - var favorite = userdata.IsFavorite; - - return likes || favorite; - }); - - case ItemFilter.Likes: - return items.Where(item => - { - var userdata = repository.GetUserData(user.Id, item.GetUserDataKey()); - - return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value; - }); - - case ItemFilter.Dislikes: - return items.Where(item => - { - var userdata = repository.GetUserData(user.Id, item.GetUserDataKey()); - - return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value; - }); - - case ItemFilter.IsFavorite: - return items.Where(item => - { - var userdata = repository.GetUserData(user.Id, item.GetUserDataKey()); - - return userdata != null && userdata.IsFavorite; - }); - - case ItemFilter.IsResumable: - return items.Where(item => - { - var userdata = repository.GetUserData(user.Id, item.GetUserDataKey()); - - return userdata != null && userdata.PlaybackPositionTicks > 0; - }); - - case ItemFilter.IsPlayed: - return items.Where(item => item.IsPlayed(currentUser)); - - case ItemFilter.IsUnplayed: - return items.Where(item => item.IsUnplayed(currentUser)); - - case ItemFilter.IsFolder: - return items.Where(item => item.IsFolder); - - case ItemFilter.IsNotFolder: - return items.Where(item => !item.IsFolder); - - case ItemFilter.IsRecentlyAdded: - return items.Where(item => (DateTime.UtcNow - item.DateCreated).TotalDays <= 10); - } - - return items; - } - - #endregion - #region [Private Methods] - /// Applies the additional filters. + /// Gets items query. /// The request. - /// Zero-based index of the. /// The user. - /// true if this object is pre filtered. - /// Manager for library. - /// true if it succeeds, false if it fails. - private bool ApplyAdditionalFilters(BaseReportRequest request, BaseItem i, User user, bool isPreFiltered, ILibraryManager libraryManager) + /// The items query. + private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user) { - var video = i as Video; - - if (!isPreFiltered) + var query = new InternalItemsQuery { - var mediaTypes = request.GetMediaTypes(); - if (mediaTypes.Length > 0) + User = user, + IsPlayed = request.IsPlayed, + MediaTypes = request.GetMediaTypes(), + IncludeItemTypes = request.GetIncludeItemTypes(), + ExcludeItemTypes = request.GetExcludeItemTypes(), + Recursive = request.Recursive, + SortBy = request.GetOrderBy(), + SortOrder = request.SortOrder ?? SortOrder.Ascending, + + Filter = i => ApplyAdditionalFilters(request, i, user, _libraryManager), + + Limit = request.Limit, + StartIndex = request.StartIndex, + IsMissing = request.IsMissing, + IsVirtualUnaired = request.IsVirtualUnaired, + IsUnaired = request.IsUnaired, + CollapseBoxSetItems = request.CollapseBoxSetItems, + NameLessThan = request.NameLessThan, + NameStartsWith = request.NameStartsWith, + NameStartsWithOrGreater = request.NameStartsWithOrGreater, + HasImdbId = request.HasImdbId, + IsYearMismatched = request.IsYearMismatched, + IsUnidentified = request.IsUnidentified, + IsPlaceHolder = request.IsPlaceHolder, + IsLocked = request.IsLocked, + IsInBoxSet = request.IsInBoxSet, + IsHD = request.IsHD, + Is3D = request.Is3D, + HasTvdbId = request.HasTvdbId, + HasTmdbId = request.HasTmdbId, + HasOverview = request.HasOverview, + HasOfficialRating = request.HasOfficialRating, + HasParentalRating = request.HasParentalRating, + HasSpecialFeature = request.HasSpecialFeature, + HasSubtitles = request.HasSubtitles, + HasThemeSong = request.HasThemeSong, + HasThemeVideo = request.HasThemeVideo, + HasTrailer = request.HasTrailer, + Tags = request.GetTags(), + OfficialRatings = request.GetOfficialRatings(), + Genres = request.GetGenres(), + Studios = request.GetStudios(), + StudioIds = request.GetStudioIds(), + Person = request.Person, + PersonIds = request.GetPersonIds(), + PersonTypes = request.GetPersonTypes(), + Years = request.GetYears(), + ImageTypes = request.GetImageTypes().ToArray(), + VideoTypes = request.GetVideoTypes().ToArray(), + AdjacentTo = request.AdjacentTo, + ItemIds = request.GetItemIds(), + MinPlayers = request.MinPlayers, + MaxPlayers = request.MaxPlayers, + MinCommunityRating = request.MinCommunityRating, + MinCriticRating = request.MinCriticRating + }; + + if (!string.IsNullOrWhiteSpace(request.Ids)) + { + query.CollapseBoxSetItems = false; + } + + foreach (var filter in request.GetFilters()) + { + switch (filter) { - if (!(!string.IsNullOrEmpty(i.MediaType) && mediaTypes.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase))) - { - return false; - } - } - - if (request.IsPlayed.HasValue) - { - var val = request.IsPlayed.Value; - if (i.IsPlayed(user) != val) - { - return false; - } - } - - // Exclude item types - var excluteItemTypes = request.GetExcludeItemTypes(); - if (excluteItemTypes.Length > 0 && excluteItemTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase)) - { - return false; - } - - // Include item types - var includeItemTypes = request.GetIncludeItemTypes(); - if (includeItemTypes.Length > 0 && !includeItemTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase)) - { - return false; - } - - if (request.IsInBoxSet.HasValue) - { - var val = request.IsInBoxSet.Value; - if (i.Parents.OfType().Any() != val) - { - return false; - } - } - - // Filter by Video3DFormat - if (request.Is3D.HasValue) - { - var val = request.Is3D.Value; - - if (video == null || val != video.Video3DFormat.HasValue) - { - return false; - } - } - - if (request.IsHD.HasValue) - { - var val = request.IsHD.Value; - - if (video == null || val != video.IsHD) - { - return false; - } - } - - if (request.IsUnidentified.HasValue) - { - var val = request.IsUnidentified.Value; - if (i.IsUnidentified != val) - { - return false; - } - } - - if (request.IsLocked.HasValue) - { - var val = request.IsLocked.Value; - if (i.IsLocked != val) - { - return false; - } - } - - if (request.HasOverview.HasValue) - { - var filterValue = request.HasOverview.Value; - - var hasValue = !string.IsNullOrEmpty(i.Overview); - - if (hasValue != filterValue) - { - return false; - } - } - - if (request.HasImdbId.HasValue) - { - var filterValue = request.HasImdbId.Value; - - var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Imdb)); - - if (hasValue != filterValue) - { - return false; - } - } - - if (request.HasTmdbId.HasValue) - { - var filterValue = request.HasTmdbId.Value; - - var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb)); - - if (hasValue != filterValue) - { - return false; - } - } - - if (request.HasTvdbId.HasValue) - { - var filterValue = request.HasTvdbId.Value; - - var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)); - - if (hasValue != filterValue) - { - return false; - } - } - - if (request.IsYearMismatched.HasValue) - { - var filterValue = request.IsYearMismatched.Value; - - if (UserViewBuilder.IsYearMismatched(i, libraryManager) != filterValue) - { - return false; - } - } - - if (request.HasOfficialRating.HasValue) - { - var filterValue = request.HasOfficialRating.Value; - - var hasValue = !string.IsNullOrEmpty(i.OfficialRating); - - if (hasValue != filterValue) - { - return false; - } - } - - if (request.IsPlaceHolder.HasValue) - { - var filterValue = request.IsPlaceHolder.Value; - - var isPlaceHolder = false; - - var hasPlaceHolder = i as ISupportsPlaceHolders; - - if (hasPlaceHolder != null) - { - isPlaceHolder = hasPlaceHolder.IsPlaceHolder; - } - - if (isPlaceHolder != filterValue) - { - return false; - } - } - - if (request.HasSpecialFeature.HasValue) - { - var filterValue = request.HasSpecialFeature.Value; - - var movie = i as IHasSpecialFeatures; - - if (movie != null) - { - var ok = filterValue - ? movie.SpecialFeatureIds.Count > 0 - : movie.SpecialFeatureIds.Count == 0; - - if (!ok) - { - return false; - } - } - else - { - return false; - } - } - - if (request.HasSubtitles.HasValue) - { - var val = request.HasSubtitles.Value; - - if (video == null || val != video.HasSubtitles) - { - return false; - } - } - - if (request.HasParentalRating.HasValue) - { - var val = request.HasParentalRating.Value; - - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (val) - { - if (string.IsNullOrEmpty(rating)) - { - return false; - } - } - else - { - if (!string.IsNullOrEmpty(rating)) - { - return false; - } - } - } - - if (request.HasTrailer.HasValue) - { - var val = request.HasTrailer.Value; - var trailerCount = 0; - - var hasTrailers = i as IHasTrailers; - if (hasTrailers != null) - { - trailerCount = hasTrailers.GetTrailerIds().Count; - } - - var ok = val ? trailerCount > 0 : trailerCount == 0; - - if (!ok) - { - return false; - } - } - - if (request.HasThemeSong.HasValue) - { - var filterValue = request.HasThemeSong.Value; - - var themeCount = 0; - var iHasThemeMedia = i as IHasThemeMedia; - - if (iHasThemeMedia != null) - { - themeCount = iHasThemeMedia.ThemeSongIds.Count; - } - var ok = filterValue ? themeCount > 0 : themeCount == 0; - - if (!ok) - { - return false; - } - } - - if (request.HasThemeVideo.HasValue) - { - var filterValue = request.HasThemeVideo.Value; - - var themeCount = 0; - var iHasThemeMedia = i as IHasThemeMedia; - - if (iHasThemeMedia != null) - { - themeCount = iHasThemeMedia.ThemeVideoIds.Count; - } - var ok = filterValue ? themeCount > 0 : themeCount == 0; - - if (!ok) - { - return false; - } - } - - // Apply tag filter - var tags = request.GetTags(); - if (tags.Length > 0) - { - var hasTags = i as IHasTags; - if (hasTags == null) - { - return false; - } - if (!(tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase)))) - { - return false; - } - } - - // Apply official rating filter - var officialRatings = request.GetOfficialRatings(); - if (officialRatings.Length > 0 && !officialRatings.Contains(i.OfficialRating ?? string.Empty)) - { - return false; - } - - // Apply genre filter - var genres = request.GetGenres(); - if (genres.Length > 0 && !(genres.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase)))) - { - return false; - } - - // Filter by VideoType - var videoTypes = request.GetVideoTypes(); - if (videoTypes.Length > 0 && (video == null || !videoTypes.Contains(video.VideoType))) - { - return false; - } - - var imageTypes = request.GetImageTypes().ToList(); - if (imageTypes.Count > 0) - { - if (!(imageTypes.Any(i.HasImage))) - { - return false; - } - } - - // Apply studio filter - var studios = request.GetStudios(); - if (studios.Length > 0 && !studios.Any(v => i.Studios.Contains(v, StringComparer.OrdinalIgnoreCase))) - { - return false; - } - - // Apply studio filter - var studioIds = request.GetStudioIds(); - if (studioIds.Length > 0 && !studioIds.Any(id => - { - var studioItem = libraryManager.GetItemById(id); - return studioItem != null && i.Studios.Contains(studioItem.Name, StringComparer.OrdinalIgnoreCase); - })) - { - return false; - } - - // Apply year filter - var years = request.GetYears(); - if (years.Length > 0 && !(i.ProductionYear.HasValue && years.Contains(i.ProductionYear.Value))) - { - return false; - } - - // Apply person filter - var personIds = request.GetPersonIds(); - if (personIds.Length > 0) - { - var names = personIds - .Select(libraryManager.GetItemById) - .Select(p => p == null ? "-1" : p.Name) - .ToList(); - - if (!(names.Any(v => i.People.Select(p => p.Name).Contains(v, StringComparer.OrdinalIgnoreCase)))) - { - return false; - } - } - - // Apply person filter - if (!string.IsNullOrEmpty(request.Person)) - { - var personTypes = request.GetPersonTypes(); - - if (personTypes.Length == 0) - { - if (!(i.People.Any(p => string.Equals(p.Name, request.Person, StringComparison.OrdinalIgnoreCase)))) - { - return false; - } - } - else - { - var types = personTypes; - - var ok = new[] { i }.Any(item => - item.People != null && - item.People.Any(p => - p.Name.Equals(request.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role, StringComparer.OrdinalIgnoreCase)))); - - if (!ok) - { - return false; - } - } + case ItemFilter.Dislikes: + query.IsLiked = false; + break; + case ItemFilter.IsFavorite: + query.IsFavorite = true; + break; + case ItemFilter.IsFavoriteOrLikes: + query.IsFavoriteOrLiked = true; + break; + case ItemFilter.IsFolder: + query.IsFolder = true; + break; + case ItemFilter.IsNotFolder: + query.IsFolder = false; + break; + case ItemFilter.IsPlayed: + query.IsPlayed = true; + break; + case ItemFilter.IsRecentlyAdded: + break; + case ItemFilter.IsResumable: + query.IsResumable = true; + break; + case ItemFilter.IsUnplayed: + query.IsPlayed = false; + break; + case ItemFilter.Likes: + query.IsLiked = true; + break; } } - if (request.MinCommunityRating.HasValue) - { - var val = request.MinCommunityRating.Value; + if (request.HasQueryLimit) + query.Limit = request.Limit; - if (!(i.CommunityRating.HasValue && i.CommunityRating >= val)) - { - return false; - } - } - - if (request.MinCriticRating.HasValue) - { - var val = request.MinCriticRating.Value; - - var hasCriticRating = i as IHasCriticRating; - - if (hasCriticRating != null) - { - if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val)) - { - return false; - } - } - else - { - return false; - } - } + return query; + } + private bool ApplyAdditionalFilters(BaseReportRequest request, BaseItem i, User user, ILibraryManager libraryManager) + { // Artists if (!string.IsNullOrEmpty(request.ArtistIds)) { - var artistIds = request.ArtistIds.Split('|'); + var artistIds = request.ArtistIds.Split(new[] { '|', ',' }); var audio = i as IHasArtist; @@ -904,52 +496,6 @@ namespace MediaBrowser.Api.Reports } } - if (request.MinPlayers.HasValue) - { - var filterValue = request.MinPlayers.Value; - - var game = i as Game; - - if (game != null) - { - var players = game.PlayersSupported ?? 1; - - var ok = players >= filterValue; - - if (!ok) - { - return false; - } - } - else - { - return false; - } - } - - if (request.MaxPlayers.HasValue) - { - var filterValue = request.MaxPlayers.Value; - - var game = i as Game; - - if (game != null) - { - var players = game.PlayersSupported ?? 1; - - var ok = players <= filterValue; - - if (!ok) - { - return false; - } - } - else - { - return false; - } - } - if (request.ParentIndexNumber.HasValue) { var filterValue = request.ParentIndexNumber.Value; @@ -1017,7 +563,7 @@ namespace MediaBrowser.Api.Reports /// The request. /// The items. /// IEnumerable{BaseItem}. - private IEnumerable ApplyPaging(GetItems request, IEnumerable items) + private IEnumerable ApplyPaging(BaseReportRequest request, IEnumerable items) { // Start at if (request.StartIndex.HasValue) @@ -1034,110 +580,6 @@ namespace MediaBrowser.Api.Reports return items; } - /// Gets items query. - /// The request. - /// The user. - /// The items query. - private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user) - { - var query = new InternalItemsQuery - { - User = user, - IsPlayed = request.IsPlayed, - MediaTypes = request.GetMediaTypes(), - IncludeItemTypes = request.GetIncludeItemTypes(), - ExcludeItemTypes = request.GetExcludeItemTypes(), - Recursive = true, - SortBy = request.GetOrderBy(), - SortOrder = request.SortOrder ?? SortOrder.Ascending, - - Filter = i => ApplyAdditionalFilters(request, i, user, true, _libraryManager), - StartIndex = request.StartIndex, - IsMissing = request.IsMissing, - IsVirtualUnaired = request.IsVirtualUnaired, - IsUnaired = request.IsUnaired, - CollapseBoxSetItems = request.CollapseBoxSetItems, - NameLessThan = request.NameLessThan, - NameStartsWith = request.NameStartsWith, - NameStartsWithOrGreater = request.NameStartsWithOrGreater, - HasImdbId = request.HasImdbId, - IsYearMismatched = request.IsYearMismatched, - IsUnidentified = request.IsUnidentified, - IsPlaceHolder = request.IsPlaceHolder, - IsLocked = request.IsLocked, - IsInBoxSet = request.IsInBoxSet, - IsHD = request.IsHD, - Is3D = request.Is3D, - HasTvdbId = request.HasTvdbId, - HasTmdbId = request.HasTmdbId, - HasOverview = request.HasOverview, - HasOfficialRating = request.HasOfficialRating, - HasParentalRating = request.HasParentalRating, - HasSpecialFeature = request.HasSpecialFeature, - HasSubtitles = request.HasSubtitles, - HasThemeSong = request.HasThemeSong, - HasThemeVideo = request.HasThemeVideo, - HasTrailer = request.HasTrailer, - Tags = request.GetTags(), - OfficialRatings = request.GetOfficialRatings(), - Genres = request.GetGenres(), - Studios = request.GetStudios(), - StudioIds = request.GetStudioIds(), - Person = request.Person, - PersonIds = request.GetPersonIds(), - PersonTypes = request.GetPersonTypes(), - Years = request.GetYears(), - ImageTypes = request.GetImageTypes().ToArray(), - VideoTypes = request.GetVideoTypes().ToArray(), - AdjacentTo = request.AdjacentTo - }; - - if (!string.IsNullOrWhiteSpace(request.Ids)) - { - query.CollapseBoxSetItems = false; - } - - foreach (var filter in request.GetFilters()) - { - switch (filter) - { - case ItemFilter.Dislikes: - query.IsLiked = false; - break; - case ItemFilter.IsFavorite: - query.IsFavorite = true; - break; - case ItemFilter.IsFavoriteOrLikes: - query.IsFavoriteOrLiked = true; - break; - case ItemFilter.IsFolder: - query.IsFolder = true; - break; - case ItemFilter.IsNotFolder: - query.IsFolder = false; - break; - case ItemFilter.IsPlayed: - query.IsPlayed = true; - break; - case ItemFilter.IsRecentlyAdded: - break; - case ItemFilter.IsResumable: - query.IsResumable = true; - break; - case ItemFilter.IsUnplayed: - query.IsPlayed = false; - break; - case ItemFilter.Likes: - query.IsLiked = true; - break; - } - } - - if (request.HasQueryLimit) - query.Limit = request.Limit; - return query; - } - /// Gets query result. /// The request. /// The query result. @@ -1197,7 +639,12 @@ namespace MediaBrowser.Api.Reports DateTime? minDate = string.IsNullOrWhiteSpace(request.MinDate) ? (DateTime?)null : DateTime.Parse(request.MinDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - var queryResult = _repo.GetActivityLogEntries(minDate, request.StartIndex, request.Limit); + + QueryResult queryResult; + if (request.HasQueryLimit) + queryResult = _repo.GetActivityLogEntries(minDate, request.StartIndex, request.Limit); + else + queryResult = _repo.GetActivityLogEntries(minDate, request.StartIndex, null); //var queryResult = _activityManager.GetActivityLogEntries(minDate, request.StartIndex, request.Limit); ReportActivitiesBuilder builder = new ReportActivitiesBuilder(_libraryManager, _userManager); diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 28e4c946c..98f86e3b5 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -1494,5 +1494,11 @@ "ImportFavoriteChannelsHelp": "If enabled, only channels that are marked as favorite on the tuner device will be imported.", "ButtonRepeat": "Repeat", "LabelEnableThisTuner": "Enable this tuner", - "LabelEnableThisTunerHelp": "Uncheck to prevent importing channels from this tuner." + "LabelEnableThisTunerHelp": "Uncheck to prevent importing channels from this tuner.", + "HeaderLocked": "Locked", + "HeaderUnidentified": "Unidentified", + "HeaderImagePrimary": "Primary", + "HeaderImageBackdrop": "Backdrop", + "HeaderImageLogo": "Logo", + "HeaderUserPrimaryImage": "User Image" }