openaire-library/utils/email/composer.ts

183 lines
9.3 KiB
TypeScript

import {Email} from "./email";
import {Body} from "./body";
import {FormArray} from "@angular/forms";
export class Composer {
private static noteBodySize = "14px";
private static noteFontSize = "11px";
// TODO move to properties
private static openaireEmail = "mailto:openaire.test@gmail.com";
private static subjectPrefix = "[OpenAIRE-Connect] ";
private static closing = "OpenAIRE team";
private static openaireAddress = "<a href='https://www.openaire.eu'>www.openaire.eu</a><br>";
private static signature = Composer.closing + "<br>" + Composer.openaireAddress;
private static ifYouAreNotResponsible(mail): string {
return "If you are not responsible for this community, please "
+ "<a href=\mailto:'" + mail + "\'>contact us</a>. ";
}
private static manageNotificationSettings(communityId: string): string {
return "Click <a href='https://beta.admin.connect.openaire.eu/manage-user-notifications?communityId="
+ communityId + "'>here</a> 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 "
+ "<a href='https://beta." + communityId + ".openaire.eu/'>" + communityName + "</a>. ";
}
public static composeEmailForNewManager(communityId: string, communityName: string, newCommunityManagers: any, mail: string): Email {
let email: Email = new Email();
email.subject = this.subjectPrefix + communityName + ": Welcome new manager";
email.body = "<div style='font-size:" + this.noteBodySize + "'><p>Welcome to OpenAIRE Connect!</p>"
+ "<p>You are receiving this e-mail as you were assigned as manager of the community <a href='https://beta."
+ communityId + ".openaire.eu/'>" + communityName + "</a> dashboard. "
+ "In order to access the administration section of your community you must first login using one of the available options. "
+ "<br>The administrative rights are associated to the e-mail address, that was used to send you this message."
+ " If you login with an account associated to a different email, please <a href='mailto:helpdesk@openaire.eu'>contact us</a>"
+ " or your colleagues, that already have access to the administration tool, to update your e-mail. <br>"
+ "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard."
+ "</p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible(mail) + "<p>"
+ "</div>";
email.recipients = newCommunityManagers;
return email;
}
public static composeEmailForNewCommunity(contactForm: any, admins: any): Email {
let email: Email = new Email();
email.subject = "RCD: Request for new community";
email.body = "<div style='font-size:" + this.noteBodySize + "'>"
+ "<span><b>Name</b>: " + contactForm.name + "</span><br>"
+ "<span><b>Surname</b>: " + contactForm.surname + "</span><br>"
+ "<span><b>Email</b>: " + contactForm.email + "</span><br>"
+ "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
+ "<span><b>Community Name</b>: " + contactForm.community + "</span>"
+ "<p>" + contactForm.message + "</p>"
+ "</div>";
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 = "<div style='font-size:" + this.noteBodySize + "'>"
+ "<p>A user" + ((info.email)?(" with email " + info.email):"") + " has reported the following issue(s) for "
+ "<a href=\'" + info.url + "\'>" + info.name + "</a></p><ul>";
info.issues.forEach((issue, index) => {
email.body += "<br><li><span><b><u>" + issue.field + "</u>: </b></span>" + issue.report + "</li>";
});
email.body += "</ul></div>";
email.recipients = recipients;
return email;
}
public static composeEmailForUserAfterFeedback(recipients: string[]): Email {
let email: Email = new Email();
email.subject = 'Feedback report received';
email.body = "<div style='font-size:" + this.noteBodySize + "'>"
+ "<p>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.</p><br>"
+ "Thank you for contacting OpenAIRE."
+ "</div>";
email.recipients = recipients;
return email;
}
public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any, mail: string) : Email {
let email: Email = new Email();
email.subject = this.subjectPrefix + communityName + ": Managers list notification";
email.body = "<div style='font-size:" + this.noteBodySize + "'>"
+ "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
+ "The list of managers is: " + managers.join(', ') + "</p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>"
+ this.youAreManagerOfTheCommunity(communityId, communityName)
+ this.ifYouAreNotResponsible(mail)
+ "<br>"
+ this.manageNotificationSettings(communityId)
+ "</p>"
+ "</div>";
email.recipients = firstVersionOfManagers;
return email;
}
public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any, subscriberMail: any, adminPortalURL: string): Email {
let email: Email = new Email();
email.subject = this.subjectPrefix + communityName + ": New subscriber notification";
email.body = "<div style='font-size" + this.noteBodySize + "'>"
+ "<p>There is a new subscriber ("+subscriberMail+") for \"" + communityName + "\" community. Click "
+ "<a href='" + adminPortalURL + "/manage-subscribers?communityId="
+ communityId + "'>here</a> to manage the subscribers list. </p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>"
+ this.youAreManagerOfTheCommunity(communityId, communityName)
+ "<br>"
+ this.manageNotificationSettings(communityId)
+ "</p>"
+ "</div>";
email.recipients = managers;
return email;
}
public static formatEmailBodyForInvitation(body: Body): string {
let fromMessageAndName = "";
if (body.fromName != "") {
fromMessageAndName = "<span>" + body.fromMessage + body.fromName + "</span>";
}
let formattedEmail = "<div style='font-size:" + this.noteBodySize + "'>"
+ body.paragraphs
+ "<p>" + body.signature + fromMessageAndName + "<br>"
+ this.openaireAddress
+ "</p>"
+ "</div>";
return formattedEmail;
}
// TODO remove this after adding this on admin
public static initializeInvitationsBody(communityId: string, communityTitle: string, fullname: string): Body {
let body: Body = new Body();
let defaultMainBody;
if(communityId !== 'covid-19') {
defaultMainBody ='<p>You are invited to subscribe to <a href="https://beta.' + communityId + '.openaire.eu/">'
+ communityTitle + '</a> dashboard.<br>'
+ 'The purpose of this dashboard is to gather, link &amp; monitor the research results related to your community.</p>'
+ '<p>The community dashboard is part of the <a href="https://connect.openaire.eu/">OpenAIRE-Connect</a> '
+ 'project and currently is in BETA version.'
+ '</p>';
} else {
defaultMainBody = '<p>This is a dashboard that gathers, links &amp; 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.</p> ' +
'<p>What you can do:</p>' +
'<ul>' +
'<li>navigate in a linked open data space, a contextual discovery</li>' +
'<li>automatically deposit in Zenodo designated communities</li>' +
'<li>link research results among themselves and to projects</li>' +
'<li>join the team of experts to curate/moderate the traffic, mining, links to the data</li>' +
'</ul> ' +
'<p>The community dashboard is part of the<a href="https://connect.openaire.eu/"> OpenAIRE-Connect</a> project.</p>'
}
return body = {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""};
}
public static initializeInvitationsEmail(communityTitle: string) {
let email: Email = new Email();
return email = {body: "", subject: this.subjectPrefix + communityTitle, recipients: []};
}
}