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 showMore = [];
33
  public maxCharacters = 500;
34

    
35
  public properties: EnvProperties;
36
  public pageContents = null;
37
  public divContents = null;
38

    
39
  public piwiksub: any;
40
  public url: string = null;
41
  public pageTitle: string = "Curators";
42

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

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

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

    
106
  ngOnDestroy() {
107
    if(this.piwiksub) {
108
      this.piwiksub.unsubscribe();
109
    }
110
  }
111

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

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

    
124
  public toggle(index: number) {
125
    this.showMore[index] = !this.showMore[index];
126
  }
127

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

    
136
  public urlPrefix(url: string): string {
137
    return StringUtils.urlPrefix(url);
138
  }
139

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

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

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