Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, ActivationEnd, NavigationStart, Router, RoutesRecognized} 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
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
12

    
13
@Component({
14
  //changeDetection: ChangeDetectionStrategy.Default,
15
  //encapsulation: ViewEncapsulation.Emulated,
16
  selector: 'app-root',
17
  styles: [`
18
  `],
19
  template: `
20
    <div [class]="(community)?(community.id +'App'):'connectApp'" >
21
        <navbar *ngIf= "properties && showMenu && !community"   portal="connect" [onlyTop]=false    [userMenuItems]=userMenuItems [menuItems]=menuItems
22
          [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="true"></navbar>
23
        <navbar *ngIf= "properties && showMenu  && community"    portal="connect" [onlyTop]=false [communityId]="community.id"  [userMenuItems]=userMenuItems [menuItems]=menuItems
24
        [community]=community [showMenu]=showMenu [properties]="properties" [enableSearch]="true" [showHomeMenuItem]="true"></navbar>
25
      <customization *ngIf= "properties  && community"   ></customization>
26
        <div class="custom-main-content"   >
27
          <main>
28
           <router-outlet></router-outlet>
29
         </main>
30
        </div>
31
          <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
32
        <cookie-law *ngIf= "isClient" position="bottom">
33
            OpenAIRE uses cookies in order to function properly.<br>
34
            Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing experience possible.
35
            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">
36
            <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>
37
            </span></a>
38
        </cookie-law>
39
         <bottom *ngIf= "properties && isClient && showMenu && !community"   [grantAdvance]="false"  [properties]="properties" ></bottom>
40
         <bottom *ngIf= "properties && isClient  && showMenu && community" class="communityPanelBackground"  [showSocialButtons] = "true" [showMenuItems]="true"  [grantAdvance]="false" [showOpenaire]="true" [communityId]="community.id"  [menuItems]=bottomMenuItems [properties]="properties"    ></bottom>
41
      </div>
42
`
43

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

    
48
   userMenuItems:MenuItem[] =[];
49

    
50

    
51
  menuItems:RootMenuItem []=[];
52
  bottomMenuItems:MenuItem[] =[];
53
  public community = null;
54
  properties:EnvProperties;
55
  showMenu:boolean = false;
56
  communities = null;
57
  subscriberOfCommunities = false;
58
  managerOfCommunities = false;
59
  //  community: {id:string, name:string, logoUrl:string};
60
   constructor(  private  route: ActivatedRoute, private propertiesService:EnvironmentSpecificService,
61
                 private _communitiesService:CommunitiesService, private _subscribeService: SubscribeService,
62
                 private router: Router) {
63
       router.events.forEach((event) => {
64
         if (event instanceof NavigationStart) {
65
           HelperFunctions.scroll();
66
         }
67
      });
68
   }
69

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

    
90
       if (typeof document !== 'undefined') {
91
         try{
92
           this.isClient = true;
93
         }catch (e) {
94
         }
95
       }
96
   }, error => {
97
     console.log("App couldn't fetch properties");
98
       console.log(error);
99

    
100
   });
101
   }
