Finished adding subscriptions for TV Shows

pull/2256/head
Jamie Rees 6 years ago
parent 7a9fc1213f
commit 16952cb44c

@ -79,7 +79,7 @@ namespace Ombi.Core.Engine
var pendingTv = 0;
var approvedTv = 0;
var availableTv = 0;
var availableTv = 0;
foreach (var tv in tvQuery)
{
foreach (var child in tv.ChildRequests)
@ -120,12 +120,9 @@ namespace Ombi.Core.Engine
var settings = await Cache.GetOrAdd(CacheKeys.OmbiSettings, async () => await OmbiSettings.GetSettingsAsync());
var result = new HideResult
{
Hide = settings.HideRequestsUsers
Hide = settings.HideRequestsUsers,
UserId = user.Id
};
if (settings.HideRequestsUsers)
{
result.UserId = user.Id;
}
return result;
}

@ -138,10 +138,10 @@ namespace Ombi.Core.Engine
{
allRequests = await MovieRepository.GetWithUser().Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
}
allRequests.ForEach(x =>
allRequests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
CheckForSubscription(shouldHide, x);
await CheckForSubscription(shouldHide, x);
});
return allRequests;
}
@ -176,19 +176,27 @@ namespace Ombi.Core.Engine
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}
allRequests.ForEach(x =>
allRequests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
CheckForSubscription(shouldHide, x);
await CheckForSubscription(shouldHide, x);
});
return allRequests;
}
private void CheckForSubscription(HideResult shouldHide, MovieRequests x)
private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x)
{
var sub = _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie);
x.Subscribed = sub != null;
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie);
x.Subscribed = sub != null;
}
}
/// <summary>
@ -209,10 +217,10 @@ namespace Ombi.Core.Engine
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
results.ForEach(x =>
results.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
CheckForSubscription(shouldHide, x);
await CheckForSubscription(shouldHide, x);
});
return results;
}

