1 |
61381
|
k.triantaf
|
import { Component, Input } from '@angular/core';
|
2 |
|
|
import { ActivatedRoute } from '@angular/router';
|
3 |
|
|
import { EnvProperties} from '../../utils/properties/env-properties';
|
4 |
|
|
|
5 |
|
|
import {ConnectHelper} from '../connectHelper';
|
6 |
|
|
import {SearchCommunityDataprovidersService} from '../contentProviders/searchDataproviders.service';
|
7 |
|
|
import {properties} from "../../../../environments/environment";
|
8 |
|
|
|
9 |
|
|
@Component({
|
10 |
|
|
selector: 'approved-by-community',
|
11 |
|
|
template: `
|
12 |
|
|
<span *ngIf="approved" class="uk-align-right uk-label custom-label uk-label-success">Community Approved</span>
|
13 |
|
|
`
|
14 |
|
|
})
|
15 |
|
|
|
16 |
|
|
export class ApprovedByCommunityComponent {
|
17 |
|
|
@Input() contentProviderId: string;
|
18 |
|
|
|
19 |
|
|
public communityId:string;
|
20 |
|
|
public approved:boolean = false;
|
21 |
|
|
private communityContentProviders = [];
|
22 |
|
|
|
23 |
|
|
properties:EnvProperties;
|
24 |
|
|
|
25 |
|
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchCommunityDataprovidersService) {}
|
26 |
|
|
|
27 |
|
|
public ngOnInit() {
|
28 |
|
|
this.properties =properties;
|
29 |
|
|
this.route.queryParams.subscribe(
|
30 |
|
|
communityId => {
|
31 |
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
32 |
|
|
if(!this.communityId) {
|
33 |
|
|
this.communityId = communityId['communityId'];
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
if(this.communityId && this.communityId != "openaire") {
|
37 |
|
|
this._searchDataprovidersService.searchDataproviders(this.properties, this.communityId).subscribe (
|
38 |
|
|
contentproviders => {
|
39 |
|
|
this.communityContentProviders = contentproviders;
|
40 |
|
|
this.approved = this.checkApproval();
|
41 |
|
|
},
|
42 |
|
|
error => {
|
43 |
|
|
this.handleError("Error getting content providers for community with id: "+this.communityId, error);
|
44 |
|
|
}
|
45 |
|
|
);
|
46 |
|
|
}
|
47 |
|
|
});
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
private checkApproval(): boolean {
|
54 |
|
|
let self = this;
|
55 |
|
|
return this.communityContentProviders.map(contentprovider => contentprovider.openaireId).some(function(id) {
|
56 |
|
|
return id == self.contentProviderId;
|
57 |
|
|
});
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
private handleError(message: string, error) {
|
61 |
|
|
console.error("Approved by Community (component): "+message, error);
|
62 |
|
|
}
|
63 |
|
|
}
|