Project

General

Profile

1
import { Component, Directive, ElementRef, Renderer, ChangeDetectionStrategy, ViewEncapsulation, Injector } from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {ActivatedRoute} from '@angular/router';
4

    
5
import { EnvProperties} from './openaireLibrary/utils/properties/env-properties';
6
import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
7
import { EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
8
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
9
import {Session} from './openaireLibrary/login/utils/helper.class';
10
import {ConnectHelper} from './openaireLibrary/connect/connectHelper';
11
import {SubscribeService} from './openaireLibrary/utils/subscribe/subscribe.service';
12

    
13
// import {LayoutService} from "./openaireLibrary/services/layout.service";
14

    
15
@Component({
16
  //changeDetection: ChangeDetectionStrategy.Default,
17
  //encapsulation: ViewEncapsulation.Emulated,
18
  selector: 'app-root',
19
  styles: [`
20
  `],
21
  template: `
22

    
23
        <navbar *ngIf= "properties && showMenu && !community" [environment]=properties.environment portal="connect" [onlyTop]=false    [userMenuItems]=userMenuItems [menuItems]=menuItems
24
        [(APIUrl)]="properties.adminToolsAPIURL" [(logInUrl)]="properties.loginUrl" [(logOutUrl)]="properties.logoutUrl"  [(cookieDomain)]="properties.cookieDomain"  [showMenu]=showMenu></navbar>
25
        <navbar *ngIf= "properties && showMenu  && community"  [environment]=properties.environment portal="connect" [onlyTop]=false [(communityId)]="community.id"  [userMenuItems]=userMenuItems [menuItems]=menuItems
26
        [(APIUrl)]="properties.adminToolsAPIURL" [(logInUrl)]="properties.loginUrl" [(logOutUrl)]="properties.logoutUrl"  [(cookieDomain)]="properties.cookieDomain" [(community)]=community [showMenu]=showMenu></navbar>
27

    
28
                   <div class="custom-main-content"   >
29
                      <main>
30
                       <router-outlet></router-outlet>
31
                     </main>
32
                    </div>
33
          <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
34
          <cookie-law *ngIf= "isClient" position="bottom">
35
              OpenAIRE uses cookies in order to function properly.<br>
36
              Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing experience possible.
37
              By using the OpenAIRE portal you accept our use of cookies. <a href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
38
              <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right" ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
39
              </span></a>
40
          </cookie-law>
41
           <bottom *ngIf= "properties && isClient && showMenu && !community"  [environment]=properties.environment [grantAdvance]="false" ></bottom>
42
           <bottom *ngIf= "properties && isClient  && showMenu && community"  [environment]=properties.environment [showSocialButtons] = "true" [showMenuItems]="true"  [grantAdvance]="false" [showOpenaire]="true" [(communityId)]="community.id" [(APIUrl)]="properties.adminToolsAPIURL" [menuItems]=bottomMenuItems ></bottom>
43

    
44
`
45

    
46
})
47
export class AppComponent {
48
   isClient:boolean = false;
49

    
50
   userMenuItems:MenuItem[] =[];
51

    
52

    
53
  menuItems:RootMenuItem []=[];
54
  bottomMenuItems:MenuItem[] =[];
55
  public community = null;
56
  properties:EnvProperties;
57
  showMenu:boolean = false;
58
  communities = null;
59
  subscriberOfCommunities = false;
60
  managerOfCommunities = false;
61

    
62
  // layout = null;
63
  //  community: {id:string, name:string, logoUrl:string};
64
   constructor(  private  route: ActivatedRoute, private propertiesService:EnvironmentSpecificService,
65
                 private _communitiesService:CommunitiesService, private _subscribeService: SubscribeService,){//, private _layoutService: LayoutService) {
66

    
67
   }
68

    
69
   ngOnInit() {
70
     this.propertiesService.loadEnvironment()
71
             .then(es => {
72
                 this.properties = this.propertiesService.envSpecific;
73

    
74
                 var communityId: string = "";
75
                 if(this.properties.environment == "development") {
76
                   this.route.queryParams.subscribe(data => {
77
                     communityId = data['communityId'];
78
                     this.buildMenu(communityId);
79
                   });
80
                 } else {
81
                   communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
82
                   this.buildMenu(communityId);
83
                 }
84
/*
85
     this.route.queryParams.subscribe(data => {
86
       var community = null;
87
       this.community = null;
88
       this.showMenu = false;
89
       this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe (
90
         communities => {
91

    
92
                for(var com of communities){
93
                  if( (
94
                    ((data['communityId'] && data['communityId']!="" &&  com.communityId  == data['communityId'])
95
                  || (ConnectHelper.getCommunityFromDomain(this.properties.domain) ==  com.communityId ))
96
                   && community !=null) ||
97
                    (
98
                      !((data['communityId'] && data['communityId']!="" &&  com.communityId  == data['communityId'])
99
                      || (ConnectHelper.getCommunityFromDomain(this.properties.domain) ==  com.communityId ))
100
                      &&
101
                      this.managerOfCommunities && this.subscriberOfCommunities)){
102
                      break;
103
                    }
104
                  if(Session.isLoggedIn() && com['status'] != "hidden"){
105
                    if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
106
                      this.managerOfCommunities = true;
107
                    }else if(com.managers.indexOf(Session.getUserEmail())!=-1){
108
                      this.managerOfCommunities = true;
109
                    }
110
                    // else if(!this.subscriberOfCommunities){
111
                    //   // check if subscriber
112
                    //   this._subscribeService.isSubscribedToCommunity(com.communityId, Session.getUserEmail(), this.properties.adminToolsAPIURL).subscribe (
113
                    //     isSubscriber => {
114
                    //       if(isSubscriber) {
115
                    //         this.subscriberOfCommunities = true;
116
                    //       }
117
                    //     },
118
                    //     error => {
119
                    //       console.error("Error fetching your subscribed communities")
120
                    //     });
121
                    //
122
                    // }
123
                  }
124

    
125

    
126

    
127
                   if((data['communityId'] && data['communityId']!="" &&  com.communityId  == data['communityId'])
128
                   || (ConnectHelper.getCommunityFromDomain(this.properties.domain) ==  com.communityId )  ){
129
                    community = com;
130
                     // this._layoutService.getLayout(com.communityId,
131
                     //     this.properties.adminToolsAPIURL + '/').subscribe (
132
                     //     layout => {
133
                     //       this.layout = layout;
134
                     //       document.documentElement.style.setProperty('--portal-main-color', this.layout.color);
135
                     //     }
136
                     // );
137
                    this.community = {id: community.communityId, name: (community.shortTitle)?community.shortTitle:community.title, logoUrl:community.logoUrl};
138
                    this.menuItems= [
139
                      {rootItem: new MenuItem("search","Search","","/search/find",false,[],["/search/find", "/search/find/publications", "/search/find/datasets", "/search/find/software", "/search/find/other", "/search/find/projects", "/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
140
                        items: [new MenuItem("","Publications","","/search/find/publications",false,["publication"],["/search/find/publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
141
                        new MenuItem("","Research Data","","/search/find/datasets",false,["dataset"],["/search/find/datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
142
                        new MenuItem("","Software","","/search/find/software",false,["software"],["/search/find/software"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
143
                        new MenuItem("","Other Research Products","","/search/find/other",false,["orp"],["/search/find/other"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
144
                       new MenuItem("","Projects","","/search/find/projects/",false,["project"],["/search/find/projects"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
145
                       new MenuItem("","Content Providers","","/search/find/dataproviders",false,["datasource"],["/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
146
                      ]},
147
                      {
148
                        rootItem: new MenuItem("monitor","Monitor","","/monitor",false,[],["/monitor"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
149
                        items: []
150
                      },
151
                      {
152
                      rootItem: new MenuItem("share","Share","","",false,[],["/participate/deposit-publications","/participate/deposit-datasets","/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
153
                      items: [
154
                      new MenuItem("","Zenodo Communities","","/participate/share-zenodo",false,[],["/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
155
                      new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
156
                      new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId})]
157
                      },
158
                      {
159
                      rootItem: new MenuItem("link","Link","","/participate/claim",false,[],["/participate/claim"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
160
                      items: []
161
                      }
162
                  ];
163

    
164
                  }
165

    
166
                }
167
                if(community == null){
168
                  this.menuItems= [];
169
                  var myCommunities = [];
170
                  if(this.managerOfCommunities){
171
                    myCommunities.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
172
                  }
173
                  if(Session.isLoggedIn()){
174
                    this._subscribeService.getCommunitiesSubscribedTo(Session.getUserEmail(), this.properties.adminToolsAPIURL).subscribe (
175
                      pids => {
176
                        if(pids.length > 0 ) {
177
                          myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
178
                        }
179
                      },
180
                      error => {
181
                        console.error("Error fetching your subscribed communities")
182
                      });
183
                  }
184
                  // if(this.subscriberOfCommunities){
185
                  //   myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
186
                  // }
187

    
188
                  this.menuItems.push({rootItem: new MenuItem("communities","Communities","","/search/find/communities",false,[],null,{}), items: []});
189
                  if(this.managerOfCommunities || this.subscriberOfCommunities){
190
                    this.menuItems.push({rootItem: new MenuItem("myCommunities","My Communities","","",false,[],[],{}), items: myCommunities});
191
                  }
192
                  this.menuItems.push({rootItem: new MenuItem("howto","Create Community","","/how-to-create-community",false,[],null,{}), items: []});
193

    
194

    
195

    
196
                  this.bottomMenuItems =[
197
                  new MenuItem("","About","https://beta.openaire.eu/project-factsheets","",false,[],[],{}),
198
                  new MenuItem("","News - Events","https://beta.openaire.eu/news-events","",false,[],[],{}),
199
                  new MenuItem("","Blog","https://blogs.openaire.eu/","",false,[],[],{}),
200
                  new MenuItem("","Contact us","https://beta.openaire.eu/contact-us","",false,[],[],{})
201
                ];
202
                // if(this.properties.showContent){
203
                //   this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
204
                // }
205
                this.userMenuItems =[
206
                   // new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],(data['communityId'] && typeof document !== 'undefined' && ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:data['communityId']}),
207
                 ];
208

    
209
              }else{
210
                this.bottomMenuItems = [
211
                  new MenuItem("","About","","/about",false,[],["/about"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
212
                  new MenuItem("","Organizations","","/organizations",false,[],["/organizations"],this.properties.environment!="development"?{}:{communityId:community.communityId})
213
                ];
214
                if(this.properties.showContent){
215
                  this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
216
                }
217
                this.userMenuItems =[ new MenuItem("","My profile","","",false,[],[],{}),
218
                   new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
219
                   new MenuItem("","Invite users","","/invite",false,[],[],this.properties.environment!="development"?{}:{communityId:community.communityId}),
220
                 ];
221
                 if(this.managerOfCommunities ){
222
                   this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{}))
223
                 }
224
              }
225
                this.showMenu = true;
226
         });
227

    
228

    
229
   });
230
*/
231
     if (typeof document !== 'undefined') {
232
       try{
233
         this.isClient = true;
234
       }catch (e) {
235
       }
236
     }
237
   }, error => {
238
     console.log("App couldn't fetch properties");
239
       console.log(error);
240

    
241
   });
242
   }
243

    
244
   public buildMenu(communityId: string) {
245
     var community = null;
246
     this.community = null;
247
     this.showMenu = false;
248
     this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe (
249
       communities => {
250
              for(var com of communities){
251
                  if( (communityId && communityId!="" &&  com.communityId == communityId
252
                   && community !=null) ||
253
                    (
254
                      !(communityId && communityId!="" &&  com.communityId  == communityId)
255
                      &&
256
                      this.managerOfCommunities && this.subscriberOfCommunities)) {
257

    
258
                    break;
259
                  }
260
                if(Session.isLoggedIn() && com['status'] != "hidden"){
261
                  if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
262
                    this.managerOfCommunities = true;
263
                  }else if(com.managers.indexOf(Session.getUserEmail())!=-1){
264
                    this.managerOfCommunities = true;
265
                  }/*else if(!this.subscriberOfCommunities){
266
                    // check if subscriber
267
                    this._subscribeService.isSubscribedToCommunity(com.communityId, Session.getUserEmail(), this.properties.adminToolsAPIURL).subscribe (
268
                      isSubscriber => {
269
                        if(isSubscriber) {
270
                          this.subscriberOfCommunities = true;
271
                        }
272
                      },
273
                      error => {
274
                        console.error("Error fetching your subscribed communities")
275
                      });
276

    
277
                  }*/
278
                }
279

    
280

    
281

    
282
                 if(communityId && communityId!="" &&  com.communityId == communityId){
283
                  community = com;
284
                   // this._layoutService.getLayout(com.communityId,
285
                   //     this.properties.adminToolsAPIURL + '/').subscribe (
286
                   //     layout => {
287
                   //       this.layout = layout;
288
                   //       document.documentElement.style.setProperty('--portal-main-color', this.layout.color);
289
                   //     }
290
                   // );
291
                  this.community = {id: community.communityId, name: (community.shortTitle)?community.shortTitle:community.title, logoUrl:community.logoUrl};
292
                  this.menuItems= [
293
                    {rootItem: new MenuItem("search","Search","","/search/find",false,[],["/search/find", "/search/find/publications", "/search/find/datasets", "/search/find/software", "/search/find/other", "/search/find/projects", "/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
294
                      items: [new MenuItem("","Publications","","/search/find/publications",false,["publication"],["/search/find/publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
295
                      new MenuItem("","Research Data","","/search/find/datasets",false,["dataset"],["/search/find/datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
296
                      new MenuItem("","Software","","/search/find/software",false,["software"],["/search/find/software"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
297
                      new MenuItem("","Other Research Products","","/search/find/other",false,["orp"],["/search/find/other"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
298
                     new MenuItem("","Projects","","/search/find/projects/",false,["project"],["/search/find/projects"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
299
                     new MenuItem("","Content Providers","","/search/find/dataproviders",false,["datasource"],["/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
300
                    ]},
301
                    {
302
                      rootItem: new MenuItem("monitor","Monitor","","/monitor",false,[],["/monitor"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
303
                      items: []
304
                    },
305
                    {
306
                    rootItem: new MenuItem("share","Share","","",false,[],["/participate/deposit-publications","/participate/deposit-datasets","/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
307
                    items: [
308
                    new MenuItem("","Zenodo Communities","","/participate/share-zenodo",false,[],["/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
309
                    new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
310
                    new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId})]
311
                    },
312
                    {
313
                    rootItem: new MenuItem("link","Link","","/participate/claim",false,[],["/participate/claim"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
314
                    items: []
315
                    }
316
                ];
317

    
318
                }
319

    
320
              }
321
              if(community == null){
322
                this.menuItems= [];
323
                var myCommunities = [];
324
                if(this.managerOfCommunities){
325
                  myCommunities.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
326
                }
327
                if(Session.isLoggedIn()){
328
                  this._subscribeService.getCommunitiesSubscribedTo(Session.getUserEmail(), this.properties.adminToolsAPIURL).subscribe (
329
                    pids => {
330
                      if(pids.length > 0 ) {
331
                        myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
332
                      }
333
                    },
334
                    error => {
335
                      console.error("Error fetching your subscribed communities")
336
                    });
337
                }
338
                // if(this.subscriberOfCommunities){
339
                //   myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
340
                // }
341

    
342
                this.menuItems.push({rootItem: new MenuItem("communities","Communities","","/search/find/communities",false,[],null,{}), items: []});
343
                if(this.managerOfCommunities || this.subscriberOfCommunities){
344
                  this.menuItems.push({rootItem: new MenuItem("myCommunities","My Communities","","",false,[],[],{}), items: myCommunities});
345
                }
346
                this.menuItems.push({rootItem: new MenuItem("howto","Create Community","","/how-to-create-community",false,[],null,{}), items: []});
347

    
348

    
349

    
350
                this.bottomMenuItems =[
351
                new MenuItem("","About","https://beta.openaire.eu/project-factsheets","",false,[],[],{}),
352
                new MenuItem("","News - Events","https://beta.openaire.eu/news-events","",false,[],[],{}),
353
                new MenuItem("","Blog","https://blogs.openaire.eu/","",false,[],[],{}),
354
                new MenuItem("","Contact us","https://beta.openaire.eu/contact-us","",false,[],[],{})
355
              ];
356
              // if(this.properties.showContent){
357
              //   this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
358
              // }
359
              this.userMenuItems =[
360
                 // new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],(data['communityId'] && typeof document !== 'undefined' && ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:data['communityId']}),
361
               ];
362

    
363
            }else{
364
              this.bottomMenuItems = [
365
                new MenuItem("","About","","/about",false,[],["/about"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
366
                new MenuItem("","Organizations","","/organizations",false,[],["/organizations"],this.properties.environment!="development"?{}:{communityId:community.communityId})
367
              ];
368
              if(this.properties.showContent){
369
                this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
370
              }
371
              this.userMenuItems =[ new MenuItem("","My profile","","",false,[],[],{}),
372
                 new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
373
                 new MenuItem("","Invite users","","/invite",false,[],[],this.properties.environment!="development"?{}:{communityId:community.communityId}),
374
               ];
375
               if(this.managerOfCommunities ){
376
                 this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{}))
377
               }
378
            }
379
              this.showMenu = true;
380
       });
381
   }
382
}
(2-2/4)