The Approving child requests now work!

pull/1425/head
Jamie.Rees 8 years ago
parent eb433867af
commit 745ff844ca

@ -16,7 +16,7 @@ namespace Ombi.Core.Tests.Engine
{
RequestService = new Mock<IRequestService<MovieRequestModel>>();
var requestService = new RequestService(null, RequestService.Object);
Engine = new MovieRequestEngine(null, requestService, null, null, null);
Engine = new MovieRequestEngine(null, requestService, null, null, null, null, null);
}
private MovieRequestEngine Engine { get; }

@ -96,7 +96,7 @@ namespace Ombi.Core.Engine
Status = movieInfo.Status,
RequestedDate = DateTime.UtcNow,
Approved = false,
RequestedUsers = new List<string> { Username },
RequestedUser =Username,
Issues = IssueState.None
};
@ -191,7 +191,7 @@ namespace Ombi.Core.Engine
results.OtherMessage = request.OtherMessage;
results.Overview = request.Overview;
results.PosterPath = request.PosterPath;
results.RequestedUsers = request.RequestedUsers?.ToList() ?? new List<string>();
results.RequestedUser = request.RequestedUser;
var model = MovieRequestService.UpdateRequest(results);
return model;
@ -202,21 +202,6 @@ namespace Ombi.Core.Engine
await MovieRequestService.DeleteRequestAsync(requestId);
}
private IEnumerable<EpisodesModel> GetListDifferences(IEnumerable<EpisodesModel> existing,
IEnumerable<EpisodesModel> request)
{
var newRequest = request
.Select(r =>
new EpisodesModel
{
SeasonNumber = r.SeasonNumber,
EpisodeNumber = r.EpisodeNumber
})
.ToList();
return newRequest.Except(existing);
}
private async Task<RequestEngineResult> AddMovieRequest(MovieRequestModel model, string message)
{
await MovieRequestService.AddRequestAsync(model);

@ -71,7 +71,7 @@ namespace Ombi.Core.Engine
Status = showInfo.status,
RequestedDate = DateTime.UtcNow,
Approved = false,
RequestedUsers = new List<string> { Username },
RequestedUser = Username,
Issues = IssueState.None,
ProviderId = tv.Id,
RequestAll = tv.RequestAll,
@ -95,22 +95,22 @@ namespace Ombi.Core.Engine
model.ChildRequests.Add(childRequest);
if (childRequest.SeasonRequests.Any())
{
var episodes = await TvApi.EpisodeLookup(showInfo.id);
//if (childRequest.SeasonRequests.Any())
//{
// var episodes = await TvApi.EpisodeLookup(showInfo.id);
foreach (var e in episodes)
{
var season = childRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season);
season?.Episodes.Add(new EpisodesRequested
{
Url = e.url,
Title = e.name,
AirDate = DateTime.Parse(e.airstamp),
EpisodeNumber = e.number
});
}
}
// foreach (var e in episodes)
// {
// var season = childRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season);
// season?.Episodes.Add(new EpisodesRequested
// {
// Url = e.url,
// Title = e.name,
// AirDate = DateTime.Parse(e.airstamp),
// EpisodeNumber = e.number
// });
// }
//}
if (tv.LatestSeason)
{
@ -218,19 +218,45 @@ namespace Ombi.Core.Engine
return await AfterRequest(newRequest);
}
private IEnumerable<SeasonRequestModel> GetListDifferences(IEnumerable<SeasonRequestModel> existing,
IEnumerable<SeasonRequestModel> request)
private IEnumerable<SeasonRequestModel> GetListDifferences(List<SeasonRequestModel> existing,
List<SeasonRequestModel> request)
{
var newRequest = request
.Select(r =>
new SeasonRequestModel
var requestsToRemove = new List<SeasonRequestModel>();
foreach (var r in request)
{
// Do we have an existing season?
var existingSeason = existing.FirstOrDefault(x => x.SeasonNumber == r.SeasonNumber);
if (existingSeason == null)
{
continue;
}
// Compare the episodes
for (var i = r.Episodes.Count - 1; i >= 0; i--)
{
var existingEpisode = existingSeason.Episodes.FirstOrDefault(x => x.EpisodeNumber == r.Episodes[i].EpisodeNumber);
if (existingEpisode == null)
{
// we are fine, we have not yet requested this
}
else
{
SeasonNumber = r.SeasonNumber,
Episodes = r.Episodes
})
.ToList();
// We already have this request
r.Episodes.RemoveAt(i);
}
}
return newRequest.Except(existing);
if (!r.Episodes.Any())
{
requestsToRemove.Add(r);
}
}
foreach (var remove in requestsToRemove)
{
request.Remove(remove);
}
return request;
}
private async Task<RequestEngineResult> AddRequest(TvRequestModel model)

