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 {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
18

    
19
@Component({
20
  //changeDetection: ChangeDetectionStrategy.Default,
21
  //encapsulation: ViewEncapsulation.Emulated,
22
  selector: 'app-root',
23
  styles: [`
24
  `],
25
  template: `
26
    <div [class]="(community)?(community.id +'App communityApp'):'connectApp'">
27
      <navbar *ngIf="properties && showMenu && !community && header" [portal]="properties.dashboard" [onlyTop]=false
28
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user" [header]="header"
29
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="false" communityId="connect"></navbar>
30
      <navbar *ngIf="properties && showMenu  && community && header" [portal]="community.id" [onlyTop]=false
31
              [communityId]="community.id" [header]="header"
32
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
33
              [showMenu]=showMenu [properties]="properties" [enableSearch]="false"
34
              searchRoute="/search/find/research-outcomes"
35
              [showHomeMenuItem]="false"></navbar>
36
      <customization *ngIf="properties  && communityId && communityId.length > 0" [properties]="properties"
37
                     [communityId]="communityId"></customization>
38
      <schema2jsonld *ngIf="properties && showMenu && !community" [URL]="properties.domain + properties.baseLink"
39
                     [logoURL]="properties.domain + properties.baseLink+'/assets/common-assets/logo-small-connect.png'"
40
                     type="home"
41
                     [searchActionRoute]="properties.searchLinkToCommunities" [searchAction]="true"
42
                     name="OpenAIRE Connect"
43
                     description="Build a Gateway for your Community: Turn Open Science into Practice. It takes your open and linked research outcomes.">
44
      </schema2jsonld>
45
      <schema2jsonld *ngIf="properties  && showMenu && communityId && communityId.length > 0 && community"
46
                     [URL]="properties.domain + properties.baseLink"
47
                     [logoURL]="community.logoUrl" type="home" [searchActionRoute]="properties.searchLinkToResults"
48
                     [name]="community.name" [description]="community.description">
49
      </schema2jsonld>
50
      <div class="custom-main-content">
51
        <main>
52
          <router-outlet></router-outlet>
53
        </main>
54
      </div>
55
      <div id="subscribeAndInviteBtn" *ngIf="isClient && properties && community">
56
        <subscribe [communityId]="community.id" [properties]="properties"></subscribe>
57
        <invite *ngIf="isManager" [longView]=false [buttonSizeSmall]=false [properties]="properties"></invite>
58
      </div>
59
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
60
      <cookie-law *ngIf="isClient" position="bottom">
61
        OpenAIRE uses cookies in order to function properly.<br>
62
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
63
        experience possible.
64
        By using the OpenAIRE portal you accept our use of cookies. <a
65
          href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
66
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
67
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
68
                                     points="7 4 13 10 7 16"></polyline></svg>
69
            </span></a>
70
      </cookie-law>
71
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
72
              [properties]="properties"></bottom>
73
      <bottom *ngIf="properties && isClient  && showMenu && community" class=" communityPanelBackground "
74
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
75
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"
76
              [darkBackground]="true" [centered]="true"></bottom>
77
      <role-verification *ngIf="community" service="connect"
78
                         [id]="community.id" [name]="community.name" [type]="'community'"></role-verification>
79
    </div>
80
  `
81

    
82
})
83
export class AppComponent {
84
  isClient: boolean = false;
85

    
86
  userMenuItems: MenuItem[] = [];
87

    
88

    
89
  menuItems: RootMenuItem [] = [];
90
  bottomMenuItems: MenuItem[] = [];
91
  public community = null;
92
  properties: EnvProperties;
93
  showMenu: boolean = false;
94
  communities = null;
95
  subscriberOfCommunities = false;
96
  user: User;
97
  communityId: string = "";
98
  header: Header;
99
  logoPath: string = 'assets/common-assets/';
100
  subscriptions = [];
101
  //  community: {id:string, name:string, logoUrl:string};
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 = "";
148
    if (this.properties.environment == "development") {
149
      this.showMenu = false;
150
      this.subscriptions.push(this.route.queryParams.subscribe(params => {
151
        communityId = (params['communityId']) ? params['communityId'] :  ConnectHelper.getCommunityFromDomain(this.properties.domain);
152
        if(communityId) {
153
          this.properties.adminToolsPortalType = "community";
154
        }
155
        this.configurationService.initCommunityInformation(this.properties, (communityId)?communityId:this.properties.adminToolsPortalType);
156
        this.buildMenu(communityId);
157
      }));
158
    } else {
159
      this.showMenu = false;
160
      communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
161
      if(communityId) {
162
        this.properties.adminToolsPortalType = "community";
163
      }
164
      this.configurationService.initCommunityInformation(this.properties, (communityId)?communityId:this.properties.adminToolsPortalType);
165
      this.buildMenu(communityId);
166
    }
167
    this.communityId = communityId;
168
  }
169

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