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
      <subscribe id="subscribeBtn" *ngIf="isClient && properties && communityId != null && communityId != ''" 
39
                 [communityId]="communityId" [properties]="properties"></subscribe>
40
<!--      && managerOfCommunities -->
41
      <invite id="inviteBtn" *ngIf="isClient && properties && communityId != null && communityId != '' && managerOfCommunities" 
42
              [longView]=false [buttonSizeSmall]=false [properties]="properties"></invite>
43

    
44
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
45
      <cookie-law *ngIf="isClient" position="bottom">
46
        OpenAIRE uses cookies in order to function properly.<br>
47
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
48
        experience possible.
49
        By using the OpenAIRE portal you accept our use of cookies. <a
50
        href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
51
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
52
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
53
                                     points="7 4 13 10 7 16"></polyline></svg>
54
            </span></a>
55
      </cookie-law>
56
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
57
              [properties]="properties"></bottom>
58
      <bottom *ngIf="properties && isClient  && showMenu && community" class=""
59
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
60
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"
61
              [darkBackground]="false" [centered]="true"></bottom>
62
    </div>
63
  `
64

    
65
})
66
export class AppComponent {
67
  isClient: boolean = false;
68

    
69
  userMenuItems: MenuItem[] = [];
70

    
71

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

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

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

    
113
      });
114
  }
115

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

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

    
157

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

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

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

    
215
          }
216

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

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