Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, NavigationStart, Router} 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, User} 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
import {UserManagementService} from "./openaireLibrary/services/user-management.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 && loginCheck" portal="monitor" [onlyTop]=false
23
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
24
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="true"></navbar>
25
      <navbar *ngIf="properties && showMenu  && community && loginCheck" portal="monitor" [onlyTop]=false [communityId]="community.id"
26
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
27
              [community]=community [showMenu]=showMenu [properties]="properties" [enableSearch]="true"
28
              [showHomeMenuItem]="true"></navbar>
29
      <div class="custom-main-content">
30
        <main>
31
          <router-outlet></router-outlet>
32
        </main>
33
      </div>
34
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
35
      <cookie-law *ngIf="isClient" position="bottom">
36
        OpenAIRE uses cookies in order to function properly.<br>
37
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
38
        experience possible.
39
        By using the OpenAIRE portal you accept our use of cookies. <a
40
        href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
41
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
42
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
43
                                     points="7 4 13 10 7 16"></polyline></svg>
44
            </span></a>
45
      </cookie-law>
46
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
47
              [properties]="properties"></bottom>
48
      <bottom *ngIf="properties && isClient  && showMenu && community" class="communityPanelBackground"
49
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
50
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"></bottom>
51
    </div>
52
  `
53

    
54
})
55
export class AppComponent {
56
  isClient: boolean = false;
57

    
58
  userMenuItems: MenuItem[] = [];
59

    
60

    
61
  menuItems: RootMenuItem [] = [];
62
  bottomMenuItems: MenuItem[] = [];
63
  public community = null;
64
  properties: EnvProperties;
65
  showMenu: boolean = false;
66
  communities = null;
67
  subscriberOfCommunities = false;
68
  managerOfCommunities = false;
69
  user: User;
70
  loginCheck: boolean = false;
71

    
72
  //  community: {id:string, name:string, logoUrl:string};
73
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
74
              private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService,
75
              private router: Router, private userManagementService: UserManagementService) {
76
    router.events.forEach((event) => {
77
      if (event instanceof NavigationStart) {
78
        HelperFunctions.scroll();
79
      }
80
    });
81
  }
82

    
83
  ngOnInit() {
84
    this.propertiesService.loadEnvironment()
85
      .then(es => {
86
        this.properties = this.propertiesService.envSpecific;
87
        var communityId: string = "";
88
        this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
89
        this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
90
          this.user = user;
91
          this.loginCheck = true;
92
          if (this.properties.environment == "development") {
93
            this.showMenu = false;
94
            this.route.queryParams.subscribe(params => {
95
              communityId = (params['communityId']) ? params['communityId'] : '';
96
              this.buildMenu(communityId);
97
            })
98
          } else {
99
            this.showMenu = false;
100
            communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
101
            this.buildMenu(communityId);
102
          }
103
          if (typeof document !== 'undefined') {
104
            try {
105
              this.isClient = true;
106
            } catch (e) {
107
            }
108
          }
109
        }, error => {
110
          console.log("App couldn't fetch properties");
111
          console.log(error);
112

    
113
        });
114
        });
115
  }
116

    
117
  public buildMenu(communityId: string) {
118
    let community = null;
119
    this.community = null;
120
    this._communitiesService.getCommunitiesState().subscribe(
121
      communities => {
122
        if (!communities || communities.length == 0 && communityId !== null && communityId !== '') {
123
          return;
124
        }
125
        for (var com of communities) {
126
          if ((communityId && communityId != "" && com.communityId == communityId
127
            && community != null) ||
128
            (
129
              !(communityId && communityId != "" && com.communityId == communityId)
130
              &&
131
              this.managerOfCommunities && this.subscriberOfCommunities)) {
132
            break;
133
          }
134
          if (this.user && com['status'] != "hidden") {
135
            if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
136
              this.managerOfCommunities = true;
137
            } else if (com.managers.indexOf(this.user.email) != -1) {
138
              this.managerOfCommunities = true;
139
            }
140
          }
141

    
142

    
143
          if (communityId && communityId != "" && com.communityId == communityId) {
144
            community = com;
145
            let isCommunityManager: boolean = false;
146
            if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
147
              isCommunityManager = true;
148
            } else if (this.user && com.managers.indexOf(this.user.email) != -1) {
149
              isCommunityManager = true;
150
            }
151
            this.community = {
152
              id: community.communityId,
153
              name: (community.shortTitle) ? community.shortTitle : community.title,
154
              logoUrl: community.logoUrl
155
            };
156
            this.menuItems = [];
157

    
158
            this.menuItems.push(
159
              {
160
                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}),
161
                items: [new MenuItem("", "Publications", "", "/search/find/publications", false, ["publication"], ["/search/find/publications"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
162
                  new MenuItem("", "Research Data", "", "/search/find/datasets", false, ["dataset"], ["/search/find/datasets"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
163
                  new MenuItem("", "Software", "", "/search/find/software", false, ["software"], ["/search/find/software"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
164
                  new MenuItem("", "Other Research Products", "", "/search/find/other", false, ["orp"], ["/search/find/other"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
165
                  new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
166
                  new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
167
                ]
168
              });
169

    
170
            this.menuItems.push({
171
              rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
172
              items: [
173
                /*
174
                new MenuItem("","Zenodo Communities","","/participate/share-zenodo",false,[],["/participate/share-zenodo"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
175
                new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
176
                new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],this.properties.environment!="development"?{}:{communityId:community.communityId})
177
                */
178
              ]
179
            });
180
            this.menuItems.push(
181
              {
182
                rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
183
                items: [
184
                  new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
185
                  new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
186
                ]
187
              });
188
            if (isCommunityManager) {
189
              this.menuItems.push(
190
                {
191
                  rootItem: new MenuItem("manage", "Manage", 'https://beta.admin.connect.openaire.eu/dashboard?communityId=' + community.communityId, "", false, [], [], {}),
192
                  items: []
193
                });
194
            }
195

    
196
          }
197

    
198
        }
199
        if (community == null) {
200
          this.menuItems = [];
201
          this.menuItems.push({
202
            rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
203
            items: []
204
          });
205
          var myCommunities = [];
206
          /*if(this.managerOfCommunities){
207
            myCommunities.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
208
          }
209
          if(Session.isLoggedIn()){
210
            this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe (
211
              pids => {
212
                if(pids.length > 0 ) {
213
                  myCommunities.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
214
                }
215
              },
216
              error => {
217
                console.error("Error fetching your subscribed communities")
218
              });
219
          }*/
220
          this.menuItems.push({
221
            rootItem: new MenuItem("communities", "Communities", "", "/search/find/communities", false, [], null, {}),
222
            items: []
223
          });
224
          this.menuItems.push({
225
            rootItem: new MenuItem("join", "Join", "", "/contact-us", false, [], null, {}),
226
            items: []
227
          });
228
          /*if(this.managerOfCommunities || this.subscriberOfCommunities){
229
            let myCommunitiesMenu =   new MenuItem("myCommunities","My Communities","","",false,[],[],{});
230
            myCommunitiesMenu.setMarkAsActive(false);
231
            this.menuItems.push({rootItem: myCommunitiesMenu, items: myCommunities});
232
          }*/
233

    
234

    
235
          this.bottomMenuItems = [
236
            new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}),
237
            new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}),
238
            new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
239
            new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {})
240
          ];
241
          // if(this.properties.showContent){
242
          //   this.bottomMenuItems.push(new MenuItem("","Content Policy","","/content",false,[],[],{}));
243
          // }
244
          this.userMenuItems = [
245
            // new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],(data['communityId'] && typeof document !== 'undefined' && ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:data['communityId']}),
246
          ];
247
          if (Session.isPortalAdministrator(this.user)) {
248
            //((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire"
249
            this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
250
              ((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
251
              "", false, [], [], {}))
252
          }
253
          /*if(this.managerOfCommunities){
254
            this.userMenuItems.push( new MenuItem("","Managing communities","","/search/find/communities",false,[],[],{role:"%22manager%22"}))
255
          }
256
          if(Session.isLoggedIn()){
257
            this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe (
258
              pids => {
259
                if(pids.length > 0 ) {
260
                  this.userMenuItems.push( new MenuItem("","Subscribed to communities","","/search/find/communities",false,[],[],{status:"%22subscribed%22"}))
261
                }
262
              },
263
              error => {
264
                console.error("Error fetching your subscribed communities")
265
              });
266
          }*/
267
          if (this.user) {
268
            this.userMenuItems.push(new MenuItem("my-communities", "My Communities", "",
269
              "/myCommunities", false, [], [], {}));
270
          }
271
        } else {
272
          this.bottomMenuItems = [
273
            // new MenuItem("","About","","/about",false,[],["/about"],this.properties.environment!="development"?{}:{communityId:community.communityId}),
274
            new MenuItem("", "Organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId})
275
          ];
276
          if (this.properties.showContent) {
277
            this.bottomMenuItems.push(new MenuItem("", "Content Policy", "", "/content", false, [], [], {}));
278
          }
279
          this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/
280
            new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
281
            new MenuItem("", "Invite users", "", "/invite", false, [], [], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
282
          ];
283
          if (this.managerOfCommunities) {
284
            this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {}))
285
          }
286
        }
287
        this.showMenu = true;
288
      });
289
  }
290
}
(2-2/2)