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 {SubscribeService} from './openaireLibrary/utils/subscribe/subscribe.service';
11
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
12
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
13

    
14
@Component({
15
  //changeDetection: ChangeDetectionStrategy.Default,
16
  //encapsulation: ViewEncapsulation.Emulated,
17
  selector: 'app-root',
18
  styles: [`
19
  `],
20
  template: `
21
    <div [class]="(community)?(community.id +'App communityApp'):'connectApp'">
22
      <navbar *ngIf="properties && showMenu && !community" [portal]="properties.dashboard" [onlyTop]=false
23
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
24
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="false" communityId="connect"></navbar>
25
      <navbar *ngIf="properties && showMenu  && community" [portal]="properties.dashboard" [onlyTop]=false
26
              [communityId]="community.id"
27
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
28
              [community]=community [showMenu]=showMenu [properties]="properties" [enableSearch]="false"
29
              searchRoute="/search/find/research-outcomes"
30
              [showHomeMenuItem]="false"></navbar>
31
      <customization *ngIf="properties  && community" [properties]="properties"
32
                     [communityId]="community.id"></customization>
33
      <div class="custom-main-content">
34
        <main>
35
          <router-outlet></router-outlet>
36
        </main>
37
      </div>
38
      <div id="subscribeAndInviteBtn" *ngIf="isClient && properties && communityId">
39
        <subscribe [communityId]="communityId" [properties]="properties"></subscribe>
40
        <invite *ngIf="managerOfCommunities" [longView]=false [buttonSizeSmall]=false [properties]="properties"></invite>
41
      </div>
42
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
43
      <cookie-law *ngIf="isClient" position="bottom">
44
        OpenAIRE uses cookies in order to function properly.<br>
45
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
46
        experience possible.
47
        By using the OpenAIRE portal you accept our use of cookies. <a
48
        href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
49
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
50
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
51
                                     points="7 4 13 10 7 16"></polyline></svg>
52
            </span></a>
53
      </cookie-law>
54
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
55
              [properties]="properties"></bottom>
56
      <bottom *ngIf="properties && isClient  && showMenu && community" class=""
57
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
58
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"
59
              [darkBackground]="false" [centered]="true"></bottom>
60
    </div>
61
  `
62

    
63
})
64
export class AppComponent {
65
  isClient: boolean = false;
66

    
67
  userMenuItems: MenuItem[] = [];
68

    
69

    
70
  menuItems: RootMenuItem [] = [];
71
  bottomMenuItems: MenuItem[] = [];
72
  public community = null;
73
  properties: EnvProperties;
74
  showMenu: boolean = false;
75
  communities = null;
76
  subscriberOfCommunities = false;
77
  managerOfCommunities = false;
78
  user: User;
79
  communityId: string = "";
80

    
81
  //  community: {id:string, name:string, logoUrl:string};
82
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
83
              private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService,
84
              private router: Router, private userManagementService: UserManagementService) {
85
    router.events.forEach((event) => {
86
      if (event instanceof NavigationStart) {
87
        HelperFunctions.scroll();
88
      }
89
    });
90
  }
91

    
92
  ngOnInit() {
93
    this.propertiesService.loadEnvironment()
94
      .then(es => {
95
        this.properties = this.propertiesService.envSpecific;
96
        this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
97
        if (typeof document !== 'undefined') {
98
          try {
99
            this.isClient = true;
100
          } catch (e) {
101
          }
102
        }
103
        this.userManagementService.getUserInfo().subscribe(user => {
104
          this.user = user;
105
          this.init();
106
        });
107
      }, error => {
108
        console.log("App couldn't fetch properties");
109
        console.log(error);
110

    
111
      });
112
  }
113

    
114
  private init() {
115
    let communityId: string = "";
116
    if (this.properties.environment == "development") {
117
      this.showMenu = false;
118
      this.route.queryParams.subscribe(params => {
119
        communityId = (params['communityId']) ? params['communityId'] :  ConnectHelper.getCommunityFromDomain(this.properties.domain);
120
        this.buildMenu(communityId);
121
      })
122
    } else {
123
      this.showMenu = false;
124
      communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
125
      this.buildMenu(communityId);
126
    }
127
    this.communityId = communityId;
128
  }
