Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
5
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
6
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service';
7
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
8

    
9
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
10
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
11

    
12
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
13
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
14
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
15
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
16

    
17
@Component({
18
  selector: 'communities',
19
  templateUrl: 'communities.component.html',
20
})
21

    
22
export class CommunitiesComponent {
23
  public piwiksub: any;
24

    
25
  public pageTitle = "OpenAIRE"
26
  public researchCommunities = [];
27
  public gifs: { "gif": string, "header": string, "text" }[] = [];
28
  public pageContents = null;
29
  public divContents = null;
30
  // Message variables
31
  public status: number;
32
  public loading: boolean = true;
33
  public subscriberErrorMessage: string = "";
34
  public errorCodes: ErrorCodes;
35
  private errorMessages: ErrorMessagesComponent;
36

    
37
  properties: EnvProperties;
38
  public keyword: string = "";
39
  public type: string = "all";
40

    
41
  constructor(
42
    private route: ActivatedRoute,
43
    private _router: Router,
44
    private _meta: Meta,
45
    private _title: Title,
46
    private _piwikService: PiwikService,
47
    private _communitiesService: CommunitiesService,
48
    private _subscribeService: SubscribeService,
49
    private helper: HelperService,
50
    private seoService: SEOService) {
51

    
52
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
53
    var title = "OpenAIRE - Connect";
54

    
55
    this._meta.updateTag({content: description}, "name='description'");
56
    this._meta.updateTag({content: description}, "property='og:description'");
57
    this._meta.updateTag({content: title}, "property='og:title'");
58
    this._title.setTitle(title);
59

    
60
    this.errorCodes = new ErrorCodes();
61
    this.errorMessages = new ErrorMessagesComponent();
62
    this.status = this.errorCodes.LOADING;
63
  }
64

    
65
  public ngOnInit() {
66
    this.route.data
67
      .subscribe((data: { envSpecific: EnvProperties }) => {
68
        this.properties = data.envSpecific;
69
        var url = data.envSpecific.baseLink + this._router.url;
70
        this.seoService.createLinkForCanonicalURL(url, false);
71
        this._meta.updateTag({content: url}, "property='og:url'");
72
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
73
          this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
74
        }
75
        this.getCommunities();
76
        this.createGifs();
77
        //this.getDivContents();
78
        this.getPageContents();
79
      });
80
  }
81

    
82
  private getPageContents() {
83
    this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
84
      this.pageContents = contents;
85
    })
86
  }
87

    
88
  private getDivContents() {
89
    this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
90
      this.divContents = contents;
91
    })
92
  }
93

    
94
  public getCommunities() {
95
    this.loading = true;
96
    this.status = this.errorCodes.LOADING;
97
    this.subscriberErrorMessage = "";
98

    
99
    this.researchCommunities = [];
100

    
101
    this._communitiesService.getCommunitiesState().subscribe(
102
      communitiesResults => {
103
        if(!communitiesResults){
104
          return;
105
        }
106
        if(communitiesResults.length == 0) {
107
          this.status = this.errorCodes.DONE;
108
          return;
109
        }
110
        this.sort(communitiesResults);
111
        communitiesResults.forEach((community, index) => {
112
          let showCommunity: boolean = true;
113
          if (community['status'] == "hidden" || community['status'] == "manager") {
114
            showCommunity = false;
115
          }
116
          if (showCommunity) {
117
            this.researchCommunities.push(community);
118
          }
119
          this.status = this.errorCodes.DONE;
120
        });
121
        this.loading = false;
122
      },
123
      error => {
124
        this.status = this.handleError("Error getting communities", error);
125
        this.loading = false;
126
      }
127
    );
128
  }
129

    
130
  private createGifs() {
131
    this.gifs.push({
132
      gif: "assets/connect-assets/home/gifs/deposit.gif",
133
      header: "Find a repository to deposit your research outcome",
134
      text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
135
    });
136
    this.gifs.push({
137
      gif: "assets/connect-assets/home/gifs/link.gif",
138
      header: "Link your research output with your community, funding, and other research products",
139
      text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
140
    });
141
    this.gifs.push({
142
      gif: "assets/connect-assets/home/gifs/overview.gif",
143
      header: "View community's overview at a glance",
144
      text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
145
    });
146
    this.gifs.push({
147
      gif: "assets/connect-assets/home/gifs/results.gif",
148
      header: "Search & browse your community's research products. ",
149
      text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
150
    });
151
    this.gifs.push({
152
      gif: "assets/connect-assets/home/gifs/graph-analysis.gif",
153
      header: "View statistics for your community's research products.",
154
      text: "This is OpenAIRE’s key service for research communities, both established and emerging ones. Our service helps you reach out and engage all your researchers to practice open science out-of-the-box."
155
    });
156
  }
157

    
158
  private sort(results: CommunityInfo[]) {
159
    results.sort((left, right): number => {
160
      if (!right.date || left.date > right.date) {
161
        return -1;
162
      } else if (!left.date || left.date < right.date) {
163
        return 1;
164
      } else {
165
        if (left.title > right.title) {
166
          return 1;
167
        } else if (left.title < right.title) {
168
          return -1;
169
        } else {
170
          return 0;
171
        }
172
      }
173
    })
174
  }
175

    
176
  public quote(param: string): string {
177
    return StringUtils.quote(param);
178
  }
179

    
180
  public ngOnDestroy() {
181
    if (this.piwiksub) {
182
      this.piwiksub.unsubscribe();
183
    }
184
  }
185

    
186
  private handleError(message: string, error): number {
187
    var code = "";
188
    if (!error.status) {
189
      var error = error.json();
190
      code = error.code;
191
    } else {
192
      code = error.status;
193
    }
194

    
195
    console.error("Communities (component): " + message, error);
196

    
197
    return this.errorMessages.getErrorCode(code);
198
  }
199
}
(3-3/4)