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

    
276
                  }*/
277
                }
278

    
279

    
280

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

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

    
342

    
343

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

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