mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
Moar !wip
This commit is contained in:
parent
9f696bfc7d
commit
1f188b3618
6 changed files with 151 additions and 39 deletions
|
@ -42,6 +42,7 @@ namespace Ombi.Core.Engine
|
|||
var movieRequests = await _movieRequestEngine.GetRequests();
|
||||
var tvRequestsTask = _tvRequestEngine.GetRequests();
|
||||
var musicRequestsTask = _musicRequestEngine.GetRequests();
|
||||
var user = await GetUser();
|
||||
foreach (var r in movieRequests)
|
||||
{
|
||||
if (r.Available || r.Approved || (r.Denied ?? false))
|
||||
|
@ -52,6 +53,8 @@ namespace Ombi.Core.Engine
|
|||
var votes = GetVotes(r.Id, RequestType.Movie);
|
||||
var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync();
|
||||
var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync();
|
||||
var myVote = await votes.FirstOrDefaultAsync(x => x.UserId == user.Id && !x.Deleted);
|
||||
|
||||
vm.Add(new VoteViewModel
|
||||
{
|
||||
Upvotes = upVotes,
|
||||
|
@ -61,7 +64,9 @@ namespace Ombi.Core.Engine
|
|||
Title = r.Title,
|
||||
Image = $"https://image.tmdb.org/t/p/w500/{r.PosterPath}",
|
||||
Background = $"https://image.tmdb.org/t/p/w1280{r.Background}",
|
||||
Description = r.Overview
|
||||
Description = r.Overview,
|
||||
AlreadyVoted = myVote != null,
|
||||
MyVote = myVote?.VoteType ?? VoteType.Downvote
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -75,6 +80,7 @@ namespace Ombi.Core.Engine
|
|||
var votes = GetVotes(r.Id, RequestType.Album);
|
||||
var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync();
|
||||
var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync();
|
||||
var myVote = await votes.FirstOrDefaultAsync(x => x.UserId == user.Id && !x.Deleted);
|
||||
vm.Add(new VoteViewModel
|
||||
{
|
||||
Upvotes = upVotes,
|
||||
|
@ -84,24 +90,27 @@ namespace Ombi.Core.Engine
|
|||
Title = r.Title,
|
||||
Image = r.Cover,
|
||||
Background = r.Cover,
|
||||
Description = r.ArtistName
|
||||
Description = r.ArtistName,
|
||||
AlreadyVoted = myVote != null,
|
||||
MyVote = myVote?.VoteType ?? VoteType.Downvote
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var r in await tvRequestsTask)
|
||||
{
|
||||
// Make model
|
||||
var votes = GetVotes(r.Id, RequestType.TvShow);
|
||||
var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync();
|
||||
var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync();
|
||||
|
||||
var finalsb = new StringBuilder();
|
||||
foreach (var childRequests in r.ChildRequests)
|
||||
{
|
||||
var finalsb = new StringBuilder();
|
||||
if (childRequests.Available || childRequests.Approved || (childRequests.Denied ?? false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var votes = GetVotes(childRequests.Id, RequestType.TvShow);
|
||||
// Make model
|
||||
var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync();
|
||||
var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync();
|
||||
var myVote = await votes.FirstOrDefaultAsync(x => x.UserId == user.Id && !x.Deleted);
|
||||
foreach (var epInformation in childRequests.SeasonRequests.OrderBy(x => x.SeasonNumber))
|
||||
{
|
||||
var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
|
||||
|
@ -118,7 +127,9 @@ namespace Ombi.Core.Engine
|
|||
Title = r.Title,
|
||||
Image = r.PosterPath,
|
||||
Background = r.Background,
|
||||
Description = finalsb.ToString()
|
||||
Description = finalsb.ToString(),
|
||||
AlreadyVoted = myVote != null,
|
||||
MyVote = myVote?.VoteType ?? VoteType.Downvote
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +220,7 @@ namespace Ombi.Core.Engine
|
|||
{
|
||||
var user = await GetUser();
|
||||
var currentVote = await GetVoteForUser(requestId, user.Id);
|
||||
if (currentVote != null && currentVote.VoteType == VoteType.Upvote)
|
||||
if (currentVote != null && currentVote.VoteType == VoteType.Downvote)
|
||||
{
|
||||
return new VoteEngineResult { ErrorMessage = "You have already voted!" };
|
||||
}
|
||||
|
|
|
@ -12,5 +12,7 @@ namespace Ombi.Core.Models.UI
|
|||
public int Downvotes { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool AlreadyVoted { get; set; }
|
||||
public VoteType MyVote { get; set; }
|
||||
}
|
||||
}
|
|
@ -7,6 +7,8 @@
|
|||
downvotes: number;
|
||||
title: string;
|
||||
description: string;
|
||||
alreadyVoted: boolean;
|
||||
myVote: VoteType;
|
||||
}
|
||||
|
||||
export interface IVoteEngineResult {
|
||||
|
@ -21,3 +23,8 @@ export enum RequestTypes {
|
|||
Movie = 1,
|
||||
Album = 2,
|
||||
}
|
||||
|
||||
export enum VoteType {
|
||||
Upvote = 0,
|
||||
Downvote = 1,
|
||||
}
|
||||
|
|
|
@ -1,21 +1,41 @@
|
|||
<h1>Vote</h1>
|
||||
|
||||
<div *ngIf="viewModel">
|
||||
|
||||
|
||||
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
|
||||
|
||||
<li role="presentation" class="active">
|
||||
<a id="currentVotes" href="#currentVotes" aria-controls="home" role="tab" data-toggle="tab" (click)="selectCurrentTab()"><i
|
||||
class="fa fa-meh-o"></i> {{ 'Votes.VotesTab' | translate }}</a>
|
||||
</li>
|
||||
|
||||
<li role="presentation">
|
||||
<a id="completedVotes" href="#completedVotes" aria-controls="profile" role="tab" data-toggle="tab" (click)="selectCompletedVotesTab()"><i
|
||||
class="fa fa-smile-o"></i> {{ 'Votes.CompletedVotesTab' | translate }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
|
||||
<div [hidden]="!showCurrent">
|
||||
<div *ngIf="currentVotes">
|
||||
<table class="table table-striped table-hover table-responsive table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="width: 10%"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>Title</td>
|
||||
<td style="width: 10%">Title</td>
|
||||
<td>Description</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let vm of viewModel">
|
||||
<tr *ngFor="let vm of currentVotes">
|
||||
<td class="vcenter">
|
||||
<button class="btn btn-info-outline" (click)="upvote(vm)"><i class="fa fa-thumbs-o-up" aria-hidden="true"></i></button>
|
||||
<button class="btn btn-info-outline" (click)="downvote(vm)"><i class="fa fa-thumbs-o-down" aria-hidden="true"></i></button>
|
||||
<button class="btn btn-info-outline col-md-6" (click)="upvote(vm)"><i class="fa fa-thumbs-o-up"
|
||||
aria-hidden="true"></i></button>
|
||||
<button class="btn btn-info-outline col-md-6" (click)="downvote(vm)" ><i class="fa fa-thumbs-o-down"
|
||||
aria-hidden="true"></i></button>
|
||||
</td>
|
||||
<td style="width: 10%"> <img *ngIf="vm.image" class="img-responsive poster" style="max-width: 100%;
|
||||
height: auto;
|
||||
|
@ -26,10 +46,47 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div [hidden]="!showCompleted">
|
||||
<div *ngIf="completedVotes">
|
||||
<table class="table table-striped table-hover table-responsive table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="width: 10%"></td>
|
||||
<td></td>
|
||||
<td style="width: 10%">Title</td>
|
||||
<td>Description</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let vm of completedVotes">
|
||||
<td class="vcenter">
|
||||
<button class="btn btn-info-outline col-md-6" [ngClass]="{'btn-success-outline': vm.myVote == VoteType.Upvote, 'btn-info-outline': vm.myVote != VoteType.Upvote}"
|
||||
(click)="upvote(vm)" [disabled]="vm.myVote == VoteType.Upvote"><i class="fa fa-thumbs-o-up"
|
||||
aria-hidden="true"></i></button>
|
||||
<button class="btn btn-info-outline col-md-6" [ngClass]="{'btn-danger-outline': vm.myVote == VoteType.Downvote, 'btn-info-outline': vm.myVote != VoteType.Downvote}"
|
||||
(click)="downvote(vm)" [disabled]="vm.myVote == VoteType.Downvote"><i class="fa fa-thumbs-o-down"
|
||||
aria-hidden="true"></i></button>
|
||||
</td>
|
||||
<td style="width: 10%"> <img *ngIf="vm.image" class="img-responsive poster" style="max-width: 100%;
|
||||
height: auto;
|
||||
width: 100%;"
|
||||
(click)="toggle($event, vm.image)" src="{{vm.image}}" alt="poster"></td>
|
||||
<td class="vcenter">{{vm.title}}</td>
|
||||
<td class="vcenter" [innerHTML]="vm.description"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p-overlayPanel #op [dismissable]="true" [styleClass]="'hideBackground'">
|
||||
<img class="img-responsive poster" width="70%" src="{{panelImage}}" alt="poster">
|
||||
</p-overlayPanel>
|
||||
</p-overlayPanel>
|
|
@ -3,7 +3,7 @@ import { Component, OnInit, ViewChild } from "@angular/core";
|
|||
import { OverlayPanel } from "primeng/primeng";
|
||||
import { NotificationService, VoteService } from "../services";
|
||||
|
||||
import { IVoteEngineResult, IVoteViewModel, RequestTypes } from "../interfaces";
|
||||
import { IVoteEngineResult, IVoteViewModel, RequestTypes, VoteType } from "../interfaces";
|
||||
|
||||
@Component({
|
||||
templateUrl: "vote.component.html",
|
||||
|
@ -11,7 +11,12 @@ import { IVoteEngineResult, IVoteViewModel, RequestTypes } from "../interfaces";
|
|||
})
|
||||
export class VoteComponent implements OnInit {
|
||||
|
||||
public showCurrent: boolean = true;
|
||||
public showCompleted: boolean;
|
||||
public viewModel: IVoteViewModel[];
|
||||
public currentVotes: IVoteViewModel[];
|
||||
public completedVotes: IVoteViewModel[];
|
||||
public VoteType = VoteType;
|
||||
public panelImage: string;
|
||||
@ViewChild("op") public overlayPanel: OverlayPanel;
|
||||
|
||||
|
@ -19,6 +24,17 @@ export class VoteComponent implements OnInit {
|
|||
|
||||
public async ngOnInit() {
|
||||
this.viewModel = await this.voteService.getModel();
|
||||
this.filterLists();
|
||||
}
|
||||
|
||||
public selectCurrentTab() {
|
||||
this.showCurrent = true;
|
||||
this.showCompleted = false;
|
||||
}
|
||||
|
||||
public selectCompletedVotesTab() {
|
||||
this.showCurrent = false;
|
||||
this.showCompleted = true;
|
||||
}
|
||||
|
||||
public toggle(event: any, image: string) {
|
||||
|
@ -44,6 +60,9 @@ export class VoteComponent implements OnInit {
|
|||
this.notificationSerivce.error(result.errorMessage);
|
||||
} else {
|
||||
this.notificationSerivce.success("Voted!");
|
||||
vm.alreadyVoted = true;
|
||||
vm.myVote = VoteType.Upvote;
|
||||
this.filterLists();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,6 +84,18 @@ export class VoteComponent implements OnInit {
|
|||
this.notificationSerivce.error(result.errorMessage);
|
||||
} else {
|
||||
this.notificationSerivce.success("Voted!");
|
||||
vm.alreadyVoted = true;
|
||||
vm.myVote = VoteType.Downvote;
|
||||
this.filterLists();
|
||||
}
|
||||
}
|
||||
|
||||
private filterLists() {
|
||||
this.completedVotes = this.viewModel.filter(vm => {
|
||||
return vm.alreadyVoted;
|
||||
});
|
||||
this.currentVotes = this.viewModel.filter(vm => {
|
||||
return !vm.alreadyVoted;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,5 +194,9 @@
|
|||
"TvDue": "TV: {{date}}",
|
||||
"MovieDue": "Movie: {{date}}",
|
||||
"MusicDue": "Music: {{date}}"
|
||||
},
|
||||
"Votes": {
|
||||
"CompletedVotesTab": "Voted",
|
||||
"VotesTab": "Votes Needed"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue