diff --git a/landingPages/feedback/feedback.component.html b/landingPages/feedback/feedback.component.html index 7c011217..d3620cda 100644 --- a/landingPages/feedback/feedback.component.html +++ b/landingPages/feedback/feedback.component.html @@ -32,6 +32,7 @@
+
@@ -44,7 +45,7 @@ class="matSelection uk-margin-bottom" panelClass="matSelectionPanel"> {{field}} -
@@ -54,10 +55,15 @@ Report issue for another field
-
-
+
+
+
Please leave us your E-mail to notify you about the reporting status.
+ +
+
+
diff --git a/landingPages/feedback/feedback.component.ts b/landingPages/feedback/feedback.component.ts index 88f0e143..03609b4d 100644 --- a/landingPages/feedback/feedback.component.ts +++ b/landingPages/feedback/feedback.component.ts @@ -18,6 +18,7 @@ import {OrganizationInfo} from "../../utils/entities/organizationInfo"; import {ProjectInfo} from "../../utils/entities/projectInfo"; import {DataProviderInfo} from "../../utils/entities/dataProviderInfo"; import {EmailService} from "../../utils/email/email.service"; +import {Composer} from "../../utils/email/composer"; @Component({ selector: 'feedback', @@ -37,16 +38,18 @@ export class FeedbackComponent implements OnInit, OnChanges { @Input() fields: string[] = []; @Output() show: EventEmitter = new EventEmitter(); + public sending: boolean = false; public sent: boolean = false; + public error: boolean = false; public form: FormGroup; public url: string = null; + public recipients: string[] = ['kostis30fylloy@gmail.com']; constructor(private fb: FormBuilder, private emailService: EmailService) { } ngOnInit(): void { - this.init(); if(typeof window !== "undefined") { this.url = window.location.href; } @@ -57,6 +60,7 @@ export class FeedbackComponent implements OnInit, OnChanges { } else if(this.dataProviderInfo) { this.title = this.dataProviderInfo.title.name; } + this.init(); } ngOnChanges(changes: SimpleChanges): void { @@ -68,6 +72,9 @@ export class FeedbackComponent implements OnInit, OnChanges { init() { this.sent = false; this.form = this.fb.group({ + name: this.fb.control(this.title), + url: this.fb.control(this.url), + email: this.fb.control('', Validators.email), issues: this.fb.array([], Validators.required) }); this.addIssue(); @@ -103,6 +110,18 @@ export class FeedbackComponent implements OnInit, OnChanges { } public sendReport() { - this.sent = true; + this.sending = true; + this.emailService.contact(this.properties.adminToolsAPIURL + '/contact', Composer.composeEmailForFeedback(this.form.value, this.recipients)).subscribe(sent => { + this.error = !sent; + if(sent) { + this.init(); + this.sent = true; + } + this.sending = false; + }, error => { + console.log(error); + this.error = true; + this.sending = false; + }); } } \ No newline at end of file diff --git a/utils/email/composer.ts b/utils/email/composer.ts index 6440f930..e702acd9 100644 --- a/utils/email/composer.ts +++ b/utils/email/composer.ts @@ -9,7 +9,7 @@ export class Composer { // TODO move to properties private static openaireEmail = "mailto:openaire.test@gmail.com"; private static subjectPrefix = "[OpenAIRE-Connect] "; - private static closing = "OpenAIRE team" + private static closing = "OpenAIRE team"; private static openaireAddress = "www.openaire.eu
"; private static signature = Composer.closing + "
" + Composer.openaireAddress; @@ -65,9 +65,19 @@ export class Composer { return email; } - /*public static composeEmailForFeedback(issues: any[], recipients: string[]): Email { - - }*/ + public static composeEmailForFeedback(info: {name: string, url: string, email: string, issues: any[],}, recipients: string[]): Email { + let email: Email = new Email(); + email.subject = 'Feedback report for ' + info.name; + email.body = "
" + + "

A user" + ((info.email)?(" with email " + info.email):"") + " has reported the following issue(s) for " + + "" + info.name + "

    "; + info.issues.forEach((issue, index) => { + email.body += "
  • " + issue.field + ": " + issue.report + "
  • "; + }); + email.body += "
"; + email.recipients = recipients; + return email; + } public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any) : Email { let email: Email = new Email(); diff --git a/utils/email/email.service.ts b/utils/email/email.service.ts index 4e8a5468..e29d1421 100644 --- a/utils/email/email.service.ts +++ b/utils/email/email.service.ts @@ -4,6 +4,7 @@ import {HttpClient} from "@angular/common/http"; import {Email} from './email'; import {CustomOptions} from '../../services/servicesUtils/customOptions.class'; import {EmailRecaptcha} from "../entities/EmailRecaptcha"; +import {Observable} from "rxjs"; @Injectable() export class EmailService { @@ -18,12 +19,11 @@ export class EmailService { //.map(request => request.json()); } - contact(url: string, email: Email, recaptcha: string) { + contact(url: string, email: Email, recaptcha: string = null):Observable { const data: EmailRecaptcha = new EmailRecaptcha(); data.email = email; data.recaptcha = recaptcha; - return this.http.post(url, data); - //.map(request => request.json()); + return this.http.post(url, data); } }