102

    
103
   public buildMenu(communityId: string) {
104
     let community = null;
105
     this.community = null;
106
     this._communitiesService.getCommunitiesState().subscribe (
107
       communities => {
108

    
109
              if(communities.length === 0 && communityId !== null && communityId !== '') {
110
                  return;
111
              }
112
              for(var com of communities){
113
                  if( (communityId && communityId!="" &&  com.communityId == communityId
114
                   && community !=null) ||
115
                    (
116
                      !(communityId && communityId!="" &&  com.communityId  == communityId)
117
                      &&
118
                      this.managerOfCommunities && this.subscriberOfCommunities)) {
119
                    break;
120
                  }
121
                if(Session.isLoggedIn() && com['status'] != "hidden"){
122
                  if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
123
                    this.managerOfCommunities = true;
124
                  }else if(com.managers.indexOf(Session.getUserEmail())!=-1){
125
                    this.managerOfCommunities = true;
126
                  }
127
                }
128

    
129

    
130

    
131
                 if(communityId && communityId!="" &&  com.communityId == communityId){
132
                  community = com;
133
                   let isCommunityManager: boolean = false;
134
                   if(Session.isCommunityCurator() || Session.isPortalAdministrator()){
135
                     isCommunityManager = true;
136
                   }else if(com.managers.indexOf(Session.getUserEmail())!=-1){
137
                     isCommunityManager = true;
138
                   }
139
                  this.community = {id: community.communityId, name: (community.shortTitle)?community.shortTitle:community.title, logoUrl:community.logoUrl};
140
                  this.menuItems= [];
141

    
142
                   this.menuItems.push(
143
                    {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}),
144
                      items: [new MenuItem("","Publications","","/search/find/publications",false,["publication"],["/search/find/publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
145
                      new MenuItem("","Research Data","","/search/find/datasets",false,["dataset"],["/search/find/datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
146
                      new MenuItem("","Software","","/search/find/software",false,["software"],["/search/find/software"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
147
                      new MenuItem("","Other Research Products","","/search/find/other",false,["orp"],["/search/find/other"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
148
                     new MenuItem("","Projects","","/search/find/projects/",false,["project"],["/search/find/projects"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
149
                     new MenuItem("","Content Providers","","/search/find/dataproviders",false,["datasource"],["/search/find/dataproviders"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
150
                    ]});
151

    
152
                   this.menuItems.push( {
153
                    rootItem: new MenuItem("deposit","Deposit","","/participate/deposit/learn-how",false,[],["/participate/deposit/learn-how"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
154
                    items: [
155
                    /*
156
                    new MenuItem("","Zenodo Communities","","/participate/share-zenodo",false,[],["/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
157
                    new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
158
                    new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId})
159
                    */
160
                    ]
161
                    });
162
                   this.menuItems.push(
163
                    {
164
                    rootItem: new MenuItem("link","Link","","/participate/claim",false,[],["/participate/claim"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
165
                    items: [
166
                      new MenuItem("","Start linking","","/participate/claim",false,[],["/participate/claim"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
167
                      new MenuItem("","Learn more",this.properties.claimsInformationLink,"",false,[],[],{})
168
                    ]
169
                    });
170
                   if(isCommunityManager){
171
                     this.menuItems.push(
172
                       {
173
                         rootItem: new MenuItem("manage","Manage",'https://beta.admin.connect.openaire.eu/dashboard?communityId='+community.communityId,"",false,[],[],{}),
174
                         items: []
175
                       });
176
                   }
177

    
178
                }
179

    
180
              }
181
              if(community == null){
182
                this.menuItems= [];
183
                this.menuItems.push({rootItem: new MenuItem("about","About","","/about/learn-how",false,[],null,{}), items: []});
184
                var myCommunities = [];
185
                /*if(this.managerOfCommunities){
186
                  myCommunities.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
187
                }
188
                if(Session.isLoggedIn()){
189
                  this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe (
190
                    pids => {
191
                      if(pids.length > 0 ) {
192
                        myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
193
                      }
194
                    },
195
                    error => {
196
                      console.error("Error fetching your subscribed communities")
197
                    });
198
                }*/
199
                this.menuItems.push({rootItem: new MenuItem("communities","Communities","","/search/find/communities",false,[],null,{}), items: []});
200
                this.menuItems.push({rootItem: new MenuItem("join","Join","","/contact-us",false,[],null,{}), items: []});
201
                /*if(this.managerOfCommunities || this.subscriberOfCommunities){
202
                  let myCommunitiesMenu =   new MenuItem("myCommunities","My Communities","","",false,[],[],{});
203
                  myCommunitiesMenu.setMarkAsActive(false);
204
                  this.menuItems.push({rootItem: myCommunitiesMenu, items: myCommunities});
205
                }*/
206

    
207

    
208

    
209

    
210
                this.bottomMenuItems =[
211
                new MenuItem("","About","https://beta.openaire.eu/project-factsheets","",false,[],[],{}),
212
                new MenuItem("","News - Events","https://beta.openaire.eu/news-events","",false,[],[],{}),
213
                new MenuItem("","Blog","https://blogs.openaire.eu/","",false,[],[],{}),
214
                new MenuItem("","Contact us","https://beta.openaire.eu/contact-us","",false,[],[],{})
215
              ];
216
              // if(this.properties.showContent){
217
              //   this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
218
              // }
219
              this.userMenuItems =[
220
                 // new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],(data['communityId'] && typeof document !== 'undefined' && ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:data['communityId']}),
221
               ];
222
                if(Session.isPortalAdministrator()){
223
                  //((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire"
224
                  this.userMenuItems.push(new MenuItem("","Manage Helptexts",
225
                    ((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
226
                    "",false,[],[],{}))
227
                }
228
                if(this.managerOfCommunities){
229
                  this.userMenuItems.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
230
                }
231
                if(Session.isLoggedIn()){
232
                  this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe (
233
                    pids => {
234
                      if(pids.length > 0 ) {
235
                        this.userMenuItems.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
236
                      }
237
                    },
238
                    error => {
239
                      console.error("Error fetching your subscribed communities")
240
                    });
241
                }
242
            }else{
243
              this.bottomMenuItems = [
244
                // new MenuItem("","About","","/about",false,[],["/about"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
245
                new MenuItem("","Organizations","","/organizations",false,[],["/organizations"],this.properties.environment!="development"?{}:{communityId:community.communityId})
246
              ];
247
              if(this.properties.showContent){
248
                this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
249
              }
250
              this.userMenuItems =[ new MenuItem("","My profile","","",false,[],[],{}),
251
                 new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
252
                 new MenuItem("","Invite users","","/invite",false,[],[],this.properties.environment!="development"?{}:{communityId:community.communityId}),
253
               ];
254
               if(this.managerOfCommunities ){
255
                 this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{}))
256
               }
257
            }
258
       });
259
   }
260
}
(2-2/4)