Project

General

Profile

1
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+ "/manage-user-notifications?communityId="
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, newCommunityManagers: any, mail: 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(mail) + "<p>"
45
                    + "</div>";
46
      email.recipients = newCommunityManagers;
47

    
48
      return email;
49
  }
50

    
51
  public static composeEmailForNewCommunity(contactForm: any, admins: any): Email {
52
    let email: Email = new Email();
53
  
54
    email.subject = "OpenAIRE - Connect";
55
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
56
               + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
57
               + "<span><b>Surname</b>: " + contactForm.surname + "</span><br>"
58
               + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
59
               + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
60
               + "<span><b>Community Name</b>: " + contactForm.community + "</span>"
61
               + "<p>" + contactForm.message + "</p>"
62
               + "</div>";
63
    email.recipients = admins;
64
    return email;
65
  }
66
  
67
  public static composeEmailForMonitor(contactForm: any, admins: any): Email {
68
    let email: Email = new Email();
69
    
70
    email.subject = "OpenAIRE - Monitor";
71
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
72
      + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
73
      + "<span><b>Surname</b>: " + contactForm.surname + "</span><br>"
74
      + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
75
      + "<span><b>Job Title</b>: " + contactForm.job + "</span><br>"
76
      + "<span><b>Organization</b>: " + contactForm.organization + " (" + contactForm.organizationType + " )</span>"
77
      + "<p>" + contactForm.message + "</p>"
78
      + "</div>";
79
    email.recipients = admins;
80
    return email;
81
  }
82
  
83
  public static composeEmailForUsageCounts(contactForm: any, admins: any): Email {
84
    let email: Email = new Email();
85
    
86
    email.subject = "OpenAIRE - UsageCounts";
87
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
88
      + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
89
      + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
90
      + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
91
      + "<span><b>Organization</b>: " + contactForm.organization + "</span>"
92
      + "<p>" + contactForm.description + "</p>"
93
      + "</div>";
94
    email.recipients = admins;
95
    return email;
96
  }
97
  
98
  public static composeEmailForGraph(contactForm: any, admins: any): Email {
99
    let email: Email = new Email();
100
    
101
    email.subject = "OpenAIRE - Research Graph";
102
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
103
      + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
104
      + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
105
      + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
106
      + "<span><b>Organization</b>: " + contactForm.organization + "</span>"
107
      + "<p>" + contactForm.description + "</p>"
108
      + "</div>";
109
    email.recipients = admins;
110
    return email;
111
  }
112
  
113
  public static composeEmailForFeedback(info: {name: string, url: string, email: string, issues: any[]}, recipients: string[]): Email {
114
    let email: Email = new Email();
115
    email.subject = 'Feedback report for ' + info.name;
116
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
117
                  + "<p>A user" + ((info.email)?(" with email " + info.email):"") + " has reported the following issue(s) for "
118
                  + "<a href=\'" + info.url + "\'>" + info.name + "</a></p><ul>";
119
    info.issues.forEach((issue, index) => {
120
      email.body += "<br><li><span><b><u>" + issue.field + "</u>: </b></span>" + issue.report + "</li>";
121
    });
122
    email.body += "</ul></div>";
123
    email.recipients = recipients;
124
    return email;
125
  }
126
  
127
  public static composeEmailForUserAfterFeedback(recipients: string[]): Email {
128
    let email: Email = new Email();
129
    email.subject = 'Feedback report received';
130
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
131
      + "<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>"
132
      + "Thank you for contacting OpenAIRE."
133
      + "</div>";
134
    email.recipients = recipients;
135
    return email;
136
  }
137
  
138
  public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any, mail: string) : Email {
139
      let email: Email = new Email();
140

    
141
      email.subject = this.subjectPrefix + communityName + ": Managers list notification";
142
      email.body = "<div style='font-size:" + this.noteBodySize + "'>"
143
                    + "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
144
                    + "The list of managers is: " + managers.join(', ') + "</p>"
145
                    + this.signature
146
                    + "<p style='font-size:" + this.noteFontSize + "'>"
147
                    + this.youAreManagerOfTheCommunity(communityId, communityName)
148
                    + this.ifYouAreNotResponsible(mail)
149
                    + "<br>"
150
                    + this.manageNotificationSettings(communityId)
151
                    + "</p>"
152
                    + "</div>";
153
      email.recipients = firstVersionOfManagers;
154

    
155
      return email;
156
  }
