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

    
20
@Component({
21
  //changeDetection: ChangeDetectionStrategy.Default,
22
  //encapsulation: ViewEncapsulation.Emulated,
23
  selector: 'app-root',
24
  styles: [`
25
  `],
26
  template: `
27
    <div [class]="(community)?(community.id +'App communityApp'):'connectApp'">
28
      <navbar *ngIf="properties && showMenu && !community && header" [portal]="properties.dashboard" [onlyTop]=false
29
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user" [header]="header"
30
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="false" communityId="connect"></navbar>
31
      <navbar *ngIf="properties && showMenu  && community && header" [portal]="community.id" [onlyTop]=false
32
              [communityId]="community.id" [header]="header"
33
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
34
              [showMenu]=showMenu [properties]="properties" [enableSearch]="false"
35
              searchRoute="/search/find/research-outcomes"
36
              [showHomeMenuItem]="false"></navbar>
37
      <customization *ngIf="properties &&  showMenu && communityId && communityId.length > 0" [properties]="properties"
38
                     [communityId]="communityId"></customization>
39
      <schema2jsonld *ngIf="properties && showMenu && !community" [URL]="properties.domain + properties.baseLink"
40
                     [logoURL]="properties.domain + properties.baseLink+'/assets/common-assets/logo-small-connect.png'"
41
                     type="home"
42
                     [searchActionRoute]="properties.searchLinkToCommunities" [searchAction]="true"
43
                     name="OpenAIRE Connect"
44
                     description="Build a Gateway for your Community: Turn Open Science into Practice. It takes your open and linked research outcomes.">
45
      </schema2jsonld>
46
      <schema2jsonld *ngIf="properties  && showMenu && communityId && communityId.length > 0 && community"
47
                     [URL]="properties.domain + properties.baseLink"
48
                     [logoURL]="community.logoUrl" type="home" [searchActionRoute]="properties.searchLinkToResults"
49
                     [name]="community.name" [description]="community.description">
50
      </schema2jsonld>
51
      <div class="custom-main-content">
52
        <main>
53
          <router-outlet></router-outlet>
54
        </main>
55
      </div>
56
      <div id="subscribeAndInviteBtn" *ngIf="isClient && properties && community">
57
        <subscribe [communityId]="community.id" [properties]="properties"></subscribe>
58
        <invite *ngIf="isManager" [longView]=false [buttonSizeSmall]=false [properties]="properties"></invite>
59
      </div>
60
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
61
      <cookie-law *ngIf="isClient" position="bottom">
62
        OpenAIRE uses cookies in order to function properly.<br>
63
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
64
        experience possible.
65
        By using the OpenAIRE portal you accept our use of cookies. <a
66
          href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
67
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
68
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
69
                                     points="7 4 13 10 7 16"></polyline></svg>
70
            </span></a>
71
      </cookie-law>
72
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
73
              [properties]="properties"></bottom>
74
      <bottom *ngIf="properties && isClient  && showMenu && community" class=" communityPanelBackground "
75
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
76
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"
77
              [darkBackground]="true" [centered]="true"></bottom>
78
      <role-verification *ngIf="community" service="connect"
79
                         [id]="community.id" [name]="community.name" [type]="'community'"></role-verification>
80
    </div>
81
  `
82
  
83
})
84
export class AppComponent {
85
  isClient: boolean = false;
86
  
87
  userMenuItems: MenuItem[] = [];
88
  
89
  
90
  menuItems: RootMenuItem [] = [];
91
  bottomMenuItems: MenuItem[] = [];
92
  public community = null;
93
  properties: EnvProperties;
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
  
102
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
103
              private _communitiesService: CommunitiesService,
104
              private router: Router, private userManagementService: UserManagementService,
105
              private configurationService: ConfigurationService, private _communityService: CommunityService) {
106
    this.subscriptions.push(router.events.forEach((event) => {
107
      if (event instanceof NavigationStart) {
108
        HelperFunctions.scroll();
109
      }
110
    }));
111
  }
112
  
113
  ngOnDestroy() {
114
    this.subscriptions.forEach(subscription => {
115
      if (subscription instanceof Subscriber) {
116
        subscription.unsubscribe();
117
      }
118
    });
119
    this._communitiesService.clearSubscriptions();
120
    this.userManagementService.clearSubscriptions();
121
    this.configurationService.clearSubscriptions();
122
    this._communityService.clearSubscriptions();
123
  }
