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
|
import {DataTableDirective} from 'angular-datatables';
|
6
|
|
7
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
8
|
import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service';
|
9
|
|
10
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
11
|
import {SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
12
|
|
13
|
|
14
|
@Component({
|
15
|
selector: 'manage-subscribers',
|
16
|
templateUrl: './manage-subscribers.component.html',
|
17
|
styles: [`
|
18
|
#dpTable_info, #dpTable_paginate, #dpTable_length, #dpTable_filter{
|
19
|
display: none;
|
20
|
}
|
21
|
`],
|
22
|
})
|
23
|
|
24
|
export class ManageSubscribersComponent implements OnInit {
|
25
|
|
26
|
public subscribers = null;
|
27
|
public res = null;
|
28
|
public properties: EnvProperties = null;
|
29
|
public communityId = null;
|
30
|
|
31
|
public subscribersSearchUtils: SearchUtilsClass = new SearchUtilsClass();
|
32
|
|
33
|
private errorCodes: ErrorCodes;
|
34
|
public rowsOnPage = 10;
|
35
|
|
36
|
dtOptions: DataTables.Settings = {};
|
37
|
showTable = false; filteringAdded = false;
|
38
|
// @ViewChild(DataTableDirective) datatableElement: DataTableDirective;
|
39
|
|
40
|
constructor (private route: ActivatedRoute,
|
41
|
private _router: Router,
|
42
|
public _fb: FormBuilder,
|
43
|
private _subscribeService: SubscribeService) {
|
44
|
|
45
|
this.errorCodes = new ErrorCodes();
|
46
|
this.subscribersSearchUtils.status = this.errorCodes.LOADING;
|
47
|
}
|
48
|
|
49
|
ngOnInit() {
|
50
|
|
51
|
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
52
|
this.properties = data.envSpecific;
|
53
|
this.route.queryParams.subscribe(
|
54
|
|
55
|
communityId => {
|
56
|
this.communityId = communityId['communityId'];
|
57
|
|
58
|
if (this.communityId != null && this.communityId != '') {
|
59
|
this._subscribeService.getCommunitySubscribers(this.communityId, this.properties.adminToolsAPIURL).subscribe(
|
60
|
res => {
|
61
|
this.res = res;
|
62
|
this.subscribersSearchUtils.totalResults = this.res.subscribers.length;
|
63
|
console.log(res);
|
64
|
console.log(this.subscribersSearchUtils.totalResults);
|
65
|
}
|
66
|
);
|
67
|
}
|
68
|
});
|
69
|
});
|
70
|
|
71
|
this.dtOptions = {
|
72
|
"info": false,
|
73
|
"paging": false,
|
74
|
"searching": false,
|
75
|
"lengthChange": false,
|
76
|
"pageLength": this.rowsOnPage,
|
77
|
"language": {
|
78
|
"search": "",
|
79
|
"searchPlaceholder": "Search subscribers..."
|
80
|
}
|
81
|
};
|
82
|
}
|
83
|
|
84
|
public goTo(page:number = 1) {
|
85
|
this.subscribersSearchUtils.page=page;
|
86
|
console.log("Page is: "+page);
|
87
|
// this._manageΖenodoCommunitieService.getZenodoCommunities(this.properties, this.properties.zenodoCommunities+"?page="+this.zenodoCommunitySearchUtils.page+"&size="+this.rowsOnPage).subscribe(
|
88
|
// zenodoCommunities => {
|
89
|
// this.zenodoCommunities = zenodoCommunities;
|
90
|
// console.log(zenodoCommunities);
|
91
|
// console.log(this.zenodoCommunitySearchUtils.page);
|
92
|
// });
|
93
|
}
|
94
|
|
95
|
totalPages(): number {
|
96
|
let totalPages:any = this.subscribersSearchUtils.totalResults/(this.rowsOnPage);
|
97
|
if(!(Number.isInteger(totalPages))) {
|
98
|
totalPages = (parseInt(totalPages, 10) + 1);
|
99
|
}
|
100
|
return totalPages;
|
101
|
}
|
102
|
|
103
|
public removeSubscriber(email:string) {
|
104
|
console.log(email);
|
105
|
this._subscribeService.unSubscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe(
|
106
|
result => {
|
107
|
this._subscribeService.getCommunitySubscribers(this.communityId, this.properties.adminToolsAPIURL).subscribe(
|
108
|
res => {
|
109
|
this.res = res;
|
110
|
this.subscribersSearchUtils.totalResults = this.res.subscribers.length;
|
111
|
}
|
112
|
);
|
113
|
}
|
114
|
)
|
115
|
}
|
116
|
}
|