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'):'connectApp'">
22
      <navbar *ngIf="properties && showMenu && !community && loginCheck" [portal]="properties.dashboard" [onlyTop]=false
23
              [userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
24
              [showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="true"></navbar>
25
      <navbar *ngIf="properties && showMenu  && community && loginCheck" [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
              [showHomeMenuItem]="true"></navbar>
30
      <customization *ngIf="properties  && community" [properties]="properties"
31
                     [communityId]="community.id"></customization>
32
      <div class="custom-main-content">
33
        <main>
34
          <router-outlet></router-outlet>
35
        </main>
36
      </div>
37
      <!--feedback *ngIf= "isClient && properties" portalName="Connect" [feedbackQuestionaire]=properties.feedbackQuestionaire></feedback-->
38
      <cookie-law *ngIf="isClient" position="bottom">
39
        OpenAIRE uses cookies in order to function properly.<br>
40
        Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
41
        experience possible.
42
        By using the OpenAIRE portal you accept our use of cookies. <a
43
        href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
44
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
45
                 ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
46
                                     points="7 4 13 10 7 16"></polyline></svg>
47
            </span></a>
48
      </cookie-law>
49
      <bottom *ngIf="properties && isClient && showMenu && !community" [grantAdvance]="false"
50
              [properties]="properties"></bottom>
51
      <bottom *ngIf="properties && isClient  && showMenu && community" class="communityPanelBackground"
52
              [showSocialButtons]="true" [showMenuItems]="true" [grantAdvance]="false" [showOpenaire]="true"
53
              [communityId]="community.id" [menuItems]=bottomMenuItems [properties]="properties"></bottom>
54
    </div>
55
  `
56

    
57
})
58
export class AppComponent {
59
  isClient: boolean = false;
60

    
61
  userMenuItems: MenuItem[] = [];
62

    
63

    
64
  menuItems: RootMenuItem [] = [];
65
  bottomMenuItems: MenuItem[] = [];
66
  public community = null;
67
  properties: EnvProperties;
68
  showMenu: boolean = false;
69
  communities = null;
70
  subscriberOfCommunities = false;
71
  managerOfCommunities = false;
72
  user: User;
73
  loginCheck: boolean = false;
74

    
75
  //  community: {id:string, name:string, logoUrl:string};
76
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
77
              private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService,
78
              private router: Router, private userManagementService: UserManagementService) {
79
    router.events.forEach((event) => {
80
      if (event instanceof NavigationStart) {
81
        HelperFunctions.scroll();
82
      }
83
    });
84
  }
85

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

    
106
      });
107
  }
108

    
109
  private init() {
110
    let communityId: string = "";
111
    this.loginCheck = true;
112
    if (this.properties.environment == "development") {
113
      this.showMenu = false;
114
      this.route.queryParams.subscribe(params => {
115
        communityId = (params['communityId']) ? params['communityId'] : '';
116
        this.buildMenu(communityId);
117
      })
118
    } else {
119
      this.showMenu = false;
120
      communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
121
      this.buildMenu(communityId);
122
    }
123
  }
124

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

    
150

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

    
166
            this.menuItems.push(
167
              {
168
                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}),
169
                items: [new MenuItem("", "Publications", "", "/search/find/publications", false, ["publication"], ["/search/find/publications"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
170
                  new MenuItem("", "Research Data", "", "/search/find/datasets", false, ["dataset"], ["/search/find/datasets"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
171
                  new MenuItem("", "Software", "", "/search/find/software", false, ["software"], ["/search/find/software"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
172
                  new MenuItem("", "Other Research Products", "", "/search/find/other", false, ["orp"], ["/search/find/other"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
173
                  new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
174
                  new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
175
                ]
176
              });
177

    
178
            this.menuItems.push({
179
              rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
180
              items: []
181
            });
182
            this.menuItems.push(
183
              {
184
                rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
185
                items: [
186
                  new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
187
                  new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
188
                ]
189
              });
190
            if (isCommunityManager) {
191
              this.menuItems.push(
192
                {
193
                  rootItem: new MenuItem("manage", "Manage", 'https://beta.admin.connect.openaire.eu/dashboard?communityId=' + community.communityId, "", false, [], [], {}),
194
                  items: []
195
                });
196
            }
197

    
198
          }
199

    
200
        }
201
        if (community == null) {
202
          this.menuItems = [];
203
          this.menuItems.push({
204
            rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
205
            items: []
206
          });
207
          this.menuItems.push({
208
            rootItem: new MenuItem("communities", "Communities", "", "/search/find/communities", false, [], null, {}),
209
            items: []
210
          });
211
          this.menuItems.push({
212
            rootItem: new MenuItem("join", "Join", "", "/contact-us", false, [], null, {}),
213
            items: []
214
          });
215
          this.bottomMenuItems = [
216
            new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}),
217
            new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}),
218
            new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
219
            new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {})
220
          ];
221
          this.userMenuItems = [];
222
          if (Session.isPortalAdministrator(this.user)) {
223
            this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
224
              ((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
225
              "", false, [], [], {}))
226
          }
227
          if (this.user) {
228
            this.userMenuItems.push(new MenuItem("my-communities", "My Communities", "",
229
              "/myCommunities", false, [], [], {}));
230
          }
231
        } else {
232
          this.bottomMenuItems = [
233
            new MenuItem("", "Organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId})
234
          ];
235
          if (this.properties.showContent) {
236
            this.bottomMenuItems.push(new MenuItem("", "Content Policy", "", "/content", false, [], [], {}));
237
          }
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.managerOfCommunities) {
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
      });
248
  }
249
}
(2-2/4)