Project

General

Profile

1
import {Component} from '@angular/core';
2
import {ActivatedRoute, 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 {UserManagementService} from "./openaireLibrary/services/user-management.service";
11
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
12
import {properties} from '../environments/environment';
13
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
14
import {Subscriber} from "rxjs";
15
import {CommunityService} from "./openaireLibrary/connect/community/community.service";
16
import {StringUtils} from "./openaireLibrary/utils/string-utils.class";
17
import {LoginErrorCodes} from "./openaireLibrary/login/utils/guardHelper.class";
18
import {CustomizationOptions} from "./openaireLibrary/connect/community/CustomizationOptions";
19
import {LayoutService} from "./openaireLibrary/services/layout.service";
20
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
21
import {Meta} from "@angular/platform-browser";
22
import {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
23
import {SEOService} from "./openaireLibrary/sharedComponents/SEO/SEO.service";
24

    
25
@Component({
26
  selector: 'app-root',
27
  styles: [`
28
  `],
29
  template: `
30
    <div [class]="(community)?(community.communityId +'App communityApp'):'connectApp'">
31
      <navbar *ngIf="properties && showMenu && !community && header" [portal]="properties.dashboard" [onlyTop]=false
32
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user" [header]="header"
33
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="false" communityId="connect"></navbar>
34
      <navbar *ngIf="properties && showMenu  && community && header" [portal]="community.communityId" [onlyTop]=false
35
              [communityId]="community.communityId" [header]="header"
36
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
37
              [showMenu]=showMenu [properties]="properties" [enableSearch]="false"
38
              searchRoute="/search/find/research-outcomes"
39
              [showHomeMenuItem]="false"></navbar>
40
      <customization *ngIf="properties &&  showMenu && communityId && communityId.length > 0 && layout" [properties]="properties"
41
                     [communityId]="communityId" [layout]="layout" ></customization>
42
      <schema2jsonld *ngIf="properties && showMenu && !community" [URL]="properties.domain + properties.baseLink"
43
                     [logoURL]="properties.domain + properties.baseLink+'/assets/common-assets/logo-small-connect.png'"
44
                     type="home"
45
                     [searchActionRoute]="properties.searchLinkToCommunities" [searchAction]="true"
46
                     name="OpenAIRE Connect"
47
                     description="Build a Gateway for your Community: Turn Open Science into Practice. It takes your open and linked research outcomes.">
48
      </schema2jsonld>
49
      <schema2jsonld *ngIf="properties  && showMenu && communityId && communityId.length > 0 && community"
50
                     [URL]="properties.domain + properties.baseLink"
51
                     [logoURL]="community.logoUrl" type="home" [searchActionRoute]="properties.searchLinkToResults"
52
                     [name]="(community.shortTitle) ? community.shortTitle : community.title" [description]="community.description">
53
      </schema2jsonld>
54
      <div class="custom-main-content">
55
        <main>
56
          <router-outlet></router-outlet>
57
        </main>
58
      </div>
59
      <div id="subscribeAndInviteBtn" *ngIf="isClient && communityId && community">
60
        <subscribe [communityId]="community.communityId"></subscribe>
61
        <invite *ngIf="isManager" [longView]="false"></invite>
62
      </div>
63
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
64
      <cookie-law *ngIf="isClient" position="bottom">
65
        OpenAIRE uses cookies in order to function properly.<br>
66
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
67
        experience possible.
68
        By using the OpenAIRE portal you accept our use of cookies. <a
69
          href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
70
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
71
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
72
                                     points="7 4 13 10 7 16"></polyline></svg>
73
            </span></a>
74
      </cookie-law>
75
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
76
              [properties]="properties"></bottom>
77
      <bottom *ngIf="properties && isClient  && showMenu && community" class=" communityPanelBackground "
78
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
79
              [communityId]="community.communityId" [menuItems]=bottomMenuItems [properties]="properties"
80
              [darkBackground]="true" [centered]="true"></bottom>
81
      <role-verification *ngIf="community" service="connect"
82
                         [id]="community.communityId" [name]="community.title" [type]="'community'"></role-verification>
83
    </div>
84
  `
85
  
86
})
87
export class AppComponent {
88
  isClient: boolean = false;
89
  userMenuItems: MenuItem[] = [];
90
  menuItems: RootMenuItem [] = [];
91
  bottomMenuItems: MenuItem[] = [];
92
  public community:CommunityInfo = null;
93
  properties: EnvProperties = properties;
94
  showMenu: boolean = false;
95
  communities = null;
96
  user: User;
97
  communityId: string = "";
98
  header: Header;
99
  logoPath: string = 'assets/common-assets/';
100
  subscriptions = [];
101
  layout: CustomizationOptions = null;
102
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
103
              private _communitiesService: CommunitiesService, private smoothScroll: SmoothScroll,
104
              private router: Router, private userManagementService: UserManagementService,
105
              private configurationService: ConfigurationService, private _communityService: CommunityService, private _layoutService: LayoutService, private _meta: Meta, private seoService: SEOService) {
106
  }
107
  
108
  ngOnDestroy() {
109
    this.subscriptions.forEach(subscription => {
110
      if (subscription instanceof Subscriber) {
111
        subscription.unsubscribe();
112
      }
113
    });
114
    this._communitiesService.clearSubscriptions();
115
    this.userManagementService.clearSubscriptions();
116
    this.configurationService.clearSubscriptions();
117
    this._communityService.clearSubscriptions();
118
    this.smoothScroll.clearSubscriptions();
119
  }
120
  
121
  ngOnInit() {
122
    if (this.properties.environment == "production" || this.properties.environment == "development") {
123
      this.subscriptions.push(this.route.queryParams.subscribe(data => {
124
        this._meta.updateTag({content: 'all', name: 'robots'});
125
        this.seoService.removeLinkForPrevURL();
126
        this.seoService.removeLinkForNextURL();
127
      }));
128
    }
129
    this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
130
    if (typeof document !== 'undefined') {
131
      try {
132
        this.isClient = true;
133
      } catch (e) {
134
      }
135
    }
136
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
137
      this.user = user;
138
      this.init();
139
    }, error => {
140
      this.init()}));
