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
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
14

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

    
74
})
75
export class AppComponent {
76
  isClient: boolean = false;
77

    
78
  userMenuItems: MenuItem[] = [];
79

    
80

    
81
  menuItems: RootMenuItem [] = [];
82
  bottomMenuItems: MenuItem[] = [];
83
  public community = null;
84
  properties: EnvProperties;
85
  showMenu: boolean = false;
86
  communities = null;
87
  subscriberOfCommunities = false;
88
  managerOfCommunities = false;
89
  user: User;
90
  communityId: string = "";
91

    
92
  //  community: {id:string, name:string, logoUrl:string};
93
  constructor(private  route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
94
              private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService,
95
              private router: Router, private userManagementService: UserManagementService,
96
              private configurationService: ConfigurationService) {
97
    router.events.forEach((event) => {
98
      if (event instanceof NavigationStart) {
99
        HelperFunctions.scroll();
100
      }
101
    });
102
  }
103

    
104
  ngOnInit() {
105
    this.propertiesService.loadEnvironment()
106
      .then(es => {
107
        this.properties = this.propertiesService.envSpecific;
108
        this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
109
        if (typeof document !== 'undefined') {
110
          try {
111
            this.isClient = true;
112
          } catch (e) {
113
          }
114
        }
115
        this.userManagementService.getUserInfo().subscribe(user => {
116
          this.user = user;
117
          this.init();
118
        },
119
          error => this.init());
120
      }, error => {
121
        console.log("App couldn't fetch properties");
122
        console.log(error);
123

    
124
      });
125
  }
126

    
127
  private init() {
128
    let communityId: string = "";
129
    if (this.properties.environment == "development") {
130
      this.showMenu = false;
131
      this.route.queryParams.subscribe(params => {
132
        communityId = (params['communityId']) ? params['communityId'] :  ConnectHelper.getCommunityFromDomain(this.properties.domain);
133
        this.configurationService.initCommunityInformation(this.properties, communityId);
134
        this.buildMenu(communityId);
135
      })
136
    } else {
137
      this.showMenu = false;
138
      communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
139
      this.configurationService.initCommunityInformation(this.properties, communityId);
140
      this.buildMenu(communityId);
141
    }
142
    this.communityId = communityId;
143
  }
144

    
145
  public buildMenu(communityId: string) {
146
    let community = null;
147
    this.community = null;
148
    this._communitiesService.getCommunitiesState().subscribe(
149
      communities => {
150
        if (!communities || communities.length == 0 && communityId !== null && communityId !== '') {
151
          return;
152
        }
153
        for (var com of communities) {
154
          if ((communityId && communityId != "" && com.communityId == communityId
155
            && community != null) ||
156
            (
157
              !(communityId && communityId != "" && com.communityId == communityId)
158
              &&
159
              this.managerOfCommunities && this.subscriberOfCommunities)) {
160
            break;
161
          }
162
          if (this.user && com['status'] != "hidden") {
163
            if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || Session.isManager('community', this.communityId, this.user)) {
164
              this.managerOfCommunities = true;
165
            } else if (com.managers.indexOf(this.user.email) != -1) {
166
              this.managerOfCommunities = true;
167
            }
168
          }
169
          if (communityId && communityId != "" && com.communityId == communityId) {
170
            community = com;
171
            let isCommunityManager: boolean = false;
172
            if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || Session.isManager('community', this.communityId, this.user)) {
173
              isCommunityManager = true;
174
            } else if (this.user && com.managers.indexOf(this.user.email) != -1) {
175
              isCommunityManager = true;
176
            }
177
            this.community = {
178
              id: community.communityId,
179
              name: (community.shortTitle) ? community.shortTitle : community.title,
180
              logoUrl: community.logoUrl,
181
              description:community.description
182
            };
183
            this.menuItems = [];
184

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

    
226
          }
227

    
228
        }
229
        if (community == null) {
230
          this.menuItems = [];
231
          this.menuItems.push({
232
            rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
233
            items: [
234
              new MenuItem("", "Learn the process", "", "/about/learn-how", false, [], [], {}),
235
              new MenuItem("", "Publications", "", "/publications", false, [], ["/publications"], {}),
236
              new MenuItem("", "Roadmap", "https://trello.com/b/yfzUz0kp/openaire-connect-dashboard", "", false, [], [], {}),
237
              new MenuItem("", "FAQs", "", "/about/faq", false, [], ["/about/faq"], {})
238
            ]
239

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