124
  
125
  ngOnInit() {
126
    this.properties = properties;
127
    this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
128
    if (typeof document !== 'undefined') {
129
      try {
130
        this.isClient = true;
131
      } catch (e) {
132
      }
133
    }
134
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
135
      this.user = user;
136
      this.init();
137
    }, error => this.init()));
138
    
139
  }
140
  
141
  get isManager() {
142
    return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
143
  }
144
  
145
  
146
  private init() {
147
    let communityId: string = ConnectHelper.getCommunityFromDomain(this.properties.domain);
148
    this.showMenu = false;
149
    this.initAdminToolCommunity(communityId);
150
    this.buildMenu(communityId);
151
    this.communityId = communityId;
152
    if (this.communityId === null) {
153
      this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink;
154
    } else {
155
      this.userManagementService.fixRedirectURL = null;
156
    }
157
  }
158
  
159
  initAdminToolCommunity(communityId) {
160
    if (communityId) {
161
      this.properties.adminToolsPortalType = "community";
162
    }
163
    this.configurationService.initCommunityInformation(this.properties, (communityId) ? communityId : this.properties.adminToolsPortalType);
164
  }
165
  
166
  public buildMenu(communityId: string) {
167
    if (communityId) {
168
      if (!this.community || this.community.communityId !== communityId) {
169
        this.subscriptions.push(this._communityService.getCommunity(communityId).subscribe(community => {
170
          if (community && !this.isPrivate(community)) {
171
            this.community = {
172
              id: community.communityId,
173
              name: (community.shortTitle) ? community.shortTitle : community.title,
174
              logoUrl: (community.isUpload) ? (properties.utilsService + '/download/' + community.logoUrl) : (StringUtils.urlPrefix(community.logoUrl) + community.logoUrl),
175
              description: community.description
176
            };
177
            this.header = {
178
              // url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
179
              route: "/",
180
              title: this.community.name,
181
              logoUrl: this.community.logoUrl,
182
              logoSmallUrl: this.community.logoUrl,
183
              position: 'left',
184
              badge: true
185
            };
186
            this.menuItems = [];
187
            this.menuItems.push({
188
              rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
189
              items: []
190
            });
191
            this.menuItems.push(
192
              {
193
                rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
194
                items: [
195
                  new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
196
                  new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
197
                ]
198
              });
199
            this.menuItems.push(
200
              {
201
                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"], {}),
202
                items: [
203
                  new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], {}),
204
                  new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], {}),
205
                  new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {}),
206
                ]
207
              });
208
            this.menuItems.push(
209
              {
210
                rootItem: new MenuItem("about", "About", "", "", false, [], [], {}),
211
                items: [
212
                  new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], {}),
213
                  new MenuItem("", "Curators", "", "/curators", false, [], ["/curators"], {}),
214
                  new MenuItem("", "Sources and methodology", "", "/content", false, [], ["/content"], {}),
215
                  new MenuItem("", "National Bulletins", "", "/national-bulletins", false, [], ["/national-bulletins"], {}),
216
                  new MenuItem("", "Subjects", "", "/subjects", false, [], ["/subjects"], {}),
217
                  new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], {}),
218
                ]
219
              });
220
            if (this.isManager) {
221
              this.menuItems.push(
222
                {
223
                  rootItem: new MenuItem("manage", "Manage", this.properties.adminPortalURL + '/' + community.communityId, "", false, [], [], {}),
224
                  items: []
225
                });
226
            }
227
            this.bottomMenuItems = [
228
              new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], {})
229
            ];
230
            if (this.properties.showContent) {
231
              this.bottomMenuItems.push(new MenuItem("", "Sources and methodology", "", "/content", false, [], [], {}));
232
            }
233
            if (this.user) {
234
              this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/
235
                new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], {}),
236
                new MenuItem("", "Invite users", "", "/invite", false, [], [], {}),
237
              ];
238
              if (this.isManager) {
239
                this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {}))
240
              }
241
            }
242
            this.showMenu = true;
243
          } else {
244
            this.showPrivateOrNoCommunity(community ? community.status : null);
245
          }
246
        }));
247
      } else {
248
        this.showMenu = true;
249
      }
