Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {EnvProperties}    from '../openaireLibrary/utils/properties/env-properties';
3
import {CuratorService} from "../openaireLibrary/connect/curators/curator.service";
4
import {Curator} from "../openaireLibrary/utils/entities/CuratorInfo";
5
import {ActivatedRoute, Router} from "@angular/router";
6
import {CommunitiesService} from "../openaireLibrary/connect/communities/communities.service";
7
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
8
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
9
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
10
import {Meta, Title} from "@angular/platform-browser";
11
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
12
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
13
import {PiwikHelper} from "../utils/piwikHelper";
14
import {Breadcrumb} from "../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
15
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
16

    
17
@Component({
18
  selector: 'curators',
19
  templateUrl: './curators.component.html'
20

    
21
})
22

    
23
export class CuratorsComponent {
24
  @Input() managers: string[];
25
  @Input() communityId = null;
26
  @Input() longView = true;
27
  public downloadUrl = null;
28
  public showLoading = true;
29

    
30
  public curators: Curator[];
31

    
32
  public curatorsLimit: number = 5;
33
  public numberOfCurators: number = 5;
34

    
35
  public showMore = [];
36
  public maxCharacters = 500;
37

    
38
  public properties: EnvProperties;
39
  public pageContents = null;
40
  public divContents = null;
41

    
42
  public piwiksub: any;
43
  public url: string = null;
44
  public pageTitle: string = "Curators";
45

    
46
  public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'About - curators'}];
47

    
48
  constructor (private route: ActivatedRoute,
49
               private curatorsService: CuratorService,
50
               private communitiesService: CommunitiesService,
51
               private _router: Router,
52
               private helper: HelperService,
53
               private _meta: Meta,
54
               private _title: Title,
55
               private seoService: SEOService,
56
               private _piwikService: PiwikService) {}
57

    
58
  ngOnInit() {
59
    this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
60
      this.showLoading = true;
61
      this.properties = data.envSpecific;
62
      if(this.longView) {
63
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
64
          this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
65
        }
66
        this.url = this.properties.baseLink + this._router.url;
67
        this.seoService.createLinkForCanonicalURL(this.url);
68
        this.updateUrl(this.url);
69
        this.updateTitle(this.pageTitle);
70
        this.updateDescription("OpenAIRE - Connect, Community Gateway, research community");
71
      }
72
      this.downloadUrl = this.properties.utilsService + '/download/';
73
      if(!this.longView) {
74
        let emails = this.managers.join();
75
        this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
76
          this.curators = curators;
77
          for(let i = 0; i < this.curators.length; i++) {
78
            this.showMore[i]= false;
79
          }
80
          this.showLoading = false;
81
          HelperFunctions.scroll();
82
        })
83
      } else {
84
        this.route.queryParams.subscribe(data => {
85
          this.communityId  = ConnectHelper.getCommunityFromDomain(this.properties.domain);
86
          if(!this.communityId) {
87
            this.communityId = data['communityId'];
88
          }
89
          //this.getDivContents();
90
          this.getPageContents();
91
          this.communitiesService.getCommunities(this.properties,
92
            this.properties.communityAPI + this.communityId).subscribe(community => {
93
              this.managers = community[0].managers;
94
              let emails = this.managers.join();
95
              this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
96
                this.curators = curators;
97
                for(let i = 0; i < this.curators.length; i++) {
98
                  this.showMore[i]= false;
99
                }
100
                this.showLoading = false;
101
                HelperFunctions.scroll();
102
              });
103
          })
104
        });
105
      }
106
    });
107
  }
108

    
109
  ngOnDestroy() {
110
    if(this.piwiksub) {
111
      this.piwiksub.unsubscribe();
112
    }
113
  }
114

    
115
  private getPageContents() {
116
    this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
117
      this.pageContents = contents;
118
    })
119
  }
120

    
121
  private getDivContents() {
122
    this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
123
      this.divContents = contents;
124
    })
125
  }
126

    
127
  public toggle(index: number) {
128
    this.showMore[index] = !this.showMore[index];
129
  }
130

    
131
  _format(name: string){
132
    if(name) {
133
      return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name);
134
    } else {
135
      return null;
136
    }
137
  }
138

    
139
  public urlPrefix(url: string): string {
140
    return StringUtils.urlPrefix(url);
141
  }
142

    
143
  private updateDescription(description: string) {
144
    this._meta.updateTag({content: description}, "name='description'");
145
    this._meta.updateTag({content: description}, "property='og:description'");
146
  }
147

    
148
  private updateTitle(title: string) {
149
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
150
    this._title.setTitle(_title);
151
    this._meta.updateTag({content: _title}, "property='og:title'");
152
  }
153

    
154
  private updateUrl(url: string) {
155
    this._meta.updateTag({content: url}, "property='og:url'");
156
  }
157
}
(3-3/4)