5 |
5 |
|
6 |
6 |
import {HelpContentService} from "../../../services/help-content.service";
|
7 |
7 |
import {CommunityService} from "../../../openaireLibrary/connect/community/community.service";
|
|
8 |
import {SubscribeService} from "../../../openaireLibrary/utils/subscribe/subscribe.service"
|
8 |
9 |
import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties';
|
9 |
10 |
|
10 |
11 |
import {CommunityInfo} from '../../../openaireLibrary/connect/community/communityInfo';
|
... | ... | |
34 |
35 |
|
35 |
36 |
public communityId = null;
|
36 |
37 |
public community = null;
|
37 |
|
public previousVersionOfManagers = null;
|
38 |
|
public changedManagers = null;
|
|
38 |
public firstVersionOfManagers: string[];
|
|
39 |
public newManagersToSubscribe: string[];
|
|
40 |
|
39 |
41 |
public properties:EnvProperties = null;
|
40 |
42 |
|
41 |
43 |
constructor (private route: ActivatedRoute,
|
42 |
44 |
private _router: Router,
|
43 |
45 |
public _fb: FormBuilder,
|
44 |
46 |
private _helpContentService: HelpContentService,
|
45 |
|
private _communityService: CommunityService){ }
|
|
47 |
private _communityService: CommunityService,
|
|
48 |
private _subscribeService: SubscribeService){ }
|
46 |
49 |
|
47 |
50 |
|
48 |
51 |
ngOnInit() {
|
... | ... | |
61 |
64 |
community => {
|
62 |
65 |
this.community = community;
|
63 |
66 |
this.params = {community: encodeURIComponent('"'+community.queryId+'"')};
|
64 |
|
this.previousVersionOfManagers = new Array<string>();
|
65 |
|
this.previousVersionOfManagers = community.managers;
|
66 |
|
// TODO remove after testing!!!!!!!
|
67 |
|
console.log("Previous version of managers: " + this.previousVersionOfManagers);
|
|
67 |
this.firstVersionOfManagers = community.managers.slice();
|
|
68 |
console.log("First version of managers " + this.firstVersionOfManagers);
|
68 |
69 |
console.log(community);
|
69 |
70 |
this.showLoading = false;
|
70 |
71 |
},
|
... | ... | |
122 |
123 |
if (!this.hasValidEmail(community) || !this.hasFilled(community["name"])) {
|
123 |
124 |
this._router.navigate(['/community-edit-form'], {queryParams: { "communityId": this.communityId}});
|
124 |
125 |
} else {
|
|
126 |
var newManagers = this.getNewManagers();
|
125 |
127 |
this._communityService.updateCommunity(this.properties.communityAPI+this.communityId, community).subscribe(
|
126 |
128 |
|
127 |
129 |
community => {
|
128 |
|
if (this.managersHaveChanged()) {
|
129 |
|
console.log("Changed Managers" + this.changedManagers)
|
|
130 |
// TODO delete after testing
|
|
131 |
console.log("New managers in component: " + newManagers);
|
|
132 |
if (newManagers !== null) {
|
|
133 |
for (let i = 0; i < newManagers.length; i++) {
|
|
134 |
console.log(newManagers[i]);
|
|
135 |
this._subscribeService.subscribeToCommunity(this.communityId, newManagers[i], this.properties.adminToolsAPIURL).subscribe(
|
|
136 |
res => {
|
|
137 |
console.log(res);
|
|
138 |
}
|
|
139 |
);
|
|
140 |
this._subscribeService.getCommunitySubscribers(this.communityId, this.properties.adminToolsAPIURL).subscribe(
|
|
141 |
res => {
|
|
142 |
console.log(res);
|
|
143 |
}
|
|
144 |
);
|
|
145 |
}
|
130 |
146 |
}
|
131 |
147 |
this.handleSuccessfulSave('Community saved!')
|
132 |
148 |
},
|
133 |
149 |
error => {
|
134 |
150 |
this.handleUpdateError('System error updating community profile', error)
|
135 |
|
}
|
|
151 |
},
|
|
152 |
() => { this.firstVersionOfManagers = this.community["managers"].slice(); }
|
136 |
153 |
);
|
137 |
154 |
this._router.navigate(['/community-edit-form'], {queryParams: { "communityId": this.communityId}});
|
138 |
155 |
}
|
... | ... | |
157 |
174 |
return community;
|
158 |
175 |
}
|
159 |
176 |
|
160 |
|
private managersHaveChanged(): boolean {
|
161 |
|
let length = this.community['managers'].length;
|
162 |
|
let hasChanged = false;
|
|
177 |
private getNewManagers(): Array<string> {
|
163 |
178 |
|
164 |
|
console.log("mphka!!!");
|
165 |
|
|
166 |
|
let j = 0;
|
167 |
|
for (let i = 0; i<length; i++) {
|
168 |
|
console.log("this.previousVersionOfManagers[i]:" + this.previousVersionOfManagers[i]);
|
169 |
|
console.log("this.community['managers'][i]):" + this.community['managers'][i]);
|
170 |
|
if (this.previousVersionOfManagers[i] != this.community['managers'][i]) {
|
171 |
|
this.changedManagers[j] = this.previousVersionOfManagers[i];
|
172 |
|
j++;
|
173 |
|
console.log("Ginomai trueee!!!");
|
174 |
|
hasChanged = true;
|
|
179 |
let newManagers = null;
|
|
180 |
for (let i = 0; i < this.community['managers'].length; i++) {
|
|
181 |
if (!this.firstVersionOfManagers.includes(this.community['managers'][i])) {
|
|
182 |
if(newManagers === null){
|
|
183 |
newManagers = new Array<string>();
|
|
184 |
}
|
|
185 |
newManagers.push(this.community['managers'][i]);
|
175 |
186 |
}
|
176 |
187 |
}
|
177 |
|
return hasChanged;
|
|
188 |
console.log("New managers are: " + newManagers);
|
|
189 |
return newManagers;
|
178 |
190 |
}
|
179 |
191 |
|
|
192 |
private subscribeNewManagers(newManagers: string[]): boolean {
|
|
193 |
return true;
|
|
194 |
}
|
180 |
195 |
|
181 |
196 |
private getNonEmptyItems(data: string[]): string[] {
|
182 |
197 |
let length = data.length;
|
Keep new managers in an array and subscribe them to the community at community-edit-form page