Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {SearchResult}     from '../../utils/entities/searchResult';
3
import { ErrorCodes} from '../../utils/properties/openaireProperties';
4
import {RouterHelper} from '../../utils/routerHelper.class';
5

    
6
@Component({
7
    selector: 'search-result',
8
    template: `
9
     <ul [class]="'uk-list uk-list-divider  uk-margin '+custom_class">
10
      <div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary uk-animation-fade" role="alert">No Results found</div>
11
      <div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning uk-animation-fade" role="alert">An Error Occured</div>
12
      <div *ngIf="status == errorCodes.OUT_OF_BOUND" class="uk-alert uk-alert-warning uk-animation-fade" role="alert">Requested page out of bounds</div>
13
      <div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger uk-animation-fade" role="alert">Service not available</div>
14
      <div *ngIf="status == errorCodes.LOADING && showLoading"   class="uk-animation-fade uk-margin-large-top  uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading"></div>
15

    
16
        <li *ngFor="let result of results" class="uk-animation-fade">
17
            <h4 class = "{{result.title.accessMode}} {{result.title.sc39}}" [title] = result.title.accessMode >
18
                <a [queryParams]="routerHelper.createQueryParam(urlParam,result.id)" routerLinkActive="router-link-active" routerLink="/search/{{type}}">
19
                    <p *ngIf="result['title'].name != undefined && result['title'].name != ''"
20
                        [innerHTML]="result['title'].name">
21
                    </p>
22
                    <p *ngIf="result['title'].name == undefined || result['title'].name == ''">
23
                        [no title available]
24
                    </p>
25
                </a>
26
            </h4>
27

    
28
            <div>
29
                <span *ngIf="result['authors'] != undefined">
30
                    <span *ngFor="let author of result['authors'].slice(0,15)">
31
                        <!--a href="{{author['url']}}"-->
32
                        <a [queryParams]="routerHelper.createQueryParams(['author','au'],[quote(author['name']),'and'])" routerLinkActive="router-link-active" [routerLink]="'/search/advanced/'+type+'s'">
33
                            {{author['name']}};
34
                        </a>
35
                    </span>
36
                    <span *ngIf="result['authors'].length > 15">...</span>
37
                </span>
38
                <span *ngIf="result.year != undefined && result.year != ''">
39
                    ({{result.year}})
40
                </span>
41
            </div>
42

    
43
            <div *ngIf="result.publisher != undefined && result.publisher != ''">Publisher: {{result.publisher}}</div>
44

    
45
            <div *ngIf="result.country != undefined && result.country != ''">Country: {{result.country}}</div>
46

    
47
            <div *ngIf="result['projects'] != undefined">
48
                <span> Project: </span>
49
                <span *ngFor="let project of result['projects'].slice(0,15) let i=index">
50
                    <!--a *ngIf="project.url != undefined" href="{{project.url}}"-->
51
                        <a *ngIf="project.id" [queryParams]="{projectId: project.id}" routerLinkActive="router-link-active" routerLink="/search/project">
52
                            {{project['funderShortname']?project['funderShortname']:project['funderName']}}
53
                            | {{ project['acronym']?project['acronym']:(project['title'].length>25?project['title'].substring(0,25)+'...':project['title'])}} ({{project.code}})</a><span
54

    
55
                            *ngIf="!project.id">{{project['funderShortname']?project['funderShortname']:project['funderName']}}<span
56
                                *ngIf="project['acronym'] || project['title']"> | {{ project['acronym']?project['acronym']:(project['title'].length>25?project['title'].substring(0,25)+'...':project['title'])}}</span><span
57
                                *ngIf="project.code">({{project.code}})</span></span><span
58

    
59
                    *ngIf="i < result['projects'].length-1">,</span>
60
                </span>
61
                <span *ngIf="result['projects'].length > 15">...</span>
62
            </div>
63

    
64
            <div *ngIf="result.description != undefined && result.description != ''">
65
                <div class="text-justify descriptionText">
66
                    {{result.description}}
67
                </div>
68
            </div>
69

    
70
            <mark *ngIf="result.embargoEndDate != undefined && result.embargoEndDate != ''">Embargo End Date: {{result.embargoEndDate}}</mark>
71

    
72

    
73
            <div *ngIf="result['funders'] != undefined">
74
              <span> Funder: </span>
75
              <span *ngFor="let funder of result['funders'] let i=index">
76

    
77
                  <span *ngIf="funder.funderShortname">
78
                    {{funder.funderShortname}}</span><span
79

    
80
                    *ngIf="i < result['funders'].length-1">,</span>
81
              </span>
82
              <span *ngIf="result.startYear && result.endYear"> (start {{result.startYear}} - end {{result.endYear}})</span>
83
            </div>
84
            <div *ngIf="result['organizations'] != undefined && result['organizations'].length > 0">
85
                <span> Organization: </span>
86
                <span *ngFor="let organization of result['organizations'].slice(0,10) let i=index">
87
                    <!--a *ngIf="organization.url != undefined" href="{{organization.url}}"-->
88
                    <a *ngIf="organization.id" [queryParams]="{organizationId: organization.id}" routerLinkActive="router-link-active" routerLink="/search/organization">
89
                            {{organization.name}}</a><span
90

    
91
                        *ngIf="!organization.id">
92
                            {{organization.name}}</span><span
93

    
94
                        *ngIf="(i < result['organizations'].length-1) && (i < 9)">,</span>
95
                </span>
96
                <span *ngIf="result['organizations'].length > 10">...</span>
97
            </div>
98

    
99
            <div *ngIf="result['type'] != undefined && result['type'] != ''">Type: {{result['type']}}</div>
100
            <div *ngIf="result['countries'] && result['countries'].length > 0">
101
                Country: <span *ngFor="let country of  result['countries'].slice(0,10) let i = index">{{country}}{{(i < ( result['countries'].slice(0,10).length-1))?", ":""}}{{(i ==  result['countries'].slice(0,10).length-1 &&  result['countries'].length > 10)?"...":""}}</span>
102
            </div>
103
            <div *ngIf="result['websiteURL'] != undefined && result['websiteURL'] != ''">
104
                <span>Website URL: </span>
105
                <span>
106
                    <a href="{{result['websiteURL']}}" target="_blank" class="custom-external custom-icon">
107
                        {{result['websiteURL']}}
108
                    </a>
109
                </span>
110
            </div>
111
            <div *ngIf="result['OAIPMHURL'] != undefined && result['OAIPMHURL'] != ''">
112
                <span>OAI-PMH URL: </span>
113
                <span>
114
                    <a href="{{result['OAIPMHURL']}}" target="_blank" class="custom-external custom-icon">
115
                        {{result['OAIPMHURL']}}
116
                    </a>
117
                </span>
118
            </div>
119

    
120
            <div *ngIf="result['compatibility'] != undefined && result['compatibility'] != ''">
121
                Compatibility: {{result.compatibility}}
122
            </div>
123

    
124
            <div *ngIf="showSubjects && result['subjects'] && result['subjects'].length > 0">
125
                Subject: <span *ngFor="let subject of  result['subjects'].slice(0,10) let i = index">{{subject}}{{(i < ( result['subjects'].slice(0,10).length-1))?", ":""}}{{(i ==  result['subjects'].slice(0,10).length-1 &&  result['subjects'].length > 10)?"...":""}}</span>
126
            </div>
127

    
128

    
129
        </li>
130
    </ul>
131
    `
132
})
133

    
134
export class SearchResultComponent {
135
    @Input() results: SearchResult[];
136
    @Input() status: number;
137
    @Input() type: string;
138
    @Input() urlParam: string;
139
    @Input() showLoading: boolean = false;
140
    @Input() showSubjects: boolean = false;
141
    @Input() custom_class: string = "search-results";
142

    
143
    public errorCodes:ErrorCodes = new ErrorCodes();
144
    public routerHelper:RouterHelper = new RouterHelper();
145
    public errorMessage: string = "No results found";
146
     constructor () {
147

    
148
    }
149

    
150
    ngOnInit() {}
151

    
152

    
153
        public  quote(params: string):string {
154
            return '"'+params+'"';
155
        }
156
}
(24-24/28)