141
  }
142
  
143
  get isManager() {
144
    return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
145
  }
146

    
147
  get isPrivate() {
148
    return this.community && !ConnectHelper.isPrivate(this.community, this.user)
149
  }
150
  
151
  private init() {
152
    let communityId: string = ConnectHelper.getCommunityFromDomain(this.properties.domain);
153
    this.showMenu = false;
154
    this.initAdminToolCommunity(communityId);
155
    this.buildMenu(communityId);
156
    // this.communityId = communityId;
157
    if (this.communityId === null) {
158
      this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink;
159
    } else {
160
      this.userManagementService.fixRedirectURL = null;
161
    }
162
  }
163
  
164
  initAdminToolCommunity(communityId) {
165
    if (communityId) {
166
      this.properties.adminToolsPortalType = "community";
167
      this.initLayout(communityId);
168
    }
169
    this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
170
  }
171
  initLayout(communityId){
172
    if(!this.layout) {
173
      this._layoutService.getLayout(this.properties, communityId).subscribe(
174
        layout => {
175
          if (layout) {
176
            this.layout = CustomizationOptions.checkForObsoleteVersion(layout.layoutOptions,this.communityId);
177
          } else {
178
            this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
179
          }
180

    
181
        },
182
        error => {
183
          this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
184
        }
185
      );
186
    }
187
  }
188
  public buildMenu(communityId: string) {
189
    if (communityId) {
190
      if (!this.community || this.communityId !== communityId) {
191
        this.subscriptions.push(this._communityService.getCommunity(communityId).subscribe(community => {
192
          if (community) {
193
           this.community = community;
194
          }else{
195
            this.community = null;
196
            this.communityId = null;
197
          }
198
          this.buildCommunityMenu();
199
        }));
200
      } else {
201
        this.buildCommunityMenu();
202
      }
203
    } else {
204
      this.buildConnectMenu();
205
    }
206
  }
207

    
208
  buildCommunityMenu(){
209
    if (this.community && !ConnectHelper.isPrivate(this.community, this.user)) {
210
      this.communityId = this.community.communityId;
211
      this.header = {
212
        // url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
213
        route: "/",
214
        title: (this.community.shortTitle) ? this.community.shortTitle : this.community.title,
215
        logoUrl: (this.community.isUpload) ? (properties.utilsService + '/download/' + this.community.logoUrl) : (StringUtils.urlPrefix(this.community.logoUrl) + this.community.logoUrl),
216
        logoSmallUrl: (this.community.isUpload) ? (properties.utilsService + '/download/' + this.community.logoUrl) : (StringUtils.urlPrefix(this.community.logoUrl) + this.community.logoUrl),
217
        position: 'left',
218
        badge: true
219
      };
220
      this.menuItems = [];
221
      this.menuItems.push({
222
        rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
223
        items: []
224
      });
225
      this.menuItems.push(
226
        {
227
          rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
228
          items: [
229
            new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
230
            new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
231
          ]
232
        });
233
      this.menuItems.push(
234
        {
235
          rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
236
          items: [
237
            new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], {resultbestaccessright: '"' + encodeURIComponent("Open Access") + '"'}),
238
            new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], {}),
239
            new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {}),
240
          ]
241
        });
242
      this.menuItems.push(
243
        {
244
          rootItem: new MenuItem("about", "About", "", "", false, [], [], {}),
245
          items: [
246
            new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], {}),
247
            new MenuItem("", "Curators", "", "/curators", false, [], ["/curators"], {}),
248
            new MenuItem("", "Sources and methodology", "", "/content", false, [], ["/content"], {}),
249
            new MenuItem("", "National Bulletins", "", "/national-bulletins", false, [], ["/national-bulletins"], {}),
250
            new MenuItem("", "Subjects", "", "/subjects", false, [], ["/subjects"], {}),
251
            new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], {}),
252
          ]
253
        });
