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 && community">
60
        <subscribe [communityId]="community.id"></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.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
  userMenuItems: MenuItem[] = [];
90
  menuItems: RootMenuItem [] = [];
91
  bottomMenuItems: MenuItem[] = [];
92
  public community = 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) {
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
    this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
123
    if (typeof document !== 'undefined') {
124
      try {
125
        this.isClient = true;
126
      } catch (e) {
127
      }
128
    }
129
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
130
      this.user = user;
131
      this.init();
132
    }, error => this.init()));
133
  }
134
  
135
  get isManager() {
136
    return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
137
  }
138
  
139
  
140
  private init() {
141
    let communityId: string = ConnectHelper.getCommunityFromDomain(this.properties.domain);
142
    this.showMenu = false;
143
    this.initAdminToolCommunity(communityId);
144
    this.buildMenu(communityId);
145
    this.communityId = communityId;
146
    if (this.communityId === null) {
147
      this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink;
148
    } else {
149
      this.userManagementService.fixRedirectURL = null;
150
    }
151
  }
152
  
153
  initAdminToolCommunity(communityId) {
154
    if (communityId) {
155
      this.properties.adminToolsPortalType = "community";
156
      this.initLayout(communityId);
157
    }
158
    this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
159
  }
160
  initLayout(communityId){
161
    if(!this.layout && this.properties.environment == "development") {
162
      this._layoutService.getLayout(this.properties, communityId).subscribe(
163
        layout => {
164
          if (layout) {
165
            this.layout = CustomizationOptions.checkForObsoleteVersion(layout.layoutOptions,this.communityId);
166
          } else {
167
            this.layout = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
168
          }
169

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