1
|
import {ChangeDetectorRef, Component, HostListener, OnInit} from '@angular/core';
|
2
|
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
|
3
|
import {ActivatedRoute, Data, NavigationEnd, Params, Router} from '@angular/router';
|
4
|
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
5
|
import {Session, User} from './openaireLibrary/login/utils/helper.class';
|
6
|
import {UserManagementService} from './openaireLibrary/services/user-management.service';
|
7
|
import {Header} from './openaireLibrary/sharedComponents/navigationBar.component';
|
8
|
import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
9
|
import {properties} from "../environments/environment";
|
10
|
import {BehaviorSubject, Subscriber} from "rxjs";
|
11
|
import {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
|
12
|
import {CommunityService} from "./openaireLibrary/connect/community/community.service";
|
13
|
import {arrow_left} from "./openaireLibrary/utils/icons/icons";
|
14
|
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
|
15
|
import {ConnectHelper} from './openaireLibrary/connect/connectHelper';
|
16
|
import {ConfigurationService} from './openaireLibrary/utils/configuration/configuration.service';
|
17
|
|
18
|
@Component({
|
19
|
selector: 'app-root',
|
20
|
templateUrl: './app.component.html',
|
21
|
})
|
22
|
export class AppComponent implements OnInit {
|
23
|
title = 'Research Community Dashboard | Administrator';
|
24
|
properties: EnvProperties = properties;
|
25
|
user: User;
|
26
|
params: BehaviorSubject<Params> = new BehaviorSubject<Params>(null);
|
27
|
data: BehaviorSubject<Data> = new BehaviorSubject<Data>(null);
|
28
|
hasSidebar: boolean = false;
|
29
|
hasHeader: boolean = false;
|
30
|
hasAdminMenu: boolean = false;
|
31
|
isFrontPage: boolean = false;
|
32
|
isDashboard: boolean = false;
|
33
|
sideBarItems: MenuItem[] = [];
|
34
|
specialSideBarMenuItem: MenuItem = null;
|
35
|
menuItems: RootMenuItem[] = [];
|
36
|
menuHeader: Header = {
|
37
|
route: "/",
|
38
|
url: null,
|
39
|
title: "Default menu header",
|
40
|
logoUrl: null,
|
41
|
logoSmallUrl: null,
|
42
|
position: 'center',
|
43
|
badge: false,
|
44
|
stickyAnimation: false
|
45
|
};
|
46
|
userMenuItems: MenuItem[] = [];
|
47
|
loading: boolean = true;
|
48
|
paramsResolved: boolean = false;
|
49
|
innerWidth;
|
50
|
public community: CommunityInfo = null;
|
51
|
private subscriptions: any[] = [];
|
52
|
headerLogoUrl: string;
|
53
|
headerUrl: string;
|
54
|
|
55
|
constructor(private route: ActivatedRoute,
|
56
|
private communityService: CommunityService,
|
57
|
private router: Router,
|
58
|
private cdr: ChangeDetectorRef,
|
59
|
private smoothScroll: SmoothScroll,
|
60
|
private layoutService: LayoutService,
|
61
|
private userManagementService: UserManagementService,
|
62
|
private configurationService: ConfigurationService) {
|
63
|
this.subscriptions.push(this.router.events.subscribe(event => {
|
64
|
if (event instanceof NavigationEnd) {
|
65
|
let r = this.route;
|
66
|
while (r.firstChild) {
|
67
|
r = r.firstChild;
|
68
|
}
|
69
|
this.paramsResolved = true;
|
70
|
this.params.next(r.snapshot.params);
|
71
|
this.data.next(r.snapshot.data);
|
72
|
}
|
73
|
}));
|
74
|
}
|
75
|
|
76
|
ngOnInit() {
|
77
|
if (typeof document !== 'undefined' && window) {
|
78
|
this.innerWidth = window.innerWidth;
|
79
|
}
|
80
|
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
|
81
|
this.hasSidebar = hasSidebar;
|
82
|
this.cdr.detectChanges();
|
83
|
}));
|
84
|
this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
|
85
|
this.hasHeader = hasHeader;
|
86
|
this.cdr.detectChanges();
|
87
|
}));
|
88
|
this.subscriptions.push(this.layoutService.hasAdminMenu.subscribe(hasAdminMenu => {
|
89
|
this.hasAdminMenu = hasAdminMenu;
|
90
|
this.cdr.detectChanges();
|
91
|
}));
|
92
|
this.subscriptions.push(this.layoutService.isFrontPage.subscribe(isFrontPage => {
|
93
|
this.isFrontPage = isFrontPage;
|
94
|
this.cdr.detectChanges();
|
95
|
}));
|
96
|
this.subscriptions.push(this.layoutService.isDashboard.subscribe(isDashboard => {
|
97
|
this.isDashboard = isDashboard;
|
98
|
this.cdr.detectChanges();
|
99
|
}));
|
100
|
this.layoutService.setSmallScreen((this.innerWidth && this.innerWidth < 1219));
|
101
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
102
|
this.subscriptions.push(this.params.subscribe(params => {
|
103
|
if (this.paramsResolved) {
|
104
|
this.loading = true;
|
105
|
if (params && params['community']) {
|
106
|
if (!this.community || this.community.communityId !== params['community']) {
|
107
|
this.subscriptions.push(this.communityService.getCommunity(params['community']).subscribe(community => {
|
108
|
if (community) {
|
109
|
this.community = community;
|
110
|
this.setProperties(community.communityId);
|
111
|
this.buildMenu();
|
112
|
this.loading = false;
|
113
|
} else {
|
114
|
this.community = null;
|
115
|
this.buildMenu();
|
116
|
this.loading = false;
|
117
|
}
|
118
|
}));
|
119
|
} else {
|
120
|
this.buildMenu();
|
121
|
this.loading = false;
|
122
|
}
|
123
|
} else {
|
124
|
this.communityService.setCommunity(null);
|
125
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
126
|
this.community = null;
|
127
|
this.buildMenu();
|
128
|
this.loading = false;
|
129
|
}
|
130
|
}
|
131
|
}));
|
132
|
this.subscriptions.push(this.data.subscribe(data => {
|
133
|
if(data && data.portal) {
|
134
|
this.setProperties(data.portal);
|
135
|
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
|
136
|
}
|
137
|
}));
|
138
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
139
|
this.user = user;
|
140
|
if (this.user) {
|
141
|
localStorage.setItem('user_id', this.user.id);
|
142
|
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
|
143
|
localStorage.setItem('isCommunityManager', Session.isCommunityCurator(this.user) + '');
|
144
|
this.buildMenu();
|
145
|
}
|
146
|
}));
|
147
|
}
|
148
|
|
149
|
@HostListener('window:resize', ['$event'])
|
150
|
onResize(event) {
|
151
|
if (this.layoutService.isSmallScreen && event.target.innerWidth > 1219) {
|
152
|
this.layoutService.setSmallScreen(false);
|
153
|
} else if (!this.layoutService.isSmallScreen && event.target.innerWidth < 1219) {
|
154
|
this.layoutService.setSmallScreen(true);
|
155
|
this.layoutService.setOpen(false);
|
156
|
}
|
157
|
}
|
158
|
|
159
|
public ngOnDestroy() {
|
160
|
this.subscriptions.forEach(value => {
|
161
|
if (value instanceof Subscriber) {
|
162
|
value.unsubscribe();
|
163
|
}
|
164
|
});
|
165
|
this.communityService.clearSubscriptions();
|
166
|
this.userManagementService.clearSubscriptions();
|
167
|
this.layoutService.clearSubscriptions();
|
168
|
this.smoothScroll.clearSubscriptions();
|
169
|
}
|
170
|
|
171
|
setProperties(id, type = null){
|
172
|
this.properties.adminToolsCommunity = id;
|
173
|
if(type) {
|
174
|
this.properties.adminToolsPortalType = type;
|
175
|
} else {
|
176
|
ConnectHelper.setPortalTypeFromPid(id);
|
177
|
}
|
178
|
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
|
179
|
}
|
180
|
|
181
|
public get open() {
|
182
|
return this.layoutService.open;
|
183
|
}
|
184
|
|
185
|
private buildMenu() {
|
186
|
this.menuItems = [];
|
187
|
this.userMenuItems = [];
|
188
|
this.sideBarItems = [];
|
189
|
if (this.user) {
|
190
|
if (this.isCurator()) {
|
191
|
this.userMenuItems.push(new MenuItem("", "Manage communities",
|
192
|
"", "/", false, [], [], {}));
|
193
|
}
|
194
|
if (Session.isPortalAdministrator(this.user)) {
|
195
|
this.userMenuItems.push(new MenuItem("adminOptions", "Super Admin options", "", "/admin-tools/portals", false, [], [], {}));
|
196
|
this.userMenuItems.push(new MenuItem("connectOptions", "Connect portal options", "", "/connect/admin-tools/pages", false, [], [], {}));
|
197
|
this.userMenuItems.push(new MenuItem("exploreOptions", "Explore portal options", "", "/openaire/admin-tools/pages", false, [], [], {}));
|
198
|
|
199
|
}
|
200
|
this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
|
201
|
}
|
202
|
if (this.community) {
|
203
|
this.headerLogoUrl = this.community.logoUrl;
|
204
|
this.headerUrl = 'https://' + ((properties.environment !== 'production')?'beta.':'') + this.community.communityId + '.openaire.eu';
|
205
|
this.menuHeader = {
|
206
|
route: "/" + this.community.communityId,
|
207
|
url: null,
|
208
|
title: 'Admin - ' + this.community.shortTitle,
|
209
|
logoUrl: null,
|
210
|
logoSmallUrl: null,
|
211
|
position: 'center',
|
212
|
badge: false,
|
213
|
stickyAnimation: false
|
214
|
};
|
215
|
this.sideBarItems.push(new MenuItem("community", "Community Info", "", "/" + this.community.communityId, false, [], [], {}, null, null, null, "/" + this.community.communityId + "/info"));
|
216
|
this.sideBarItems.push(new MenuItem("users", "Users", "", "/" + this.community.communityId + "/users", false, [], [], {}, null, null, null, "/" + this.community.communityId + "/users"));
|
217
|
this.sideBarItems.push(new MenuItem("admin-tools", "Pages & Entities", "", "/" + this.community.communityId + "/admin-tools/pages", false, [], [], {}, null, null, null, "/" + this.community.communityId + "/admin-tools"));
|
218
|
this.sideBarItems.push(new MenuItem("customization", "Customization", "", "/" + this.community.communityId + "/customize-layout", false, [], [], {}));
|
219
|
if (this.community.type === 'ri') {
|
220
|
this.sideBarItems.push(new MenuItem("mining", "Mining", "", "/" + this.community.communityId + "/mining/manage-profiles", false, [], [], {}, null, null, null, "/" + this.community.communityId + "/mining"));
|
221
|
}
|
222
|
this.specialSideBarMenuItem = new MenuItem("back", "Manage communities", "", "/", false, [], null, {});
|
223
|
this.specialSideBarMenuItem.icon = '<span class="uk-icon-button small uk-icon uk-button-secondary">' + arrow_left.data + '</span>';
|
224
|
this.specialSideBarMenuItem.customClass = 'uk-text-uppercase uk-text-bold uk-text-secondary';
|
225
|
} else {
|
226
|
this.headerLogoUrl = null;
|
227
|
this.headerUrl = 'https://' + ((properties.environment !== 'production')?'beta.':'') + 'connect.openaire.eu';
|
228
|
this.menuHeader = {
|
229
|
route: null,
|
230
|
url: null,
|
231
|
title: 'Admin - Research Community Dashboard',
|
232
|
logoUrl: null,
|
233
|
logoSmallUrl: null,
|
234
|
position: 'center',
|
235
|
badge: false,
|
236
|
stickyAnimation: false
|
237
|
};
|
238
|
this.sideBarItems.push(new MenuItem("communities", "Manage Communities", "", "/", false, [], [], {}));
|
239
|
this.specialSideBarMenuItem = null;
|
240
|
}
|
241
|
}
|
242
|
|
243
|
private isCurator() {
|
244
|
return this.user && (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isKindOfCommunityManager(this.user));
|
245
|
}
|
246
|
}
|