Skip to content

Commit

Permalink
feat(vo):added function to send mail to whole vo (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz authored Jun 28, 2018
1 parent 5f1a95c commit 4e08536
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 20 deletions.
19 changes: 18 additions & 1 deletion src/app/api-connector/vo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,24 @@ export class VoService {

}

sendMailToVo(subject, message,reply?): Observable<any> {
sendNewsletterToVo(subject, message,reply?): Observable<any> {
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('subject', subject);
urlSearchParams.append('message', message);
urlSearchParams.append('reply',reply)

let header = new Headers({
'X-CSRFToken': this.settings.getCSRFToken(),
});
return this.http.post(this.settings.getApiBaseURL() + 'vo_manager/sendNewsletterToMembers/', urlSearchParams, {
withCredentials: true,
headers: header,
}).map((res: Response) => res.json()).catch((error: any) => Observable.throw(error.json().error || 'Server error'))

}


sendMailToVo(subject, message,reply?): Observable<any> {
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('subject', subject);
urlSearchParams.append('message', message);
Expand Down
79 changes: 65 additions & 14 deletions src/app/vo_manager/VoOverviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {VoService} from "../api-connector/vo.service";
import {Project} from "../projectmanagement/project.model";
import {ProjectMember} from "../projectmanagement/project_member.model";
import {GroupService} from "../api-connector/group.service";
import * as moment from 'moment';
import * as moment from 'moment';

@Component({
selector: 'voOverview',
Expand All @@ -16,9 +16,12 @@ import * as moment from 'moment';
export class VoOverviewComponent {

public emailSubject: string;
public emailReply:string='';
public emailReply: string = '';
public emailText: string;
public emailStatus: number = 0;
public emailHeader: string;
public emailVerify: string;
public emailType: number;
public newsletterSubscriptionCounter: number;

member_id: number;
Expand All @@ -45,8 +48,35 @@ export class VoOverviewComponent {

}

sendMailToVo(subject: string, message: string,reply?:string) {
this.voserice.sendMailToVo(encodeURIComponent(subject), encodeURIComponent(message),encodeURIComponent(reply)).subscribe(result => {

sendEmail(subject: string, message: string, reply?: string) {
switch (this.emailType) {
case 0: {
this.sendMailToVo(subject, message, reply);
break;
}
case 1: {
this.sendNewsletterToVo(subject, message, reply);
break;
}
}
}

sendNewsletterToVo(subject: string, message: string, reply?: string) {
this.voserice.sendNewsletterToVo(encodeURIComponent(subject), encodeURIComponent(message), encodeURIComponent(reply)).subscribe(result => {
if (result == 1) {
this.emailStatus = 1;
}
else {
this.emailStatus = 2;
}
})

}


sendMailToVo(subject: string, message: string, reply?: string) {
this.voserice.sendMailToVo(encodeURIComponent(subject), encodeURIComponent(message), encodeURIComponent(reply)).subscribe(result => {
if (result == 1) {
this.emailStatus = 1;
}
Expand All @@ -57,12 +87,33 @@ export class VoOverviewComponent {

}

setEmailType(type: number) {
this.emailType = type;
switch (this.emailType) {
case 0: {
this.emailHeader = 'Send email to all members of\n' +
' the vo';
this.emailVerify = 'Are you sure you want to send this email to all members of the vo?';
break;
}
case 1: {
this.emailHeader = 'Send newsletter to vo';
this.emailVerify = 'Are you sure you want to send this newsletter?'
break;
}

}

}

public resetEmailModal() {

this.emailSubject=null;
this.emailText=null;
this.emailReply='';
this.emailHeader = null;
this.emailSubject = null;
this.emailText = null;
this.emailType=null;
this.emailVerify=null;
this.emailReply = '';
this.emailStatus = 0;

}
Expand Down Expand Up @@ -92,15 +143,15 @@ export class VoOverviewComponent {
is_admin,
[result['Facility'], result['FacilityId']]
)
newProject.Lifetime = group['lifetime']
if (newProject.Lifetime != -1){
newProject.LifetimeDays=Math.ceil(Math.abs(moment(dateCreated).add(newProject.Lifetime,'months').toDate().getTime()-dateCreated.getTime()))/(1000*3600*24)
newProject.Lifetime = group['lifetime']
if (newProject.Lifetime != -1) {
newProject.LifetimeDays = Math.ceil(Math.abs(moment(dateCreated).add(newProject.Lifetime, 'months').toDate().getTime() - dateCreated.getTime())) / (1000 * 3600 * 24)

}
else{
newProject.LifetimeDays=-1;
}
this.projects.push(newProject);
else {
newProject.LifetimeDays = -1;
}
this.projects.push(newProject);
})
}

Expand Down
14 changes: 9 additions & 5 deletions src/app/vo_manager/voOverview.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ <h1>Vo Overview
<div class="col-lg-12">


<button (click)="emailModal.show()" type="button " class="btn btn-secondary"
<button (click)="setEmailType(1);emailModal.show();" type="button " class="btn btn-secondary"
style="margin-bottom: auto;margin-left:auto; margin-top: auto"><i class="icon-envelope-letter"></i>
Send newsletter ({{newsletterSubscriptionCounter}})
</button>

<button (click)="setEmailType(0);emailModal.show();" type="button " class="btn btn-secondary"
style="margin-bottom: auto;margin-left:auto; margin-top: auto"><i class="icon-envelope-letter"></i>
Send email
</button>


<div class="card">
<div class="card-header">
Expand Down Expand Up @@ -109,8 +114,7 @@ <h4 class="modal-title">Members of the Project {{ usersModalProjectID }}
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"> Send email to all members of
the vo</h4>
<h4 class="modal-title"> {{emailHeader}}</h4>
<button type="button" class="close" (click)="emailModal.hide()" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
Expand Down Expand Up @@ -174,13 +178,13 @@ <h4 class="modal-title">Send email</h4>
<div class="modal-body">

<div class="alert alert-warning" role="alert">
Are you sure you want to send this email to all members of the vo?
{{emailVerify}}
</div>

</div>
<div class="modal-footer">
<button class="btn btn-success col-md-4"
(click)="sendMailToVo(emailSubject,emailText,emailReply);verifyModal.hide();;f.reset();resetEmailModal();successModal.show()">
(click)="sendEmail(emailSubject,emailText,emailReply);verifyModal.hide();f.reset();resetEmailModal();successModal.show()">
Yes
</button>
<button class="btn btn-danger col-md-4" type="reset"
Expand Down

0 comments on commit 4e08536

Please sign in to comment.