Project

General

Profile

« Previous | Next » 

Revision 55222

[Trunk|Connect]: communities.component: First page of connect changed according to ui/ux designers - css added for this page [this is not the final commit].

View differences:

communities.component.ts
1
import {Component, Input, Output, EventEmitter}  from '@angular/core';
2
import {ViewChild, ChangeDetectionStrategy}      from '@angular/core';
3
import {ViewEncapsulation}                       from '@angular/core';
4
import {ActivatedRoute, Router}                  from '@angular/router';
5
import {Location}                                from '@angular/common';
6
import {Title, Meta}                             from '@angular/platform-browser';
1
import {Component, Input, Output, EventEmitter} from '@angular/core';
2
import {ViewChild, ChangeDetectionStrategy}     from '@angular/core';
3
import {ViewEncapsulation}                      from '@angular/core';
4
import {ActivatedRoute, Router}                 from '@angular/router';
5
import {Location}                               from '@angular/common';
6
import {Title, Meta}                            from '@angular/platform-browser';
7 7

  
8
import {Observable}                              from 'rxjs/Observable';
8
import {Observable}                             from 'rxjs/Observable';
9 9

  
10 10
import "rxjs/add/observable/zip";
11 11

  
12
import {ConnectHelper}                           from '../openaireLibrary/connect/connectHelper';
13
import {EnvProperties}                           from '../openaireLibrary/utils/properties/env-properties';
14
import {ErrorCodes}                              from '../openaireLibrary/utils/properties/errorCodes';
12
import {ConnectHelper}                          from '../openaireLibrary/connect/connectHelper';
13
import {EnvProperties}                          from '../openaireLibrary/utils/properties/env-properties';
15 14

  
16
import {ConfigurationService}                    from '../openaireLibrary/utils/configuration/configuration.service';
17
import {CommunitiesService}                      from '../openaireLibrary/connect/communities/communities.service';
18
import {PiwikService}                            from '../openaireLibrary/utils/piwik/piwik.service';
19
import {Session} from '../openaireLibrary/login/utils/helper.class';
15
import {ConfigurationService}                   from '../openaireLibrary/utils/configuration/configuration.service';
16
import {CommunitiesService}                     from '../openaireLibrary/connect/communities/communities.service';
17
import {SubscribeService}                       from '../openaireLibrary/utils/subscribe/subscribe.service';
18
import {CommunityInfo}                          from '../openaireLibrary/connect/community/communityInfo';
19

  
20
import {PiwikService}                           from '../openaireLibrary/utils/piwik/piwik.service';
21
import {Session}                                from '../openaireLibrary/login/utils/helper.class';
22
import {StringUtils}                       from '../openaireLibrary/utils/string-utils.class';
23

  
24
import {ErrorCodes}                             from '../openaireLibrary/utils/properties/errorCodes';
25
import {ErrorMessagesComponent}                 from '../openaireLibrary/utils/errorMessages.component';
26

  
20 27
@Component({
21 28
    selector: 'communities',
22 29
    templateUrl: 'communities.component.html',
......
31 38
  public communitiesResults = null;
32 39
  public communitiesToShow = null;
33 40

  
41
  public researchCommunities = [];
42
  public researchInitiatives = [];
43
  public subscriberOfCommunities = [];
44
  public managerOfCommunities = [];
45

  
46
  // Message variables
47
  public status: number;
48
  public subscriberOfCommunitiesStatus: number;
49
  public loading: boolean = true;
50
  public errorCodes: ErrorCodes;
51
  private errorMessages: ErrorMessagesComponent;
52

  
34 53
  properties:EnvProperties;
35 54
  public keyword:string="";
36 55
  public type:string="all";
......
42 61
      private _title: Title,
43 62
      private _piwikService:PiwikService,
44 63
      private _communitiesService:CommunitiesService,
64
      private _subscribeService: SubscribeService,
45 65
      private config: ConfigurationService) {
46 66

  
47
                var description = "OpenAIRE - Connect, Community Dashboard, research community";
48
                var title = "OpenAIRE - Connect";
67
          var description = "OpenAIRE - Connect, Community Dashboard, research community";
68
          var title = "OpenAIRE - Connect";
49 69

  
50
                this._meta.updateTag({content:description},"name='description'");
51
                this._meta.updateTag({content:description},"property='og:description'");
52
                this._meta.updateTag({content:title},"property='og:title'");
53
                this._title.setTitle(title);
54
      }
70
          this._meta.updateTag({content:description},"name='description'");
71
          this._meta.updateTag({content:description},"property='og:description'");
72
          this._meta.updateTag({content:title},"property='og:title'");
73
          this._title.setTitle(title);
55 74

  
56
        public ngOnInit() {
57
          this.route.data
58
              .subscribe((data: { envSpecific: EnvProperties }) => {
59
                 this.properties = data.envSpecific;
60
                 var url = data.envSpecific.baseLink+this._router.url
61
                 this._meta.updateTag({content:url},"property='og:url'");
62
                 if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
63
                   this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
64
                 }
75
          this.errorCodes = new ErrorCodes();
76
          this.errorMessages = new ErrorMessagesComponent();
77
          this.status = this.errorCodes.LOADING;
78
          this.subscriberOfCommunitiesStatus = this.errorCodes.LOADING;
79
  }
65 80

  
66
                 this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
67
                       communitiesResults => {
68
                             this.communitiesResults = communitiesResults;
69
                             this.communitiesToShow = this.communitiesResults.slice();
70
                             //console.log(communitiesResults);
71
                      },
72
                      error => {
73
                        this.handleError("Error getting communities", error);
74
                      }
75
                  );
76
              });