254
      if (this.isManager) {
255
        this.menuItems.push(
256
          {
257
            rootItem: new MenuItem("manage", "Manage", this.properties.adminPortalURL + '/' + this.community.communityId, "", false, [], [], {}),
258
            items: []
259
          });
260
      }
261
      this.bottomMenuItems = [
262
        new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], {})
263
      ];
264
      if (this.properties.showContent) {
265
        this.bottomMenuItems.push(new MenuItem("", "Sources and methodology", "", "/content", false, [], [], {}));
266
      }
267
      if (this.user) {
268
        this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/
269
          new MenuItem("", "My ORCID links", "", "/my-orcid-links", false, [], [], {}),
270
          new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], {}),
271
          new MenuItem("", "Invite users", "", "/invite", false, [], [], {}),
272
        ];
273
        if (this.isManager) {
274
          this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {}))
275
        }
276
      }
277
      this.showMenu = true;
278
    } else {
279
      this.communityId = null;
280
      this.properties.adminToolsPortalType = "connect";
281
      this.configurationService.initCommunityInformation(this.properties, "connect");
282
      this.initAdminToolCommunity(null);
283
      this.buildConnectMenu(true);
284
      if (this.community && this.community.status == "manager") {
285
        if (!this.user ) {
286
          if(typeof location !== 'undefined' && location.pathname.indexOf("user-info") == -1) {
287
            this.router.navigate(['/user-info'], {
288
              queryParams: {
289
                "errorCode": LoginErrorCodes.NOT_LOGIN,
290
                "redirectUrl": location.pathname + location.search + location.hash
291
              }
292
            });
293
          }
294
        }  else {
295
          if(typeof location !== 'undefined' && location.pathname.indexOf("user-info") == -1) {
296
            this.router.navigate(['/'], {queryParamsHandling: "merge"});
297
          }
298
        }
299
      }else  if (this.community && this.community.status == "hidden") {
300
        this.router.navigate(['/error']);
301
      }else{
302
        this.router.navigate(['/'], this.community && this.community.status ? {  queryParamsHandling: "merge" } : {});
303
      }
304
    }
305
  }
306
  buildConnectMenu(restrictedData: boolean = false) {
307
    let url = "https://" + (properties.environment != "production" ? "beta." : "") + "connect.openaire.eu";
308
    this.header = {
309
      route: restrictedData ? "" : "/",
310
      url: restrictedData ? url : "",
311
      title: 'connect',
312
      logoUrl: this.logoPath + 'logo-large-connect.png',
313
      logoSmallUrl: this.logoPath + 'logo-small-connect.png',
314
      position: 'left',
315
      badge: true
316
    };
317
    this.menuItems = [];
318
    this.menuItems.push({
319
      rootItem: new MenuItem("about", "About", restrictedData ? url + "/about/learn-how" : "", restrictedData ? "" : "/about/learn-how", false, [], ["/about/learn-how"], {}),
320
      items: [
321
        new MenuItem("", "Learn the process", restrictedData ? url + "/about/learn-how" : "", restrictedData ? "" : "/about/learn-how", false, [], ["/about/learn-in-depth"], {}),
322
        new MenuItem("", "Publications", restrictedData ? url + "/publications" : "", restrictedData ? "" : "/publications", false, [], ["/publications"], {}),
323
        new MenuItem("", "Roadmap", "https://trello.com/b/yfzUz0kp/openaire-connect-dashboard", "", false, [], [], {}),
324
        new MenuItem("", "FAQs", restrictedData ? url + "/about/faq" : "", restrictedData ? "" : "/about/faq", false, [], ["/about/faq"], {})
325
      ]
326
      
327
    });
328
    this.menuItems.push({
329
      rootItem: new MenuItem("communities", "Communities", restrictedData ? url + "/search/find/communities" : "", restrictedData ? "" : "/search/find/communities", false, [], ['/search/find/communities'], {}),
330
      items: []
331
    });
332
    this.menuItems.push({
333
      rootItem: new MenuItem("contact-us", "Contact us", restrictedData ? url + "/contact-us" : "", restrictedData ? "" : "/contact-us", false, [], ['/contact-us'], {}),
334
      items: []
335
    });
336
    this.bottomMenuItems = [
337
      new MenuItem("", "About", "https://openaire.eu/project-factsheets", "", false, [], [], {}),
338
      new MenuItem("", "News - Events", "https://openaire.eu/news-events", "", false, [], [], {}),
339
      new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
340
      new MenuItem("", "Contact us", restrictedData ? url + "/contact-us" : "", restrictedData ? "" : "/contact-us", false, [], [], {})
341
    ];
342
    this.userMenuItems = [];
343
    if (Session.isPortalAdministrator(this.user)) {
344
      this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
345
        properties.adminPortalURL + "/connect/admin-tools/pages", "", false, [], [], {}))
346
    }
347
    if (this.user) {
348
      this.userMenuItems.push(new MenuItem("my-communities", "My Communities", restrictedData ? url + "/myCommunities" : "",
349
        restrictedData ? "" : "/myCommunities", false, [], [], {}));
350
    }
351
    this.showMenu = true;
352
  }
353
}
(2-2/4)