Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3

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

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

    
14
@Component({
15
  //changeDetection: ChangeDetectionStrategy.Default,
16
  //encapsulation: ViewEncapsulation.Emulated,
17
  selector: 'app-root',
18
  styles: [`
19
  `],
20
  template: `
21
    <div [class]="(community)?(community.id +'App'):'connectApp'" >
22
        <navbar *ngIf= "properties && showMenu && !community"   portal="connect" [onlyTop]=false    [userMenuItems]=userMenuItems [menuItems]=menuItems
23
          [showMenu]=showMenu [properties]="properties"></navbar>
24
        <navbar *ngIf= "properties && showMenu  && community"    portal="connect" [onlyTop]=false [communityId]="community.id"  [userMenuItems]=userMenuItems [menuItems]=menuItems
25
        [community]=community [showMenu]=showMenu [properties]="properties"></navbar>
26

    
27
                   <div class="custom-main-content"   >
28
                      <main>
29
                       <router-outlet></router-outlet>
30
                     </main>
31
                    </div>
32
          <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
33
          <cookie-law *ngIf= "isClient" position="bottom">
34
              OpenAIRE uses cookies in order to function properly.<br>
35
              Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing experience possible.
36
              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">
37
              <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>
38
              </span></a>
39
          </cookie-law>
40
           <bottom *ngIf= "properties && isClient && showMenu && !community"   [grantAdvance]="false"  [properties]="properties" ></bottom>
41
           <bottom *ngIf= "properties && isClient  && showMenu && community" class="communityPanelBackground"  [showSocialButtons] = "true" [showMenuItems]="true"  [grantAdvance]="false" [showOpenaire]="true" [communityId]="community.id"  [menuItems]=bottomMenuItems [properties]="properties"    ></bottom>
42
        </div>
43
`
44

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

    
49
   userMenuItems:MenuItem[] =[];
50

    
51

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

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

    
66
   }
67

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

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

    
124

    
125

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

    
163
                  }
164

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

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

    
193

    
194

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

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

    
227

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

    
240
   });
241
   }
242

    
243
   public buildMenu(communityId: string) {
244
     var community = null;
245
     this.community = null;
246
     this.showMenu = false;
247
     this._communitiesService.getCommunitiesState().subscribe (
248
       communities => {
249
              for(var com of communities){
250
                  if( (communityId && communityId!="" &&  com.communityId == communityId
251
                   && community !=null) ||
252
                    (
253
                      !(communityId && communityId!="" &&  com.communityId  == communityId)
254
                      &&
255
                      this.managerOfCommunities && this.subscriberOfCommunities)) {
256
                    break;
257
                  }
258
                if(Session.isLoggedIn() && com['status'] != "hidden"){
259
                  if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
260
                    this.managerOfCommunities = true;
261
                  }else if(com.managers.indexOf(Session.getUserEmail())!=-1){
262
                    this.managerOfCommunities = true;
263
                  }/*else if(!this.subscriberOfCommunities){
264
                    // check if subscriber
265
                    this._subscribeService.isSubscribedToCommunity(com.communityId, Session.getUserEmail(), this.properties.adminToolsAPIURL).subscribe (
266
                      isSubscriber => {
267
                        if(isSubscriber) {
268
                          this.subscriberOfCommunities = true;
269
                        }
270
                      },
271
                      error => {
272
                        console.error("Error fetching your subscribed communities")
273
                      });
274

    
275
                  }*/
276
                }
277

    
278

    
279

    
280
                 if(communityId && communityId!="" &&  com.communityId == communityId){
281
                  community = com;
282
                   document.documentElement.style.setProperty('--portal-main-color', "#4C9CD5");
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(this.properties, Session.getUserEmail()).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)