Project

General

Profile

1 57600 k.triantaf
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
2 57931 k.triantaf
import {ActivatedRoute, NavigationEnd, Params, Router} from '@angular/router';
3 57449 argiro.kok
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
4
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
5 57865 konstantin
import {Session, User} from './openaireLibrary/login/utils/helper.class';
6 57449 argiro.kok
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
7 58829 k.triantaf
import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service";
8 57931 k.triantaf
import {BehaviorSubject, Subscriber} from "rxjs";
9 57936 argiro.kok
import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
10 59556 argiro.kok
import {MenuItem, RootMenuItem} from "./openaireLibrary/sharedComponents/menu";
11 59675 argiro.kok
import {Stakeholder, Topic, Visibility} from "./openaireLibrary/monitor/entities/stakeholder";
12 59062 k.triantaf
import {LinksResolver} from "./search/links-resolver";
13 59619 k.triantaf
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
14 59675 argiro.kok
import {arrow_left} from "./openaireLibrary/utils/icons/icons";
15 59724 k.triantaf
import {properties} from "../environments/environment";
16 57449 argiro.kok
17 57673 k.triantaf
18 57449 argiro.kok
@Component({
19 57929 argiro.kok
  selector: 'app-root',
20
  templateUrl: './app.component.html'
21 57449 argiro.kok
})
22 57673 k.triantaf
export class AppComponent implements OnInit, OnDestroy {
23 59732 k.triantaf
  properties: EnvProperties = properties;
24 57929 argiro.kok
  user: User;
25 57931 k.triantaf
  params: BehaviorSubject<Params> = new BehaviorSubject<Params>(null);
26 57929 argiro.kok
  hasSidebar: boolean = false;
27
  hasHeader: boolean = false;
28 57936 argiro.kok
  hasAdminMenu: boolean = false;
29 59048 k.triantaf
  hasMiniMenu: boolean = false;
30
  isFrontPage: boolean = false;
31
  isViewPublic: boolean = false;
32
  sideBarItems: MenuItem[] = [];
33 59724 k.triantaf
  specialSideBarMenuItem: MenuItem = null;
34 59556 argiro.kok
  menuItems: RootMenuItem[] = [];
35 59724 k.triantaf
  menuHeader: Header = {
36
    route: "/",
37
    url: null,
38
    title: "Default menu header",
39
    logoUrl: null,
40
    logoSmallUrl: null,
41
    position: 'center',
42 59725 argiro.kok
    badge: false,
43 59732 k.triantaf
    stickyAnimation: false
44 59724 k.triantaf
  };
45 59732 k.triantaf
46 59751 argiro.kok
  userMenuItems: MenuItem[] = [];
47 57936 argiro.kok
  adminMenuItems: MenuItem[] = [];
48 59048 k.triantaf
  stakeholder: Stakeholder = null;
49
  activeTopic: Topic = null;
50 59724 k.triantaf
  loading: boolean = true;
51
  paramsResolved: boolean = false;
52 59218 argiro.kok
  innerWidth;
53 57929 argiro.kok
  private subscriptions: any[] = [];
54 57931 k.triantaf
55
  constructor(private route: ActivatedRoute,
56 57929 argiro.kok
              private propertiesService: EnvironmentSpecificService,
57
              private router: Router,
58
              private userManagementService: UserManagementService,
59
              private layoutService: LayoutService,
60
              private stakeholderService: StakeholderService,
61
              private cdr: ChangeDetectorRef) {
62 57931 k.triantaf
    this.subscriptions.push(this.router.events.subscribe(event => {
63
      if (event instanceof NavigationEnd) {
64
        let r = this.route;
65
        while (r.firstChild) {
66
          r = r.firstChild;
67
        }
68
        let params = r.snapshot.params;
69 59724 k.triantaf
        this.paramsResolved = true;
70 57931 k.triantaf
        this.params.next(params);
71
      }
72
    }));
73 57929 argiro.kok
  }
74 57931 k.triantaf
75 57929 argiro.kok
  ngOnInit() {
76 59724 k.triantaf
    if (window) {
77 59218 argiro.kok
      this.innerWidth = window.innerWidth;
78
    }
79 57929 argiro.kok
    this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
80
      this.hasSidebar = hasSidebar;
81 59048 k.triantaf
      if (this.hasSidebar === false) {
82 57954 k.triantaf
        this.layoutService.setOpen(false);
83
      }
84 57929 argiro.kok
      this.cdr.detectChanges();
85
    }));
