summaryrefslogtreecommitdiff
path: root/src/web/src/app/search-item/search-item.component.ts
blob: 5780f85ef98a80cd04a9fee1dc9a7d1504a44517 (plain)
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
import { Input } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { AppService } from '../app.service';

@Component({
    selector: 'app-search-item',
    templateUrl: './search-item.component.html',
    styleUrls: ['./search-item.component.css'],
})
export class SearchItemComponent implements OnInit {
    @Input() model: any;
    isRated: boolean;

    constructor(private service: AppService) {}

    ngOnInit(): void {}

    getImage() {
        return 'https://image.tmdb.org/t/p/original' + this.model.poster_path;
    }

    getYear() {
        if (this.model.media_type === 'tv') {
            if (this.model.first_air_date) {
                return this.model.first_air_date.substring(0, 4);
            }
        }
        if (this.model.media_type === 'movie') {
            if (this.model.release_date) {
                return this.model.release_date.substring(0, 4);
            }
        }
        return 'Not Dated';
    }
    getTitle() {
        if (this.model.media_type === 'movie') {
            return this.model.original_title;
        }
        if (this.model.media_type === 'tv') {
            return this.model.original_name;
        }
    }
    getRating() {
        if (this.model.vote_average === 0) {
            this.isRated = false;
            return 'Unrated';
        }
        this.isRated = true;
        return this.model.vote_average;
    }

    storeData() {
        this.service.emitData(this.model);
    }
}