250
    } else {
251
      this.buildConnectMenu();
252
    }
253
  }
254
  
255
  isPrivate(community) {
256
    return community && (community.status == "hidden" || (community.status == "manager" && !(Session.isCommunityCurator(this.user) || Session.isManager("community", community.communityId, this.user))))
257
  }
258
  
259
  showPrivateOrNoCommunity(restrictedData: string) {
260
    this.communityId = null;
261
    this.community = null;
262
    this.properties.adminToolsPortalType = "connect";
263
    this.configurationService.initCommunityInformation(this.properties, "connect");
264
    this.initAdminToolCommunity(null);
265
    this.buildConnectMenu(true);
266
    if (restrictedData == "manager") {
267
      if (!this.user) {
268
        this.router.navigate(['/user-info'], {
269
          queryParams: {
270
            "errorCode": LoginErrorCodes.NOT_LOGIN,
271
            "redirectUrl": location.pathname+ location.search + location.hash
272
          }
273
        });
274
      } else {
275
        this.router.navigate(['/error'], {queryParams: {'page': -1}});
276
      }
277
    } else {
278
      this.router.navigate(['/error'], restrictedData ? {queryParams: {'page': -1}} : {});
279
    }
280
  }
281
  
282
  buildConnectMenu(restrictedData: boolean = false) {
283
    let url = "https://" + (properties.environment != "production" ? "beta." : "") + "connect.openaire.eu";
284
    this.header = {
285
      route: restrictedData ? "" : "/",
286
      url: restrictedData ? url : "",
287
      title: 'connect',
288
      logoUrl: this.logoPath + 'logo-large-connect.png',
289
      logoSmallUrl: this.logoPath + 'logo-small-connect.png',
290
      position: 'left',
291
      badge: true
292
    };
293
    this.menuItems = [];
294
    this.menuItems.push({
295
      rootItem: new MenuItem("about", "About", restrictedData ? url + "/about/learn-how" : "", restrictedData ? "" : "/about/learn-how", false, [], ["/about/learn-how"], {}),
296
      items: [
297
        new MenuItem("", "Learn the process", restrictedData ? url + "/about/learn-how" : "", restrictedData ? "" : "/about/learn-how", false, [], ["/about/learn-in-depth"], {}),
298
        new MenuItem("", "Publications", restrictedData ? url + "/publications" : "", restrictedData ? "" : "/publications", false, [], ["/publications"], {}),
299
        new MenuItem("", "Roadmap", "https://trello.com/b/yfzUz0kp/openaire-connect-dashboard", "", false, [], [], {}),
300
        new MenuItem("", "FAQs", restrictedData ? url + "/about/faq" : "", restrictedData ? "" : "/about/faq", false, [], ["/about/faq"], {})
301
      ]
302
      
303
    });
304
    this.menuItems.push({
305
      rootItem: new MenuItem("communities", "Communities", restrictedData ? url + "/about/faq" : "", restrictedData ? "" : "/search/find/communities", false, [], ['/search/find/communities'], {}),
306
      items: []
307
    });
308
    this.menuItems.push({
309
      rootItem: new MenuItem("contact-us", "Contact us", restrictedData ? url + "/contact-us" : "", restrictedData ? "" : "/contact-us", false, [], ['/contact-us'], {}),
310
      items: []
311
    });
312
    this.bottomMenuItems = [
313
      new MenuItem("", "About", "https://openaire.eu/project-factsheets", "", false, [], [], {}),
314
      new MenuItem("", "News - Events", "https://openaire.eu/news-events", "", false, [], [], {}),
315
      new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
316
      new MenuItem("", "Contact us", restrictedData ? url + "/contact-us" : "", restrictedData ? "" : "/contact-us", false, [], [], {})
317
    ];
318
    this.userMenuItems = [];
319
    if (Session.isPortalAdministrator(this.user)) {
320
      this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
321
        properties.adminPortalURL + "/connect/pages", "", false, [], [], {}))
322
    }
323
    if (this.user) {
324
      this.userMenuItems.push(new MenuItem("my-communities", "My Communities", restrictedData ? url + "/myCommunities" : "",
325
        restrictedData ? "" : "/myCommunities", false, [], [], {}));
326
    }
327
    this.showMenu = true;
328
  }
329
}
(2-2/4)