1
|
import {Component, OnInit, Input} from '@angular/core';
|
2
|
import {SimpleChanges, OnChanges} from '@angular/core';
|
3
|
import {FormGroup, FormArray, FormBuilder, Validators} from '@angular/forms';
|
4
|
import {ActivatedRoute, Router} from '@angular/router';
|
5
|
|
6
|
import {HelpContentService} from '../../services/help-content.service';
|
7
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
8
|
|
9
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
10
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
11
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
12
|
import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
13
|
|
14
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
15
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
16
|
import{ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service';
|
17
|
@Component({
|
18
|
selector: 'add-zenodo-communities',
|
19
|
templateUrl: './add-zenodo-communities.component.html',
|
20
|
})
|
21
|
|
22
|
export class AddZenodoCommunitiesComponent implements OnInit {
|
23
|
|
24
|
public zenodoCommunities = null; // zenodo search API results
|
25
|
public totalZenodoCommunities = null;
|
26
|
@Input() properties:EnvProperties = null;
|
27
|
@Input() communityId = null;
|
28
|
|
29
|
public zenodoCommunitySearchUtils:SearchUtilsClass = new SearchUtilsClass();
|
30
|
|
31
|
private errorCodes: ErrorCodes;
|
32
|
public rowsOnPage = 10;
|
33
|
@Input() masterCommunity = null;
|
34
|
@Input() selectedCommunities = [];
|
35
|
constructor (private route: ActivatedRoute,
|
36
|
private _router: Router,
|
37
|
public _fb: FormBuilder,
|
38
|
private _helpContentService: HelpContentService,
|
39
|
private _zenodoCommunitieService: ZenodoCommunitiesService,
|
40
|
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
|
41
|
|
42
|
this.errorCodes = new ErrorCodes();
|
43
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.LOADING;
|
44
|
}
|
45
|
|
46
|
ngOnInit() {
|
47
|
this.zenodoCommunitySearchUtils.keyword = "";
|
48
|
if(!Session.isLoggedIn()){
|
49
|
console.info(this._router.url);
|
50
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
51
|
} else {
|
52
|
if (this.communityId != null && this.communityId != '') {
|
53
|
this._zenodoCommunitieService.getZenodoCommunities(this.properties, this.properties.zenodoCommunities+"?page="+this.zenodoCommunitySearchUtils.page+"&size="+this.rowsOnPage).subscribe(
|
54
|
result => {
|
55
|
this.zenodoCommunities = result[0];
|
56
|
this.totalZenodoCommunities = result[1];
|
57
|
this.zenodoCommunitySearchUtils.totalResults = result[1];
|
58
|
this.zenodoCommunitySearchUtils.page = 1;
|
59
|
this.zenodoCommunitySearchUtils.size =this.rowsOnPage;
|
60
|
if(this.totalZenodoCommunities == 0){
|
61
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.NONE;
|
62
|
}else{
|
63
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.DONE;
|
64
|
}
|
65
|
|
66
|
},
|
67
|
error => {
|
68
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.ERROR;
|
69
|
}
|
70
|
);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
}
|
75
|
|
76
|
public goTo(page:number = 1) {
|
77
|
if(!Session.isLoggedIn()){
|
78
|
console.info(this._router.url);
|
79
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
80
|
} else {
|
81
|
this.zenodoCommunitySearchUtils.page=page;
|
82
|
this._zenodoCommunitieService.getZenodoCommunities(this.properties,
|
83
|
this.properties.zenodoCommunities+"?page="+this.zenodoCommunitySearchUtils.page
|
84
|
+"&size="+this.rowsOnPage
|
85
|
+((this.zenodoCommunitySearchUtils.keyword)?("&q="+this.zenodoCommunitySearchUtils.keyword):"")
|
86
|
).subscribe(
|
87
|
result => {
|
88
|
this.zenodoCommunities = result[0];
|
89
|
this.totalZenodoCommunities = result[1];
|
90
|
this.zenodoCommunitySearchUtils.totalResults = result[1];
|
91
|
this.zenodoCommunitySearchUtils.size =this.rowsOnPage;
|
92
|
if(this.totalZenodoCommunities == 0){
|
93
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.NONE;
|
94
|
}else{
|
95
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.DONE;
|
96
|
}
|
97
|
|
98
|
},
|
99
|
error => {
|
100
|
this.zenodoCommunitySearchUtils.status = this.errorCodes.ERROR;
|
101
|
}
|
102
|
);
|
103
|
}
|
104
|
}
|
105
|
|
106
|
totalPages(): number {
|
107
|
let totalPages:any = this.zenodoCommunitySearchUtils.totalResults/(this.rowsOnPage);
|
108
|
if(!(Number.isInteger(totalPages))) {
|
109
|
totalPages = (parseInt(totalPages, 10) + 1);
|
110
|
}
|
111
|
return totalPages;
|
112
|
}
|
113
|
|
114
|
|
115
|
public addCommunity(community) {
|
116
|
if(!Session.isLoggedIn()){
|
117
|
console.info(this._router.url);
|
118
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
119
|
} else {
|
120
|
this._manageZenodoCommunitiesService.addZCommunity(this.properties, this.communityId, community.id ).subscribe(
|
121
|
data => {
|
122
|
console.info("data ADD");
|
123
|
console.info(data);
|
124
|
// this.undo[project.id] = data.id;
|
125
|
community["openaireId"]=data.id;
|
126
|
this.selectedCommunities.push(community);
|
127
|
},
|
128
|
err => {
|
129
|
console.info("error ADD");
|
130
|
console.log(err.status);
|
131
|
},
|
132
|
() => {
|
133
|
console.info("completed ADD");
|
134
|
}
|
135
|
)
|
136
|
}
|
137
|
}
|
138
|
|
139
|
/* public removeCommunity( comm) {
|
140
|
if(!Session.isLoggedIn()){
|
141
|
console.info(this._router.url);
|
142
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
143
|
} else {
|
144
|
var openaireId = this.getOpenaireId(comm);
|
145
|
this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.communityId,openaireId, ).subscribe(
|
146
|
data => {
|
147
|
console.log(this.selectedCommunities.length);
|
148
|
console.info("REMOVE: "+ this.communityId + " "+openaireId);
|
149
|
console.log(comm);
|
150
|
var pos = -1;
|
151
|
for(var i=0; i< this.selectedCommunities.length;i++) {
|
152
|
console.info(this.selectedCommunities[i].id+ " "+ this.selectedCommunities[i].openaireId+" "+ comm.id);
|
153
|
if( this.selectedCommunities[i].id == comm.id) {
|
154
|
pos= i;
|
155
|
break;
|
156
|
}
|
157
|
}
|
158
|
console.log(pos);
|
159
|
if(pos != -1){
|
160
|
this.selectedCommunities.splice(pos, 1);
|
161
|
}
|
162
|
console.log(this.selectedCommunities.length);
|
163
|
|
164
|
},
|
165
|
err => {
|
166
|
console.info("error remove");
|
167
|
console.log(err.status);
|
168
|
},
|
169
|
() => {
|
170
|
console.info("completed remove");
|
171
|
}
|
172
|
)
|
173
|
}
|
174
|
}*/
|
175
|
|
176
|
public inCommunity(community: any): any {
|
177
|
for(let com of this.selectedCommunities) {
|
178
|
if(com.id == community.id) {
|
179
|
return true;
|
180
|
}
|
181
|
}
|
182
|
return false;
|
183
|
}
|
184
|
public getOpenaireId(community: any): string {
|
185
|
for(let com of this.selectedCommunities) {
|
186
|
if(com.id == community.id) {
|
187
|
return com.openaireId;
|
188
|
}
|
189
|
}
|
190
|
return null;
|
191
|
}
|
192
|
}
|