1 |
53925
|
argiro.kok
|
import {Component, OnInit, Input, ViewChild, ViewEncapsulation} from '@angular/core';
|
2 |
53600
|
argiro.kok
|
import {SimpleChanges, OnChanges} from '@angular/core';
|
3 |
|
|
import {FormGroup, FormArray, FormBuilder, Validators} from '@angular/forms';
|
4 |
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
5 |
55972
|
argiro.kok
|
import { Subject } from 'rxjs';
|
6 |
53600
|
argiro.kok
|
|
7 |
53905
|
argiro.kok
|
import { DataTableDirective } from 'angular-datatables';
|
8 |
|
|
|
9 |
53600
|
argiro.kok
|
import {HelpContentService} from '../../services/help-content.service';
|
10 |
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
11 |
|
|
|
12 |
|
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
13 |
|
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
14 |
53905
|
argiro.kok
|
import {ZenodoCommunitiesService} from '../../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
15 |
|
|
import {ZenodoCommunityInfo} from '../../openaireLibrary/connect/zenodoCommunities/zenodoCommunityInfo';
|
16 |
53600
|
argiro.kok
|
|
17 |
53735
|
konstantin
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
18 |
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
19 |
53905
|
argiro.kok
|
import{ManageZenodoCommunitiesService} from '../../services/manageZenodoCommunities.service';
|
20 |
53735
|
konstantin
|
|
21 |
53600
|
argiro.kok
|
@Component({
|
22 |
|
|
selector: 'manage-zenodo-communities',
|
23 |
|
|
templateUrl: './manage-zenodo-communities.component.html',
|
24 |
53905
|
argiro.kok
|
styles: [`
|
25 |
|
|
#dpTable_info, #dpTable_paginate, #dpTable_length, #dpTable_filter{
|
26 |
|
|
display: none;
|
27 |
|
|
}
|
28 |
|
|
|
29 |
53925
|
argiro.kok
|
`],
|
30 |
|
|
encapsulation: ViewEncapsulation.None // this used in order styles to work
|
31 |
53600
|
argiro.kok
|
})
|
32 |
|
|
|
33 |
|
|
export class ManageZenodoCommunitiesComponent implements OnInit {
|
34 |
53905
|
argiro.kok
|
@Input() properties:EnvProperties = null;
|
35 |
|
|
@Input() communityId = null;
|
36 |
53600
|
argiro.kok
|
|
37 |
53925
|
argiro.kok
|
@Input() searchUtils:SearchUtilsClass = null;
|
38 |
53600
|
argiro.kok
|
|
39 |
56471
|
argiro.kok
|
errorCodes: ErrorCodes;
|
40 |
53600
|
argiro.kok
|
public rowsOnPage = 10;
|
41 |
53905
|
argiro.kok
|
@Input() masterCommunity = null;
|
42 |
|
|
@Input() selectedCommunities = [];
|
43 |
53600
|
argiro.kok
|
|
44 |
53905
|
argiro.kok
|
@ViewChild(DataTableDirective) datatableElement: DataTableDirective;
|
45 |
|
|
dtTrigger: Subject<any> = new Subject(); //necessary
|
46 |
|
|
dtOptions: DataTables.Settings = {};
|
47 |
|
|
private triggered: boolean = false;
|
48 |
|
|
|
49 |
|
|
@ViewChild('AlertModalDeleteCommunity') alertModalDeleteCommunity;
|
50 |
|
|
selectedToDelete = null;
|
51 |
53600
|
argiro.kok
|
constructor (private route: ActivatedRoute,
|
52 |
|
|
private _router: Router,
|
53 |
|
|
public _fb: FormBuilder,
|
54 |
|
|
private _helpContentService: HelpContentService,
|
55 |
53905
|
argiro.kok
|
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
|
56 |
|
|
private _manageZenodoCommunitiesService: ManageZenodoCommunitiesService) {
|
57 |
53600
|
argiro.kok
|
|
58 |
|
|
this.errorCodes = new ErrorCodes();
|
59 |
53925
|
argiro.kok
|
|
60 |
53600
|
argiro.kok
|
}
|
61 |
|
|
|
62 |
|
|
ngOnInit() {
|
63 |
|
|
|
64 |
53905
|
argiro.kok
|
|
65 |
53925
|
argiro.kok
|
this.searchUtils.keyword = "";
|
66 |
53905
|
argiro.kok
|
this.dtOptions = {
|
67 |
|
|
// "paging": true,
|
68 |
|
|
// "searching": true,
|
69 |
|
|
// "lengthChange": false,
|
70 |
|
|
"pageLength": this.rowsOnPage,
|
71 |
|
|
"language": {
|
72 |
|
|
"search": "",
|
73 |
|
|
"searchPlaceholder": "Search projects..."
|
74 |
53925
|
argiro.kok
|
}
|
75 |
53600
|
argiro.kok
|
|
76 |
53905
|
argiro.kok
|
};
|
77 |
|
|
if(!this.triggered) {
|
78 |
|
|
this.triggerInitialLoad();
|
79 |
|
|
} else {
|
80 |
|
|
var table = $('#dpTable').DataTable();
|
81 |
|
|
table.clear();
|
82 |
|
|
|
83 |
|
|
this.rerender();
|
84 |
|
|
}
|
85 |
|
|
|
86 |
53925
|
argiro.kok
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
87 |
53905
|
argiro.kok
|
}
|
88 |
|
|
|
89 |
|
|
public ngOnDestroy() {
|
90 |
|
|
|
91 |
|
|
$.fn['dataTable'].ext.search.pop();
|
92 |
|
|
}
|
93 |
|
|
rerender(): void {
|
94 |
53925
|
argiro.kok
|
if(this.datatableElement.dtInstance){
|
95 |
|
|
this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
|
96 |
|
|
// Destroy the table first
|
97 |
|
|
dtInstance.destroy();
|
98 |
53905
|
argiro.kok
|
|
99 |
53925
|
argiro.kok
|
// Call the dtTrigger to rerender again
|
100 |
|
|
this.dtTrigger.next();
|
101 |
|
|
});
|
102 |
|
|
}
|
103 |
53905
|
argiro.kok
|
}
|
104 |
|
|
|
105 |
|
|
ngAfterViewInit(): void {
|
106 |
|
|
$.fn['dataTable'].ext.search.push((settings, data, dataIndex) => {
|
107 |
|
|
|
108 |
53925
|
argiro.kok
|
if (this.filterData(data, this.searchUtils.keyword )) {
|
109 |
53905
|
argiro.kok
|
return true;
|
110 |
|
|
}
|
111 |
|
|
return false;
|
112 |
|
|
});
|
113 |
|
|
|
114 |
54788
|
konstantin
|
//console.info("ngAfterViewInit");
|
115 |
53925
|
argiro.kok
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
116 |
|
|
|
117 |
53905
|
argiro.kok
|
}
|
118 |
|
|
|
119 |
|
|
filterData(row: any, query: string) {
|
120 |
|
|
let returnValue: boolean = false;
|
121 |
|
|
|
122 |
|
|
if(query) {
|
123 |
|
|
for(var i=0; i <3; i++){
|
124 |
|
|
var r= this.filterQuery(row[i], query);
|
125 |
|
|
if(r) {
|
126 |
|
|
returnValue = true;
|
127 |
|
|
break;
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
if(!returnValue) {
|
132 |
|
|
return false;
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
return true;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
filterQuery(data, query){
|
140 |
|
|
if(data.toLowerCase().indexOf(query.toLowerCase()) > -1){
|
141 |
|
|
return true;
|
142 |
|
|
}else{
|
143 |
|
|
return false;
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
/*
|
149 |
|
|
Trigger a table draw in order to get the initial filtering
|
150 |
|
|
*/
|
151 |
|
|
triggerInitialLoad(){
|
152 |
|
|
this.triggered = true;
|
153 |
54788
|
konstantin
|
//console.info("triggerInitialLoad");
|
154 |
53905
|
argiro.kok
|
setTimeout(function(){
|
155 |
|
|
var table = (<any>$('#dpTable')).DataTable();
|
156 |
|
|
table.page( 0 ).draw( false );
|
157 |
|
|
}, 500);
|
158 |
|
|
this.dtTrigger.next();
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
goTo(page:number = 1){
|
162 |
53925
|
argiro.kok
|
this.searchUtils.page=page;
|
163 |
53905
|
argiro.kok
|
|
164 |
|
|
var table = $('#dpTable').DataTable();
|
165 |
|
|
table.page( page - 1 ).draw( false );
|
166 |
|
|
|
167 |
|
|
var info = table.page.info();
|
168 |
53925
|
argiro.kok
|
this.searchUtils.totalResults = info.recordsDisplay;
|
169 |
53905
|
argiro.kok
|
}
|
170 |
|
|
|
171 |
|
|
public confirmedDeleteCommunity(data : any) {
|
172 |
53925
|
argiro.kok
|
|
173 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
174 |
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
175 |
|
|
} else {
|
176 |
53905
|
argiro.kok
|
this._manageZenodoCommunitiesService.removeZCommunity(this.properties, this.communityId,this.selectedToDelete.openaireId ).subscribe(
|
177 |
|
|
data => {
|
178 |
|
|
var pos = -1;
|
179 |
|
|
for(var i=0; i< this.selectedCommunities.length;i++) {
|
180 |
|
|
if( this.selectedCommunities[i].id == this.selectedToDelete.id) {
|
181 |
|
|
pos= i;
|
182 |
|
|
break;
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
if(pos != -1){
|
186 |
|
|
this.selectedCommunities.splice(pos, 1);
|
187 |
53925
|
argiro.kok
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
188 |
53905
|
argiro.kok
|
}
|
189 |
53925
|
argiro.kok
|
this.searchUtils.totalResults = this.selectedCommunities.length;
|
190 |
53905
|
argiro.kok
|
var table = $('#dpTable').DataTable();
|
191 |
|
|
table.clear();
|
192 |
|
|
this.rerender();
|
193 |
|
|
|
194 |
|
|
},
|
195 |
|
|
err => {
|
196 |
|
|
console.log(err.status);
|
197 |
54788
|
konstantin
|
}/*,
|
198 |
53905
|
argiro.kok
|
() => {
|
199 |
|
|
console.info("completed remove");
|
200 |
54788
|
konstantin
|
}*/
|
201 |
53905
|
argiro.kok
|
)
|
202 |
53735
|
konstantin
|
}
|
203 |
53600
|
argiro.kok
|
}
|
204 |
|
|
|
205 |
53905
|
argiro.kok
|
public removeCommunity( comm) {
|
206 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
207 |
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
208 |
|
|
} else {
|
209 |
53905
|
argiro.kok
|
this.selectedToDelete = comm;
|
210 |
|
|
this.alertModalDeleteCommunity.cancelButton = true;
|
211 |
|
|
this.alertModalDeleteCommunity.okButton = true;
|
212 |
|
|
this.alertModalDeleteCommunity.alertTitle = "Remove zenodo community?";
|
213 |
|
|
let title = "";
|
214 |
|
|
if(comm.title) {
|
215 |
|
|
title = comm.title;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
this.alertModalDeleteCommunity.message = "Zenodo community";
|
220 |
|
|
if(title) {
|
221 |
|
|
this.alertModalDeleteCommunity.message += " '"+title+"' ";
|
222 |
|
|
}
|
223 |
|
|
this.alertModalDeleteCommunity.message += "will be removed from your community. Are you sure?";
|
224 |
|
|
this.alertModalDeleteCommunity.okButtonText = "Yes";
|
225 |
|
|
this.alertModalDeleteCommunity.open();
|
226 |
53735
|
konstantin
|
}
|
227 |
53600
|
argiro.kok
|
}
|
228 |
|
|
|
229 |
53905
|
argiro.kok
|
|
230 |
53925
|
argiro.kok
|
totalPages(): number {
|
231 |
|
|
let totalPages:any = this.searchUtils.totalResults/(this.rowsOnPage);
|
232 |
|
|
if(!(Number.isInteger(totalPages))) {
|
233 |
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
234 |
|
|
}
|
235 |
|
|
return totalPages;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
|
239 |
53600
|
argiro.kok
|
}
|