1
|
import {Component, ViewChild, OnInit, Input, ElementRef, OnDestroy} from '@angular/core';
|
2
|
import { ActivatedRoute, Router } from '@angular/router';
|
3
|
|
4
|
import {ManageZenodoCommunitiesComponent} from './manage-zenodo-communities.component';
|
5
|
import {AddZenodoCommunitiesComponent} from './add-zenodo-communities.component';
|
6
|
|
7
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
8
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
9
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
10
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
11
|
import { SearchZenodoCommunitiesService } from '../../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
12
|
|
13
|
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
|
14
|
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
|
15
|
import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
16
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
17
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
18
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
19
|
import {Title} from '@angular/platform-browser';
|
20
|
|
21
|
@Component({
|
22
|
selector: 'zenodo-communities',
|
23
|
template: `
|
24
|
<div id="manage-communities">
|
25
|
<div class="menubar uk-margin-bottom ">
|
26
|
<a *ngIf="!toggle" (click)="toggleAction()" class="uk-button uk-button-primary uk-float-right">{{toggleLinkMessage}}</a>
|
27
|
<div class="manage-projects-title uk-text-large">{{pageTitle}}</div>
|
28
|
</div>
|
29
|
|
30
|
<div *ngIf="toggle" >
|
31
|
<div *ngIf="zenodoSearchUtils.status == errorCodes.LOADING "
|
32
|
class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert">
|
33
|
<span class="loading-gif uk-align-center" ></span>
|
34
|
</div>
|
35
|
<div *ngIf="zenodoSearchUtils.status == errorCodes.ERROR "
|
36
|
class="uk-animation-fade uk-margin-top uk-width-1-1 uk-alert uk-alert-warning" role="alert">
|
37
|
No zenodo communities found
|
38
|
</div>
|
39
|
|
40
|
<manage-zenodo-communities *ngIf="zenodoSearchUtils.status != errorCodes.LOADING && zenodoSearchUtils.status != errorCodes.ERROR" [masterCommunity]=masterZenodoCommunity [(selectedCommunities)]=selectedCommunities [properties]=properties [communityId]=communityId [(searchUtils)]=zenodoSearchUtils></manage-zenodo-communities>
|
41
|
<fab *ngIf="zenodoSearchUtils.status != errorCodes.LOADING && zenodoSearchUtils.status != errorCodes.ERROR" (clicked)="toggleAction()" ></fab>
|
42
|
</div>
|
43
|
<div *ngIf="!toggle" >
|
44
|
<add-zenodo-communities [masterCommunity]=masterZenodoCommunity [(selectedCommunities)]=selectedCommunities [properties]=properties [communityId]=communityId ></add-zenodo-communities>
|
45
|
</div>
|
46
|
</div>
|
47
|
`
|
48
|
})
|
49
|
|
50
|
export class ZenodoCommunitiesComponent implements OnInit, OnDestroy {
|
51
|
private communityId: string = null;
|
52
|
private community: CommunityInfo = null;
|
53
|
|
54
|
@Input() communityProjects = [];
|
55
|
@ViewChild (ManageZenodoCommunitiesComponent) manageZenodoCommunitiesComponent: ManageZenodoCommunitiesComponent ;
|
56
|
@ViewChild (AddZenodoCommunitiesComponent) addZenodoCommunitiesComponent: AddZenodoCommunitiesComponent ;
|
57
|
|
58
|
public warningMessage = '';
|
59
|
public infoMessage = '';
|
60
|
|
61
|
public toggle = true;
|
62
|
public updateCommunityProjectsOnToggle = false;
|
63
|
public pageTitle = 'Manage zenodo communities';
|
64
|
public toggleLinkMessage = 'Manage zenodo communities';
|
65
|
|
66
|
masterZenodoCommunityId = null;
|
67
|
masterZenodoCommunity = null;
|
68
|
public properties: EnvProperties = null;
|
69
|
|
70
|
selectedCommunityIds = null;
|
71
|
// ["ecfunded", "zenodo", "lory_hslu", "cs19", "",
|
72
|
// "hbp","dighl", "wind_energy", "lory", "fp7-bmc","fp7postgrantoapilotoutputs","cernopenlab"];
|
73
|
selectedCommunities = [];
|
74
|
|
75
|
zenodocommunitiesloadedCount = 0;
|
76
|
zenodoSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
77
|
private errorCodes: ErrorCodes = new ErrorCodes();
|
78
|
|
79
|
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
|
80
|
private _ΖenodoCommunitieService: ZenodoCommunitiesService, private title: Title,
|
81
|
private _communityService: CommunityService,
|
82
|
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {}
|
83
|
|
84
|
ngOnInit() {
|
85
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
86
|
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
87
|
this.properties = data.envSpecific;
|
88
|
this.route.queryParams.subscribe(params => {
|
89
|
HelperFunctions.scroll();
|
90
|
|
91
|
if (params['communityId']) {
|
92
|
this.communityId = params['communityId'];
|
93
|
this.title.setTitle('Administration Dashboard | Zenodo Communities');
|
94
|
if (!Session.isLoggedIn()) {
|
95
|
this._router.navigate(['/user-info'], {
|
96
|
queryParams: { 'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} });
|
97
|
} else {
|
98
|
if (this.communityId != null && this.communityId !== '') {
|
99
|
|
100
|
this._communityService.getCommunity(this.properties,
|
101
|
this.properties.communityAPI + this.communityId).subscribe (
|
102
|
community => {
|
103
|
this.community = community;
|
104
|
this.masterZenodoCommunityId = this.community.zenodoCommunity;
|
105
|
if (this.masterZenodoCommunityId) {
|
106
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties,
|
107
|
this.properties.zenodoCommunities + this.masterZenodoCommunityId,
|
108
|
null).subscribe(
|
109
|
result => {
|
110
|
this.masterZenodoCommunity = result;
|
111
|
|
112
|
},
|
113
|
error => {
|
114
|
const emptyCommunity: ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
115
|
emptyCommunity.id = this.masterZenodoCommunityId;
|
116
|
emptyCommunity.title = this.masterZenodoCommunityId;
|
117
|
this.masterZenodoCommunity = emptyCommunity;
|
118
|
// console.log("Master Zenodo community'"+this.masterZenodoCommunityId+"' couldn't be loaded");
|
119
|
}
|
120
|
);
|
121
|
}
|
122
|
this.zenodoSearchUtils.status = this.errorCodes.LOADING;
|
123
|
this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe (
|
124
|
result => {
|
125
|
this.selectedCommunityIds = result;
|
126
|
this.zenodoSearchUtils.totalResults = this.selectedCommunityIds.length;
|
127
|
if (this.selectedCommunityIds.length === 0) {
|
128
|
this.zenodoSearchUtils.status = this.errorCodes.NONE;
|
129
|
}
|
130
|
for (let i = 0; i < this.selectedCommunityIds.length; i++) {
|
131
|
this.getZenodoCommunityById(
|
132
|
this.selectedCommunityIds[i]['zenodoid'],
|
133
|
this.selectedCommunityIds[i]['id']);
|
134
|
}
|
135
|
|
136
|
},
|
137
|
error => {
|
138
|
console.log('list of zenodo communities couldn\'t be loaded');
|
139
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
140
|
} // this.handleError('System error retrieving community profile', error)
|
141
|
);
|
142
|
|
143
|
},
|
144
|
error => {
|
145
|
console.log('Community couldn\'t be loaded');
|
146
|
this.zenodoSearchUtils.status = this.errorCodes.ERROR;
|
147
|
}
|
148
|
);
|
149
|
|
150
|
|
151
|
}
|
152
|
}
|
153
|
|
154
|
|
155
|
}
|
156
|
});
|
157
|
});
|
158
|
}
|
159
|
|
160
|
|
161
|
|
162
|
public ngOnDestroy() {}
|
163
|
|
164
|
public toggleAction() {
|
165
|
if (!Session.isLoggedIn()) {
|
166
|
this._router.navigate(['/user-info'], {
|
167
|
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} });
|
168
|
} else {
|
169
|
HelperFunctions.scroll();
|
170
|
|
171
|
this.toggle = !this.toggle;
|
172
|
if (this.toggle) {
|
173
|
this.pageTitle = 'Manage zenodo communities';
|
174
|
|
175
|
} else {
|
176
|
this.updateCommunityProjectsOnToggle = false;
|
177
|
this.pageTitle = 'Search zenodo communities';
|
178
|
}
|
179
|
}
|
180
|
}
|
181
|
|
182
|
getZenodoCommunityById(zenodoid, openaireId) {
|
183
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties,
|
184
|
this.properties.zenodoCommunities + zenodoid, openaireId).subscribe(
|
185
|
result => {
|
186
|
this.selectedCommunities.push(result);
|
187
|
this.zenodocommunitiesloadedCount++;
|
188
|
if (this.zenodocommunitiesloadedCount >= this.selectedCommunityIds.length) {
|
189
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
190
|
}
|
191
|
|
192
|
|
193
|
},
|
194
|
error => {
|
195
|
const emptyCommunity: ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
196
|
emptyCommunity.id = zenodoid;
|
197
|
emptyCommunity.openaireId = openaireId;
|
198
|
emptyCommunity.title = zenodoid;
|
199
|
this.selectedCommunities.push(emptyCommunity);
|
200
|
this.zenodocommunitiesloadedCount++;
|
201
|
if (this.zenodocommunitiesloadedCount >= this.selectedCommunityIds.length) {
|
202
|
this.zenodoSearchUtils.status = this.errorCodes.DONE;
|
203
|
}
|
204
|
console.log('Zenodo community\'' + zenodoid + '\' couldn\'t be loaded');
|
205
|
}
|
206
|
);
|
207
|
}
|
208
|
}
|