2021-04-15 20:52:58 +02:00
import { Component , OnDestroy , OnInit , ViewChild } from '@angular/core' ;
2020-10-09 11:35:22 +02:00
import { ActivatedRoute , Router } from '@angular/router' ;
2020-10-05 18:36:30 +02:00
import { EmailService } from '../openaireLibrary/utils/email/email.service' ;
import { Email } from '../openaireLibrary/utils/email/email' ;
import { EnvProperties } from '../openaireLibrary/utils/properties/env-properties' ;
import { Composer } from '../openaireLibrary/utils/email/composer' ;
2020-11-16 13:56:17 +01:00
import { Meta , Title } from '@angular/platform-browser' ;
2020-10-05 18:36:30 +02:00
import { HelperFunctions } from '../openaireLibrary/utils/HelperFunctions.class' ;
import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
import { properties } from '../../environments/environment' ;
2020-10-08 16:20:26 +02:00
import { FAQ } from "../openaireLibrary/utils/entities/FAQ" ;
2020-10-09 11:35:22 +02:00
import { Breadcrumb } from "../openaireLibrary/utils/breadcrumbs/breadcrumbs.component" ;
2020-11-16 13:56:17 +01:00
import { Subscription } from 'rxjs' ;
import { PiwikService } from '../openaireLibrary/utils/piwik/piwik.service' ;
import { SEOService } from '../openaireLibrary/sharedComponents/SEO/SEO.service' ;
2020-10-05 18:36:30 +02:00
@Component ( {
selector : 'contact' ,
templateUrl : './contact.component.html' ,
styleUrls : [ 'contact.component.css' ]
} )
2021-04-15 20:52:58 +02:00
export class ContactComponent implements OnInit , OnDestroy {
2020-10-05 18:36:30 +02:00
public showLoading = true ;
public errorMessage = '' ;
public email : Email ;
2020-10-08 16:20:26 +02:00
public faqs : FAQ [ ] = [ ] ;
2020-10-05 18:36:30 +02:00
public properties : EnvProperties = properties ;
2020-11-16 13:56:17 +01:00
subs : Subscription [ ] = [ ] ;
description = "Do you have questions? Contact us" ;
title = "OpenAIRE - Research Graph | Support" ;
2020-10-05 18:36:30 +02:00
public contactForm : FormGroup ;
@ViewChild ( 'AlertModal' ) modal ;
2020-10-09 11:35:22 +02:00
public breadcrumbs : Breadcrumb [ ] = [
{
name : 'home' ,
route : '/'
} ,
{
name : 'support'
}
] ;
2020-10-05 18:36:30 +02:00
constructor ( private router : Router ,
2020-10-09 11:35:22 +02:00
private route : ActivatedRoute ,
2020-10-05 18:36:30 +02:00
private emailService : EmailService ,
2020-11-16 13:56:17 +01:00
private _title : Title ,
private _piwikService :PiwikService ,
private _meta : Meta , private seoService : SEOService ,
2020-10-05 18:36:30 +02:00
private fb : FormBuilder ) {
2020-10-08 16:20:26 +02:00
this . setFaqs ( ) ;
2020-10-05 18:36:30 +02:00
}
ngOnInit() {
2020-11-16 13:56:17 +01:00
this . _title . setTitle ( this . title ) ;
this . _meta . updateTag ( { content :this.description } , "name='description'" ) ;
this . _meta . updateTag ( { content :this.description } , "property='og:description'" ) ;
this . _meta . updateTag ( { content :this.title } , "property='og:title'" ) ;
2020-10-05 18:36:30 +02:00
this . email = { body : '' , subject : '' , recipients : [ ] } ;
this . reset ( ) ;
this . showLoading = false ;
2020-11-16 13:56:17 +01:00
var url = this . properties . domain + this . properties . baseLink + this . router . url ;
this . seoService . createLinkForCanonicalURL ( url , false ) ;
this . _meta . updateTag ( { content :url } , "property='og:url'" ) ;
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . subs . push ( this . _piwikService . trackView ( this . properties , this . title ) . subscribe ( ) ) ;
}
2020-10-05 18:36:30 +02:00
}
public send ( event ) {
HelperFunctions . scroll ( ) ;
if ( event . valid === true ) {
this . sendMail ( this . properties . admins ) ;
} else {
this . errorMessage = 'Please fill in all the required fields!' ;
}
}
public reset() {
this . contactForm = this . fb . group ( {
name : this.fb.control ( '' , Validators . required ) ,
email : this.fb.control ( '' , [ Validators . required , Validators . email ] ) ,
affiliation : this.fb.control ( '' , Validators . required ) ,
organization : this.fb.control ( '' , Validators . required ) ,
description : this.fb.control ( '' , Validators . required ) ,
recaptcha : this.fb.control ( '' , Validators . required ) ,
} ) ;
this . errorMessage = '' ;
}
private sendMail ( admins : any ) {
this . showLoading = true ;
2020-11-16 13:56:17 +01:00
this . subs . push ( this . emailService . contact ( this . properties ,
2020-10-09 18:37:06 +02:00
Composer . composeEmailForGraph ( this . contactForm . value , admins ) ,
2020-10-05 18:36:30 +02:00
this . contactForm . value . recaptcha ) . subscribe (
res = > {
this . showLoading = false ;
if ( res ) {
this . reset ( ) ;
this . modalOpen ( ) ;
} else {
this . errorMessage = 'Email sent failed! Please try again.' ;
this . contactForm . get ( 'recaptcha' ) . setValue ( '' ) ;
}
} ,
error = > {
this . handleError ( 'Email sent failed! Please try again.' , error ) ;
this . showLoading = false ;
this . contactForm . get ( 'recaptcha' ) . setValue ( '' ) ;
}
2020-11-16 13:56:17 +01:00
) ) ;
2020-10-05 18:36:30 +02:00
}
public modalOpen() {
this . modal . okButton = true ;
this . modal . alertTitle = 'Your request has been successfully submitted' ;
this . modal . alertMessage = false ;
this . modal . cancelButton = false ;
this . modal . okButtonLeft = false ;
this . modal . okButtonText = 'OK' ;
this . modal . open ( ) ;
}
handleError ( message : string , error ) {
this . errorMessage = message ;
console . log ( 'Server responded: ' + error ) ;
this . showLoading = false ;
}
public goToHome() {
this . router . navigate ( [ '/' ] ) ;
}
2020-10-08 16:20:26 +02:00
private setFaqs() {
this . faqs . push ( {
"question" : "What are \"trusted\" sources?" ,
"answer" : "OpenAIRE data sources are considered \"trusted\" when researchers rely on them to share, discover, monitor, and assess their scientific products. " +
"Known sources collected by OpenAIRE are institutional repositories (e.g. university archives, libraries), catch-all repositories (e.g. Zenodo, Figshare, Dryad, B2Share, etc.), " +
"data repositories (e.g. Pangaea, GESIS, bio sources), thematic repositories (e.g. ArXiv, EuropePMC, RePec, etc.), " +
"Open Access publishers (e.g. F1000, OpenEdition, etc.), knowledge graphs (e.g. Microsoft Academic Graph, OpenCitations), " +
"registries (e.g. CrossRef, DataCite, ORCID, GRID.ac, OpenDOAR, re3data.org, etc), aggregators " +
"(e.g. Unpaywall, BASE, Scielo, DOAJ, CORE-UK, etc.), funders (e.g. European Commission, NSF, Wellcome Trust, etc.)."
} ) ;
this . faqs . push ( {
"question" : "What do you mean with “transparent graph”?" ,
"answer" : "The OpenAIRE Research Graph is transparent because it keeps tracks of the provenance of each and every information it contains. " +
"For each field you can know if they have been collected from one of our sources, if it has been inferred (and with which algorithm and with which confidence level)"
} ) ;
}
2021-04-13 00:21:12 +02:00
2020-11-16 13:56:17 +01:00
public ngOnDestroy() {
2021-04-15 20:52:58 +02:00
this . subs . forEach ( sub = > {
if ( sub instanceof Subscription ) {
sub . unsubscribe ( ) ;
}
} ) ;
2020-11-16 13:56:17 +01:00
}
2020-10-05 18:36:30 +02:00
}