mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 22:03:15 -07:00
Display played state in the requests list
This commit is contained in:
parent
eedc8753c3
commit
84c02ae436
6 changed files with 60 additions and 11 deletions
|
@ -33,7 +33,8 @@ namespace Ombi.Core.Engine
|
|||
INotificationHelper helper, IRuleEvaluator r, IMovieSender sender, ILogger<MovieRequestEngine> log,
|
||||
OmbiUserManager manager, IRepository<RequestLog> rl, ICacheService cache,
|
||||
ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub, IMediaCacheService mediaCacheService,
|
||||
IFeatureService featureService)
|
||||
IFeatureService featureService,
|
||||
IUserPlayedMovieRepository userPlayedMovieRepository)
|
||||
: base(user, requestService, r, manager, cache, ombiSettings, sub)
|
||||
{
|
||||
MovieApi = movieApi;
|
||||
|
@ -43,6 +44,7 @@ namespace Ombi.Core.Engine
|
|||
_requestLog = rl;
|
||||
_mediaCacheService = mediaCacheService;
|
||||
_featureService = featureService;
|
||||
_userPlayedMovieRepository = userPlayedMovieRepository;
|
||||
}
|
||||
|
||||
private IMovieDbApi MovieApi { get; }
|
||||
|
@ -52,6 +54,7 @@ namespace Ombi.Core.Engine
|
|||
private readonly IRepository<RequestLog> _requestLog;
|
||||
private readonly IMediaCacheService _mediaCacheService;
|
||||
private readonly IFeatureService _featureService;
|
||||
protected readonly IUserPlayedMovieRepository _userPlayedMovieRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Requests the movie.
|
||||
|
@ -252,7 +255,7 @@ namespace Ombi.Core.Engine
|
|||
var requests = await (OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count)
|
||||
.ToListAsync();
|
||||
|
||||
await CheckForSubscription(shouldHide.UserId, requests);
|
||||
await FillAdditionalFields(shouldHide.UserId, requests);
|
||||
return new RequestsViewModel<MovieRequests>
|
||||
{
|
||||
Collection = requests,
|
||||
|
@ -296,7 +299,7 @@ namespace Ombi.Core.Engine
|
|||
var total = requests.Count();
|
||||
requests = requests.Skip(position).Take(count).ToList();
|
||||
|
||||
await CheckForSubscription(shouldHide.UserId, requests);
|
||||
await FillAdditionalFields(shouldHide.UserId, requests);
|
||||
return new RequestsViewModel<MovieRequests>
|
||||
{
|
||||
Collection = requests,
|
||||
|
@ -381,7 +384,7 @@ namespace Ombi.Core.Engine
|
|||
// TODO fix this so we execute this on the server
|
||||
requests = requests.Skip(position).Take(count).ToList();
|
||||
|
||||
await CheckForSubscription(shouldHide.UserId, requests);
|
||||
await FillAdditionalFields(shouldHide.UserId, requests);
|
||||
return new RequestsViewModel<MovieRequests>
|
||||
{
|
||||
Collection = requests,
|
||||
|
@ -424,7 +427,7 @@ namespace Ombi.Core.Engine
|
|||
var total = requests.Count();
|
||||
requests = requests.Skip(position).Take(count).ToList();
|
||||
|
||||
await CheckForSubscription(shouldHide.UserId, requests);
|
||||
await FillAdditionalFields(shouldHide.UserId, requests);
|
||||
return new RequestsViewModel<MovieRequests>
|
||||
{
|
||||
Collection = requests,
|
||||
|
@ -506,7 +509,7 @@ namespace Ombi.Core.Engine
|
|||
allRequests = await MovieRepository.GetWithUser().ToListAsync();
|
||||
}
|
||||
|
||||
await CheckForSubscription(shouldHide.UserId, allRequests);
|
||||
await FillAdditionalFields(shouldHide.UserId, allRequests);
|
||||
|
||||
return allRequests;
|
||||
}
|
||||
|
@ -514,10 +517,15 @@ namespace Ombi.Core.Engine
|
|||
public async Task<MovieRequests> GetRequest(int requestId)
|
||||
{
|
||||
var request = await MovieRepository.GetWithUser().Where(x => x.Id == requestId).FirstOrDefaultAsync();
|
||||
await CheckForSubscription((await GetUser()).Id, new List<MovieRequests> { request });
|
||||
await FillAdditionalFields((await GetUser()).Id, new List<MovieRequests> { request });
|
||||
|
||||
return request;
|
||||
}
|
||||
private async Task FillAdditionalFields(string UserId, List<MovieRequests> requests)
|
||||
{
|
||||
await CheckForSubscription(UserId, requests);
|
||||
await CheckForPlayed(requests);
|
||||
}
|
||||
|
||||
private async Task CheckForSubscription(string UserId, List<MovieRequests> movieRequests)
|
||||
{
|
||||
|
@ -543,6 +551,19 @@ namespace Ombi.Core.Engine
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CheckForPlayed(List<MovieRequests> movieRequests)
|
||||
{
|
||||
var theMovieDbIds = movieRequests.Select(x => x.TheMovieDbId);
|
||||
var plays = await _userPlayedMovieRepository.GetAll().Where(x =>
|
||||
theMovieDbIds.Contains(x.TheMovieDbId))
|
||||
.ToListAsync();
|
||||
foreach (var request in movieRequests)
|
||||
{
|
||||
request.WatchedByRequestedUser = plays.Exists(x => x.TheMovieDbId == request.TheMovieDbId && x.UserId == request.RequestedUserId);
|
||||
request.PlayedByUsersCount = plays.Count(x => x.TheMovieDbId == request.TheMovieDbId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the movie request.
|
||||
|
@ -563,7 +584,7 @@ namespace Ombi.Core.Engine
|
|||
}
|
||||
|
||||
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
|
||||
await CheckForSubscription(shouldHide.UserId, results);
|
||||
await FillAdditionalFields(shouldHide.UserId, results);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
|
|
@ -84,5 +84,10 @@ namespace Ombi.Store.Entities.Requests
|
|||
|
||||
[NotMapped]
|
||||
public override bool CanApprove => !Approved && !Available || !Approved4K && !Available4K;
|
||||
|
||||
[NotMapped]
|
||||
public bool WatchedByRequestedUser { get; set; }
|
||||
[NotMapped]
|
||||
public int PlayedByUsersCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ export interface IMovieRequests extends IFullBaseRequest {
|
|||
deniedReason4K: string;
|
||||
requestedDate4k: Date;
|
||||
requestedDate: Date;
|
||||
watchedByRequestedUser: boolean;
|
||||
playedByUsersCount: number;
|
||||
|
||||
// For the UI
|
||||
rootPathOverrideTitle: string;
|
||||
|
@ -212,4 +214,4 @@ export class BaseRequestOptions {
|
|||
requestOnBehalf: string | undefined;
|
||||
rootFolderOverride: number | undefined;
|
||||
qualityPathOverride: number | undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,24 @@
|
|||
<td mat-cell id="requestedStatus{{element.id}}" *matCellDef="let element"> {{element.requestStatus | translate}} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="watchedByRequestedUser">
|
||||
<th
|
||||
mat-header-cell
|
||||
*matHeaderCellDef
|
||||
mat-sort-header
|
||||
disableClear
|
||||
matTooltip="{{ 'Requests.WatchedTooltip' | translate}}">
|
||||
{{ 'Requests.Watched' | translate}}
|
||||
</th>
|
||||
<td mat-cell id="watchedByRequestedUser{{element.id}}" *matCellDef="let element">
|
||||
<mat-checkbox
|
||||
[checked]="element.watchedByRequestedUser"
|
||||
disabled="true"
|
||||
matTooltip="{{'Requests.WatchedByUsersCount' | translate: {count: element.playedByUsersCount} }}">
|
||||
</mat-checkbox>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="actions">
|
||||
<th mat-header-cell *matHeaderCellDef> </th>
|
||||
<td mat-cell *matCellDef="let element">
|
||||
|
|
|
@ -24,7 +24,7 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|||
public dataSource: MatTableDataSource<IMovieRequests>;
|
||||
public resultsLength: number;
|
||||
public isLoadingResults = true;
|
||||
public displayedColumns: string[] = ['title', 'requestedUser.requestedBy', 'status', 'requestStatus','requestedDate', 'actions'];
|
||||
public displayedColumns: string[] = ['title', 'requestedUser.requestedBy', 'status', 'requestStatus','requestedDate', 'watchedByRequestedUser', 'actions'];
|
||||
public gridCount: string = "15";
|
||||
public isAdmin: boolean;
|
||||
public is4kEnabled = false;
|
||||
|
@ -263,4 +263,4 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|||
}
|
||||
return request.requestedDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,9 @@
|
|||
"RequestedBy": "Requested By",
|
||||
"Status": "Status",
|
||||
"RequestStatus": "Request status",
|
||||
"Watched": "Watched",
|
||||
"WatchedTooltip": "The user who made the request has watched it",
|
||||
"WatchedByUsersCount": "{{count}} users have watched this.",
|
||||
"Denied": " Denied:",
|
||||
"TheatricalRelease": "Theatrical Release: {{date}}",
|
||||
"ReleaseDate": "Released: {{date}}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue