2020-03-16 14:09:46 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
ElementRef,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnChanges,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
SimpleChanges,
|
|
|
|
ViewChild
|
|
|
|
} from "@angular/core";
|
|
|
|
import {ResultLandingInfo} from "../../utils/entities/resultLandingInfo";
|
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
|
|
import {FormArray, FormBuilder, FormGroup, Validators} from "@angular/forms";
|
|
|
|
import {AlertModal} from "../../utils/modal/alert";
|
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|
|
|
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";
|
2020-03-19 10:10:42 +01:00
|
|
|
import {Composer} from "../../utils/email/composer";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'feedback',
|
|
|
|
templateUrl: 'feedback.component.html'
|
|
|
|
})
|
|
|
|
export class FeedbackComponent implements OnInit, OnChanges {
|
|
|
|
@ViewChild('feedback') feedback: ElementRef;
|
|
|
|
@ViewChild('backModal') backModal: AlertModal;
|
|
|
|
@Input() showForm: boolean = false;
|
|
|
|
@Input() resultLandingInfo: ResultLandingInfo = null;
|
|
|
|
@Input() organizationInfo: OrganizationInfo = null;
|
|
|
|
@Input() projectInfo: ProjectInfo = null;
|
|
|
|
@Input() dataProviderInfo: DataProviderInfo = null;
|
|
|
|
@Input() title: string = null;
|
|
|
|
@Input() properties: EnvProperties = null;
|
|
|
|
@Input() entityType: string = null;
|
|
|
|
@Input() fields: string[] = [];
|
|
|
|
@Output() show: EventEmitter<boolean> = new EventEmitter<boolean>();
|
|
|
|
|
2020-03-19 10:10:42 +01:00
|
|
|
public sending: boolean = false;
|
2020-03-16 14:09:46 +01:00
|
|
|
public sent: boolean = false;
|
2020-03-19 10:10:42 +01:00
|
|
|
public error: boolean = false;
|
2020-03-16 14:09:46 +01:00
|
|
|
public form: FormGroup;
|
|
|
|
public url: string = null;
|
2020-03-19 13:26:55 +01:00
|
|
|
public recipients: string[] = [];
|
2020-11-11 15:43:13 +01:00
|
|
|
subscriptions =[];
|
2020-03-16 14:09:46 +01:00
|
|
|
constructor(private fb: FormBuilder,
|
|
|
|
private emailService: EmailService) {
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
ngOnInit(): void {
|
|
|
|
if(typeof window !== "undefined") {
|
|
|
|
this.url = window.location.href;
|
|
|
|
}
|
|
|
|
if(this.resultLandingInfo) {
|
|
|
|
this.title = this.resultLandingInfo.title;
|
|
|
|
} else if(this.organizationInfo) {
|
|
|
|
this.title = this.organizationInfo.title.name;
|
|
|
|
} else if(this.dataProviderInfo) {
|
|
|
|
this.title = this.dataProviderInfo.title.name;
|
|
|
|
}
|
2020-03-19 13:26:55 +01:00
|
|
|
this.recipients = [this.properties.feedbackmail];
|
2020-03-19 10:10:42 +01:00
|
|
|
this.init();
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if(changes.showForm) {
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.sent = false;
|
|
|
|
this.form = this.fb.group({
|
2020-03-19 10:10:42 +01:00
|
|
|
name: this.fb.control(this.title),
|
|
|
|
url: this.fb.control(this.url),
|
|
|
|
email: this.fb.control('', Validators.email),
|
2020-03-27 10:11:56 +01:00
|
|
|
issues: this.fb.array([], Validators.required),
|
|
|
|
recaptcha: this.fb.control('', Validators.required),
|
2020-03-16 14:09:46 +01:00
|
|
|
});
|
|
|
|
this.addIssue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public addIssue() {
|
|
|
|
let issue: FormGroup = this.fb.group({
|
|
|
|
field: this.fb.control('', Validators.required),
|
|
|
|
report: this.fb.control('', Validators.required)
|
|
|
|
});
|
|
|
|
this.issues.push(issue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeIssue(index: number) {
|
|
|
|
this.issues.removeAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get issues(): FormArray {
|
|
|
|
return <FormArray>this.form.get('issues');
|
|
|
|
}
|
|
|
|
|
|
|
|
changeShowForm(value: boolean) {
|
|
|
|
this.show.emit(value);
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
public openBackModal() {
|
|
|
|
this.backModal.alertTitle = 'Go back to ' + this.entityType + '\'s page';
|
|
|
|
this.backModal.message = 'All changes will be deleted. Are you sure you want to proceed?';
|
|
|
|
this.backModal.okButtonText = 'Yes';
|
|
|
|
this.backModal.cancelButtonText = 'No';
|
|
|
|
this.backModal.open();
|
|
|
|
}
|
|
|
|
|
2020-03-27 10:11:56 +01:00
|
|
|
public handleRecaptcha(captchaResponse: string) {
|
|
|
|
this.form.get('recaptcha').setValue(captchaResponse);
|
|
|
|
}
|
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
public sendReport() {
|
2020-03-19 10:10:42 +01:00
|
|
|
this.sending = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.emailService.contact(this.properties,
|
2020-03-27 10:11:56 +01:00
|
|
|
Composer.composeEmailForFeedback(this.form.value, this.recipients), this.form.get('recaptcha').value).subscribe(sent => {
|
2020-03-19 10:10:42 +01:00
|
|
|
this.error = !sent;
|
|
|
|
if(sent) {
|
2020-03-19 13:26:55 +01:00
|
|
|
if(this.form.get('email').value !== '') {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.emailService.contact(this.properties,
|
2020-03-19 13:26:55 +01:00
|
|
|
Composer.composeEmailForUserAfterFeedback([this.form.get('email').value])).subscribe(sent => {
|
|
|
|
if(sent) {
|
|
|
|
//console.log('An email has been sent to user ' + this.form.get('email').value);
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2020-03-19 13:26:55 +01:00
|
|
|
}
|
2020-03-19 10:10:42 +01:00
|
|
|
this.init();
|
|
|
|
this.sent = true;
|
|
|
|
}
|
|
|
|
this.sending = false;
|
|
|
|
}, error => {
|
|
|
|
console.log(error);
|
|
|
|
this.error = true;
|
|
|
|
this.sending = false;
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
}
|