diff --git a/angular.json b/angular.json index 0d4443d..605a4d4 100644 --- a/angular.json +++ b/angular.json @@ -1,5 +1,5 @@ { - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json", "version": 1, "newProjectRoot": "projects", "projects": { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 933316c..f267c3f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -188,8 +188,8 @@ export class AppComponent implements OnInit{ items: [] }); community.items.push({ - rootItem: new MenuItem('communityAffiliations', 'Community Affiliations', '/affiliations', - '/affiliations', false, [], [], {communityId: this.communityId}), + rootItem: new MenuItem('communityAffiliations', 'Community Organizations', '/organizations', + '/organizations', false, [], [], {communityId: this.communityId}), items: [] }); /*community.items.push({ diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts index f0c052c..b542848 100644 --- a/src/app/app.routing.ts +++ b/src/app/app.routing.ts @@ -33,6 +33,11 @@ const appRoutes: Routes = [ loadChildren: './pages/curator/curator.module#CuratorModule', resolve: { envSpecific: EnvironmentSpecificResolver } }, + { + path: 'organizations', + loadChildren: './pages/affiliations/affiliations.module#AffiliationsModule', + resolve: { envSpecific: EnvironmentSpecificResolver } + }, { path: 'communities', loadChildren: './pages/community/communities.module#CommunitiesModule', diff --git a/src/app/pages/affiliations/affiliations-routing.module.ts b/src/app/pages/affiliations/affiliations-routing.module.ts new file mode 100644 index 0000000..6979146 --- /dev/null +++ b/src/app/pages/affiliations/affiliations-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {AffiliationsComponent} from './affiliations.component'; +import {IsCommunity} from '../../openaireLibrary/connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../openaireLibrary/connect/communityGuard/connectAdminLoginGuard.guard'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: AffiliationsComponent} + ]) + ] +}) +export class AffiliationsRoutingModule { } diff --git a/src/app/pages/affiliations/affiliations.component.html b/src/app/pages/affiliations/affiliations.component.html new file mode 100644 index 0000000..fb831ce --- /dev/null +++ b/src/app/pages/affiliations/affiliations.component.html @@ -0,0 +1,119 @@ + + + + + +
+

+ My Affiliations + Related Organizations +

+
+ +
+
+ + +
+ +
+ +
+ +
+
+ {{message}} +
+ +
+
+
+
+ +
+ + + + + + + + + + + + + + + + + +
+ Name + + * + + : + + +
+ Logo Url + + * + + : + + +
+ Website Url + + * + + : + + +
+
+ + diff --git a/src/app/pages/affiliations/affiliations.component.ts b/src/app/pages/affiliations/affiliations.component.ts new file mode 100644 index 0000000..abd95a5 --- /dev/null +++ b/src/app/pages/affiliations/affiliations.component.ts @@ -0,0 +1,279 @@ +import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; + +import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; + +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; +import {Affiliation} from '../../openaireLibrary/utils/entities/CuratorInfo'; +import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class'; +import {AlertModal} from '../../openaireLibrary/utils/modal/alert'; +import {UtilitiesService} from '../../openaireLibrary/services/utilities.service'; +import {AffiliationService} from "../../openaireLibrary/connect/affiliations/affiliation.service"; + +@Component({ + selector: 'affiliations', + templateUrl: './affiliations.component.html', +}) + +export class AffiliationsComponent implements OnInit { + + @ViewChild('affiliationModal') affiliationModal: AlertModal; + @ViewChild('removeAffiliationModal') removeAffiliationModal: AlertModal; + public showLoading = false; + public message = ''; + public messageType = ''; + + public affiliation: Affiliation = new Affiliation(); + public properties: EnvProperties = null; + + private index = 0; + private maxCharacters = 70; + + @Input() hasChanged: boolean = false; + @Input() curatorAffiliations: boolean = false; + @Input() public affiliations: Affiliation[] = []; + @Output() affiliationsChange: EventEmitter = new EventEmitter(); + @Output() resetCuratorMessages: EventEmitter = new EventEmitter(); + public communityId: string; + + constructor(private element: ElementRef, + private route: ActivatedRoute, + private _router: Router, + private affiliationService: AffiliationService, + private utilitiesService: UtilitiesService) { + } + + + ngOnInit() { + this.route.data.subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} + }); + } else { + this.showLoading = true; + this.message = ''; + + this.route.queryParams.subscribe( + communityId => { + this.communityId = communityId['communityId']; + + if(!this.curatorAffiliations) { + this.getAffiliations(); + } + } + ); + } + }); + } + + getAffiliations() { + this.affiliationService.initAffiliations(this.properties, this.properties.communityAPI + this.communityId + "/organizations"); + this.affiliationService.affiliations.subscribe( + affiliations => { + this.affiliations = affiliations; + this.showLoading = false; + }, + error => { + console.error("Affiliations Component: Error getting affiliations for community with id: "+this.communityId, error); + this.showLoading = false; + } + ); + } + + initAffiliation(affiliation: Affiliation = null) { + this.resetMessages(); + this.affiliation = new Affiliation(); + if (affiliation) { + this.affiliation.name = affiliation.name; + this.affiliation.logo_url = affiliation.logo_url; + this.affiliation.website_url = affiliation.website_url; + if(!this.curatorAffiliations) { + this.affiliation.communityId = affiliation.communityId; + this.affiliation.id = affiliation.id; + } + if(this.curatorAffiliations) { + this.affiliationModal.okButtonText = 'OK'; + } else { + this.affiliationModal.okButtonText = 'Save Affiliation'; + } + } else { + this.index = -1; + this.affiliation.name = ''; + this.affiliation.logo_url = ''; + this.affiliation.website_url = ''; + if(!this.curatorAffiliations) { + this.affiliation.communityId = this.communityId; + } + } + this.affiliationModal.okButtonLeft = false; + if(this.curatorAffiliations) { + this.affiliationModal.okButtonText = 'OK'; + } else { + this.affiliationModal.okButtonText = 'Save Affiliation'; + } + this.affiliationModal.open(); + } + + public chooseAffiliation(index: number, action: string = 'delete') { + this.resetMessages(); + this.index = index; + const affiliation: Affiliation = this.affiliations[index]; + if (action === 'delete') { + this.removeAffiliationModal.message = 'Do you want to remove ' + + affiliation.name + ' from your Affiliations?'; + this.removeAffiliationModal.okButtonText = 'Yes'; + this.removeAffiliationModal.cancelButtonText = 'No'; + this.removeAffiliationModal.open(); + } else if (action === 'edit') { + this.initAffiliation(affiliation); + } + } + + updateCommunityAffiliations(index: number) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: + {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} + }); + } else { + HelperFunctions.scroll(); + + console.info(this.affiliation); + + this.showLoading = true; + + this.affiliationService.updateAffiliation(this.properties.communityAPI + this.communityId + '/organizations', + this.affiliation).subscribe((affiliation) => { + if (affiliation) { + if (index === -1) { + this.affiliations.push(affiliation); + } else { + this.affiliations[index] = affiliation; + } + if(this.affiliation.id) { + this.handleUpdateSuccess('Your organization has been updated successfully!'); + } else { + this.handleUpdateSuccess('Your organization has been saved successfully!'); + } + } + }, + error => { + if(this.affiliation.id) { + this.handleUpdateError('Your organization could not be updated. Try again later!', error); + } else { + this.handleUpdateError('Organization could not be saved. Try again later!', error); + } + }); + } + } + + addAffiliation() { + console.info(this.affiliation); + if (!this.isEmptyAffiliation()) { + + if(!HelperFunctions.isTiny(this.affiliation.logo_url)) { + this.utilitiesService.getTiny(this.properties.tinyUrl + this.affiliation.logo_url).subscribe((logo_url)=> { + this.affiliation.logo_url = logo_url; + + if(!HelperFunctions.isTiny(this.affiliation.website_url)) { + this.utilitiesService.getTiny(this.properties.tinyUrl + this.affiliation.website_url).subscribe((website_url) => { + this.affiliation.website_url = website_url; + if (!this.curatorAffiliations) { + this.updateCommunityAffiliations(this.index); + } else { + if (this.index === -1) { + this.affiliations.push(this.affiliation); + } else { + this.affiliations[this.index] = this.affiliation; + } + } + this.change(); + }); + } + }) + } else { + if(!this.curatorAffiliations) { + this.updateCommunityAffiliations(this.index); + } else { + if (this.index === -1) { + this.affiliations.push(this.affiliation); + } else { + this.affiliations[this.index] = this.affiliation; + } + } + this.change(); + } + } + } + + removeAffiliation() { + console.info(this.affiliations[this.index]); + console.info(this.affiliation); + if(!this.curatorAffiliations) { + HelperFunctions.scroll(); + + this.showLoading = true; + this.affiliationService.deleteAffiliation(this.properties.communityAPI + this.communityId + '/organizations', + this.affiliations[this.index].id).subscribe((deleteOK) => { + this.affiliations.splice(this.index, 1); + this.handleUpdateSuccess('Organization has been deleted'); + }, + error => { + this.handleUpdateError('Organization could not be deleted. Try again later!', error); + } + ); + } else { + this.affiliations.splice(this.index, 1); + this.change(); + } + } + + + private change() { + this.hasChanged = true; + if(this.curatorAffiliations) { + this.affiliationsChange.emit(this.hasChanged); + } + } + + private resetMessages() { + this.message = ''; + if(this.curatorAffiliations) { + this.resetCuratorMessages.emit(true); + } + } + + handleUpdateError(message: string, error) { + this.resetMessages(); + this.message = message; + this.messageType = "warning"; + console.log('Server responded: ', error); + + this.showLoading = false; + } + + handleUpdateSuccess(message) { + this.resetMessages(); + this.message = message; + this.messageType = "success"; + this.showLoading = false; + } + + isEmptyAffiliation(): boolean { + return ((!this.affiliation.name || this.affiliation.name === '') || + (!this.affiliation.logo_url || this.affiliation.logo_url === '') || + (!this.affiliation.website_url || this.affiliation.website_url === '')); + } + + _format(name: string){ + if(name) { + return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name); + } else { + return null; + } + } + +} diff --git a/src/app/pages/affiliations/affiliations.module.ts b/src/app/pages/affiliations/affiliations.module.ts new file mode 100644 index 0000000..1e3048d --- /dev/null +++ b/src/app/pages/affiliations/affiliations.module.ts @@ -0,0 +1,31 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; + +import {AffiliationsComponent} from './affiliations.component'; + +import {AffiliationsRoutingModule} from './affiliations-routing.module'; +import {IsCommunity} from '../../openaireLibrary/connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../openaireLibrary/connect/communityGuard/connectAdminLoginGuard.guard'; +import {AffiliationService} from '../../openaireLibrary/connect/affiliations/affiliation.service'; +import {AlertModalModule} from '../../openaireLibrary/utils/modal/alertModal.module'; +import {UtilitiesService} from '../../openaireLibrary/services/utilities.service'; + +@NgModule({ + imports: [ + AffiliationsRoutingModule, CommonModule, FormsModule, RouterModule, + AlertModalModule + ], + declarations: [ + AffiliationsComponent + ], + providers: [ + AffiliationService, UtilitiesService, IsCommunity, ConnectAdminLoginGuard + ], + exports: [ + AffiliationsComponent + ] +}) + +export class AffiliationsModule { } diff --git a/src/app/pages/curator/curator.component.html b/src/app/pages/curator/curator.component.html index 1a6675a..7719b93 100644 --- a/src/app/pages/curator/curator.component.html +++ b/src/app/pages/curator/curator.component.html @@ -23,7 +23,7 @@
Please add name.
+ [(ngModel)]="curator.name" (input)="resetMessages(); onNameChange()" #name="ngModel" required> @@ -34,13 +34,13 @@ Curator Photo
- +
-
@@ -54,7 +54,7 @@ class="form-control uk-textarea" rows="6" id="bio" [(ngModel)]="curator.bio" - (input)="change()"> + (input)="resetMessages(); change()"> @@ -75,88 +75,17 @@
-
-

My Affiliations -

-
- -
-
- + +
- - - + + +
- - - - - - - - - - - - - - - - -
- Name - - * - - : - - -
- Logo Url - - * - - : - - -
- Website Url - - * - - : - - -
-
- - Your photo will be removed after save your data. Are you sure you want to proceed? diff --git a/src/app/pages/curator/curator.component.ts b/src/app/pages/curator/curator.component.ts index f9867a0..06de1ae 100644 --- a/src/app/pages/curator/curator.component.ts +++ b/src/app/pages/curator/curator.component.ts @@ -8,7 +8,6 @@ import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.cla import {CuratorService} from '../../openaireLibrary/connect/curators/curator.service'; import {Affiliation, Curator} from '../../openaireLibrary/utils/entities/CuratorInfo'; import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class'; -import {AlertModal} from '../../openaireLibrary/utils/modal/alert'; import {UtilitiesService} from '../../openaireLibrary/services/utilities.service'; @Component({ @@ -18,23 +17,19 @@ import {UtilitiesService} from '../../openaireLibrary/services/utilities.service export class CuratorComponent implements OnInit { - @ViewChild('affiliationModal') affiliationModal: AlertModal; - @ViewChild('removeAffiliationModal') removeAffiliationModal: AlertModal; public showLoading = true; public updateErrorMessage = ''; public successfulSaveMessage = ''; + public affiliationsChanged = false; public hasChanged = false; public curatorId = null; public curator: Curator = null; - public affiliation: Affiliation = new Affiliation(); public photo: any = null; public properties: EnvProperties = null; private file: File = null; private enabled = true; - private index = 0; - private maxCharacters = 70; private deletePhoto =false; constructor(private element: ElementRef, @@ -89,23 +84,6 @@ export class CuratorComponent implements OnInit { }); } - initAffiliation(affiliation: Affiliation = null) { - this.affiliation = new Affiliation(); - if (affiliation) { - this.affiliation.name = affiliation.name; - this.affiliation.logo_url = affiliation.logo_url; - this.affiliation.website_url = affiliation.website_url; - this.affiliationModal.okButtonText = 'Edit Affiliation'; - } else { - this.index = -1; - this.affiliation.name = ''; - this.affiliation.logo_url = ''; - this.affiliation.website_url = ''; - } - this.affiliationModal.okButtonLeft = false; - this.affiliationModal.open(); - } - public resetForm() { if (!Session.isLoggedIn()) { this._router.navigate(['/user-info'], { @@ -152,10 +130,12 @@ export class CuratorComponent implements OnInit { private change() { this.hasChanged = true; + this.affiliationsChanged = true; } private resetChange() { this.hasChanged = false; + this.affiliationsChanged = false; } private resetMessages() { @@ -163,20 +143,6 @@ export class CuratorComponent implements OnInit { this.updateErrorMessage = ''; } - public chooseAffiliation(index: number, action: string = 'delete') { - this.index = index; - const affiliation: Affiliation = this.curator.affiliations[index]; - if (action === 'delete') { - this.removeAffiliationModal.message = 'Do you want to remove ' + - affiliation.name + ' from your Affiliations?'; - this.removeAffiliationModal.okButtonText = 'Yes'; - this.removeAffiliationModal.cancelButtonText = 'No'; - this.removeAffiliationModal.open(); - } else if (action === 'edit') { - this.initAffiliation(affiliation); - } - } - handleUpdateError(message: string, error) { this.resetMessages(); this.updateErrorMessage = message; @@ -220,7 +186,7 @@ export class CuratorComponent implements OnInit { {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} }); } else { - if (this.hasChanged && this.curator && this.curator.name && this.curator.name !== '') { + if ((this.hasChanged || this.affiliationsChanged) && this.curator && this.curator.name && this.curator.name !== '') { this.showLoading = true; if (this.file) { this.utilitiesService.uploadPhoto(this.properties.uploadService + '/' + this.curator._id, this.file).subscribe((res) => { @@ -264,40 +230,6 @@ export class CuratorComponent implements OnInit { } } - isEmptyAffiliation(): boolean { - return ((!this.affiliation.name || this.affiliation.name === '') || - (!this.affiliation.logo_url || this.affiliation.logo_url === '') || - (!this.affiliation.website_url || this.affiliation.website_url === '')); - } - - addAffiliation() { - if (!this.isEmptyAffiliation()) { - if(!HelperFunctions.isTiny(this.affiliation.logo_url)) { - this.utilitiesService.getTiny(this.properties.tinyUrl + this.affiliation.logo_url).subscribe((res)=> { - this.affiliation.logo_url = res; - if (this.index === -1) { - this.curator.affiliations.push(this.affiliation); - } else { - this.curator.affiliations[this.index] = this.affiliation; - } - this.change(); - }) - } else { - if (this.index === -1) { - this.curator.affiliations.push(this.affiliation); - } else { - this.curator.affiliations[this.index] = this.affiliation; - } - this.change(); - } - } - } - - removeAffiliation() { - this.curator.affiliations.splice(this.index, 1); - this.change(); - } - onNameChange() { this.hasChanged = true; if (!this.curator.name || this.curator.name === '') { @@ -307,14 +239,6 @@ export class CuratorComponent implements OnInit { } } - _format(name: string){ - if(name) { - return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name); - } else { - return null; - } - } - removePhoto() { this.deletePhoto = true; this.hasChanged = true; diff --git a/src/app/pages/curator/curator.module.ts b/src/app/pages/curator/curator.module.ts index e353693..0c320ed 100644 --- a/src/app/pages/curator/curator.module.ts +++ b/src/app/pages/curator/curator.module.ts @@ -11,11 +11,12 @@ import {ConnectAdminLoginGuard} from '../../openaireLibrary/connect/communityGua import {CuratorService} from '../../openaireLibrary/connect/curators/curator.service'; import {AlertModalModule} from '../../openaireLibrary/utils/modal/alertModal.module'; import {UtilitiesService} from '../../openaireLibrary/services/utilities.service'; +import {AffiliationsModule} from "../affiliations/affiliations.module"; @NgModule({ imports: [ CuratorRoutingModule, CommonModule, FormsModule, RouterModule, - AlertModalModule + AlertModalModule, AffiliationsModule ], declarations: [ CuratorComponent