Project

General

Profile

1
import {Email} from "./email";
2
import {Body} from "./body";
3
import {FormArray} from "@angular/forms";
4

    
5
export class Composer {
6
  private static noteBodySize = "14px";
7
  private static noteFontSize = "11px";
8

    
9
  // TODO move to properties
10
  private static openaireEmail = "mailto:openaire.test@gmail.com";
11
  private static subjectPrefix = "[OpenAIRE-Connect] ";
12
  private static closing = "OpenAIRE team";
13
  private static openaireAddress = "<a href='https://www.openaire.eu'>www.openaire.eu</a><br>";
14
  private static signature =  Composer.closing + "<br>" + Composer.openaireAddress;
15

    
16
  private static ifYouAreNotResponsible(mail): string {
17
      return "If you are not responsible for this community, please "
18
              + "<a href=\mailto:'" + mail + "\'>contact us</a>. ";
19
  }
20

    
21
  private static manageNotificationSettings(communityId: string): string {
22
      return "Click  <a href='https://beta.admin.connect.openaire.eu/manage-user-notifications?communityId="
23
              + communityId + "'>here</a> to manage your notification settings. ";
24
  }
25

    
26
  private static youAreManagerOfTheCommunity(communityId: string, communityName: string): string {
27
      return "You are receiving this e-mail as manager of the community "
28
              + "<a href='https://beta." + communityId + ".openaire.eu/'>" + communityName + "</a>. ";
29
  }
30

    
31
  public static composeEmailForNewManager(communityId: string, communityName: string, newCommunityManagers: any, mail: string): Email {
32
      let email: Email = new Email();
33

    
34
      email.subject = this.subjectPrefix + communityName + ": Welcome new manager";
35
      email.body = "<div style='font-size:" + this.noteBodySize + "'><p>Welcome to OpenAIRE Connect!</p>"
36
                    + "<p>You are receiving this e-mail as you were assigned as manager of the community  <a href='https://beta."
37
                    + communityId + ".openaire.eu/'>" + communityName + "</a> dashboard. "
38
                    + "In order to access the administration section of your community you must first login using one of the available options. "
39
                    + "<br>The administrative rights are associated to the e-mail address, that was used to send you this message."
40
                    + " If you login with an account associated to a different email, please  <a href='mailto:helpdesk@openaire.eu'>contact us</a>"
41
                    + " or your colleagues, that already have access to the administration tool, to update your e-mail. <br>"
42
                    + "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard."
43
                    + "</p>"
44
                    + this.signature
45
                    + "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible(mail) + "<p>"
46
                    + "</div>";
47
      email.recipients = newCommunityManagers;
48

    
49
      return email;
50
  }
51

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

    
112
      email.subject = this.subjectPrefix + communityName + ": Managers list notification";
113
      email.body = "<div style='font-size:" + this.noteBodySize + "'>"
114
                    + "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
115
                    + "The list of managers is: " + managers.join(', ') + "</p>"
116
                    + this.signature
117
                    + "<p style='font-size:" + this.noteFontSize + "'>"
118
                    + this.youAreManagerOfTheCommunity(communityId, communityName)
119
                    + this.ifYouAreNotResponsible(mail)
120
                    + "<br>"
121
                    + this.manageNotificationSettings(communityId)
122
                    + "</p>"
123
                    + "</div>";
124
      email.recipients = firstVersionOfManagers;
125

    
126
      return email;
127
  }
128

    
129
  public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any, subscriberMail: any, adminPortalURL: string): Email {
130
    let email: Email = new Email();
131

    
132
    email.subject = this.subjectPrefix + communityName + ": New subscriber notification";
133
    email.body = "<div style='font-size" + this.noteBodySize + "'>"
134
                 + "<p>There is a new subscriber ("+subscriberMail+") for \"" + communityName + "\" community. Click  "
135
                 + "<a href='" + adminPortalURL +  "/manage-subscribers?communityId="
136
                 + communityId + "'>here</a> to manage the subscribers list. </p>"
137
                 + this.signature
138
                 + "<p style='font-size:" + this.noteFontSize + "'>"
139
                 + this.youAreManagerOfTheCommunity(communityId, communityName)
140
                 + "<br>"
141
                 + this.manageNotificationSettings(communityId)
142
                 + "</p>"
143
                 + "</div>";
144
    email.recipients = managers;
145

    
146
    return email;
147
  }
148

    
149
  public static formatEmailBodyForInvitation(body: Body): string {
150
    let fromMessageAndName = "";
151

    
152
    if (body.fromName != "") {
153
      fromMessageAndName = "<span>" + body.fromMessage + body.fromName + "</span>";
154
    }
155

    
156
    let formattedEmail = "<div style='font-size:" + this.noteBodySize + "'>"
157
                         + body.paragraphs
158
                         + "<p>" + body.signature + fromMessageAndName + "<br>"
159
                         + this.openaireAddress
160
                         + "</p>"
161
                         + "</div>";
162

    
163
    return formattedEmail;
164
  }
165
  
166
  // TODO remove this after adding this on admin
167
  public static initializeInvitationsBody(communityId: string, communityTitle: string, fullname: string): Body {
168
    let body: Body = new Body();
169
    let defaultMainBody;
170
    if(communityId !== 'covid-19') {
171
       defaultMainBody ='<p>You are invited to subscribe to <a href="https://beta.' + communityId + '.openaire.eu/">'
172
        + communityTitle + '</a> dashboard.<br>'
173
        + 'The purpose of this dashboard  is to gather, link &amp; monitor the research results related to your community.</p>'
174
        + '<p>The community dashboard is part of the <a href="https://connect.openaire.eu/">OpenAIRE-Connect</a> '
175
        + 'project and currently is in BETA version.'
176
        + '</p>';
177
    } else {
178
      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. ' +
179
        'We have a community of experts moderating and curating the content.</p> ' +
180
        '<p>What you can do:</p>' +
181
        '<ul>' +
182
        '<li>navigate in a linked open data space, a contextual discovery</li>' +
183
        '<li>automatically deposit in Zenodo designated communities</li>' +
184
        '<li>link research results among themselves and to projects</li>' +
185
        '<li>join the team of experts to curate/moderate the traffic, mining, links to the data</li>' +
186
        '</ul> ' +
187
        '<p>The community dashboard is part of the<a href="https://connect.openaire.eu/"> OpenAIRE-Connect</a> project.</p>'
188
    }
189

    
190
    return body = {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""};
191
  }
192

    
193
  public static initializeInvitationsEmail(communityTitle: string) {
194
    let email: Email = new Email();
195

    
196
    return email = {body: "", subject: this.subjectPrefix + communityTitle, recipients: []};
197
  }
198
}
(2-2/5)