@ -172,6 +172,7 @@ namespace Ombi.Core.Engine
// Find the existing request season
var existingSeason =
existingRequestChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber);
if(existingSeason == null) continue;
foreach (var ep in existingSeason.Episodes)
{

@ -1,8 +1,6 @@
using Newtonsoft.Json;
using Ombi.Store.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Ombi.Core.Models.Requests
{
@ -22,7 +20,7 @@ namespace Ombi.Core.Models.Requests
public IssueState Issues { get; set; }
public string OtherMessage { get; set; }
public string AdminNote { get; set; }
public List<string> RequestedUsers { get; set; } = new List<string>();
public string RequestedUser { get; set; }
public int IssueId { get; set; }
public bool Denied { get; set; }
public string DeniedReason { get; set; }
@ -30,24 +28,13 @@ namespace Ombi.Core.Models.Requests
[JsonIgnore]
public bool Released => DateTime.UtcNow > ReleaseDate;
[JsonIgnore]
public IEnumerable<string> AllUsers
{
get
{
var u = new List<string>();
if (RequestedUsers != null && RequestedUsers.Any())
u.AddRange(RequestedUsers);
return u;
}
}
[JsonIgnore]
public bool CanApprove => !Approved && !Available;
public bool UserHasRequested(string username)
{
return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
return RequestedUser.Equals(username, StringComparison.OrdinalIgnoreCase);
}
}
}

@ -14,7 +14,7 @@
available: boolean,
otherMessage: string,
adminNote: string,
requestedUser: string[],
requestedUser: string,
issueId: number,
denied: boolean,
deniedReason: string,

@ -1,7 +1,6 @@
import { Component } from '@angular/core';
@Component({
selector: 'ombi',
templateUrl: './request.component.html'
})
export class RequestComponent {

@ -78,29 +78,8 @@
</div>
<!--Child Requests-->
<button type="button" class="btn btn-sm btn-info-outline" data-toggle="collapse" (click)="showChildren(request)" [attr.data-target]="'#' + request.id +'childRequests'">Children</button>
<div id="{{request.id}}childRequests" class="collapse">
<div *ngFor="let child of request.childRequests">
<hr />
<div *ngIf="request.requestedUsers">
Requested By: <span *ngFor="let user of request.requestedUsers">{{user}} </span>
</div>
<div *ngIf="child.seasonRequests">
Seasons Requested: <span *ngFor="let s of child.seasonRequests">{{s.seasonNumber}} </span>
</div>
<div>
<span>Request status: </span>
<span *ngIf="request.available" class="label label-success">Available</span>
<span *ngIf="request.approved && !request.available" class="label label-info">Processing Request</span>
<span *ngIf="request.denied" class="label label-danger">Request Denied</span>
<span *ngIf="request.deniedReason" title="{{request.deniedReason}}"><i class="fa fa-info-circle"></i></span>
<span *ngIf="!request.approved && !request.availble && !request.denied" class="label label-warning">Pending Approval</span>
</div>
</div>
</div>
<button type="button" class="btn btn-sm btn-info-outline" (click)="showChildren(request)">Requests</button>
</div>
<div class="col-sm-3 col-sm-push-3">
@ -216,12 +195,36 @@
<h4 class="modal-title">{{selectedSeason?.title}}</h4>
</div>
<div class="modal-body">
<div class="col-md-8">
</div>
<div class="col-md-4">
<div class="row" *ngFor="let child of selectedSeason.childRequests">
<div class="col-md-12">
<!--Child Requests-->
<div class="col-md-9">
<span class="col-md-12">Requested By: <b>{{child.requestedUser}}</b></span>
<span class="col-md-12" *ngIf="child.requestAll">Requested All Seasons</span>
<!--Seasons-->
<span *ngIf="child.approved && !child.available" class="label label-info">Processing Request</span>
<span *ngIf="child.denied" class="label label-danger">Request Denied</span>
<span *ngIf="child.deniedReason" title="{{child.deniedReason}}"><i class="fa fa-info-circle"></i></span>
<span *ngIf="!child.approved && !child.availble && !child.denied" class="label label-warning">Pending Approval</span>
<div class="col-md-12" *ngFor="let seasons of child.seasonRequests">
<span>Season: {{seasons.seasonNumber}}</span>
<span>Episodes:</span>
<div *ngFor="let episode of seasons.episodes">
<!--Episodes-->
<span># {{episode.episodeNumber}}</span>
<span *ngIf="episode.available" class="label label-success">Available</span>
</div>
</div>
</div>
<div class="col-md-3">
<button *ngIf="!child.approved" type="button" (click)="approveSeasonRequest(child)" class="btn btn-sm btn-success-outline" style="text-align: right"><i class="fa fa-plus"></i> Approve</button>
</div>
</div>
<hr />
</div>
</div>
<div class="modal-footer">

@ -13,7 +13,7 @@ import 'rxjs/add/operator/map';
import { RequestService } from '../services/request.service';
import { IdentityService } from '../services/identity.service';
import { ITvRequestModel } from '../interfaces/IRequestModel';
import { ITvRequestModel, IChildTvRequest } from '../interfaces/IRequestModel';
@Component({
selector: 'tv-requests',
@ -98,6 +98,12 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
this.updateRequest(request);
}
public approveSeasonRequest(request: IChildTvRequest) {
request.approved = true;
this.requestService.updateTvRequest(this.selectedSeason)
.subscribe();
}
public showChildren(request: ITvRequestModel) {
this.selectedSeason = request;
this.showChildDialogue = true;

@ -52,7 +52,7 @@ export class RequestService extends ServiceAuthHelpers {
}
updateTvRequest(request: ITvRequestModel): Observable<ITvRequestModel> {
return this.http.post(`${this.url}tv/`, JSON.stringify(request), { headers: this.headers }).map(this.extractData);
return this.http.put(`${this.url}tv/`, JSON.stringify(request), { headers: this.headers }).map(this.extractData);
}
getRequestsCount(): Observable<IRequestCountModel> {

Loading…
Cancel
Save