[Admin | Trunk]: Personal info add getCurators function to avoid duplicate code

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@59485 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-09-28 12:12:27 +00:00
parent 316bdbbaf6
commit ada1b125c4
1 changed files with 42 additions and 65 deletions

View File

@ -25,8 +25,8 @@ export class CuratorComponent implements OnInit {
public updateErrorMessage = '';
public successfulSaveMessage = '';
public curatorsEnabled;
public newCurator;
public curatorsEnabled = false;
public newCurator = false;
public communityId = null;
@ -71,37 +71,10 @@ export class CuratorComponent implements OnInit {
this.updateErrorMessage = '';
this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
this.curatorId = this.user.id;
this.curatorService.getCurator(this.properties, this.curatorId).subscribe(
curator => {
if (curator && Object.keys(curator).length > 0) {
this.curator = curator;
this.curator.email = this.user.email;
if (this.curator.photo && this.curator.photo !== '') {
this.photo = this.properties.utilsService + '/download/' + this.curator.photo;
} else {
this.photo = 'assets/common-assets/curator-default.png';
}
this.curatorsPageStatus();
this.showLoading = false;
HelperFunctions.scroll();
} else {
this.newCurator = true;
this.curator = new Curator();
this.curator._id = this.curatorId;
this.curator.email = this.user.email;
this.curator.name = this.user.fullname;
this.curator.affiliations = [];
this.curator.bio = '';
this.curator.photo = null;
this.photo = 'assets/common-assets/curator-default.png';
this.showLoading = false;
HelperFunctions.scroll();
}
},
error => {
}
);
if(this.user) {
this.curatorId = this.user.id;
this.getCurator();
}
});
});
}
@ -109,6 +82,40 @@ export class CuratorComponent implements OnInit {
}
public getCurator() {
this.curatorService.getCurator(this.properties, this.curatorId).subscribe(
curator => {
if (curator && Object.keys(curator).length > 0) {
this.curator = curator;
this.curator.email = this.user.email;
if (this.curator.photo && this.curator.photo !== '') {
this.photo = this.properties.utilsService + '/download/' + this.curator.photo;
} else {
this.photo = 'assets/common-assets/curator-default.png';
}
this.curatorsPageStatus();
this.showLoading = false;
HelperFunctions.scroll();
} else {
this.newCurator = true;
this.curator = new Curator();
this.curator._id = this.curatorId;
this.curator.email = this.user.email;
this.curator.name = this.user.fullname;
this.curator.affiliations = [];
this.curator.bio = '';
this.curator.photo = null;
this.photo = 'assets/common-assets/curator-default.png';
this.showLoading = false;
HelperFunctions.scroll();
}
},
error => {
}
);
}
public resetForm() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
@ -119,42 +126,14 @@ export class CuratorComponent implements OnInit {
if (this.curatorId != null && this.curatorId !== '') {
this.showLoading = true;
this.updateErrorMessage = '';
this.curatorService.getCurator(this.properties, this.curatorId).subscribe(
curator => {
if (curator) {
this.curator = curator;
this.curator.email = this.user.email;
if (this.curator.photo && this.curator.photo !== '') {
this.photo = this.properties.utilsService + '/download/' + this.curator.photo;
} else {
this.photo = 'assets/common-assets/curator-default.png';
}
this.showLoading = false;
this.curatorsPageStatus();
HelperFunctions.scroll();
} else {
this.newCurator = true;
this.curator = new Curator();
this.curator._id = this.curatorId;
this.curator.email = this.user.email
this.curator.name = this.user.fullname;
this.curator.affiliations = [];
this.curator.bio = '';
this.curator.photo = null;
this.photo = 'assets/common-assets/curator-default.png';
this.showLoading = false;
HelperFunctions.scroll();
}
},
error => {
}
);
this.getCurator();
}
this.resetChange();
}
}
private curatorsPageStatus() {
this.curatorsEnabled = false;
this.helpContentService.getCommunityFull(this.communityId, this.properties.adminToolsAPIURL).subscribe((community) => {
for (let page of community.pages) {
if (page['route'] === '/curators') {
@ -162,8 +141,6 @@ export class CuratorComponent implements OnInit {
return;
}
}
this.curatorsEnabled = false;
console.log(this.curatorsEnabled);
});
}