diff --git a/src/app/pages/curator/curator.component.ts b/src/app/pages/curator/curator.component.ts index 89c075c..c8069af 100644 --- a/src/app/pages/curator/curator.component.ts +++ b/src/app/pages/curator/curator.component.ts @@ -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); }); }