81
  public ngOnInit() {
82
    this.route.data
83
          .subscribe((data: { envSpecific: EnvProperties }) => {
84
            this.properties = data.envSpecific;
85
            var url = data.envSpecific.baseLink+this._router.url
86
            this._meta.updateTag({content:url},"property='og:url'");
87
            if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
88
              this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
89
            }
90

  
91
            this.getCommunities();
92
          });
93
    }
94

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

  
100
      this.researchCommunities = [];
101
      this.researchInitiatives = [];
102
      this.subscriberOfCommunities = [];
103
      this.managerOfCommunities = [];
104

  
105
      this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
106
        communitiesResults => {
107
          //this.communitiesResults = communitiesResults;
108
          //this.communitiesToShow = this.communitiesResults.slice();
109
          //console.log(communitiesResults);
110
          var mail = Session.getUserEmail();
111
          communitiesResults.forEach((community, index) => {
112
            let showCommunity: boolean = true;
113
            let isManager: boolean = false;
114
            let isSubscriber: boolean = false;
115

  
116
            if(community['status'] == "hidden"){
117
              showCommunity = false;
118
            }else if(community['status'] == "manager"){
119
              if(mail == null){ // no user
120
                showCommunity = false;
121
              }else if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
122
                isManager = true;
123
              }else if(community.managers.indexOf(mail)!=-1){
124
                isManager = true;
125
              } else {
126
                showCommunity = false;
127
              }
128
            }
129

  
130
            if(showCommunity) {
131
              if(community.type == "community"){
132
                this.researchCommunities.push(community);
133
              } else if(community.type == "ri") {
134
                this.researchInitiatives.push(community);
135
              }
136

  
137
              if(isManager) {
138
                this.managerOfCommunities.push(community);
139
              }
140
            }
141

  
142
            this.status = this.errorCodes.DONE;
143

  
144
            if(mail != null && showCommunity && !isManager){
145
              this._subscribeService.isSubscribedToCommunity(community.communityId, mail, this.properties.adminToolsAPIURL).subscribe (
146
                res => {
147
                  isSubscriber = res;
148
                  if(isSubscriber) {
149
                    this.subscriberOfCommunities.push(community);
150
                  }
151

  
152
                  this.subscriberOfCommunitiesStatus = this.errorCodes.DONE;
153
                  this.loading = false;
154
                },
155
                error => {
156
                  this.handleError("Error getting response if email: "+mail+" is subscribed to community with id: "+community.communityId, error, this.subscriberOfCommunitiesStatus);
157
                  this.loading = false;
158
                });
159
            } else {
160
              this.subscriberOfCommunitiesStatus = this.errorCodes.DONE;
161
              this.loading = false;
162
            }
163
          });
164
        },
165
        error => {
166
          this.handleError("Error getting communities", error, status);
167
          this.subscriberOfCommunitiesStatus = this.errorCodes.DONE;
168
          this.loading = false;
77 169
        }
170
      );
171
    }
78 172

  
79
        public ngOnDestroy() {
80
          if(this.piwiksub){
81
            this.piwiksub.unsubscribe();
82
          }
83
        }
173
    public quote(param: string): string {
174
      return StringUtils.quote(param);
175
    }
176

  
177
    public ngOnDestroy() {
178
      if(this.piwiksub){
179
        this.piwiksub.unsubscribe();
180
      }
181
    }
182

  
84 183
        isProduction():boolean{
85 184
          return this.properties.environment!="development";
86

  
87 185
        }
88 186
        getProductionPrefix():string{
89 187
          return (this.properties.environment =="beta")?"beta.":""
......
105 203
          return true;
106 204

  
107 205
        }
206

  
108 207
        existsIn(word, keyword):boolean{
109 208
          if(word!= null && (keyword=="" || word.toLowerCase().indexOf(keyword.toLowerCase())!=-1)){
110 209
            return true;
......
132 231

  
133 232
        }
134 233

  
135
        private handleError(message: string, error) {
136
            console.error("Communities (component): "+message, error);
137
        }
234
    private handleError(message: string, error, status) {
235
      var code = "";
236
      if(!error.status) {
237
        var error =  error.json();
238
        code = error.code;
239
      } else {
240
        code = error.status;
241
      }
242
      status = this.errorMessages.getErrorCode(code);
243

  
244
      console.error("Communities (component): "+message, error);
245
    }
138 246
}

Also available in: Unified diff