@ -1,10 +1,8 @@
import { C omponent} from '@angular/core' ;
import { C hangeDetectorRef, C omponent, ViewChild } from '@angular/core' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { EnvProperties } from './openaireLibrary/utils/properties/env-properties' ;
import { MenuItem } from './openaireLibrary/sharedComponents/menu' ;
import { EnvironmentSpecificService } from './openaireLibrary/utils/properties/environment-specific.service' ;
import { Session , User } from './openaireLibrary/login/utils/helper.class' ;
import { UserManagementService } from "./openaireLibrary/services/user-management.service" ;
import { ConfigurationService } from "./openaireLibrary/utils/configuration/configuration.service" ;
@ -15,6 +13,14 @@ import {properties} from "../environments/environment";
import { SmoothScroll } from "./openaireLibrary/utils/smooth-scroll" ;
import { SEOService } from "./openaireLibrary/sharedComponents/SEO/SEO.service" ;
import { OpenaireEntities } from "./openaireLibrary/utils/properties/searchFields" ;
import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
import { QuickContactComponent } from './openaireLibrary/sharedComponents/quick-contact/quick-contact.component' ;
import { EmailService } from './openaireLibrary/utils/email/email.service' ;
import { Composer } from "./openaireLibrary/utils/email/composer" ;
import { AlertModal } from './openaireLibrary/utils/modal/alert' ;
import { NotificationHandler } from "./openaireLibrary/utils/notification-handler" ;
import { QuickContactService } from './openaireLibrary/sharedComponents/quick-contact/quick-contact.service' ;
import { LayoutService } from './openaireLibrary/dashboard/sharedComponents/sidebar/layout.service' ;
@Component ( {
//changeDetection: ChangeDetectionStrategy.Default,
@ -46,6 +52,9 @@ import {OpenaireEntities} from "./openaireLibrary/utils/properties/searchFields"
< / span > < / a >
< / c o o k i e - l a w >
< bottom id = "bottom" * ngIf = "isClient && properties" [ properties ] = " properties " > < / bottom >
< quick - contact # quickContact * ngIf = "showQuickContact && contactForm" ( sendEmitter ) = " send ( $ event ) "
[ contactForm ] = "contactForm" [ sending ] = "sending" [ contact ] = "'Help'" > < / q u i c k - c o n t a c t >
< modal - alert # modal [ overflowBody ] = " false " > < / m o d a l - a l e r t >
`
} )
export class AppComponent {
@ -56,17 +65,29 @@ export class AppComponent {
properties : EnvProperties = properties ;
user : User ;
header : Header ;
public showQuickContact : boolean ;
public contactForm : FormGroup ;
public sending : boolean = false ;
@ViewChild ( 'quickContact' ) quickContact : QuickContactComponent ;
@ViewChild ( 'modal' ) modal : AlertModal ;
subscriptions = [ ] ;
constructor ( private route : ActivatedRoute , private propertiesService : EnvironmentSpecificService ,
private router : Router , private userManagementService : UserManagementService , private smoothScroll : SmoothScroll ,
private configurationService : ConfigurationService , private _meta : Meta , private seoService : SEOService , ) {
private configurationService : ConfigurationService , private _meta : Meta , private seoService : SEOService ,
private emailService : EmailService , private fb : FormBuilder , private quickContactService : QuickContactService ,
private layoutService : LayoutService , private cdr : ChangeDetectorRef ) {
}
ngOnInit() {
if ( typeof document !== 'undefined' ) {
this . isClient = true ;
}
this . subscriptions . push ( this . layoutService . hasQuickContact . subscribe ( hasQuickContact = > {
this . showQuickContact = hasQuickContact ;
this . cdr . detectChanges ( ) ;
} ) ) ;
this . configurationService . initCommunityInformation ( this . properties , this . properties . adminToolsCommunity ) ;
this . feedbackmail = this . properties . feedbackmail ;
if ( this . properties . environment == "production" || this . properties . environment == "development" ) {
@ -88,6 +109,10 @@ export class AppComponent {
position : 'left' ,
badge : true
} ;
this . reset ( ) ;
} ) ) ;
this . subscriptions . push ( this . quickContactService . isDisplayed . subscribe ( display = > {
this . showQuickContact = display ;
} ) ) ;
}
@ -138,7 +163,6 @@ export class AppComponent {
new MenuItem ( "" , "Registries" , "" , "/search/entity-registries" , false , [ "datasource" ] , [ "/search/entity-registries" ] , { } ) ,
new MenuItem ( "" , "Browse all" , "" , "/search/find/dataproviders" , false , [ "datasource" ] , [ "/search/find/dataproviders" ] , { } ) ]
) ,
new MenuItem ( "contact" , "Contact us" , "" , "/contact-us" , false , [ ] , [ "/contact-us" ] , { } ) ,
] ;
if ( Session . isPortalAdministrator ( this . user ) ) {
this . userMenuItems . push ( new MenuItem ( "" , "Manage all links" , "" , "/claims" , false , [ ] , [ "/claims" ] , { } ) ) ;
@ -150,6 +174,66 @@ export class AppComponent {
if ( this . user ) {
this . userMenuItems . push ( new MenuItem ( "" , "User information" , "" , "/user-info" , false , [ ] , [ ] , { } ) ) ;
}
}
public send ( event ) {
if ( event . valid === true ) {
this . sendMail ( this . properties . admins ) ;
}
}
private sendMail ( admins : string [ ] ) {
this . sending = true ;
this . subscriptions . push ( this . emailService . contact ( this . properties ,
Composer . composeEmailForExplore ( this . contactForm . value , admins ) ,
this . contactForm . value . recaptcha ) . subscribe (
res = > {
if ( res ) {
this . sending = false ;
this . reset ( ) ;
this . modalOpen ( ) ;
} else {
this . handleError ( 'Email <b>sent failed!</b> Please try again.' ) ;
}
} ,
error = > {
this . handleError ( 'Email <b>sent failed!</b> Please try again.' , error ) ;
}
) ) ;
}
public reset() {
if ( this . quickContact ) {
this . quickContact . close ( ) ;
}
this . contactForm = this . fb . group ( {
name : this.fb.control ( '' , Validators . required ) ,
surname : this.fb.control ( '' , Validators . required ) ,
email : this.fb.control ( '' , [ Validators . required , Validators . email ] ) ,
affiliation : this.fb.control ( '' ) ,
message : this.fb.control ( '' , Validators . required ) ,
recaptcha : this.fb.control ( '' , Validators . required ) ,
} ) ;
}
public modalOpen() {
this . modal . okButton = true ;
this . modal . alertTitle = 'Your request has been successfully submitted' ;
this . modal . message = 'Our team will respond to your submission soon.' ;
this . modal . cancelButton = false ;
this . modal . okButtonLeft = false ;
this . modal . okButtonText = 'OK' ;
this . modal . open ( ) ;
}
handleError ( message : string , error = null ) {
if ( error ) {
console . error ( error ) ;
}
this . sending = false ;
this . quickContact . close ( ) ;
NotificationHandler . rise ( message , 'danger' ) ;
this . contactForm . get ( 'recaptcha' ) . setValue ( '' ) ;
}
}