import {Component, ViewChild} from '@angular/core'; import {ActivatedRoute, NavigationEnd, Params, Router} from '@angular/router'; import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {MenuItem, RootMenuItem} 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 {properties} from "../environments/environment"; import {BehaviorSubject, Subscriber} from "rxjs"; import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service"; import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component"; import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll"; import {QuickContactService} from './openaireLibrary/sharedComponents/quick-contact/quick-contact.service'; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; import {Composer} from "./openaireLibrary/utils/email/composer"; import {NotificationHandler} from "./openaireLibrary/utils/notification-handler"; import {EmailService} from "./openaireLibrary/utils/email/email.service"; import {StringUtils} from "./openaireLibrary/utils/string-utils.class"; import {QuickContactComponent} from "./openaireLibrary/sharedComponents/quick-contact/quick-contact.component"; import {AlertModal} from "./openaireLibrary/utils/modal/alert"; @Component({ selector: 'app-root', template: `
Get Started
OpenAIRE uses cookies in order to function properly.
Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing experience possible. By using the OpenAIRE portal you accept our use of cookies. Read more
Our team will respond to your submission soon.
` }) export class AppComponent { userMenuItems: MenuItem[] = []; menuItems: RootMenuItem [] = []; bottomMenuItems: MenuItem[] = []; properties: EnvProperties = properties; showMenu: boolean = false; user: User; params: BehaviorSubject = new BehaviorSubject(null); url: string; header: Header; logoPath: string = 'assets/common-assets/'; /* Contact */ public showQuickContact: boolean; public showGetStarted: boolean = true; public contactForm: FormGroup; public organizationTypes: string[] = [ 'Funding agency', 'University / Research Center', 'Research Infrastructure', 'Government', 'Non-profit', 'Industry', 'Other' ]; public sending = false; @ViewChild('modal') modal: AlertModal; @ViewChild('quickContact') quickContact: QuickContactComponent; private subscriptions: any[] = []; constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService, private router: Router, private stakeholderService: StakeholderService, private smoothScroll: SmoothScroll, private userManagementService: UserManagementService, private quickContactService: QuickContactService, private fb: FormBuilder, private emailService: EmailService) { this.subscriptions.push(router.events.forEach((event) => { if (event instanceof NavigationEnd) { this.url = event.url; let r = this.route; while (r.firstChild) { r = r.firstChild; } let params = r.snapshot.params; this.params.next(params); if (event.url === '/contact-us') { this.quickContactService.setDisplay(false); } else if (event.url !== '/contact-us' && !this.showQuickContact) { this.quickContactService.setDisplay(true); } this.showGetStarted = event.url !== '/get-started'; } })); } ngOnInit() { this.userManagementService.fixRedirectURL = properties.afterLoginRedirectLink; this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.user = user; this.setUserMenu(); this.header = { route: "/", url: null, title: 'monitor', logoUrl: this.logoPath + 'logo-large-monitor.png', logoSmallUrl: this.logoPath + 'logo-small-monitor.png', position: 'left', badge: true, menuPosition: 'center' }; this.buildMenu(); this.reset(); })); this.subscriptions.push(this.quickContactService.isDisplayed.subscribe(display => { this.showQuickContact = display; })); } public ngOnDestroy() { this.subscriptions.forEach(value => { if (value instanceof Subscriber) { value.unsubscribe(); } }); this.userManagementService.clearSubscriptions(); this.stakeholderService.clearSubscriptions(); this.smoothScroll.clearSubscriptions(); } public buildMenu() { this.menuItems = []; this.menuItems.push({ rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}), items: [] }); this.menuItems.push({ rootItem: new MenuItem("stakeholders", "Browse Dashboards", "", "/browse", false, [], null, {}), items: [] }); /*this.menuItems.push({ rootItem: new MenuItem("contact-us", "Contact us", "", "/contact-us", false, [], null, {}), items: [] });*/ this.bottomMenuItems = [ new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}), new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}), new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}), new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {}) ]; this.showMenu = true; } public setUserMenu() { this.userMenuItems = []; if (this.user) { if (Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isKindOfMonitorManager(this.user)) { this.userMenuItems.push(new MenuItem("", "Manage profiles", this.properties.domain + properties.baseLink + "/dashboard/admin", "", false, [], [], {})) } this.userMenuItems.push(new MenuItem("", "My Dashboards", "", "/my-dashboards", false, [], [], {})); this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {})); } } public send(event) { if (event.valid === true) { this.sendMail(this.properties.admins); } } 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]), job: this.fb.control('', Validators.required), organization: this.fb.control('', Validators.required), organizationType: this.fb.control('', [Validators.required, StringUtils.validatorType(this.organizationTypes)]), message: this.fb.control('', Validators.required), recaptcha: this.fb.control('', Validators.required), }); } private sendMail(admins: string[]) { this.sending = true; this.subscriptions.push(this.emailService.contact(this.properties, Composer.composeEmailForMonitor(this.contactForm.value, admins), this.contactForm.value.recaptcha).subscribe( res => { if (res) { this.sending = false; this.reset(); this.modalOpen(); } else { this.handleError('Email sent failed! Please try again.'); } }, error => { this.handleError('Email sent failed! Please try again.', error); } )); } 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 = null) { if (error) { console.error(error); } this.sending = false; this.quickContact.close(); NotificationHandler.rise(message, 'danger'); this.contactForm.get('recaptcha').setValue(''); } }