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]="true"
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
              {
173
                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}),
174
                items: [
175
                  new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
176
                  new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
177
                  new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
178
                ]
179
              });*/
180

    
181
            this.menuItems.push({
182
              rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
183
              items: []
184
            });
185
            this.menuItems.push(
186
              {
187
                rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
188
                items: [
189
                  /*new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
190
                  new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})*/
191
                ]
192
              });
193
            this.menuItems.push(
194
              {
195
                rootItem: new MenuItem("about", "About", "", "", false, [], [], {}),
196
                items: [
197
                  new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
198
                  new MenuItem("", "Curators", "", "/curators", false, [], ["/curators"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
199
                  new MenuItem("", "Sources and methology", "", "/content", false, [], ["/content"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
200
                  new MenuItem("", "National Bulletins", "", "/national-bulletins", false, [], ["/national-bulletins"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
201
                  new MenuItem("", "Subjects", "", "/subjects", false, [], ["/subjects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
202
                  new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
203
                ]
204
              });
205
            if (isCommunityManager) {
206
              this.menuItems.push(
207
                {
208
                  rootItem: new MenuItem("manage", "Manage", 'https://beta.admin.connect.openaire.eu/dashboard?communityId=' + community.communityId, "", false, [], [], {}),
209
                  items: []
210
                });
211
            }
212

    
213
          }
214

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

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