86
    this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
87
      this.hasHeader = hasHeader;
88
      this.cdr.detectChanges();
89
    }));
90 57936 argiro.kok
    this.subscriptions.push(this.layoutService.hasAdminMenu.subscribe(hasAdminMenu => {
91
      this.hasAdminMenu = hasAdminMenu;
92
      this.cdr.detectChanges();
93
    }));
94 58837 argiro.kok
    this.subscriptions.push(this.layoutService.hasMiniMenu.subscribe(hasMiniMenu => {
95
      this.hasMiniMenu = hasMiniMenu;
96
      this.cdr.detectChanges();
97
    }));
98
    this.subscriptions.push(this.layoutService.isFrontPage.subscribe(isFrontPage => {
99
      this.isFrontPage = isFrontPage;
100
      this.cdr.detectChanges();
101
    }));
102 59048 k.triantaf
    this.route.queryParams.subscribe(params => {
103
      this.isViewPublic = (params['view'] == 'public');
104
    });
105 57959 k.triantaf
    this.layoutService.setOpen(false);
106 59724 k.triantaf
    this.subscriptions.push(this.params.subscribe(params => {
107 59732 k.triantaf
      if (this.paramsResolved) {
108 59724 k.triantaf
        this.loading = true;
109
        this.layoutService.setSmallScreen((this.innerWidth && this.innerWidth < 1219));
110
        this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
111
        let isSearch = this.router.url.includes('search');
112
        if (params && params['stakeholder']) {
113
          this.stakeholder = this.stakeholderService.stakeholder;
114
          if (!this.stakeholder || this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
115
            this.stakeholderService.getStakeholder(params['stakeholder']).subscribe(stakeholder => {
116
              if (stakeholder) {
117
                this.stakeholder = stakeholder;
118
                LinksResolver.setProperties(this.stakeholder.alias);
119
                this.buildMenu();
120
                if (isSearch) {
121
                  this.activeTopic = null;
122
                } else if (params && params['topic'] && !this.activeTopic) {
123
                  this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
124 59048 k.triantaf
                } else {
125 59724 k.triantaf
                  this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
126 59048 k.triantaf
                }
127 59777 argiro.kok
                // this.setSideBar();
128 59724 k.triantaf
                this.loading = false;
129
              } else {
130 59062 k.triantaf
                LinksResolver.resetProperties();
131 58875 k.triantaf
                this.navigateToError();
132 59556 argiro.kok
                this.buildMenu();
133 59724 k.triantaf
                this.loading = false;
134
              }
135
            }, error => {
136
              LinksResolver.resetProperties();
137
              this.navigateToError();
138 59556 argiro.kok
              this.buildMenu();
139 59724 k.triantaf
              this.loading = false;
140
            });
141 57931 k.triantaf
          } else {
142 59556 argiro.kok
            this.buildMenu();
143 59724 k.triantaf
            if (isSearch) {
144
              this.activeTopic = null;
145
            } else if (params && params['topic']) {
146
              this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
147
            } else {
148
              this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
149
            }
150
            this.loading = false;
151 57929 argiro.kok
          }
152 59724 k.triantaf
        } else {
153
          LinksResolver.resetProperties();
154
          this.stakeholderService.setStakeholder(null);
155
          this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
156
          this.stakeholder = null;
157
          this.buildMenu();
158
          this.loading = false;
159
        }
160
      }
161
    }));
