Project

General

Profile

1 61381 k.triantaf
import {Email} from "./email";
2
import {Body} from "./body";
3
import {FormArray} from "@angular/forms";
4
import {properties} from "../../../../environments/environment";
5
6
export class Composer {
7
  private static noteBodySize = "14px";
8
  private static noteFontSize = "11px";
9
10
  private static subjectPrefix = "[OpenAIRE-Connect] ";
11
  private static closing = "OpenAIRE team";
12
  private static openaireAddress = "<a href='https://www.openaire.eu'>www.openaire.eu</a><br>";
13
  private static signature =  Composer.closing + "<br>" + Composer.openaireAddress;
14
15
  private static ifYouAreNotResponsible(mail): string {
16
      return "If you are not responsible for this community, please "
17
              + "<a href='mailto:" + mail + "'>contact us</a>. ";
18
  }
19
20
  private static manageNotificationSettings(communityId: string): string {
21
      return "Click  <a href='" + properties.adminPortalURL + "/" + communityId + "/users/notifications"
22
              + communityId + "'>here</a> to manage your notification settings. ";
23
  }
24
25
  private static youAreManagerOfTheCommunity(communityId: string, communityName: string): string {
26
      return "You are receiving this e-mail as manager of the community "
27
              + "<a href='https://"+ (properties.environment == "production"?'':'beta.') + communityId + ".openaire.eu/'>" + communityName + "</a>. ";
28
  }
29
30
  public static composeEmailForNewManager(communityId: string, communityName: string): Email {
31
      let email: Email = new Email();
32
33
      email.subject = this.subjectPrefix + communityName + ": Welcome new manager";
34
      email.body = "<div style='font-size:" + this.noteBodySize + "'><p>Welcome to OpenAIRE Connect!</p>"
35
                    + "<p>You are receiving this e-mail as you were assigned as manager of the community  <a href='https://beta."
36
                    + communityId + ".openaire.eu/'>" + communityName + "</a> dashboard. "
37
                    + "In order to access the administration section of your community you must first login using one of the available options. "
38
                    + "<br>The administrative rights are associated to the e-mail address, that was used to send you this message."
39
                    + " If you login with an account associated to a different email, please  <a href='mailto:helpdesk@openaire.eu'>contact us</a>"
40
                    + " or your colleagues, that already have access to the administration tool, to update your e-mail. <br>"
41
                    + "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard."
42
                    + "</p>"
43
                    + this.signature
44
                    + "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible(properties.admins[0]) + "<p>"
45
                    + "</div>";
46
      return email;
47
  }
48
49
  public static composeEmailForNewCommunity(contactForm: any, admins: any): Email {
50
    let email: Email = new Email();
51
52
    email.subject = "OpenAIRE - Connect";
53
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
54
               + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
55
               + "<span><b>Surname</b>: " + contactForm.surname + "</span><br>"
56
               + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
57
               + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
58
               + "<span><b>Community Name</b>: " + contactForm.community + "</span>"
59
               + "<p>" + contactForm.message + "</p>"
60
               + "</div>";
61
    email.recipients = admins;
62
    return email;
63
  }
64
65
  public static composeEmailForMonitor(contactForm: any, admins: any): Email {
66
    let email: Email = new Email();
67
68
    email.subject = "OpenAIRE - Monitor";
69
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
70
      + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
71
      + "<span><b>Surname</b>: " + contactForm.surname + "</span><br>"
72
      + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
73
      + "<span><b>Job Title</b>: " + contactForm.job + "</span><br>"
74
      + "<span><b>Organization</b>: " + contactForm.organization + " (" + contactForm.organizationType + " )</span>"
75
      + "<p>" + contactForm.message + "</p>"
76
      + "</div>";
77
    email.recipients = admins;
78
    return email;
79
  }
80
81
  public static composeEmailForUsageCounts(contactForm: any, admins: any): Email {
82
    let email: Email = new Email();
83
84
    email.subject = "OpenAIRE - UsageCounts";
85
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
86
      + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
87
      + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
88
      + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
89
      + "<span><b>Organization</b>: " + contactForm.organization + "</span>"
90
      + "<p>" + contactForm.description + "</p>"
91
      + "</div>";
92
    email.recipients = admins;
93
    return email;
94
  }
95
96
  public static composeEmailForGraph(contactForm: any, admins: any): Email {
97
    let email: Email = new Email();
98
99
    email.subject = "OpenAIRE - Research Graph";
100
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
101
      + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
102
      + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
103
      + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
104
      + "<span><b>Organization</b>: " + contactForm.organization + "</span>"
105
      + "<p>" + contactForm.description + "</p>"
106
      + "</div>";
107
    email.recipients = admins;
108
    return email;
109
  }
110
111
  public static composeEmailForFeedback(info: {name: string, url: string, email: string, issues: any[]}, recipients: string[]): Email {
112
    let email: Email = new Email();
113
    email.subject = 'Feedback report for ' + info.name;
114
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
115
                  + "<p>A user" + ((info.email)?(" with email " + info.email):"") + " has reported the following issue(s) for "
116
                  + "<a href=\'" + info.url + "\'>" + info.name + "</a></p><ul>";
117
    info.issues.forEach((issue, index) => {
118
      email.body += "<br><li><span><b><u>" + issue.field + "</u>: </b></span>" + issue.report + "</li>";
119
    });
120
    email.body += "</ul></div>";
121
    email.recipients = recipients;
122
    return email;
123
  }
124
125
  public static composeEmailForUserAfterFeedback(recipients: string[]): Email {
126
    let email: Email = new Email();
127
    email.subject = 'Feedback report received';
128
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
129
      + "<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>"
130
      + "Thank you for contacting OpenAIRE."
131
      + "</div>";
132
    email.recipients = recipients;
133
    return email;
134
  }
135
136
  public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string) : Email {
137
      let email: Email = new Email();
138
139
      email.subject = this.subjectPrefix + communityName + ": Managers list notification";
140
      email.body = "<div style='font-size:" + this.noteBodySize + "'>"
141
                    + "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
142
                    + "The list of managers is: ((__managers__))</p>"
143
                    + this.signature
144
                    + "<p style='font-size:" + this.noteFontSize + "'>"
145
                    + this.youAreManagerOfTheCommunity(communityId, communityName)
146
                    + this.ifYouAreNotResponsible(properties.admins[0])
147
                    + "<br>"
148
                    + this.manageNotificationSettings(communityId)
149
                    + "</p>"
150
                    + "</div>";
151
      return email;
152
  }
