mirror of
https://github.com/jellyfin/jellyfin-plugin-reports.git
synced 2024-11-23 05:39:45 +00:00
Enable nullable
This commit is contained in:
parent
d6321ac41b
commit
58a5238534
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@ -49,7 +51,7 @@ namespace Jellyfin.Plugin.Reports.Api.Activities
|
||||
var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Group = g.Trim(), Rows = x })
|
||||
.GroupBy(x => x.Group)
|
||||
.OrderBy(x => x.Key)
|
||||
.Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() });
|
||||
.Select(x => new ReportGroup(x.Key, x.Select(r => r.Rows).ToList()));
|
||||
|
||||
result.Groups = rowsGroup.ToList();
|
||||
result.IsGrouped = true;
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,6 +18,9 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <summary> A report builder base. </summary>
|
||||
public abstract class ReportBuilderBase
|
||||
{
|
||||
/// <summary> Manager for library. </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportBuilderBase class. </summary>
|
||||
/// <param name="libraryManager"> Manager for library. </param>
|
||||
@ -25,9 +29,6 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary> Manager for library. </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
protected Func<bool, string> GetBoolString => s => s == true ? "x" : string.Empty;
|
||||
|
||||
/// <summary> Gets the headers. </summary>
|
||||
@ -144,7 +145,7 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
return "Episode";
|
||||
}
|
||||
|
||||
string headerName = "";
|
||||
string headerName = string.Empty;
|
||||
if (internalHeader != HeaderMetadata.None)
|
||||
{
|
||||
string localHeader = internalHeader.ToString();
|
||||
@ -158,8 +159,7 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <returns> The media source information. </returns>
|
||||
protected MediaSourceInfo GetMediaSourceInfo(BaseItem item)
|
||||
{
|
||||
var mediaSource = item as IHasMediaSources;
|
||||
if (mediaSource != null)
|
||||
if (item is IHasMediaSources mediaSource)
|
||||
return mediaSource.GetMediaSources(false).FirstOrDefault(n => n.Type == MediaSourceType.Default);
|
||||
|
||||
return null;
|
||||
|
@ -13,49 +13,43 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
/// <param name="value"> The value. </param>
|
||||
/// <param name="fieldType"> Type of the field. </param>
|
||||
/// <returns> The field converted to string. </returns>
|
||||
public static string ConvertToString<T>(T value, ReportFieldType fieldType)
|
||||
public static string? ConvertToString<T>(T value, ReportFieldType fieldType)
|
||||
{
|
||||
if (value == null)
|
||||
return string.Empty;
|
||||
switch (fieldType)
|
||||
{
|
||||
case ReportFieldType.String:
|
||||
return value.ToString();
|
||||
case ReportFieldType.Boolean:
|
||||
return value.ToString();
|
||||
case ReportFieldType.Date:
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0:d}", value);
|
||||
case ReportFieldType.Time:
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0:t}", value);
|
||||
case ReportFieldType.DateTime:
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0:g}", value);
|
||||
case ReportFieldType.Minutes:
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}mn", value);
|
||||
case ReportFieldType.Int:
|
||||
return value.ToString();
|
||||
default:
|
||||
if (value is Guid guid)
|
||||
return guid.ToString("N", CultureInfo.InvariantCulture);
|
||||
return value.ToString();
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return fieldType switch
|
||||
{
|
||||
ReportFieldType.Boolean | ReportFieldType.Int | ReportFieldType.String => value.ToString(),
|
||||
ReportFieldType.Date => string.Format(CultureInfo.InvariantCulture, "{0:d}", value),
|
||||
ReportFieldType.Time => string.Format(CultureInfo.InvariantCulture, "{0:t}", value),
|
||||
ReportFieldType.DateTime => string.Format(CultureInfo.InvariantCulture, "{0:g}", value),
|
||||
ReportFieldType.Minutes => string.Format(CultureInfo.InvariantCulture, "{0}mn", value),
|
||||
_ when value is Guid guid => guid.ToString("N", CultureInfo.InvariantCulture),
|
||||
_ => value.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary> Gets filtered report header metadata. </summary>
|
||||
/// <param name="reportColumns"> The report columns. </param>
|
||||
/// <param name="defaultReturnValue"> The default return value. </param>
|
||||
/// <returns> The filtered report header metadata. </returns>
|
||||
public static List<HeaderMetadata> GetFilteredReportHeaderMetadata(string reportColumns, Func<List<HeaderMetadata>> defaultReturnValue = null)
|
||||
public static List<HeaderMetadata> GetFilteredReportHeaderMetadata(string reportColumns, Func<List<HeaderMetadata>>? defaultReturnValue = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(reportColumns))
|
||||
{
|
||||
var s = reportColumns.Split('|').Select(x => ReportHelper.GetHeaderMetadataType(x)).Where(x => x != HeaderMetadata.None);
|
||||
return s.ToList();
|
||||
}
|
||||
else
|
||||
if (defaultReturnValue != null)
|
||||
return defaultReturnValue();
|
||||
else
|
||||
return new List<HeaderMetadata>();
|
||||
|
||||
if (defaultReturnValue == null)
|
||||
{
|
||||
return new List<HeaderMetadata>();
|
||||
}
|
||||
|
||||
return defaultReturnValue();
|
||||
}
|
||||
|
||||
/// <summary> Gets header metadata type. </summary>
|
||||
|
@ -4,6 +4,5 @@ namespace Jellyfin.Plugin.Reports.Api.Common
|
||||
{
|
||||
ReportData,
|
||||
ReportActivities
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Jellyfin.Plugin.Reports.Api.Common;
|
||||
using Jellyfin.Plugin.Reports.Api.Model;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
{
|
||||
@ -46,7 +48,7 @@ namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Group = g.Trim(), Rows = x })
|
||||
.GroupBy(x => x.Group)
|
||||
.OrderBy(x => x.Key)
|
||||
.Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() });
|
||||
.Select(x => new ReportGroup(x.Key, x.Select(r => r.Rows).ToList()));
|
||||
|
||||
result.Groups = rowsGroup.ToList();
|
||||
result.IsGrouped = true;
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System.Globalization;
|
||||
#nullable disable
|
||||
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Jellyfin.Plugin.Reports.Api.Model;
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using Jellyfin.Plugin.Reports.Api.Model;
|
||||
|
||||
namespace Jellyfin.Plugin.Reports.Api.Data
|
||||
|
@ -6,35 +6,26 @@ namespace Jellyfin.Plugin.Reports.Api.Model
|
||||
/// <summary> A report group. </summary>
|
||||
public class ReportGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportGroup class. </summary>
|
||||
public ReportGroup()
|
||||
{
|
||||
Rows = new List<ReportRow>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportGroup class. </summary>
|
||||
/// <param name="rows"> The rows. </param>
|
||||
public ReportGroup(List<ReportRow> rows)
|
||||
public ReportGroup(string name, List<ReportRow> rows)
|
||||
{
|
||||
Name = name;
|
||||
Rows = rows;
|
||||
}
|
||||
|
||||
/// <summary> Gets or sets the name. </summary>
|
||||
/// <value> The name. </value>
|
||||
public string Name { get; set; }
|
||||
/// <summary>Gets the name.</summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary> Gets or sets the rows. </summary>
|
||||
/// <value> The rows. </value>
|
||||
public List<ReportRow> Rows { get; set; }
|
||||
/// <summary>Gets the rows.</summary>
|
||||
/// <value>The rows.</value>
|
||||
public List<ReportRow> Rows { get; }
|
||||
|
||||
/// <summary> Returns a string that represents the current object. </summary>
|
||||
/// <returns> A string that represents the current object. </returns>
|
||||
/// <seealso cref="M:System.Object.ToString()"/>
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
/// <seealso cref="Object.ToString()"/>
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Jellyfin.Plugin.Reports.Api.Common;
|
||||
#nullable disable
|
||||
|
||||
using Jellyfin.Plugin.Reports.Api.Common;
|
||||
|
||||
namespace Jellyfin.Plugin.Reports.Api.Model
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Jellyfin.Plugin.Reports.Api.Model
|
||||
#nullable disable
|
||||
|
||||
namespace Jellyfin.Plugin.Reports.Api.Model
|
||||
{
|
||||
/// <summary> A report item. </summary>
|
||||
public class ReportItem
|
||||
@ -19,7 +21,7 @@
|
||||
|
||||
/// <summary> Returns a string that represents the current object. </summary>
|
||||
/// <returns> A string that represents the current object. </returns>
|
||||
/// <seealso cref="M:System.Object.ToString()"/>
|
||||
/// <seealso cref="Object.ToString()"/>
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jellyfin.Plugin.Reports.Api.Model
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Jellyfin.Plugin.Reports.Api.Common;
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Jellyfin.Data.Enums;
|
||||
|
@ -1,6 +1,4 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Net.Mime;
|
||||
using System.Net.Mime;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Reports.Api.Common;
|
||||
using Jellyfin.Plugin.Reports.Api.Model;
|
||||
|
@ -1,25 +1,27 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Querying;
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Activity;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using Jellyfin.Data.Queries;
|
||||
using Jellyfin.Plugin.Reports.Api.Activities;
|
||||
using Jellyfin.Plugin.Reports.Api.Common;
|
||||
using Jellyfin.Plugin.Reports.Api.Data;
|
||||
using Jellyfin.Plugin.Reports.Api.Model;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Activity;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using User = Jellyfin.Data.Entities.User;
|
||||
|
||||
namespace Jellyfin.Plugin.Reports.Api
|
||||
{
|
||||
/// <summary> The reports service. </summary>
|
||||
/// <seealso cref="T:MediaBrowser.Api.BaseApiService"/>
|
||||
/// <seealso cref="BaseApiService"/>
|
||||
public class ReportsService
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -7,6 +7,7 @@
|
||||
<RootNamespace>Jellyfin.Plugin.Reports</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
|
Loading…
Reference in New Issue
Block a user