From 4b7d7410aebfe525c1692b2629ede5ed06cc376b Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Tue, 13 Aug 2019 13:45:32 +0100 Subject: [PATCH] Made some good process on getting the backend up and running for requesting albums etc --- .../Engine/V2/MusicSearchEngineV2.cs | 9 +++-- .../Models/Search/SearchViewModel.cs | 1 - .../Search/V2/Music/ArtistInformation.cs | 9 ----- .../Models/Search/V2/Music/ReleaseGroup.cs | 17 ++++++++++ .../Rule/Rules/Search/ExistingRule.cs | 33 +++++++++++++----- .../Rule/Rules/Search/LidarrAlbumCacheRule.cs | 34 +++++++++++++------ .../app/interfaces/IMusicSearchResultV2.ts | 11 +++++- .../artist/artist-details.component.html | 5 +++ .../artist/artist-details.component.ts | 2 +- .../artist-release-panel.component.html | 2 +- .../artist-release-panel.component.scss | 10 ++++++ .../artist-release-panel.component.ts | 4 +-- .../media-details.component.scss | 2 +- src/Ombi/ClientApp/src/styles/buttons.scss | 16 ++++++--- src/Ombi/wwwroot/translations/en.json | 1 + 15 files changed, 114 insertions(+), 42 deletions(-) create mode 100644 src/Ombi.Core/Models/Search/V2/Music/ReleaseGroup.cs create mode 100644 src/Ombi/ClientApp/src/app/media-details/components/artist/panels/artist-release-panel/artist-release-panel.component.scss diff --git a/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs index 1ba26d764..e413174cf 100644 --- a/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs @@ -67,13 +67,16 @@ namespace Ombi.Core.Engine.V2 foreach (var g in artist.ReleaseGroups) { - info.ReleaseGroups.Add(new ReleaseGroup + var release = new ReleaseGroup { - Type = g.PrimaryType, + ReleaseType = g.PrimaryType, Id = g.Id, Title = g.Title, ReleaseDate = g.FirstReleaseDate, - }); + }; + + await RunSearchRules(release); + info.ReleaseGroups.Add(release); } info.Links = GetLinksForArtist(artist); diff --git a/src/Ombi.Core/Models/Search/SearchViewModel.cs b/src/Ombi.Core/Models/Search/SearchViewModel.cs index a388ccfff..c59b5284d 100644 --- a/src/Ombi.Core/Models/Search/SearchViewModel.cs +++ b/src/Ombi.Core/Models/Search/SearchViewModel.cs @@ -28,7 +28,6 @@ namespace Ombi.Core.Models.Search [NotMapped] public string TheMovieDbId { get; set; } - [NotMapped] public bool Subscribed { get; set; } [NotMapped] diff --git a/src/Ombi.Core/Models/Search/V2/Music/ArtistInformation.cs b/src/Ombi.Core/Models/Search/V2/Music/ArtistInformation.cs index 3ecfdd696..04dfd44d8 100644 --- a/src/Ombi.Core/Models/Search/V2/Music/ArtistInformation.cs +++ b/src/Ombi.Core/Models/Search/V2/Music/ArtistInformation.cs @@ -53,13 +53,4 @@ namespace Ombi.Core.Models.Search.V2.Music public string Google { get; set; } public string Apple { get; set; } } - - public class ReleaseGroup - { - public string Id { get; set; } - public string Title { get; set; } - public string ReleaseDate { get; set; } - public string Type { get; set; } - - } } \ No newline at end of file diff --git a/src/Ombi.Core/Models/Search/V2/Music/ReleaseGroup.cs b/src/Ombi.Core/Models/Search/V2/Music/ReleaseGroup.cs new file mode 100644 index 000000000..75c049b27 --- /dev/null +++ b/src/Ombi.Core/Models/Search/V2/Music/ReleaseGroup.cs @@ -0,0 +1,17 @@ +using Ombi.Store.Entities; + +namespace Ombi.Core.Models.Search.V2.Music +{ + public class ReleaseGroup : SearchViewModel + { + public new string Id { get; set; } + public override RequestType Type => RequestType.Album; + public string Title { get; set; } + public string ReleaseDate { get; set; } + public string ReleaseType { get; set; } + public decimal PercentOfTracks { get; set; } + public bool Monitored { get; set; } + public bool PartiallyAvailable => PercentOfTracks != 100 && PercentOfTracks > 0; + public bool FullyAvailable => PercentOfTracks == 100; + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs index d56de74ac..853ad399c 100644 --- a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Ombi.Core.Models.Search; +using Ombi.Core.Models.Search.V2.Music; using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -89,17 +90,33 @@ namespace Ombi.Core.Rule.Rules.Search } if (obj.Type == RequestType.Album) { - var album = (SearchAlbumViewModel) obj; - var albumRequest = await Music.GetRequestAsync(album.ForeignAlbumId); - if (albumRequest != null) // Do we already have a request for this? + if (obj is SearchAlbumViewModel album) { - obj.Requested = true; - obj.RequestId = albumRequest.Id; - obj.Approved = albumRequest.Approved; - obj.Available = albumRequest.Available; + var albumRequest = await Music.GetRequestAsync(album.ForeignAlbumId); + if (albumRequest != null) // Do we already have a request for this? + { + obj.Requested = true; + obj.RequestId = albumRequest.Id; + obj.Approved = albumRequest.Approved; + obj.Available = albumRequest.Available; - return Success(); + return Success(); + } } + if (obj is ReleaseGroup release) + { + var albumRequest = await Music.GetRequestAsync(release.Id); + if (albumRequest != null) // Do we already have a request for this? + { + obj.Requested = true; + obj.RequestId = albumRequest.Id; + obj.Approved = albumRequest.Approved; + obj.Available = albumRequest.Available; + + return Success(); + } + } + return Success(); } return Success(); diff --git a/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs b/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs index fe28c3acf..ac01a2dfa 100644 --- a/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/LidarrAlbumCacheRule.cs @@ -2,13 +2,14 @@ using System.Linq; using System.Threading.Tasks; using Ombi.Core.Models.Search; +using Ombi.Core.Models.Search.V2.Music; using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities; using Ombi.Store.Repository; namespace Ombi.Core.Rule.Rules.Search { - public class LidarrAlbumCacheRule : SpecificRule, ISpecificRule + public class LidarrAlbumCacheRule : BaseSearchRule, IRules { public LidarrAlbumCacheRule(IExternalRepository db) { @@ -17,20 +18,33 @@ namespace Ombi.Core.Rule.Rules.Search private readonly IExternalRepository _db; - public Task Execute(object objec) + public Task Execute(SearchViewModel objec) { - var obj = (SearchAlbumViewModel) objec; - // Check if it's in Lidarr - var result = _db.GetAll().FirstOrDefault(x => x.ForeignAlbumId.Equals(obj.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase)); - if (result != null) + if (objec is SearchAlbumViewModel obj) { - obj.PercentOfTracks = result.PercentOfTracks; - obj.Monitored = true; // It's in Lidarr so it's monitored + // Check if it's in Lidarr + var result = _db.GetAll().FirstOrDefault(x => + x.ForeignAlbumId.Equals(obj.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase)); + if (result != null) + { + obj.PercentOfTracks = result.PercentOfTracks; + obj.Monitored = true; // It's in Lidarr so it's monitored + } + } + + if (objec is ReleaseGroup release) + { + // Check if it's in Lidarr + var result = _db.GetAll().FirstOrDefault(x => + x.ForeignAlbumId.Equals(release.Id, StringComparison.InvariantCultureIgnoreCase)); + if (result != null) + { + release.PercentOfTracks = result.PercentOfTracks; + release.Monitored = true; // It's in Lidarr so it's monitored + } } return Task.FromResult(Success()); } - - public override SpecificRules Rule => SpecificRules.LidarrAlbum; } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/interfaces/IMusicSearchResultV2.ts b/src/Ombi/ClientApp/src/app/interfaces/IMusicSearchResultV2.ts index cf141fea7..1f66ac8ba 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/IMusicSearchResultV2.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/IMusicSearchResultV2.ts @@ -23,7 +23,16 @@ export interface IReleaseGroups { id: string; title: string; releaseDate: string; - type: string; + releaseType: string; + approved: boolean; + requested: boolean; + requestId: number; + available: boolean; + subscribed: boolean; + showSubscribe: boolean; + monitored: boolean; + partiallyAvailable: boolean; + fullyAvailable: boolean; image: string; // Set by another api call } diff --git a/src/Ombi/ClientApp/src/app/media-details/components/artist/artist-details.component.html b/src/Ombi/ClientApp/src/app/media-details/components/artist/artist-details.component.html index 6a352c940..d24ce157d 100644 --- a/src/Ombi/ClientApp/src/app/media-details/components/artist/artist-details.component.html +++ b/src/Ombi/ClientApp/src/app/media-details/components/artist/artist-details.component.html @@ -28,6 +28,11 @@
+ +