Project

General

Profile

« Previous | Next » 

Revision 59305

[use-UoaAdminToolsLibrary | Connect]: Merge trunk into branch.

View differences:

curators.component.ts
1 1
import {Component, Input} from '@angular/core';
2
import {EnvProperties}    from '../openaireLibrary/utils/properties/env-properties';
2
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
3 3
import {CuratorService} from "../openaireLibrary/connect/curators/curator.service";
4 4
import {Curator} from "../openaireLibrary/utils/entities/CuratorInfo";
5 5
import {ActivatedRoute, Router} from "@angular/router";
......
15 15
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
16 16
import {Subscription} from "rxjs";
17 17
import {properties} from "../../environments/environment";
18
import {UserRegistryService} from "../openaireLibrary/services/user-registry.service";
18 19

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

  
23
  
23 24
})
24 25

  
25 26
export class CuratorsComponent {
......
28 29
  @Input() longView = true;
29 30
  public downloadUrl = null;
30 31
  public showLoading = true;
31

  
32
  
32 33
  public curators: Curator[];
33

  
34
  
34 35
  public curatorsLimit: number = 5;
35 36
  public numberOfCurators: number = 5;
36

  
37
  
37 38
  public showMore = [];
38 39
  public maxCharacters = 500;
39

  
40
  
40 41
  public properties: EnvProperties;
41 42
  public pageContents = null;
42 43
  public divContents = null;
43

  
44
  
44 45
  public url: string = null;
45 46
  public pageTitle: string = "Curators";
46

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

  
49
  
49 50
  subs: Subscription[] = [];
50

  
51
  constructor (private route: ActivatedRoute,
52
               private curatorsService: CuratorService,
53
               private communityService: CommunityService,
54
               private _router: Router,
55
               private helper: HelperService,
56
               private _meta: Meta,
57
               private _title: Title,
58
               private seoService: SEOService,
59
               private _piwikService: PiwikService) {}
60

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

  
136
  
110 137
  ngOnDestroy() {
111 138
    for (let sub of this.subs) {
112 139
      sub.unsubscribe();
113 140
    }
114 141
  }
115

  
142
  
116 143
  private getPageContents() {
117 144
    this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
118 145
      this.pageContents = contents;
119 146
    }));
120 147
  }
121

  
148
  
122 149
  private getDivContents() {
123 150
    this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
124 151
      this.divContents = contents;
125 152
    }));
126 153
  }
127

  
154
  
128 155
  public toggle(index: number) {
129 156
    this.showMore[index] = !this.showMore[index];
130 157
  }
131

  
132
  _format(name: string){
133
    if(name) {
158
  
159
  _format(name: string) {
160
    if (name) {
134 161
      return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name);
135 162
    } else {
136 163
      return null;
137 164
    }
138 165
  }
139

  
166
  
140 167
  public urlPrefix(url: string): string {
141 168
    return StringUtils.urlPrefix(url);
142 169
  }
143

  
170
  
144 171
  private updateDescription(description: string) {
145 172
    this._meta.updateTag({content: description}, "name='description'");
146 173
    this._meta.updateTag({content: description}, "property='og:description'");
147 174
  }
148

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

  
181
  
155 182
  private updateUrl(url: string) {
156 183
    this._meta.updateTag({content: url}, "property='og:url'");
157 184
  }

Also available in: Unified diff