import {Email} from "./email"; import {Body} from "./body"; import {properties} from "../../../../environments/environment"; import {User} from "../../login/utils/helper.class"; import {StakeholderConfiguration} from "../../monitor-admin/utils/indicator-utils"; export class Composer { private static noteBodySize = "14px"; private static noteFontSize = "11px"; private static subjectPrefix = "[OpenAIRE-Connect] "; private static closing = "OpenAIRE team"; private static openaireAddress = "www.openaire.eu
"; private static signature = Composer.closing + "
" + Composer.openaireAddress; private static ifYouAreNotResponsible(mail): string { return "If you are not responsible for this community, please " + "contact us. "; } private static manageNotificationSettings(communityId: string): string { return "Click here to manage your notification settings. "; } private static youAreManagerOfTheCommunity(communityId: string, communityName: string): string { return "You are receiving this e-mail as manager of the community " + "" + communityName + ". "; } public static composeEmailForNewManager(communityId: string, communityName: string): Email { let email: Email = new Email(); email.subject = this.subjectPrefix + communityName + ": Welcome new manager"; email.body = "

Welcome to OpenAIRE Connect!

" + "

You are receiving this e-mail as you were assigned as manager of the " + communityName + " gateway. " + "In order to access the administration section of your community you must first login using one of the available options. " + "
The administrative rights are associated with the e-mail address that was used to send you this message." + " If you login with an account associated to a different email, please contact us" + " or your colleagues, that already have access to the administration tool, to update your e-mail.
" + "If you do not know which is the email associated with your OpenAIRE account, you can follow the instructions of this video (from 00:30 to 1:00).
" + "Once logged in, you can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the gateway." + "

" + this.signature + "

" + this.ifYouAreNotResponsible(properties.admins[0]) + "

" + "

"; return email; } public static composeEmailForNewCommunity(contactForm: any, admins: any): Email { let email: Email = new Email(); email.subject = "OpenAIRE - Connect"; email.body = "
" + "Name: " + contactForm.name + "
" + "Surname: " + contactForm.surname + "
" + "Email: " + contactForm.email + "
" + "Affiliation: " + contactForm.affiliation + "
" + "Community Name: " + contactForm.community + "" + "

" + contactForm.message + "

" + "
"; email.recipients = admins; return email; } public static composeEmailForMonitor(contactForm: any, admins: string[]): Email { let email: Email = new Email(); email.subject = "OpenAIRE - Monitor"; email.body = "
" + "Name: " + contactForm.name + "
" + "Surname: " + contactForm.surname + "
" + "Email: " + contactForm.email + "
" + "Job Title: " + contactForm.job + "
" + "Organization: " + contactForm.organization + " (" + contactForm.organizationType + " )" + "

" + contactForm.message + "

" + "
"; email.recipients = admins; return email; } public static composeEmailForExplore(contactForm: any, admins: any): Email { let email: Email = new Email(); email.subject = "OpenAIRE - Explore [" + properties.environment.toUpperCase() + "]"; email.body = "
" + "Name: " + contactForm.name + "
" + "Surname: " + contactForm.surname + "
" + "Email: " + contactForm.email + "
" + "Affiliation: " + (contactForm.affiliation ? contactForm.affiliation : '-') + "
" + "

" + contactForm.message + "

" + "
"; email.recipients = admins; return email; } public static composeEmailforIrishMonitor(contactForm: any, admins: any): Email { let email: Email = new Email(); email.subject = "National OA Monitor Ireland | " + contactForm.subject; email.body = "
" + "Name: " + contactForm.name + "
" + "Email: " + contactForm.email + "
" + "

" + contactForm.message + "

" + "
"; email.recipients = admins; return email; } public static composeEmailForDevelop(contactForm: any, admins: any, user: User): Email { let email: Email = new Email(); email.subject = "OpenAIRE - Develop [" + properties.environment.toUpperCase() + "]"; email.body = "
" + "Name: " + user.firstname + "
" + "Surname: " + user.lastname + "
" + "Email: " + user.email + "
" + "Subject: " + (contactForm.subject ? contactForm.subject : '-') + "
" + "

" + contactForm.message + "

" + "
"; email.recipients = admins; return email; } public static composeEmailForUsageCounts(contactForm: any, admins: any): Email { let email: Email = new Email(); email.subject = "OpenAIRE - UsageCounts"; email.body = "
" + "Name: " + contactForm.name + "
" + "Email: " + contactForm.email + "
" + "Affiliation: " + contactForm.affiliation + "
" + "Organization: " + contactForm.organization + "" + "

" + contactForm.description + "

" + "
"; email.recipients = admins; return email; } public static composeEmailForGraph(contactForm: any, admins: any): Email { let email: Email = new Email(); email.subject = "OpenAIRE - Research Graph"; email.body = "
" + "Name: " + contactForm.name + "
" + "Email: " + contactForm.email + "
" + "Affiliation: " + contactForm.affiliation + "
" + "Organization: " + contactForm.organization + "" + "

" + contactForm.description + "

" + "
"; email.recipients = admins; return email; } public static composeEmailForFeedback(info: {name: string, url: string, email: string, issues: any[]}, recipients: string[]): Email { let email: Email = new Email(); email.subject = 'Feedback report for ' + info.name; email.body = "
" + "

A user" + ((info.email)?(" with email " + info.email):"") + " has reported the following issue(s) for " + "" + info.name + "

"; email.recipients = recipients; return email; } public static composeEmailForSdgsSuggestion(info: {name: string, url: string, email: string, subjects: any[]}, recipients: string[], subjectType: "sdg" | "fos"): Email { let typeName: string = ""; if(subjectType == "sdg") { typeName = "Sustainable Development Goals (SDGs)"; } else { typeName = "Fields of Science (FoS)"; } let email: Email = new Email(); email.subject = 'Feedback report for ' + info.name; email.body = "
" + "

A user" + ((info.email)?(" with email " + info.email):"") + " has reported the following "+typeName+" for " + "" + info.name + "

"; email.recipients = recipients; return email; } public static composeEmailForUserAfterFeedback(recipients: string[]): Email { let email: Email = new Email(); email.subject = 'Feedback report received'; email.body = "
" + "

This is an automated message to let you know that your feedback has been successfully received. Our graph experts will get back to you as soon as possible.


" + "Thank you for contacting OpenAIRE." + "
"; email.recipients = recipients; return email; } public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string) : Email { let email: Email = new Email(); email.subject = this.subjectPrefix + communityName + ": Managers list notification"; email.body = "
" + "

There are updates in the managers list for \"" + communityName + "\" community.
" + "The list of managers is: ((__managers__))

" + this.signature + "

" + this.youAreManagerOfTheCommunity(communityId, communityName) + this.ifYouAreNotResponsible(properties.admins[0]) + "
" + this.manageNotificationSettings(communityId) + "

" + "
"; return email; } public static composeEmailToInformManagers(communityName: string, communityId: string, subscriberName: string): Email { let email: Email = new Email(); email.subject = this.subjectPrefix + communityName + ": New Member notification"; email.body = "
" + "

There is a new member ("+subscriberName+") for \"" + communityName + "\" community. Click " + "here to manage the members list.

" + this.signature + "

" + this.youAreManagerOfTheCommunity(communityId, communityName) + "
" + this.manageNotificationSettings(communityId) + "

" + "
"; return email; } public static composeEmailToReportCachingProcess(report: any) { let email: Email = new Email(); email.recipients = [report.creator]; email.subject = 'OpenAIRE | Monitor Dashboard - ' + report.name + '\'s caching process has been finished'; email.body = "
" + "

" + "

Success: " + report.success + "/" + report.total + "
" + "
Errors: " + report.errors.map(error => error.url + ' - ' + error.status).join('
') + "
" + "

" + "
"; return email; } public static formatEmailBodyForInvitation(body: Body): string { let fromMessageAndName = ""; if (body.fromName != "") { fromMessageAndName = "" + body.fromMessage + body.fromName + ""; } let formattedEmail = "
" + body.paragraphs + "

" + body.signature + fromMessageAndName + "
" + this.openaireAddress + "

" + "
"; return formattedEmail; } // TODO remove this after adding this on admin public static initializeInvitationsBody(communityId: string, communityTitle: string, fullname: string): Body { let defaultMainBody = '

You are invited to join ' + communityTitle + ' dashboard.
'; if(communityId !== 'covid-19') { defaultMainBody += 'The purpose of this dashboard is to gather, link & monitor the research results related to your community.

' + '

The community dashboard is part of the OpenAIRE-Connect ' + 'project.' + '

'; } else { defaultMainBody += 'This is a dashboard that gathers, links & monitors research results related COVID-19 (multi-disciplinary) from authoritative OA sources around the world. ' + 'We have a community of experts moderating and curating the content.

' + '

What you can do:

' + ' ' + '

The community dashboard is part of the OpenAIRE-Connect project.

' } return {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""}; } public static initializeInvitationsEmail(communityTitle: string) { let email: Email = new Email(); return {body: "", subject: this.subjectPrefix + communityTitle, recipients: []}; } public static composeEmailForMonitorDashboard(name: string, recipient: string, role: "manager" | "member") { let email: Email = new Email(); email.subject = 'OpenAIRE Monitor Dashboard | ' + name; email.body = this.composeMessageForMonitorDashboard(name, role); email.recipient = recipient; return email; } public static composeMessageForMonitorDashboard(name: string, role: "manager" | "member", user: string = null, invitation: any = null) { let pdppLink = 'http://catalogue.openaire.eu/files/Personal%20Data%20Protection%20Policy%20for%20OpenAIRE%20Services%20April%202022.pdf'; let message = '

Dear ((__user__)),

' + '

You have been invited to be a ' + role +' of the OpenAIRE Monitor Dashboard for the ' + name + '.

' + '

Click this URL and use the verification code below to accept the invitation.

' + '

The verification code is ((__code__)).

' + '

By logging in and using the service you accept and agree to the OpenAIRE personal data protection policy.

' + (role === "manager"? '

As a manager of the OpenAIRE Monitor Dashboard, you will have access to the administration part of the dashboard, ' + 'where you will be able to customize and manage the profile of the ' + name + '.

': '

As a member of the OpenAIRE Monitor Dashboard, you will have access to the restricted access areas of the profile for the ' + name + '.') + '

Please contact us at ' + properties.helpdeskEmail + ' if you have any questions or concerns.

' + '

Kind Regards
The OpenAIRE Team

' + '

OpenAIRE Monitor

'; if(user) { message = message.replace('((__user__))', user); } if(invitation) { message = message.replace('((__link__))', invitation.link).replace('((__code__))', invitation.code); } return message; } public static composeMessageForIrishDashboard(name: string, recipient: string, role: "manager" | "member") { let email: Email = new Email(); email.subject = 'National Open Access Monitor Ireland | ' + name; email.recipient = recipient; email.body = '

Dear user,

' + '

You have been invited to be a ' + StakeholderConfiguration.ROLES[role] +' of the for the National Open Access Monitor, Ireland dashboard for the ' + name + '.

' + '

Click this URL and use the verification code below to accept the invitation.

' + '

The verification code is ((__code__)).

' + '

At your first sign in you will be asked to accept and consent to the "OpenAIRE Personal Data Protection Policy and Consent Form" to be able to use the service.

' + (role === "manager"? '

As a ' + StakeholderConfiguration.ROLES[role] + ' of the National Open Access Monitor, Ireland, you will have access to the administration part of the dashboard, where you will be able to also invite other users to become ' + StakeholderConfiguration.ROLES['member'] + 's.

': '

As a ' + StakeholderConfiguration.ROLES[role] + ' of the National Open Access Monitor, Ireland, you will have access to the sandbox of the profile for the ' + name + '.') + '

Please contact us at ' + properties.helpdeskEmail + ' if you have any questions or concerns.

' + '

Kind Regards
The OpenAIRE Team

' + '

National Open Access Monitor, Ireland

'; return email; } public static composeEmailForCommunityDashboard(name: string, role: "manager" | "member", recipient: string) { let email: Email = new Email(); email.subject = 'OpenAIRE Connect | ' + name; email.body = this.composeMessageForCommunityDashboard(name, role); email.recipient = recipient; return email; } public static composeMessageForCommunityDashboard(name: string, role: "manager" | "member", user: string = null, invitation: any = null) { let message = '

Dear ((__user__)),

' + '

You have been invited to be a ' + role + ' of the OpenAIRE Research Community Dashboard for the ' + name + '.

' + '

Click this URL and use the verification code below to accept the invitation.

' + '

The verification code is ((__code__)).

' + (role === 'manager'? '

As a manager of the OpenAIRE Research Community Dashboard, you will have access to the administration part of the dashboard, ' + 'where you will be able to customize and manage the content of the ' + name + '.

': '

As a member of the OpenAIRE Research Community Dashboard, you will have access to the community dashboard and link research results with projects, communities and other research projects.

') + '

Please contact us at ' + properties.helpdeskEmail + ' if you have any questions or concerns.

' + '

Kind Regards
The OpenAIRE Team

' + '

OpenAIRE Connect

'; if(user) { message = message.replace('((__user__))', user); } if(invitation) { message = message.replace('((__link__))', invitation.link).replace('((__code__))', invitation.code); } return message; } }