@ -157,6 +157,8 @@ namespace Ombi.Core.Engine
.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return allRequests;
}
@ -182,25 +184,28 @@ namespace Ombi.Core.Engine
.ThenInclude(x => x.Episodes)
.Skip(position).Take(count).ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return ParseIntoTreeNode(allRequests);
}
public async Task<IEnumerable<TvRequests>> GetRequests()
{
var shouldHide = await HideFromOtherUsers();
IQueryable<TvRequests> allRequests;
List<TvRequests> allRequests;
if (shouldHide.Hide)
{
allRequests = TvRepository.Get(shouldHide.UserId);
allRequests = await TvRepository.Get(shouldHide.UserId).ToListAsync();
FilterChildren(allRequests, shouldHide);
}
else
{
allRequests = TvRepository.Get();
allRequests = await TvRepository.Get().ToListAsync();
}
return await allRequests.ToListAsync();
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return allRequests;
}
private static void FilterChildren(IEnumerable<TvRequests> allRequests, HideResult shouldHide)
@ -233,6 +238,8 @@ namespace Ombi.Core.Engine
allRequests = await TvRepository.GetChild().Include(x => x.SeasonRequests).Where(x => x.ParentRequestId == tvId).ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return allRequests;
}
@ -249,6 +256,8 @@ namespace Ombi.Core.Engine
allRequests = TvRepository.Get();
}
var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync();
results.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return results;
}
@ -265,6 +274,7 @@ namespace Ombi.Core.Engine
allRequests = TvRepository.Get();
}
var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync();
results.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
return ParseIntoTreeNode(results);
}
@ -446,6 +456,29 @@ namespace Ombi.Core.Engine
}
}
private async Task CheckForSubscription(HideResult shouldHide, TvRequests x)
{
foreach (var tv in x.ChildRequests)
{
await CheckForSubscription(shouldHide, tv);
}
}
private async Task CheckForSubscription(HideResult shouldHide, ChildRequests x)
{
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.TvShow);
x.Subscribed = sub != null;
}
}
private async Task<RequestEngineResult> AddExistingRequest(ChildRequests newRequest, TvRequests existingRequest)
{
// Add the child

@ -13,6 +13,15 @@ namespace Ombi.Store.Entities.Requests
public int? IssueId { get; set; }
public SeriesType SeriesType { get; set; }
/// <summary>
/// This is to see if the user is subscribed in the UI
/// </summary>
[NotMapped]
public bool Subscribed { get; set; }
[NotMapped]
public bool ShowSubscribe { get; set; }
[ForeignKey(nameof(IssueId))]
public List<Issues> Issues { get; set; }

@ -14,6 +14,8 @@ namespace Ombi.Store.Entities.Requests
[NotMapped]
public bool Subscribed { get; set; }
[NotMapped]
public bool ShowSubscribe { get; set; }
public int RootPathOverride { get; set; }
public int QualityOverride { get; set; }

@ -17,11 +17,6 @@ namespace Ombi.Store.Entities.Requests
public DateTime ReleaseDate { get; set; }
public string Status { get; set; }
/// <summary>
/// This is to see if the user is subscribed in the UI
/// </summary>
[NotMapped]
public bool Subscribed { get; set; }
/// <summary>
/// This is so we can correctly send the right amount of seasons to Sonarr
/// </summary>

@ -13,6 +13,7 @@ export interface IMovieRequests extends IFullBaseRequest {
qualityOverride: number;
digitalReleaseDate: Date;
subscribed: boolean;
showSubscribe: boolean;
// For the UI
rootPathOverrideTitle: string;
@ -78,6 +79,8 @@ export interface ITvRequests {
export interface IChildRequests extends IBaseRequest {
seasonRequests: INewSeasonRequests[];
subscribed: boolean;
showSubscribe: boolean;
}
export interface ITvUpdateModel {

@ -128,8 +128,8 @@
<div style="float:right">
<a *ngIf="!request.subscribed" style="color:white" (click)="subscribe(request)" pTooltip="Subscribe for notifications"> <i class="fa fa-rss"></i></a>
<a *ngIf="request.subscribed" style="color:red" (click)="unSubscribe(request)" pTooltip="Unsubscribe notification"> <i class="fa fa-rss"></i></a>
<a *ngIf="request.showSubscribe && !request.subscribed" style="color:white" (click)="subscribe(request)" pTooltip="Subscribe for notifications"> <i class="fa fa-rss"></i></a>
<a *ngIf="request.showSubscribe && request.subscribed" style="color:red" (click)="unSubscribe(request)" pTooltip="Unsubscribe notification"> <i class="fa fa-rss"></i></a>
</div>
<div *ngIf="isAdmin">
<div *ngIf="!request.approved" id="approveBtn">

@ -219,7 +219,7 @@ export class MovieRequestsComponent implements OnInit {
public unSubscribe(request: IMovieRequests) {
request.subscribed = false;
this.requestService.subscribeToMovie(request.id)
this.requestService.unSubscribeToMovie(request.id)
.subscribe(x => {
this.notificationService.success("Unsubscribed Movie!");
});

@ -11,8 +11,11 @@
<span *ngIf="isAdmin && !child.requestedUser.alias">{{child.requestedUser.userName}}</span>
</div>
<div class="col-md-1 col-md-push-9">
<button id="subscribeBtn" *ngIf="child.showSubscribe && !child.subscribed" (click)="subscribe(child)" class="btn btn-sm btn-primary-outline" pTooltip="Subscribe for notifications" type="submit"><i class="fa fa-rss"></i> Subscribe</button>
<button id="subscribeBtn" *ngIf="child.showSubscribe && child.subscribed" (click)="unSubscribe(child)" class="btn btn-sm btn-danger-outline" pTooltip="UnSubscribe for notifications" type="submit"><i class="fa fa-rss"></i> UnSubscribe</button>
<div *ngIf="isAdmin">
<button id="approveBtn" *ngIf="child.canApprove && !child.approved" (click)="approve(child)" class="btn btn-sm btn-success-outline" type="submit"><i class="fa fa-plus"></i> {{ 'Common.Approve' | translate }}</button>
<button id="unavailableBtn" *ngIf="child.available" (click)="changeAvailability(child, false)" style="text-align: right" value="false" class="btn btn-sm btn-info-outline change"><i class="fa fa-minus"></i> {{ 'Requests.MarkUnavailable' | translate }}</button>

@ -94,6 +94,22 @@ export class TvRequestChildrenComponent {
});
}
public subscribe(request: IChildRequests) {
request.subscribed = true;
this.requestService.subscribeToTv(request.id)
.subscribe(x => {
this.notificationService.success("Subscribed To TV Show!");
});
}
public unSubscribe(request: IChildRequests) {
request.subscribed = false;
this.requestService.unSubscribeToTv(request.id)
.subscribe(x => {
this.notificationService.success("Unsubscribed TV Show!");
});
}
private removeRequestFromUi(key: IChildRequests) {
const index = this.childRequests.indexOf(key, 0);
if (index > -1) {

Loading…
Cancel
Save