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 {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
11
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
12
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
13
import {properties} from '../environments/environment';
14
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
15
import {Subscriber} from "rxjs";
16
import {CommunityService} from "./openaireLibrary/connect/community/community.service";
17
import {StringUtils} from "./openaireLibrary/utils/string-utils.class";
18
import {LoginErrorCodes} from "./openaireLibrary/login/utils/guardHelper.class";
19
import {CustomizationOptions} from "./openaireLibrary/connect/community/CustomizationOptions";
20
import {LayoutService} from "./openaireLibrary/services/layout.service";
21

    
22
@Component({
23
  //changeDetection: ChangeDetectionStrategy.Default,
24
  //encapsulation: ViewEncapsulation.Emulated,
25
  selector: 'app-root',
26
  styles: [`
27
  `],
28
  template: `
29
    <div [class]="(community)?(community.id +'App communityApp'):'connectApp'">
30
      <navbar *ngIf="properties && showMenu && !community && header" [portal]="properties.dashboard" [onlyTop]=false
31
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user" [header]="header"
32
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="false" communityId="connect"></navbar>
33
      <navbar *ngIf="properties && showMenu  && community && header" [portal]="community.id" [onlyTop]=false
34
              [communityId]="community.id" [header]="header"
35
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
36
              [showMenu]=showMenu [properties]="properties" [enableSearch]="false"
37
              searchRoute="/search/find/research-outcomes"
38
              [showHomeMenuItem]="false"></navbar>
39
      <customization *ngIf="properties &&  showMenu && communityId && communityId.length > 0 && layout" [properties]="properties"
40
                     [communityId]="communityId" [layout]="layout" ></customization>
41
      <schema2jsonld *ngIf="properties && showMenu && !community" [URL]="properties.domain + properties.baseLink"
42
                     [logoURL]="properties.domain + properties.baseLink+'/assets/common-assets/logo-small-connect.png'"
43
                     type="home"
44
                     [searchActionRoute]="properties.searchLinkToCommunities" [searchAction]="true"
45
                     name="OpenAIRE Connect"
46
                     description="Build a Gateway for your Community: Turn Open Science into Practice. It takes your open and linked research outcomes.">
47
      </schema2jsonld>
48
      <schema2jsonld *ngIf="properties  && showMenu && communityId && communityId.length > 0 && community"
49
                     [URL]="properties.domain + properties.baseLink"
50
                     [logoURL]="community.logoUrl" type="home" [searchActionRoute]="properties.searchLinkToResults"
51
                     [name]="community.name" [description]="community.description">
52
      </schema2jsonld>
53
      <div class="custom-main-content">
54
        <main>
55
          <router-outlet></router-outlet>
56
        </main>
57
      </div>
58
      <div id="subscribeAndInviteBtn" *ngIf="isClient && properties && community">
59
        <subscribe [communityId]="community.id" [properties]="properties"></subscribe>
60
        <invite *ngIf="isManager" [longView]=false [buttonSizeSmall]=false [properties]="properties"></invite>
61
      </div>
62
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
63
      <cookie-law *ngIf="isClient" position="bottom">
64
        OpenAIRE uses cookies in order to function properly.<br>
65
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
66
        experience possible.
67
        By using the OpenAIRE portal you accept our use of cookies. <a
68
          href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
69
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
70
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
71
                                     points="7 4 13 10 7 16"></polyline></svg>
72
            </span></a>
73
      </cookie-law>
74
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
75
              [properties]="properties"></bottom>
76
      <bottom *ngIf="properties && isClient  && showMenu && community" class=" communityPanelBackground "
77
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
78
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"
79
              [darkBackground]="true" [centered]="true"></bottom>
80
      <role-verification *ngIf="community" service="connect"
81
                         [id]="community.id" [name]="community.name" [type]="'community'"></role-verification>
82
    </div>
83
  `
84
  
85
})
86
export class AppComponent {
87
  isClient: boolean = false;
88
  
89
  userMenuItems: MenuItem[] = [];
90
  
91
  
92
  menuItems: RootMenuItem [] = [];
93
  bottomMenuItems: MenuItem[] = [];
94
  public community = null;
95
  properties: EnvProperties;
96
  showMenu: boolean = false;
97
  communities = null;
98
  user: User;
99
  communityId: string = "";
100
  header: Header;
101
  logoPath: string = 'assets/common-assets/';
102
  subscriptions = [];
103
  layout: CustomizationOptions = null;
104
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
105
              private _communitiesService: CommunitiesService,
106
              private router: Router, private userManagementService: UserManagementService,
107
              private configurationService: ConfigurationService, private _communityService: CommunityService, private _layoutService: LayoutService) {
108
    this.subscriptions.push(router.events.forEach((event) => {
109
      if (event instanceof NavigationStart) {
110
        HelperFunctions.scroll();
111
      }
112
    }));
113
  }
114
  
115
  ngOnDestroy() {
116
    this.subscriptions.forEach(subscription => {
117
      if (subscription instanceof Subscriber) {
118
        subscription.unsubscribe();
119
      }
120
    });
121
    this._communitiesService.clearSubscriptions();
122
    this.userManagementService.clearSubscriptions();
123
    this.configurationService.clearSubscriptions();
124
    this._communityService.clearSubscriptions();
125
  }
126
  
127
  ngOnInit() {
128
    this.properties = properties;
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 => this.init()));
140
  }
141
  
142
  get isManager() {
143
    return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
144
  }
145
  
146
  
147
  private init() {
148
    let communityId: string = ConnectHelper.getCommunityFromDomain(this.properties.domain);
149
    this.showMenu = false;
150
    this.initAdminToolCommunity(communityId);
151
    this.buildMenu(communityId);
152
    this.communityId = communityId;
153
    if (this.communityId === null) {
154
      this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink;
155
    } else {
156
      this.userManagementService.fixRedirectURL = null;
157
    }
158
  }
159
  
160
  initAdminToolCommunity(communityId) {
161
    if (communityId) {
162
      this.properties.adminToolsPortalType = "community";
163
      this.initLayout(communityId);
164
    }
165
    this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
166
  }
167
  initLayout(communityId){
168
    if(!this.layout && this.properties.environment == "development") {
169
      this._layoutService.getLayout(this.properties, communityId).subscribe(
170
        layout => {
171
          if (layout) {
172
            this.layout = CustomizationOptions.checkForObsoleteVersion(layout.layoutOptions,this.communityId);
173
          } else {
174
            this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
175
          }
176

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