157

    
158
  public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any, subscriberMail: any, adminPortalURL: string): Email {
159
    let email: Email = new Email();
160

    
161
    email.subject = this.subjectPrefix + communityName + ": New subscriber notification";
162
    email.body = "<div style='font-size" + this.noteBodySize + "'>"
163
                 + "<p>There is a new subscriber ("+subscriberMail+") for \"" + communityName + "\" community. Click  "
164
                 + "<a href='" + adminPortalURL +  "/manage-subscribers?communityId="
165
                 + communityId + "'>here</a> to manage the subscribers list. </p>"
166
                 + this.signature
167
                 + "<p style='font-size:" + this.noteFontSize + "'>"
168
                 + this.youAreManagerOfTheCommunity(communityId, communityName)
169
                 + "<br>"
170
                 + this.manageNotificationSettings(communityId)
171
                 + "</p>"
172
                 + "</div>";
173
    email.recipients = managers;
174

    
175
    return email;
176
  }
177

    
178
  public static formatEmailBodyForInvitation(body: Body): string {
179
    let fromMessageAndName = "";
180

    
181
    if (body.fromName != "") {
182
      fromMessageAndName = "<span>" + body.fromMessage + body.fromName + "</span>";
183
    }
184

    
185
    let formattedEmail = "<div style='font-size:" + this.noteBodySize + "'>"
186
                         + body.paragraphs
187
                         + "<p>" + body.signature + fromMessageAndName + "<br>"
188
                         + this.openaireAddress
189
                         + "</p>"
190
                         + "</div>";
191

    
192
    return formattedEmail;
193
  }
194
  
195
  // TODO remove this after adding this on admin
196
  public static initializeInvitationsBody(communityId: string, communityTitle: string, fullname: string): Body {
197
    let body: Body = new Body();
198
    let defaultMainBody = '<p>You are invited to subscribe to <a href="https://' + (properties.environment == "production"?'':'beta.')  + communityId + '.openaire.eu/">'
199
      + communityTitle + '</a> dashboard.<br>';
200
    if(communityId !== 'covid-19') {
201
       defaultMainBody += 'The purpose of this dashboard  is to gather, link &amp; monitor the research results related to your community.</p>'
202
        + '<p>The community dashboard is part of the <a href="https://connect.openaire.eu/">OpenAIRE-Connect</a> '
203
        + 'project.'
204
        + '</p>';
205
    } else {
206
      defaultMainBody += 'This is a dashboard that gathers, links &amp; monitors research results related COVID-19 (multi-disciplinary) from authoritative OA sources around the world. ' +
207
        'We have a community of experts moderating and curating the content.</p> ' +
208
        '<p>What you can do:</p>' +
209
        '<ul>' +
210
        '<li>navigate in a linked open data space, a contextual discovery</li>' +
211
        '<li>automatically deposit in Zenodo designated communities</li>' +
212
        '<li>link research results among themselves and to projects</li>' +
213
        '<li>join the team of experts to curate/moderate the traffic, mining, links to the data</li>' +
214
        '</ul> ' +
215
        '<p>The community dashboard is part of the<a href="https://connect.openaire.eu/"> OpenAIRE-Connect</a> project.</p>'
216
    }
217

    
218
    return body = {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""};
219
  }
220

    
221
  public static initializeInvitationsEmail(communityTitle: string) {
222
    let email: Email = new Email();
223

    
224
    return email = {body: "", subject: this.subjectPrefix + communityTitle, recipients: []};
225
  }
226
  
227
  public static composeEmailForMonitorDashboard(name: string, recipient: string, role: "manager" | "member") {
228
    let email: Email = new Email();
229
    email.subject = 'OpenAIRE Monitor Dashboard | ' + name;
230
    email.body = '<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__))">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 + '">OpenAIRE Monitor</a></p>'
242
    email.recipient = recipient;
243
    return email;
244
  }
245
}
(2-2/5)