Project

General

Profile

1
import {Component, Input, Output, EventEmitter}  from '@angular/core';
2
import {ViewChild, ChangeDetectionStrategy}      from '@angular/core';
3
import {ViewEncapsulation}                       from '@angular/core';
4
import {ActivatedRoute, Router}                  from '@angular/router';
5
import {Location}                                from '@angular/common';
6
import {Title, Meta}                             from '@angular/platform-browser';
7

    
8
import {Observable}                              from 'rxjs/Observable';
9

    
10
import "rxjs/add/observable/zip";
11

    
12
import {ConnectHelper}                           from '../openaireLibrary/connect/connectHelper';
13
import {EnvProperties}                           from '../openaireLibrary/utils/properties/env-properties';
14
import {ErrorCodes}                              from '../openaireLibrary/utils/properties/errorCodes';
15

    
16
import {ConfigurationService}                    from '../openaireLibrary/utils/configuration/configuration.service';
17
import {CommunitiesService}                      from '../openaireLibrary/connect/communities/communities.service';
18
import {PiwikService}                            from '../openaireLibrary/utils/piwik/piwik.service';
19
import {Session} from '../openaireLibrary/login/utils/helper.class';
20
@Component({
21
    selector: 'communities',
22
    templateUrl: 'communities.component.html',
23
})
24

    
25
export class CommunitiesComponent {
26
  public piwiksub: any;
27
  public subfunders: any;
28

    
29
  public pageTitle = "OpenAIRE"
30

    
31
  public communitiesResults = null;
32
  public communitiesToShow = null;
33

    
34
  properties:EnvProperties;
35
  public keyword:string="";
36
  public type:string="all";
37
  constructor (
38
      private route: ActivatedRoute,
39
      private _router: Router,
40
      private location: Location,
41
      private _meta: Meta,
42
      private _title: Title,
43
      private _piwikService:PiwikService,
44
      private _communitiesService:CommunitiesService,
45
      private config: ConfigurationService) {
46

    
47
                var description = "Community Dashboard";
48
                var title = "Community Dashboard";
49

    
50
                this._meta.updateTag({content:description},"name='description'");
51
                this._meta.updateTag({content:description},"property='og:description'");
52
                this._meta.updateTag({content:title},"property='og:title'");
53
                this._title.setTitle(title);
54
      }
55

    
56
        public ngOnInit() {
57
          this.route.data
58
              .subscribe((data: { envSpecific: EnvProperties }) => {
59
                 this.properties = data.envSpecific;
60
                 var url = data.envSpecific.baseLink+this._router.url
61
                 this._meta.updateTag({content:url},"property='og:url'");
62
                 if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
63
                   this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
64
                 }
65

    
66
                 this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
67
                       communitiesResults => {
68
                             this.communitiesResults = communitiesResults;
69
                             this.communitiesToShow = this.communitiesResults.slice();
70
                             //console.log(communitiesResults);
71
                 });
72
              });
73
        }
74

    
75
        public ngOnDestroy() {
76
          if(this.piwiksub){
77
            this.piwiksub.unsubscribe();
78
          }
79
        }
80
        isProduction():boolean{
81
          return ConnectHelper.isProduction(document.location.hostname);
82

    
83
        }
84
        getProductionPrefix():string{
85
          return ConnectHelper.getProductionPrefix(document.location.hostname);
86
        }
87
        showCommunity(community):boolean{
88
          if(community['status'] == "hidden"){
89
            return false;
90
          }else if(community['status'] == "manager"){
91
            var mail = Session.getUserEmail();
92
            if(mail == null){ // no user
93
              return false;
94
            }else if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
95
              return true;
96
            }else if(community.managers.indexOf(mail)!=-1){
97
              return true;
98
            }
99
            return false;
100
          }
101
          return true;
102

    
103
        }
104
        existsIn(word, keyword):boolean{
105
          if(word!= null && (keyword=="" || word.toLowerCase().indexOf(keyword.toLowerCase())!=-1)){
106
            return true;
107
          }
108
          return false;
109
        }
110
        isType(communityType):boolean{
111
          if(this.type == "all" || communityType == this.type){
112
            return true;
113
          }
114
          return false;
115
        }
116
        searchChanged(){
117
          this.communitiesToShow = [];
118
          for(var i=0; i <this.communitiesResults.length; i++){
119
            if((this.existsIn(this.communitiesResults[i].description, this.keyword) ||
120
            this.existsIn(this.communitiesResults[i].title, this.keyword) ||
121
            this.existsIn(this.communitiesResults[i].shortTitle, this.keyword))
122
            && this.isType(this.communitiesResults[i].type)){
123
              this.communitiesToShow.push(this.communitiesResults[i]);
124
            }
125
          }
126

    
127

    
128

    
129
        }
130
}
(3-3/4)