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'