[develop | DONE]: Add email sender in admin panel.
This commit is contained in:
parent
46759a8715
commit
5f902e5e82
|
@ -6,6 +6,10 @@ import {NotificationHandler} from "../openaireLibrary/utils/notification-handler
|
|||
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
||||
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
|
||||
import {Option} from "../openaireLibrary/sharedComponents/input/input.component";
|
||||
import {FullScreenModalComponent} from "../openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.component";
|
||||
import {EmailService} from "../openaireLibrary/utils/email/email.service";
|
||||
import {Email} from "../openaireLibrary/utils/email/email";
|
||||
import {properties} from "../../environments/environment";
|
||||
|
||||
@Component({
|
||||
selector: 'admin',
|
||||
|
@ -19,6 +23,10 @@ import {Option} from "../openaireLibrary/sharedComponents/input/input.component"
|
|||
<icon name="add" [flex]="true"></icon>
|
||||
<span class="uk-margin-xsmall-left">Copy Services</span>
|
||||
</button>
|
||||
<button (click)="openSendEmailModal()" [disabled]="!issuer || !recipients" class="uk-button uk-button-default uk-margin-small-left uk-flex uk-flex-middle">
|
||||
<icon name="mail" [flex]="true"></icon>
|
||||
<span class="uk-margin-xsmall-left">Send Email</span>
|
||||
</button>
|
||||
</div>
|
||||
<div inner class="uk-section-small uk-container uk-container-small">
|
||||
<div *ngIf="loading" class="uk-height-large uk-position-relative">
|
||||
|
@ -166,6 +174,26 @@ import {Option} from "../openaireLibrary/sharedComponents/input/input.component"
|
|||
</ul>
|
||||
</div>
|
||||
</modal-alert>
|
||||
<fs-modal #sendEmailModal [okButtonDisabled]="!emailForm?.valid" (okEmitter)="sendEmail()">
|
||||
<div *ngIf="emailForm" class="uk-section uk-container uk-container-small">
|
||||
<div class="uk-text-small uk-margin-bottom">
|
||||
<label class="uk-text-bold">Recipients: </label><span [innerHTML]="getRecipientsAsString()"></span>
|
||||
</div>
|
||||
<form [formGroup]="emailForm">
|
||||
<div input [formInput]="emailForm.get('subject')" class="uk-margin-bottom" placeholder="Subject"></div>
|
||||
<label class="uk-text-bold">Message</label>
|
||||
<ckeditor #ckEditor [readonly]="false" debounce="500"
|
||||
[formControl]="emailForm.get('body')"
|
||||
[config]="{ extraAllowedContent: '* [uk-*](*) ; span', disallowedContent: 'script; *[on*]',
|
||||
removeButtons: 'Save,NewPage,DocProps,Preview,Print,' +
|
||||
'Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,' +
|
||||
'CreateDiv,Flash,PageBreak,' +
|
||||
'Subscript,Superscript,Anchor,Smiley,Iframe,Styles,Font,About,Language',
|
||||
extraPlugins: 'divarea', height: 500}">
|
||||
</ckeditor>
|
||||
</form>
|
||||
</div>
|
||||
</fs-modal>
|
||||
`
|
||||
})
|
||||
export class AdminComponent implements OnInit, OnDestroy{
|
||||
|
@ -182,11 +210,15 @@ export class AdminComponent implements OnInit, OnDestroy{
|
|||
activeIssuerIndex = 0;
|
||||
page = 1;
|
||||
copyServicesForm: FormGroup;
|
||||
emailForm: FormGroup;
|
||||
recipients: string[] = [];
|
||||
@ViewChild("copyModal") copyModal: AlertModal;
|
||||
@ViewChild("deleteModal") deleteModal: AlertModal;
|
||||
@ViewChild("infoModal") infoModal: AlertModal;
|
||||
@ViewChild("sendEmailModal") sendEmailModal: FullScreenModalComponent;
|
||||
|
||||
constructor(private apisService: ApisService,
|
||||
private emailService: EmailService,
|
||||
private fb: FormBuilder) {
|
||||
}
|
||||
|
||||
|
@ -198,6 +230,7 @@ export class AdminComponent implements OnInit, OnDestroy{
|
|||
this.activeIssuer = apisByIssuers[0].issuer;
|
||||
this.issuer = this.activeIssuer;
|
||||
this.apis = apisByIssuers[0].apis;
|
||||
this.setRecipients();
|
||||
}
|
||||
this.issuers = apisByIssuers.map(api => {
|
||||
return {
|
||||
|
@ -222,6 +255,20 @@ export class AdminComponent implements OnInit, OnDestroy{
|
|||
})
|
||||
}
|
||||
|
||||
setRecipients() {
|
||||
this.recipients = this.apis.map(api => api.service?.contacts?api.service.contacts:(api.details?.contacts?api.details.contacts:[])).flat();
|
||||
/* Remove duplicates */
|
||||
this.recipients = this.recipients.filter((email, index) => this.recipients.indexOf(email) === index);
|
||||
}
|
||||
|
||||
getRecipientsAsString() {
|
||||
if(this.recipients.length > 8) {
|
||||
return this.recipients.slice(0, 7).join(', ') + ' <span class="uk-text-bold">+' + (this.recipients.length - 8).toString() + ' more </span>';
|
||||
} else {
|
||||
return this.recipients.join(', ');
|
||||
}
|
||||
}
|
||||
|
||||
openCopyModal() {
|
||||
this.copyModal.alertTitle = 'Copy Service from another Issuer';
|
||||
this.copyModal.okButtonText = 'Copy';
|
||||
|
@ -252,6 +299,7 @@ export class AdminComponent implements OnInit, OnDestroy{
|
|||
this.issuer = issuer;
|
||||
let apisByIssuer = this.apisByIssuers.find(apisByIssuer => apisByIssuer.issuer == issuer);
|
||||
this.apis = apisByIssuer.apis;
|
||||
this.setRecipients();
|
||||
this.page = 1;
|
||||
}
|
||||
|
||||
|
@ -279,6 +327,7 @@ export class AdminComponent implements OnInit, OnDestroy{
|
|||
this.subscriptions.push(this.apisService.delete(this.apis[this.index].service.id).subscribe(() => {
|
||||
this.apis.splice(this.index, 1);
|
||||
this.apisByIssuers[this.activeIssuerIndex].apis = this.apis;
|
||||
this.setRecipients();
|
||||
NotificationHandler.rise('Your service has been created deleted.');
|
||||
this.loading = false;
|
||||
}, error => {
|
||||
|
@ -287,4 +336,30 @@ export class AdminComponent implements OnInit, OnDestroy{
|
|||
this.loading = false;
|
||||
}));
|
||||
}
|
||||
|
||||
openSendEmailModal() {
|
||||
this.emailForm = this.fb.group({
|
||||
subject: this.fb.control('[OpenAIRE Develop]: ', Validators.required),
|
||||
body: this.fb.control('', Validators.required)
|
||||
});
|
||||
this.sendEmailModal.title = 'Email Sender';
|
||||
this.sendEmailModal.okButton = true;
|
||||
this.sendEmailModal.back = true;
|
||||
this.sendEmailModal.okButtonText = 'Send';
|
||||
this.sendEmailModal.open();
|
||||
}
|
||||
|
||||
sendEmail() {
|
||||
let email = new Email();
|
||||
email.body = this.emailForm.get('body').value;
|
||||
email.subject = this.emailForm.get('subject').value;
|
||||
email.recipients = this.recipients;
|
||||
this.emailService.sendEmail(properties, email).subscribe( (res) => {
|
||||
if(res) {
|
||||
NotificationHandler.rise('Message has been sent!');
|
||||
} else {
|
||||
NotificationHandler.rise('An error has occurred. Please try again later!', 'danger');
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,14 @@ import {PageContentModule} from "../openaireLibrary/dashboard/sharedComponents/p
|
|||
import {AlertModalModule} from "../openaireLibrary/utils/modal/alertModal.module";
|
||||
import {InputModule} from "../openaireLibrary/sharedComponents/input/input.module";
|
||||
import {PagingModule} from "../openaireLibrary/utils/paging.module";
|
||||
import {FullScreenModalModule} from "../openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.module";
|
||||
import {ReactiveFormsModule} from "@angular/forms";
|
||||
import {CKEditorModule} from "ng2-ckeditor";
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild([
|
||||
{path: '', component: AdminComponent}
|
||||
]), IconsModule, LoadingModule, PageContentModule, AlertModalModule, InputModule, PagingModule],
|
||||
]), IconsModule, LoadingModule, PageContentModule, AlertModalModule, InputModule, PagingModule, FullScreenModalModule, ReactiveFormsModule, CKEditorModule],
|
||||
declarations: [AdminComponent],
|
||||
exports: [AdminComponent]
|
||||
})
|
||||
|
|
|
@ -23,18 +23,16 @@ import {NotificationHandler} from './openaireLibrary/utils/notification-handler'
|
|||
<loading [full]="true"></loading>
|
||||
</div>
|
||||
<div *ngIf="!loading">
|
||||
<div class="sidebar_main_swipe" [class.sidebar_main_active]="open && hasSidebar"
|
||||
<div id="modal-container"></div>
|
||||
<navbar *ngIf="hasHeader" portal="developers" [header]="menuHeader"
|
||||
[userMenuItems]=userMenuItems [menuItems]="menuItems" [user]="user"></navbar>
|
||||
<div class="sidebar_main_swipe uk-flex uk-background-default" [class.sidebar_main_active]="open && hasSidebar"
|
||||
[class.sidebar_mini]="!open && hasSidebar"
|
||||
[class.sidebar_hover]="hover">
|
||||
<div id="modal-container"></div>
|
||||
<navbar *ngIf="hasHeader" portal="developers" [header]="menuHeader"
|
||||
[userMenuItems]=userMenuItems [menuItems]="menuItems" [user]="user"></navbar>
|
||||
<div>
|
||||
<dashboard-sidebar *ngIf="hasSidebar" [items]="sideBarItems" [backItem]="backItem"></dashboard-sidebar>
|
||||
<main>
|
||||
<router-outlet></router-outlet>
|
||||
</main>
|
||||
</div>
|
||||
<dashboard-sidebar *ngIf="hasSidebar" [items]="sideBarItems" [backItem]="backItem"></dashboard-sidebar>
|
||||
<main class="uk-width-1-1">
|
||||
<router-outlet></router-outlet>
|
||||
</main>
|
||||
</div>
|
||||
<quick-contact #quickContact *ngIf="showQuickContact && contactForm" (sendEmitter)="send($event)"
|
||||
[contact]="'Help'" [contactForm]="contactForm" [sending]="sending">
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit aebcb81c7b05d6605422e63ada164715d39b9c01
|
||||
Subproject commit 06a2ae16ee5576fec34cc1afad614eff45dc715d
|
|
@ -1 +1 @@
|
|||
Subproject commit 9e58421a1adf3fbeb361e21616feaea8c7f867af
|
||||
Subproject commit 6bb1e61b059bef1bff3bfb0611b0df46f7840426
|
|
@ -1 +1 @@
|
|||
Subproject commit 2dadcf85926bc0f11fff22ed94dc197ddd8587c6
|
||||
Subproject commit 5e8c1addb1ebfa508aac8cb9540a755940c95b79
|
|
@ -21,6 +21,7 @@
|
|||
<link href="assets/common-assets/logo/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon"/>
|
||||
<meta name="robots" content="noindex">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://cdn.ckeditor.com/4.5.11/full-all/ckeditor.js"></script>
|
||||
<script src="https://unpkg.com/smoothscroll-polyfill@0.4.3/dist/smoothscroll.min.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
|
|
Loading…
Reference in New Issue