From 5f902e5e829da4d519e13bbe6cfb7fd340c8677a Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 7 Nov 2023 17:20:29 +0200 Subject: [PATCH] [develop | DONE]: Add email sender in admin panel. --- src/app/admin/admin.component.ts | 75 ++++++++++++++++++++++++++++++++ src/app/admin/admin.module.ts | 5 ++- src/app/app.component.ts | 18 ++++---- src/app/openaireLibrary | 2 +- src/assets/common-assets | 2 +- src/assets/openaire-theme | 2 +- src/index.html | 1 + 7 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 5a7ac92..c636ce2 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -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" Copy Services +
@@ -166,6 +174,26 @@ import {Option} from "../openaireLibrary/sharedComponents/input/input.component"
+ +
+
+ +
+
+
+ + + +
+
+
` }) 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(', ') + ' +' + (this.recipients.length - 8).toString() + ' more '; + } 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'); + } + }) + } } diff --git a/src/app/admin/admin.module.ts b/src/app/admin/admin.module.ts index d8b3837..9ec6b01 100644 --- a/src/app/admin/admin.module.ts +++ b/src/app/admin/admin.module.ts @@ -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] }) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 072ec5e..b4d934a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -23,18 +23,16 @@ import {NotificationHandler} from './openaireLibrary/utils/notification-handler'
- + + diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index aebcb81..06a2ae1 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit aebcb81c7b05d6605422e63ada164715d39b9c01 +Subproject commit 06a2ae16ee5576fec34cc1afad614eff45dc715d diff --git a/src/assets/common-assets b/src/assets/common-assets index 9e58421..6bb1e61 160000 --- a/src/assets/common-assets +++ b/src/assets/common-assets @@ -1 +1 @@ -Subproject commit 9e58421a1adf3fbeb361e21616feaea8c7f867af +Subproject commit 6bb1e61b059bef1bff3bfb0611b0df46f7840426 diff --git a/src/assets/openaire-theme b/src/assets/openaire-theme index 2dadcf8..5e8c1ad 160000 --- a/src/assets/openaire-theme +++ b/src/assets/openaire-theme @@ -1 +1 @@ -Subproject commit 2dadcf85926bc0f11fff22ed94dc197ddd8587c6 +Subproject commit 5e8c1addb1ebfa508aac8cb9540a755940c95b79 diff --git a/src/index.html b/src/index.html index 6870ee3..93e4265 100644 --- a/src/index.html +++ b/src/index.html @@ -21,6 +21,7 @@ +