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
import {properties} from "../../environments/environment";
17

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

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

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

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

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

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

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

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

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

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

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

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

    
100
    this.researchCommunities = [];
101

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

    
131
  private createGifs() {
132
    this.gifs.push({
133
      gif: "assets/connect-assets/home/gifs/deposit.gif",
134
      header: "Find a repository to deposit your research outcome",
135
      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."
136
    });
137
    this.gifs.push({
138
      gif: "assets/connect-assets/home/gifs/link.gif",
139
      header: "Link your research output with your community, funding, and other research products",
140
      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."
141
    });
142
    this.gifs.push({
143
      gif: "assets/connect-assets/home/gifs/overview.gif",
144
      header: "View community's overview at a glance",
145
      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."
146
    });
147
    this.gifs.push({
148
      gif: "assets/connect-assets/home/gifs/results.gif",
149
      header: "Search & browse your community's research products. ",
150
      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."
151
    });
152
    this.gifs.push({
153
      gif: "assets/connect-assets/home/gifs/graph-analysis.gif",
154
      header: "View statistics for your community's research products.",
155
      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."
156
    });
157
  }
158

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

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

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

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

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

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