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
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
22

    
23
@Component({
24
  //changeDetection: ChangeDetectionStrategy.Default,
25
  //encapsulation: ViewEncapsulation.Emulated,
26
  selector: 'app-root',
27
  styles: [`
28
  `],
29
  template: `
30
    <div [class]="(community)?(community.id +'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.id" [onlyTop]=false
35
              [communityId]="community.id" [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.name" [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 && properties && community">
60
        <subscribe [communityId]="community.id" [properties]="properties"></subscribe>
61
        <invite *ngIf="isManager" [longView]=false [buttonSizeSmall]=false [properties]="properties"></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.id" [menuItems]=bottomMenuItems [properties]="properties"
80
              [darkBackground]="true" [centered]="true"></bottom>
81
      <role-verification *ngIf="community" service="connect"
82
                         [id]="community.id" [name]="community.name" [type]="'community'"></role-verification>
83
    </div>
84
  `
85
  
86
})
87
export class AppComponent {
88
  isClient: boolean = false;
89
  
90
  userMenuItems: MenuItem[] = [];
91
  
92
  
93
  menuItems: RootMenuItem [] = [];
94
  bottomMenuItems: MenuItem[] = [];
95
  public community = null;
96
  properties: EnvProperties;
97
  showMenu: boolean = false;
98
  communities = null;
99
  user: User;
100
  communityId: string = "";
101
  header: Header;
102
  logoPath: string = 'assets/common-assets/';
103
  subscriptions = [];
104
  layout: CustomizationOptions = null;
105
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
106
              private _communitiesService: CommunitiesService, private smoothScroll: SmoothScroll,
107
              private router: Router, private userManagementService: UserManagementService,
108
              private configurationService: ConfigurationService, private _communityService: CommunityService, private _layoutService: LayoutService) {
109
  }
110
  
111
  ngOnDestroy() {
112
    this.subscriptions.forEach(subscription => {
113
      if (subscription instanceof Subscriber) {
114
        subscription.unsubscribe();
115
      }
116
    });
117
    this._communitiesService.clearSubscriptions();
118
    this.userManagementService.clearSubscriptions();
119
    this.configurationService.clearSubscriptions();
120
    this._communityService.clearSubscriptions();
121
    this.smoothScroll.clearSubscriptions();
122
  }
123
  
124
  ngOnInit() {
125
    this.properties = properties;
126
    this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
127
    if (typeof document !== 'undefined') {
128
      try {
129
        this.isClient = true;
130
      } catch (e) {
131
      }
132
    }
133
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
134
      this.user = user;
135
      this.init();
136
    }, error => this.init()));
137
  }
138
  
139
  get isManager() {
140
    return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
141
  }
142
  
143
  
144
  private init() {
145
    let communityId: string = ConnectHelper.getCommunityFromDomain(this.properties.domain);
146
    this.showMenu = false;
147
    this.initAdminToolCommunity(communityId);
148
    this.buildMenu(communityId);
149
    this.communityId = communityId;
150
    if (this.communityId === null) {
151
      this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink;
152
    } else {
153
      this.userManagementService.fixRedirectURL = null;
154
    }
155
  }
156
  
157
  initAdminToolCommunity(communityId) {
158
    if (communityId) {
159
      this.properties.adminToolsPortalType = "community";
160
      this.initLayout(communityId);
161
    }
162
    this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
163
  }
164
  initLayout(communityId){
165
    if(!this.layout && this.properties.environment == "development") {
166
      this._layoutService.getLayout(this.properties, communityId).subscribe(
167
        layout => {
168
          if (layout) {
169
            this.layout = CustomizationOptions.checkForObsoleteVersion(layout.layoutOptions,this.communityId);
170
          } else {
171
            this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
172
          }
173

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