From b3fbb00d8a197789536a8a723985de7a10ca501c Mon Sep 17 00:00:00 2001 From: "sofia.baltzi" Date: Mon, 26 Nov 2018 14:35:12 +0000 Subject: [PATCH] Add/Fix form error messages and loading git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@53970 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../subscribe/invite/invite.component.html | 22 +++--- .../subscribe/invite/invite.component.ts | 71 +++++++++++++++---- .../utils/subscribe/invite/invite.module.ts | 3 +- 3 files changed, 75 insertions(+), 21 deletions(-) diff --git a/src/app/utils/subscribe/invite/invite.component.html b/src/app/utils/subscribe/invite/invite.component.html index e66c58e..3b7318f 100644 --- a/src/app/utils/subscribe/invite/invite.component.html +++ b/src/app/utils/subscribe/invite/invite.component.html @@ -5,8 +5,12 @@
Invite users to subscribe
- -
+
+ +
+ + +
@@ -20,12 +24,12 @@ - +
From: -
To * :To * : -
Please add valid email/s.
-
Please add a recipient.
- Please add valid email/s. +
Please add a recipient.
+
separate multiple emails with a comma
@@ -66,7 +70,7 @@
Message: - {{successfulSentMessage}} + diff --git a/src/app/utils/subscribe/invite/invite.component.ts b/src/app/utils/subscribe/invite/invite.component.ts index fa65eeb..723f93f 100644 --- a/src/app/utils/subscribe/invite/invite.component.ts +++ b/src/app/utils/subscribe/invite/invite.component.ts @@ -11,6 +11,7 @@ import {Body} from '../../../openaire import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties'; import {EmailService} from '../../../openaireLibrary/utils/email/email.service'; import {CommunityService} from "../../../openaireLibrary/connect/community/community.service"; +import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes'; @Component({ selector: 'invite', @@ -25,8 +26,12 @@ export class InviteComponent implements OnInit { private properties: EnvProperties = null; public community = null; - public showLoading: boolean = true; + //public showLoading: boolean = true; public errorMessage: string = ''; + public successfulSentMessage: string = ''; + public inviteErrorMessage: string = ''; + public missingCommunityId: string = ''; + public showAddRecipientMessage: boolean = false; public email: Email; public body: Body; @@ -40,6 +45,8 @@ export class InviteComponent implements OnInit { public defaultBody =''; public communityIdParam = {}; + public status: number = 1; + public errorCodes: ErrorCodes; constructor ( private element: ElementRef, @@ -57,6 +64,8 @@ export class InviteComponent implements OnInit { } this.communityIdParam = (ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:this.communityId}; }); + this.errorCodes = new ErrorCodes(); + this.status = this.errorCodes.LOADING; } @@ -64,7 +73,8 @@ export class InviteComponent implements OnInit { this.route.data.subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; this.errorMessage = ""; - this.showLoading = true; + this.missingCommunityId = ""; + this.status = this.errorCodes.LOADING; if (this.communityId != null && this.communityId != '') { this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe ( community => { @@ -78,11 +88,14 @@ export class InviteComponent implements OnInit { this.email = {body: "", subject: "[OpenAIRE-Connect] " + community.title, recipients: []}; this.recipients = ""; - this.showLoading = false; + this.status = this.errorCodes.DONE; }, - error => this.handleError('System error retrieving community name', error) + error => this.handleError(error) ); + } else { + this.status = this.errorCodes.DONE; + this.missingCommunityId = "There is no community selected!"; } this.scroll(); @@ -97,7 +110,9 @@ export class InviteComponent implements OnInit { } public invite() { - this.showLoading = true; + this.successfulSentMessage = ""; + this.inviteErrorMessage = ""; + this.status = this.errorCodes.LOADING; if (this.recipients != "") { if (this.validateEmails()) { this.composeEmail(); @@ -106,18 +121,42 @@ export class InviteComponent implements OnInit { this._emailService.sendEmail(this.properties.sendMailUrl, this.email).subscribe( res => { console.log("The email has been sent successfully!"); - this.showLoading = false; + this.status = this.errorCodes.DONE; + console.log("Emails Sent: "+res); + if(res > 1) { + this.successfulSentMessage = res + " emails sent successfully!"; + } else { + this.successfulSentMessage = res + " email sent successfully!"; + } + + this.body = {/*salutation: "Dear Sir/Madame,",*/ fromMessage: ", on behalf of ", fromName: "", paragraphs: this.defaultBody, /*closing: "Kind regards,",*/ signature: "OpenAIRE team", ps: ""}; + this.email = {body: "", subject: "[OpenAIRE-Connect] " + this.community.title, recipients: []}; + this.recipients = ""; }, error => { console.log(error); - this.showLoading = false; - this.errorMessage = "gdgd";//inviteErrorMessage + this.status = this.errorCodes.DONE; + //this.errorMessage = "gdgd";//inviteErrorMessage + this.inviteErrorMessage = "There was an error sending emails. Please try again."; } ); + } else { + this.scroll(); + this.status = this.errorCodes.DONE; } + } else { + this.showAddRecipientMessage = true; + this.scroll(); + this.status = this.errorCodes.DONE; } } + public resetMessages() { + this.errorMessage = ""; + this.successfulSentMessage = ""; + this.inviteErrorMessage = ""; + } + public validateEmails(): boolean { if (this.parseEmails()) { if (this.hasValidEmails()) { @@ -190,10 +229,18 @@ export class InviteComponent implements OnInit { return formattedEmail; } - public handleError(message: string, error) { - this.errorMessage = message; + public handleError(error) { + if(error.status == '401') { + this.status = this.errorCodes.FORBIDDEN; + } else if(error.status == '403') { + this.status = this.errorCodes.FORBIDDEN; + } else if(error.status == '404') { + this.status = this.errorCodes.NOT_FOUND; + } else if(error.status == '500') { + this.status = this.errorCodes.ERROR; + } else { + this.status = this.errorCodes.NOT_AVAILABLE; + } console.log('Server responded: ' + error); - - this.showLoading = false; } } diff --git a/src/app/utils/subscribe/invite/invite.module.ts b/src/app/utils/subscribe/invite/invite.module.ts index df032a9..1cfccf2 100644 --- a/src/app/utils/subscribe/invite/invite.module.ts +++ b/src/app/utils/subscribe/invite/invite.module.ts @@ -12,10 +12,11 @@ import {PreviousRouteRecorder} from '../../../openaireLibrary/utils/piwik/p import {FreeGuard} from '../../../openaireLibrary/login/freeGuard.guard'; import {EmailService} from '../../../openaireLibrary/utils/email/email.service'; import {CommunityService} from '../../../openaireLibrary/connect/community/community.service'; +import {ErrorMessagesModule} from '../../../openaireLibrary/utils/errorMessages.module'; @NgModule({ imports: [ - CommonModule, FormsModule, RouterModule, InviteRoutingModule, CKEditorModule + CommonModule, FormsModule, RouterModule, InviteRoutingModule, CKEditorModule, ErrorMessagesModule ], declarations: [ InviteComponent