153
154
  public static composeEmailToInformManagers(communityName: string, communityId: string, subscriberName: string): Email {
155
    let email: Email = new Email();
156
157
    email.subject = this.subjectPrefix + communityName + ": New subscriber notification";
158
    email.body = "<div style='font-size" + this.noteBodySize + "'>"
159
                 + "<p>There is a new subscriber ("+subscriberName+") for \"" + communityName + "\" community. Click  "
160
                 + "<a href='" + properties.adminPortalURL + "/" + communityId + "/users/subscribers"
161
                 + "'>here</a> to manage the subscribers list. </p>"
162
                 + this.signature
163
                 + "<p style='font-size:" + this.noteFontSize + "'>"
164
                 + this.youAreManagerOfTheCommunity(communityId, communityName)
165
                 + "<br>"
166
                 + this.manageNotificationSettings(communityId)
167
                 + "</p>"
168
                 + "</div>";
169
    return email;
170
  }
171
172
  public static formatEmailBodyForInvitation(body: Body): string {
173
    let fromMessageAndName = "";
174
175
    if (body.fromName != "") {
176
      fromMessageAndName = "<span>" + body.fromMessage + body.fromName + "</span>";
177
    }
178
179
    let formattedEmail = "<div style='font-size:" + this.noteBodySize + "'>"
180
                         + body.paragraphs
181
                         + "<p>" + body.signature + fromMessageAndName + "<br>"
182
                         + this.openaireAddress
183
                         + "</p>"
184
                         + "</div>";
185
186
    return formattedEmail;
187
  }
188
189
  // TODO remove this after adding this on admin
190
  public static initializeInvitationsBody(communityId: string, communityTitle: string, fullname: string): Body {
191
    let body: Body = new Body();
192
    let defaultMainBody = '<p>You are invited to subscribe to <a href="https://' + (properties.environment == "production"?'':'beta.')  + communityId + '.openaire.eu/">'
193
      + communityTitle + '</a> dashboard.<br>';
194
    if(communityId !== 'covid-19') {
195
       defaultMainBody += 'The purpose of this dashboard  is to gather, link &amp; monitor the research results related to your community.</p>'
196
        + '<p>The community dashboard is part of the <a href="https://connect.openaire.eu/">OpenAIRE-Connect</a> '
197
        + 'project.'
198
        + '</p>';
199
    } else {
200
      defaultMainBody += 'This is a dashboard that gathers, links &amp; monitors research results related COVID-19 (multi-disciplinary) from authoritative OA sources around the world. ' +
201
        'We have a community of experts moderating and curating the content.</p> ' +
202
        '<p>What you can do:</p>' +
203
        '<ul>' +
204
        '<li>navigate in a linked open data space, a contextual discovery</li>' +
205
        '<li>automatically deposit in Zenodo designated communities</li>' +
206
        '<li>link research results among themselves and to projects</li>' +
207
        '<li>join the team of experts to curate/moderate the traffic, mining, links to the data</li>' +
208
        '</ul> ' +
209
        '<p>The community dashboard is part of the<a href="https://connect.openaire.eu/"> OpenAIRE-Connect</a> project.</p>'
210
    }
211
212
    return body = {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""};
213
  }