129

    
130
  public buildMenu(communityId: string) {
131
    let community = null;
132
    this.community = null;
133
    this._communitiesService.getCommunitiesState().subscribe(
134
      communities => {
135
        if (!communities || communities.length == 0 && communityId !== null && communityId !== '') {
136
          return;
137
        }
138
        for (var com of communities) {
139
          if ((communityId && communityId != "" && com.communityId == communityId
140
            && community != null) ||
141
            (
142
              !(communityId && communityId != "" && com.communityId == communityId)
143
              &&
144
              this.managerOfCommunities && this.subscriberOfCommunities)) {
145
            break;
146
          }
147
          if (this.user && com['status'] != "hidden") {
148
            if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
149
              this.managerOfCommunities = true;
150
            } else if (com.managers.indexOf(this.user.email) != -1) {
151
              this.managerOfCommunities = true;
152
            }
153
          }
154

    
155

    
156
          if (communityId && communityId != "" && com.communityId == communityId) {
157
            community = com;
158
            let isCommunityManager: boolean = false;
159
            if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
160
              isCommunityManager = true;
161
            } else if (this.user && com.managers.indexOf(this.user.email) != -1) {
162
              isCommunityManager = true;
163
            }
164
            this.community = {
165
              id: community.communityId,
166
              name: (community.shortTitle) ? community.shortTitle : community.title,
167
              logoUrl: community.logoUrl
168
            };
169
            this.menuItems = [];
170

    
171
            this.menuItems.push({
172
              rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
173
              items: []
174
            });
175
            this.menuItems.push(
176
              {
177
                rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
178
                items: [
179
                  new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
180
                  new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
181
                ]
182
              });
183
            this.menuItems.push(
184
              {
185
                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}),
186
                items: [
187
                  new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
188
                  new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
189
                  new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
190
                ]
191
              });
192
            this.menuItems.push(
193
              {
194
                rootItem: new MenuItem("about", "About", "", "", false, [], [], {}),
195
                items: [
196
                  new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
197
                  new MenuItem("", "Curators", "", "/curators", false, [], ["/curators"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
198
                  new MenuItem("", "Sources and methology", "", "/content", false, [], ["/content"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
199
                  new MenuItem("", "National Bulletins", "", "/national-bulletins", false, [], ["/national-bulletins"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
200
                  new MenuItem("", "Subjects", "", "/subjects", false, [], ["/subjects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
201
                  new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
202
                ]
203
              });
204
            if (isCommunityManager) {
205
              this.menuItems.push(
206
                {
207
                  rootItem: new MenuItem("manage", "Manage", 'https://beta.admin.connect.openaire.eu/dashboard?communityId=' + community.communityId, "", false, [], [], {}),
208
                  items: []
209
                });
210
            }
211

    
212
          }
213

    
214
        }
215
        if (community == null) {
216
          this.menuItems = [];
217
          this.menuItems.push({
218
            rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
219
            items: [
220
              new MenuItem("", "Learn the process", "", "/about/learn-how", false, [], [], {}),
221
              new MenuItem("", "Publications", "", "/publications", false, [], ["/publications"], {}),
222
              new MenuItem("", "Roadmap", "https://trello.com/b/yfzUz0kp/openaire-connect-dashboard", "", false, [], [], {}),
223
              new MenuItem("", "FAQs", "", "/about/faq", false, [], ["/about/faq"], {})
224
            ]
225

    
226
          });
227
          this.menuItems.push({
228
            rootItem: new MenuItem("communities", "Communities", "", "/search/find/communities", false, [], null, {}),
229
            items: []
230
          });
231
          this.menuItems.push({
232
            rootItem: new MenuItem("contact-us", "Contact us", "", "/contact-us", false, [], null, {}),
233
            items: []
234
          });
235
          this.bottomMenuItems = [
236
            new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}),
237
            new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}),
238
            new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
239
            new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {})
240
          ];
241
          this.userMenuItems = [];
242
          if (Session.isPortalAdministrator(this.user)) {
243
            this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
244
              ((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
245
              "", false, [], [], {}))
246
          }
247
          if (this.user) {
248
            this.userMenuItems.push(new MenuItem("my-communities", "My Communities", "",
249
              "/myCommunities", false, [], [], {}));
250
          }
251
        } else {
252
          this.bottomMenuItems = [
253
            new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId})
254
          ];
255
          if (this.properties.showContent) {
256
            this.bottomMenuItems.push(new MenuItem("", "Sources and methology", "", "/content", false, [], [], {}));
257
          }
258
          if(this.user) {
259
            this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/
260
              new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
261
              new MenuItem("", "Invite users", "", "/invite", false, [], [], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
262
            ];
263
            if (this.managerOfCommunities) {
264
              this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {}))
265
            }
266
          }
267
        }
268
        this.showMenu = true;
269
      });
270
  }
271
}
(2-2/4)