/
discover-collections.component.ts
69 lines (60 loc) · 2.31 KB
/
discover-collections.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { SearchV2Service, RequestService, MessageService } from "../../../services";
import { IMovieCollectionsViewModel } from "../../../interfaces/ISearchTvResultV2";
import { IDiscoverCardResult } from "../../interfaces";
import { RequestType } from "../../../interfaces";
@Component({
templateUrl: "./discover-collections.component.html",
styleUrls: ["./discover-collections.component.scss"],
})
export class DiscoverCollectionsComponent implements OnInit {
public collectionId: number;
public collection: IMovieCollectionsViewModel;
public loadingFlag: boolean;
public discoverResults: IDiscoverCardResult[] = [];
constructor(private searchService: SearchV2Service,
private route: ActivatedRoute,
private requestService: RequestService,
private messageService: MessageService) {
this.route.params.subscribe((params: any) => {
this.collectionId = params.collectionId;
});
}
public async ngOnInit() {
this.loadingFlag = true;
this.collection = await this.searchService.getMovieCollections(this.collectionId);
this.createModel();
}
public async requestCollection() {
await this.collection.collection.forEach(async (movie) => {
await this.requestService.requestMovie({theMovieDbId: movie.id, languageCode: null}).toPromise();
});
this.messageService.send("Requested Collection");
}
private createModel() {
this.finishLoading();
this.collection.collection.forEach(m => {
this.discoverResults.push({
available: m.available,
posterPath: `https://image.tmdb.org/t/p/w300/${m.posterPath}`,
requested: m.requested,
title: m.title,
type: RequestType.movie,
id: m.id,
url: `http://www.imdb.com/title/${m.imdbId}/`,
rating: 0,
overview: m.overview,
approved: m.approved,
imdbid: m.imdbId,
denied:false
});
});
}
private loading() {
this.loadingFlag = true;
}
private finishLoading() {
this.loadingFlag = false;
}
}