162
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
163
      this.user = user;
164
      if (user) {
165
        this.buildMenu();
166
      }
167
    }, error => {
168
      console.log("App couldn't fetch properties");
169
      console.log(error);
170
    }));
171 57929 argiro.kok
  }
172 59048 k.triantaf
173 57929 argiro.kok
  public ngOnDestroy() {
174
    this.subscriptions.forEach(value => {
175
      if (value instanceof Subscriber) {
176
        value.unsubscribe();
177
      }
178
    });
179
  }
180 58875 k.triantaf
181
  private navigateToError() {
182 59412 argiro.kok
    this.router.navigate(['/error'], {queryParams: {'page': this.properties.baseLink + this.router.url}});
183 58875 k.triantaf
  }
184 59048 k.triantaf
185 57929 argiro.kok
  public get open() {
186
    return this.layoutService.open;
187
  }
188 59048 k.triantaf
189 57954 k.triantaf
  public toggleOpen(event: MouseEvent) {
190
    event.preventDefault();
191
    this.layoutService.setOpen(!this.open);
192 57929 argiro.kok
  }
193 59048 k.triantaf
194
  private setSideBar() {
195
    let items: MenuItem[] = [];
196 59765 argiro.kok
    if(this.isPublicOrIsMember(this.stakeholder.visibility)) {
197
      this.stakeholder.topics.forEach((topic) => {
198
        if (this.isPublicOrIsMember(topic.visibility)) {
199
          let topicItem: MenuItem = new MenuItem(topic.alias, topic.name, "", (
200
            '/' + this.stakeholder.alias + '/' + topic.alias),
201
            null, [], [], {});
202
          topicItem.icon = topic.icon;
203
          items.push(topicItem);
204
        }
205
      });
206
      if (items.length === 0) {
207
        items.push(new MenuItem('noTopics', 'No topics available yet', "", "", false, [], [], {}));
208 59048 k.triantaf
      }
209 59765 argiro.kok
    }else{
210
      let topicItem: MenuItem = new MenuItem("private", "Private Data", "","", null, [], [], {});
211
      items.push(topicItem);
212 59048 k.triantaf
    }
213
    this.sideBarItems = items;
214
  }
