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;
|
2022-04-19 15:07:21 +02:00
|
|
|
@Output() showFormChange: EventEmitter<boolean> = new EventEmitter<boolean>();
|
2020-03-16 14:09:46 +01:00
|
|
|
@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[] = [];
|
2022-06-09 15:45:39 +02:00
|
|
|
@Input() preSelectedField: string = "";
|
2020-03-16 14:09:46 +01:00
|
|
|
|
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[] = [];
|
2022-04-19 15:07:21 +02:00
|
|
|
subscriptions = [];
|
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
constructor(private fb: FormBuilder,
|
|
|
|
private emailService: EmailService) {
|
|
|
|
}
|
2022-04-19 15:07:21 +02:00
|
|
|
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-04-19 15:07:21 +02:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
ngOnInit(): void {
|
2022-04-19 15:07:21 +02:00
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
this.url = window.location.href;
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
2022-04-19 15:07:21 +02:00
|
|
|
if (this.resultLandingInfo) {
|
2020-03-16 14:09:46 +01:00
|
|
|
this.title = this.resultLandingInfo.title;
|
2022-04-19 15:07:21 +02:00
|
|
|
} else if (this.organizationInfo) {
|
2020-03-16 14:09:46 +01:00
|
|
|
this.title = this.organizationInfo.title.name;
|
2022-04-19 15:07:21 +02:00
|
|
|
} else if (this.dataProviderInfo) {
|
2020-03-16 14:09:46 +01:00
|
|
|
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 {
|
2022-04-19 15:07:21 +02:00
|
|
|
if (changes.showForm) {
|
2020-03-16 14:09:46 +01:00
|
|
|
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({
|
2022-06-09 15:45:39 +02:00
|
|
|
field: this.fb.control(this.preSelectedField, Validators.required),
|
2020-03-16 14:09:46 +01:00
|
|
|
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) {
|
2022-04-19 15:07:21 +02:00
|
|
|
this.showFormChange.emit(value);
|
2020-03-16 14:09:46 +01:00
|
|
|
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;
|
2022-04-19 15:07:21 +02:00
|
|
|
if (sent) {
|
|
|
|
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 => {
|
2022-04-19 15:07:21 +02:00
|
|
|
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
|
|
|
}
|