mirror of https://github.com/Ombi-app/Ombi
Merge branch 'feature/vote' of https://github.com/tidusjar/ombi into feature/vote
commit
9cf8ea7a6f
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,35 @@
|
||||
<h1>Vote</h1>
|
||||
|
||||
<div *ngIf="viewModel">
|
||||
|
||||
<table class="table table-striped table-hover table-responsive table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>Title</td>
|
||||
<td>Description</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let vm of viewModel">
|
||||
<td class="vcenter">
|
||||
<button class="btn btn-info-outline" (click)="upvote(vm)"><i class="fa fa-arrow-up" aria-hidden="true"></i></button>
|
||||
<button class="btn btn-info-outline" (click)="downvote(vm)"><i class="fa fa-arrow-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>
|
||||
|
||||
<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,70 @@
|
||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
||||
|
||||
import { OverlayPanel } from "primeng/primeng";
|
||||
import { NotificationService, VoteService } from "../services";
|
||||
|
||||
import { IVoteEngineResult, IVoteViewModel, RequestTypes } from "../interfaces";
|
||||
|
||||
@Component({
|
||||
templateUrl: "vote.component.html",
|
||||
styleUrls: ["vote.component.scss"],
|
||||
})
|
||||
export class VoteComponent implements OnInit {
|
||||
|
||||
public viewModel: IVoteViewModel[];
|
||||
public panelImage: string;
|
||||
@ViewChild("op") public overlayPanel: OverlayPanel;
|
||||
|
||||
constructor(private voteService: VoteService, private notificationSerivce: NotificationService) { }
|
||||
|
||||
public async ngOnInit() {
|
||||
this.viewModel = await this.voteService.getModel();
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue