mirror of https://github.com/Ombi-app/Ombi
Merge branch 'develop' of https://github.com/tidusjar/ombi into develop
commit
1de276a425
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@
|
||||
import { PlatformLocation } from "@angular/common";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
import { IVoteEngineResult, IVoteViewModel } from "../interfaces";
|
||||
import { ServiceHelpers } from "./service.helpers";
|
||||
|
||||
@Injectable()
|
||||
export class VoteService extends ServiceHelpers {
|
||||
constructor(public http: HttpClient, public platformLocation: PlatformLocation) {
|
||||
super(http, "/api/v1/Vote/", platformLocation);
|
||||
}
|
||||
|
||||
public async getModel(): Promise<IVoteViewModel[]> {
|
||||
return await this.http.get<IVoteViewModel[]>(`${this.url}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
|
||||
public async upvoteMovie(requestId: number): Promise<IVoteEngineResult> {
|
||||
return await this.http.post<IVoteEngineResult>(`${this.url}up/movie/${requestId}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
public async upvoteTv(requestId: number): Promise<IVoteEngineResult> {
|
||||
return await this.http.post<IVoteEngineResult>(`${this.url}up/tv/${requestId}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
public async upvoteAlbum(requestId: number): Promise<IVoteEngineResult> {
|
||||
return await this.http.post<IVoteEngineResult>(`${this.url}up/album/${requestId}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
public async downvoteMovie(requestId: number): Promise<IVoteEngineResult> {
|
||||
return await this.http.post<IVoteEngineResult>(`${this.url}down/movie/${requestId}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
public async downvoteTv(requestId: number): Promise<IVoteEngineResult> {
|
||||
return await this.http.post<IVoteEngineResult>(`${this.url}down/tv/${requestId}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
public async downvoteAlbum(requestId: number): Promise<IVoteEngineResult> {
|
||||
return await this.http.post<IVoteEngineResult>(`${this.url}down/album/${requestId}`, {headers: this.headers}).toPromise();
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
<h1>Vote</h1>
|
||||
|
||||
|
||||
|
||||
<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 style="width: 10%">Title</td>
|
||||
<td>Description</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let vm of currentVotes">
|
||||
<td class="vcenter">
|
||||
<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;
|
||||
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 [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>
|
@ -0,0 +1,12 @@
|
||||
.vcenter {
|
||||
vertical-align: middle;
|
||||
float: none;
|
||||
}
|
||||
|
||||
.hideBackground {
|
||||
border: 0px solid transparent !important;
|
||||
background: transparent !important;
|
||||
-webkit-box-shadow: 0 0px 0px 0 transparent !important;
|
||||
-moz-box-shadow: 0 0px 0px 0 transparent !important;
|
||||
box-shadow: 0 0px 0px 0 transparent !important;
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
||||
|
||||
import { OverlayPanel } from "primeng/primeng";
|
||||
import { NotificationService, VoteService } from "../services";
|
||||
|
||||
import { IVoteEngineResult, IVoteViewModel, RequestTypes, VoteType } from "../interfaces";
|
||||
|
||||
@Component({
|
||||
templateUrl: "vote.component.html",
|
||||
styleUrls: ["vote.component.scss"],
|
||||
})
|
||||
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;
|
||||
|
||||
constructor(private voteService: VoteService, private notificationSerivce: NotificationService) { }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public async upvote(vm: IVoteViewModel) {
|
||||
let result: IVoteEngineResult = {errorMessage:"", isError: false, message:"",result:false};
|
||||
switch(vm.requestType) {
|
||||
case RequestTypes.Album:
|
||||
result = await this.voteService.upvoteAlbum(vm.requestId);
|
||||
break;
|
||||
case RequestTypes.Movie:
|
||||
result = await this.voteService.upvoteMovie(vm.requestId);
|
||||
break;
|
||||
case RequestTypes.TvShow:
|
||||
result = await this.voteService.upvoteTv(vm.requestId);
|
||||
break;
|
||||
}
|
||||
|
||||
if(result.isError) {
|
||||
this.notificationSerivce.error(result.errorMessage);
|
||||
} else {
|
||||
this.notificationSerivce.success("Voted!");
|
||||
vm.alreadyVoted = true;
|
||||
vm.myVote = VoteType.Upvote;
|
||||
this.filterLists();
|
||||
}
|
||||
}
|
||||
|
||||
public async downvote(vm: IVoteViewModel) {
|
||||
let result: IVoteEngineResult = {errorMessage:"", isError: false, message:"",result:false};
|
||||
switch(vm.requestType) {
|
||||
case RequestTypes.Album:
|
||||
result = await this.voteService.downvoteAlbum(vm.requestId);
|
||||
break;
|
||||
case RequestTypes.Movie:
|
||||
result = await this.voteService.downvoteMovie(vm.requestId);
|
||||
break;
|
||||
case RequestTypes.TvShow:
|
||||
result = await this.voteService.downvoteTv(vm.requestId);
|
||||
break;
|
||||
}
|
||||
|
||||
if(result.isError) {
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue