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