215
216 57929 argiro.kok
  buildMenu() {
217 59556 argiro.kok
    this.menuItems = [];
218
    this.adminMenuItems = [];
219 57929 argiro.kok
    this.userMenuItems = [];
220 59747 argiro.kok
    if (this.user) {
221 59751 argiro.kok
      if (this.isCurator()) {
222
        this.userMenuItems.push(new MenuItem("", "Manage profiles",
223
          "", "/admin", false, [], [], {}));
224
      }
225 59777 argiro.kok
      this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
226 59747 argiro.kok
    }
227 59724 k.triantaf
    if (this.stakeholder) {
228 59556 argiro.kok
      if (this.isFrontPage) {
229 59777 argiro.kok
        this.setSideBar();
230 59556 argiro.kok
        this.menuHeader = {
231
          route: "/" + this.stakeholder.alias,
232
          url: null,
233
          title: this.stakeholder.name,
234
          logoUrl: null,
235
          logoSmallUrl: null,
236
          position: 'center',
237 59725 argiro.kok
          badge: false,
238
          stickyAnimation: false
239 59556 argiro.kok
        };
240 59751 argiro.kok
        if (this.isCurator()) {
241 59556 argiro.kok
          this.menuItems.push({
242
            rootItem: new MenuItem("manage", "Manage",
243 59724 k.triantaf
              "", "/admin", false, [], null, {}), items: []
244 59556 argiro.kok
          });
245 59724 k.triantaf
246 59713 argiro.kok
        }
247 59765 argiro.kok
248
        if(this.isPublicOrIsMember(this.stakeholder.visibility)) {
249
          this.specialSideBarMenuItem = new MenuItem("search", "Search research outcomes", "", this.properties.searchLinkToResults, false, [], null, {})
250
          this.specialSideBarMenuItem.icon = '<span uk-icon="search"></span>';
251
        }else{
252
          this.specialSideBarMenuItem =null;
253
        }
254 59724 k.triantaf
255 59556 argiro.kok
      } else {
256
        this.menuHeader = {
257
          route: "/admin/" + this.stakeholder.alias,
258
          url: null,
259
          title: 'Admin - ' + this.stakeholder.name,
260
          logoUrl: null,
261
          logoSmallUrl: null,
262
          position: 'center',
263 59725 argiro.kok
          badge: false,
264
          stickyAnimation: false
265 59556 argiro.kok
        };
266
        this.menuItems.push({
267
          rootItem: new MenuItem("", "Dashboard",
268 59724 k.triantaf
            "", '/' + this.stakeholder.alias + '/', false, [], null, {}), items: []
269 59556 argiro.kok
        });
270 59724 k.triantaf
        this.adminMenuItems.push(new MenuItem("general", "General", "", "/admin/" + this.stakeholder.alias, false, [], [], {}, "<i uk-icon=\"image\"></i>"));
271
        this.adminMenuItems.push(new MenuItem("indicators", "Indicators", "", "/admin/" + this.stakeholder.alias + '/indicators', false, [], [], {}, "<i uk-icon=\"image\"></i>"));
272
        this.adminMenuItems.push(new MenuItem("users", "Users", "", "/admin/" + this.stakeholder.alias + "/users", false, [], [], {}, "<i uk-icon=\"users\"></i>"));
273
        this.specialSideBarMenuItem = new MenuItem("back", "Manage profiles", "", "/admin", false, [], null, {});
274 59729 k.triantaf
        this.specialSideBarMenuItem.icon = '<span class="uk-icon-button small uk-icon uk-button-secondary">' + arrow_left.data + '</span>'; // '<span class="uk-icon-button uk-icon portal-button  " uk-icon="chevron-left"></span>';
275
        this.specialSideBarMenuItem.customClass = 'uk-text-uppercase uk-text-bold uk-text-secondary';
276 59556 argiro.kok
      }
277 59724 k.triantaf
    } else {
278
      if (this.isFrontPage || !this.hasAdminMenu) {
279
        this.menuHeader = {
280
          route: null,
281
          url: "https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu',
282
          title: "Monitor",
283
          logoUrl: 'assets/common-assets/logo-large-monitor.png',
284
          logoSmallUrl: "assets/common-assets/logo-small-monitor.png",
285
          position: 'left',
286 59725 argiro.kok
          badge: true,
287
          stickyAnimation: false
288 59724 k.triantaf
        };
289 59751 argiro.kok
        this.menuItems.push({
290
          rootItem: new MenuItem("about", "About",
291
            "https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu/about/learn-how', "", false, [], null, {}), items: []
292
        });
293
        this.menuItems.push({
294
          rootItem: new MenuItem("browse", "Browse",
295
            "https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu/browse', "", false, [], null, {}), items: []
296
        });
297
        this.menuItems.push({
298
          rootItem: new MenuItem("contact", "Contact us",
299
            "https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu/contact-us', "", false, [], null, {}), items: []
300
        });
301 59724 k.triantaf
      } else {
302
        this.menuHeader = {
303
          route: "/",
304
          url: null,
305
          title: "Monitor Dashboard",
306
          logoUrl: null,
307
          logoSmallUrl: null,
308
          position: 'center',
309 59725 argiro.kok
          badge: false,
310
          stickyAnimation: false
311 59724 k.triantaf
        };
312 59556 argiro.kok
        this.adminMenuItems = [];
313
        this.specialSideBarMenuItem = null;
314
        this.adminMenuItems.push(new MenuItem("stakeholders", "Manage profiles", "", "/admin", false, [], [], {}, "<i uk-icon=\"cog\"></i>"));
315 59725 argiro.kok
        /*let adminOptions = new MenuItem("adminOptions", "Admin Options", "", null, false, [], [], {})
316 59556 argiro.kok
        adminOptions.items.push(new MenuItem("pages", "Pages", "", "/pages", false, [], [], {}));
317
        adminOptions.items.push(new MenuItem("portals", "Portals", "", "/portals", false, [], [], {}));
318
        adminOptions.items.push(new MenuItem("entities", "Entities", "", "/entities", false, [], [], {}));
319
        adminOptions.items.push(new MenuItem("classes", "Class help texts", "", "/classes", false, [], [], {}));
320
        this.adminMenuItems.push(adminOptions);
321 59725 argiro.kok
        let monitorOptions = new MenuItem("monitorOptions", "Monitor Options", "", null, false, [], [], {})
322
        monitorOptions.items.push(new MenuItem("pages", "Pages", "", "/pages", false, [], [], {communityId: 'monitor'}));
323
        monitorOptions.items.push(new MenuItem("entities", "Entities", "", "/entities", false, [], [], {communityId: 'monitor'}));
324
        monitorOptions.items.push(new MenuItem("classes", "Class help texts", "", "/classContents", false, [], [], {communityId: 'monitor'}));
325
        monitorOptions.items.push(new MenuItem("helptexts", "Help texts", "", "/helptexts", false, [], [], {communityId: 'monitor'}));
326 59556 argiro.kok
        this.adminMenuItems.push(monitorOptions);*/
327 59724 k.triantaf
328 59556 argiro.kok
      }
329 57865 konstantin
    }
330 59724 k.triantaf
331 57929 argiro.kok
  }
332 59751 argiro.kok
  public isCurator() {
333
    return this.user && (Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isKindOfMonitorManager(this.user));
334 59048 k.triantaf
  }
335 59751 argiro.kok
  public isManager(stakeholder:Stakeholder) {
336
    return this.user && (Session.isPortalAdministrator(this.user) || Session.isCurator(stakeholder.type, this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user));
337
  }
338 59724 k.triantaf
339 59732 k.triantaf
  private resolvePageInner() {
340
    if(document !== undefined) {
341
      let header = document.getElementById('pager_header_content');
342
      let inner = document.getElementById('page_content_inner');
343
      if(header) {
344
        inner.setAttribute('style', '{margin-top:' + header.offsetHeight+ '}');
345
      } else {
346
        inner.setAttribute('style', '{margin-top:' + 0 + '}');
347
      }
348
    }
349
  }
350
351 59675 argiro.kok
  public isPublicOrIsMember(visibility: Visibility): boolean {
352 59765 argiro.kok
    if (visibility == "PRIVATE" || (this.isViewPublic && visibility != "PUBLIC")) {
353 59048 k.triantaf
        return false;
354
      }
355 59765 argiro.kok
      return true;
356 59048 k.triantaf
  }
357 59724 k.triantaf
358
  createSearchParameters() {
359
    if (!this.stakeholder) {
360 59079 argiro.kok
      return {};
361
    }
362 59724 k.triantaf
    if (this.stakeholder.type == "funder") {
363
      return {"relfunder": encodeURIComponent("\"" + this.stakeholder.index_id + "||" + this.stakeholder.index_name + "||" + this.stakeholder.index_shortName + "\"")};
364
    } else if (this.stakeholder.type == "ri") {
365 59079 argiro.kok
      // https://beta.explore.openaire.eu/search/find/research-outcomes?f0=q&fv0=&resultbestaccessright=%22Open%20Access%22&community=%22mes%7C%7CEuropean%20Marine%20Science%22&qf=true
366 59724 k.triantaf
      return {"community": encodeURIComponent("\"" + this.stakeholder.index_id + "||" + this.stakeholder.index_name + "\"")};
367
    } else if (this.stakeholder.type == "organization") {
368
      return {"cf": true};
369 59079 argiro.kok
    }
370
  }
371 57449 argiro.kok
}