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 {CommunityService} from "../openaireLibrary/connect/community/community.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
import {Subscription} from "rxjs";
17
import {properties} from "../../environments/environment";
18
import {UserRegistryService} from "../openaireLibrary/services/user-registry.service";
19

    
20
@Component({
21
  selector: 'curators',
22
  templateUrl: './curators.component.html'
23
  
24
})
25

    
26
export class CuratorsComponent {
27
  @Input() managers: string[];
28
  @Input() communityId = null;
29
  @Input() longView = true;
30
  public downloadUrl = null;
31
  public showLoading = true;
32
  
33
  public curators: Curator[];
34
  
35
  public curatorsLimit: number = 5;
36
  public numberOfCurators: number = 5;
37
  
38
  public showMore = [];
39
  public maxCharacters = 500;
40
  
41
  public properties: EnvProperties;
42
  public pageContents = null;
43
  public divContents = null;
44
  
45
  public url: string = null;
46
  public pageTitle: string = "Curators";
47
  
48
  public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'About - curators'}];
49
  
50
  subs: Subscription[] = [];
51
  
52
  constructor(private route: ActivatedRoute,
53
              private curatorsService: CuratorService,
54
              private communityService: CommunityService,
55
              private userRegistryService: UserRegistryService,
56
              private _router: Router,
57
              private helper: HelperService,
58
              private _meta: Meta,
59
              private _title: Title,
60
              private seoService: SEOService,
61
              private _piwikService: PiwikService) {
62
  }
63
  
64
  ngOnInit() {
65
    this.showLoading = true;
66
    this.properties = properties;
67
    if (this.longView) {
68
      if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
69
        this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe());
70
      }
71
      this.url = this.properties.domain + this._router.url;
72
      this.seoService.createLinkForCanonicalURL(this.url);
73
      this.updateUrl(this.url);
74
      this.updateTitle(this.pageTitle);
75
      this.updateDescription("OpenAIRE - Connect, Community Gateway, research community");
76
    }
77
    this.downloadUrl = this.properties.utilsService + '/download/';
78
    //if (properties.environment !== 'development') {
79
      if (!this.longView) {
80
        let emails = this.managers.join();
81
        this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
82
          this.curators = curators;
83
          for (let i = 0; i < this.curators.length; i++) {
84
            this.showMore[i] = false;
85
          }
86
          this.showLoading = false;
87
          HelperFunctions.scroll();
88
        }));
89
      } else {
90
        this.subs.push(this.route.queryParams.subscribe(data => {
91
          this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
92
          if (!this.communityId) {
93
            this.communityId = data['communityId'];
94
          }
95
          //this.getDivContents();
96
          this.getPageContents();
97
          this.subs.push(this.communityService.getCommunityByState(this.properties,
98
            this.properties.communityAPI + this.communityId).subscribe(community => {
99
            this.managers = community.managers;
100
            let emails = this.managers.join();
101
            this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
102
              this.curators = curators;
103
              for (let i = 0; i < this.curators.length; i++) {
104
                this.showMore[i] = false;
105
              }
106
              this.showLoading = false;
107
              HelperFunctions.scroll();
108
            }));
109
          }));
110
        }));
111
      }
112
    // } else {
113
    //   this.subs.push(this.route.queryParams.subscribe(data => {
114
    //     this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
115
    //     if (!this.communityId) {
116
    //       this.communityId = data['communityId'];
117
    //     }
118
    //     if(this.longView) {
119
    //       //this.getDivContents();
120
    //       this.getPageContents();
121
    //     }
122
    //     this.subs.push(this.userRegistryService.getManagersEmail('community', this.communityId).subscribe(managers => {
123
    //       let emails = managers.map(manager => manager.email).join();
124
    //       this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
125
    //         this.curators = curators;
126
    //         for (let i = 0; i < this.curators.length; i++) {
127
    //           this.showMore[i] = false;
128
    //         }
129
    //         this.showLoading = false;
130
    //         HelperFunctions.scroll();
131
    //       }));
132
    //     }));
133
    //   }));
134
    // }
135
  }
136
  
137
  ngOnDestroy() {
138
    for (let sub of this.subs) {
139
      sub.unsubscribe();
140
    }
141
  }
142
  
143
  private getPageContents() {
144
    this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
145
      this.pageContents = contents;
146
    }));
147
  }
148
  
149
  private getDivContents() {
150
    this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
151
      this.divContents = contents;
152
    }));
153
  }
154
  
155
  public toggle(index: number) {
156
    this.showMore[index] = !this.showMore[index];
157
  }
158
  
159
  _format(name: string) {
160
    if (name) {
161
      return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name);
162
    } else {
163
      return null;
164
    }
165
  }
166
  
167
  public urlPrefix(url: string): string {
168
    return StringUtils.urlPrefix(url);
169
  }
170
  
171
  private updateDescription(description: string) {
172
    this._meta.updateTag({content: description}, "name='description'");
173
    this._meta.updateTag({content: description}, "property='og:description'");
174
  }
175
  
176
  private updateTitle(title: string) {
177
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
178
    this._title.setTitle(_title);
179
    this._meta.updateTag({content: _title}, "property='og:title'");
180
  }
181
  
182
  private updateUrl(url: string) {
183
    this._meta.updateTag({content: url}, "property='og:url'");
184
  }
185
}
(3-3/4)