diff --git a/src/Ombi.Core/Engine/VoteEngine.cs b/src/Ombi.Core/Engine/VoteEngine.cs
index 6f399f45b..2ab35c2fa 100644
--- a/src/Ombi.Core/Engine/VoteEngine.cs
+++ b/src/Ombi.Core/Engine/VoteEngine.cs
@@ -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!" };
}
diff --git a/src/Ombi.Core/Models/UI/VoteViewModel.cs b/src/Ombi.Core/Models/UI/VoteViewModel.cs
index 71d6c95a9..f58db3dbc 100644
--- a/src/Ombi.Core/Models/UI/VoteViewModel.cs
+++ b/src/Ombi.Core/Models/UI/VoteViewModel.cs
@@ -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; }
}
}
\ No newline at end of file
diff --git a/src/Ombi/ClientApp/app/interfaces/IVote.ts b/src/Ombi/ClientApp/app/interfaces/IVote.ts
index fb772fea6..e6aaf9607 100644
--- a/src/Ombi/ClientApp/app/interfaces/IVote.ts
+++ b/src/Ombi/ClientApp/app/interfaces/IVote.ts
@@ -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,
+}
diff --git a/src/Ombi/ClientApp/app/vote/vote.component.html b/src/Ombi/ClientApp/app/vote/vote.component.html
index 4f322352d..6d8f8a797 100644
--- a/src/Ombi/ClientApp/app/vote/vote.component.html
+++ b/src/Ombi/ClientApp/app/vote/vote.component.html
@@ -1,35 +1,92 @@
Vote
-
-
-
-
-
- |
- |
- Title |
- Description |
-
-
-
-
-
-
-
- |
-  |
- {{vm.title}} |
- |
-
-
-
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+ Title |
+ Description |
+
+
+
+
+
+
+
+ |
+  |
+ {{vm.title}} |
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+ Title |
+ Description |
+
+
+
+
+
+
+
+ |
+  |
+ {{vm.title}} |
+ |
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+

+
\ No newline at end of file
diff --git a/src/Ombi/ClientApp/app/vote/vote.component.ts b/src/Ombi/ClientApp/app/vote/vote.component.ts
index 908c1759a..ffab837cd 100644
--- a/src/Ombi/ClientApp/app/vote/vote.component.ts
+++ b/src/Ombi/ClientApp/app/vote/vote.component.ts
@@ -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,8 +24,19 @@ 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) {
this.panelImage = image;
this.overlayPanel.toggle(event);
@@ -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();
}
}
@@ -64,7 +83,19 @@ export class VoteComponent implements OnInit {
if(result.isError) {
this.notificationSerivce.error(result.errorMessage);
} else {
- this.notificationSerivce.success("Voted!");
+ 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;
+ });
+ }
}
diff --git a/src/Ombi/wwwroot/translations/en.json b/src/Ombi/wwwroot/translations/en.json
index 1fd65e663..93f6c39f0 100644
--- a/src/Ombi/wwwroot/translations/en.json
+++ b/src/Ombi/wwwroot/translations/en.json
@@ -194,5 +194,9 @@
"TvDue": "TV: {{date}}",
"MovieDue": "Movie: {{date}}",
"MusicDue": "Music: {{date}}"
+ },
+ "Votes": {
+ "CompletedVotesTab": "Voted",
+ "VotesTab": "Votes Needed"
}
}