214
215
  public static initializeInvitationsEmail(communityTitle: string) {
216
    let email: Email = new Email();
217
218
    return email = {body: "", subject: this.subjectPrefix + communityTitle, recipients: []};
219
  }
220
221
  public static composeEmailForMonitorDashboard(name: string, recipient: string, role: "manager" | "member") {
222
    let email: Email = new Email();
223
    email.subject = 'OpenAIRE Monitor Dashboard | ' + name;
224
    email.body =  this.composeMessageForMonitorDashboard(name, role);
225
    email.recipient = recipient;
226
    return email;
227
  }
228
229
  public static composeMessageForMonitorDashboard(name: string, role: "manager" | "member", user: string = null, invitation: any = null) {
230
    let message = '<p>Dear ((__user__)),</p>' +
231
      '<p>You have been invited to be a ' + role +' of the OpenAIRE Monitor Dashboard for the ' + name + '.</p>' +
232
      '<p>Click <a href="((__link__))" target="_blank">this URL</a> and use the verification code below to accept the invitation.</p>' +
233
      '<p>The verification code is <b>((__code__))</b>.</p>' +
234
      (role === "manager"?
235
        '<p>As a manager of the OpenAIRE Monitor Dashboard, you will have access to the administration part of the dashboard, ' +
236
        'where you will be able to customize and manage the profile of the ' + name + '.</p>':
237
        '<p>As a member of the OpenAIRE Monitor Dashboard, you will have access to the restricted access areas of the profile for the ' + name + '.') +
238
      '<p>Please contact us at <a href="mailto:' + properties.helpdeskEmail+'">' +  properties.helpdeskEmail +
239
      '</a> if you have any questions or concerns.</p>' +
240
      '<p>Kind Regards<br>The OpenAIRE Team</p>' +
241
      '<p><a href="' + properties.domain + '" target="_blank">OpenAIRE Monitor</a></p>';
242
    if(user) {
243
      message = message.replace('((__user__))', user);
244
    }
245
    if(invitation) {
246
      message = message.replace('((__link__))', invitation.link).replace('((__code__))', invitation.code);
247
    }
248
    return message;
249
  }
250
251
  public static composeEmailForCommunityDashboard(name: string, recipient: string) {
252
    let email: Email = new Email();
253
    email.subject = 'OpenAIRE Connect | ' + name;
254
    email.body = this.composeMessageForCommunityDashboard(name);
255
    email.recipient = recipient;
256
    return email;
257
  }
258
259
  public static composeMessageForCommunityDashboard(name: string, user: string = null, invitation: any = null) {
260
    let message = '<p>Dear ((__user__)),</p>' +
261
      '<p>You have been invited to be a manager of the OpenAIRE Research Community Dashboard for the ' + name + '.</p>' +
262
      '<p>Click <a href="((__link__))" target="_blank">this URL</a> and use the verification code below to accept the invitation.</p>' +
263
      '<p>The verification code is <b>((__code__))</b>.</p>' +
264
      '<p>As a manager of the OpenAIRE Research Community Dashboard, you will have access to the administration part of the dashboard, ' +
265
      'where you will be able to customize and manage the content of the ' + name + '.</p>' +
266
      '<p>Please contact us at <a href="mailto:' + properties.helpdeskEmail+'">' +  properties.helpdeskEmail +
267
      '</a> if you have any questions or concerns.</p>' +
268
      '<p>Kind Regards<br>The OpenAIRE Team</p>' +
269
      '<p><a href="https://' + (properties.environment == "production"?'':'beta.')  + 'connect.openaire.eu/" target="_blank">OpenAIRE Connect</a></p>';
270
    if(user) {
271
      message = message.replace('((__user__))', user);
272
    }
273
    if(invitation) {
274
      message = message.replace('((__link__))', invitation.link).replace('((__code__))', invitation.code);
275
    }
276
    return message;
277
  }
278
}