From bd01b4f50e4f61e2130570a29e1ccb092bf003d8 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 9 Jul 2024 09:18:00 +0200 Subject: [PATCH 1/4] started refactoring tremplated mail --- .../facilityprojectsoverview.component.ts | 4 - ...t-csv-templated-email-modal.component.html | 213 ++++++++++++ ...ect-csv-templated-email-modal.component.ts | 109 ++++++ .../project-csv-templated-email.scss | 25 ++ .../project-email-modal.component.html | 312 +++++++++--------- .../shared_modules/shared-module.module.ts | 5 + src/app/vo_manager/VoOverviewComponent.ts | 33 +- src/app/vo_manager/voOverview.component.html | 3 +- 8 files changed, 518 insertions(+), 186 deletions(-) create mode 100644 src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html create mode 100644 src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.ts create mode 100644 src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email.scss diff --git a/src/app/facility_manager/facilityprojectsoverview.component.ts b/src/app/facility_manager/facilityprojectsoverview.component.ts index 4bbf018218..bcade8d803 100644 --- a/src/app/facility_manager/facilityprojectsoverview.component.ts +++ b/src/app/facility_manager/facilityprojectsoverview.component.ts @@ -196,10 +196,6 @@ export class FacilityProjectsOverviewComponent extends AbstractBaseClass impleme this.sortProjectService.sortDirection = direction; } - searchForUserInFacility(searchString: string): void { - this.facilityService.getFilteredMembersOfFacility(searchString); - } - filterMembers(bare_searchString: string): void { this.filteredMembers = []; const searchString: string = bare_searchString.toLowerCase(); diff --git a/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html new file mode 100644 index 0000000000..337d2c0538 --- /dev/null +++ b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html @@ -0,0 +1,213 @@ + + + + + + \ No newline at end of file diff --git a/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.ts b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.ts new file mode 100644 index 0000000000..24c7ab91b7 --- /dev/null +++ b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.ts @@ -0,0 +1,109 @@ +import { + Component, EventEmitter, Input, OnDestroy, OnInit, +} from '@angular/core'; +import { BsModalRef } from 'ngx-bootstrap/modal'; +import { Application } from '../../../../applications/application.model/application.model'; +import { IResponseTemplate } from '../../../../api-connector/response-template'; +import { EmailService } from '../../../../api-connector/email.service'; +import { STATUS_LINK } from '../../../../../links/links'; +import { CsvMailTemplateModel } from '../../../classes/csvMailTemplate.model'; + +@Component({ + selector: 'app-project-csv-templated-email-modal', + templateUrl: './project-csv-templated-email-modal.component.html', + styleUrls: ['./project-csv-templated-email.scss'], + providers: [EmailService], +}) +export class ProjectCsvTemplatedEmailModalComponent implements OnInit, OnDestroy { + selectedProjects: Application[]; + csvMailTemplate: CsvMailTemplateModel; + csvFile: File; + + emailAdminsOnly: boolean; + emailSubject: string; + emailReply: string; + emailText: string; + templates: string[]; + validCSVExample = `Project, VM, LOCATION +Proj1, VM_1, Bielefeld +Proj2, VM_2, Giessen`; + + public event: EventEmitter = new EventEmitter(); + + constructor( + public bsModalRef: BsModalRef, + private emailService: EmailService, + ) { + // eslint-disable-next-line no-empty-function + } + + ngOnInit() { + this.getMailTemplates(); + } + + onCsvFileSelected(event): void { + const inputElement = event.target as HTMLInputElement; + this.csvFile = inputElement.files[0]; + if (this.csvFile) { + this.emailService.sendCsvTemplate(this.csvFile).subscribe( + (csvTemplate: CsvMailTemplateModel) => { + this.csvMailTemplate = csvTemplate; + + }, + (error: CsvMailTemplateModel) => { + this.csvMailTemplate = error; + console.log(error['error']); + }, + ); + } + } + + getMailTemplates(): void { + this.emailService.getMailTemplates().subscribe((res: string[]) => { + this.templates = res; + }); + } + + sentProjectsTemplatedMail(): void { + const project_ids = this.selectedProjects.map((pr: Application) => pr.project_application_perun_id); + + this.emailService + .sendCsvTemplatedMail( + this.csvFile, + project_ids, + this.emailSubject, + this.emailText, + this.emailAdminsOnly, + this.emailReply, + ) + .subscribe( + (res: IResponseTemplate) => { + this.event.emit(res.value as boolean); + }, + () => { + this.event.emit(false); + }, + ); + } + + sentProjectsMail(): void { + const project_ids = this.selectedProjects.map((pr: Application) => pr.project_application_perun_id); + + this.emailService + .sendMailToProjects(project_ids, this.emailSubject, this.emailText, this.emailAdminsOnly, this.emailReply) + .subscribe( + (res: IResponseTemplate) => { + this.event.emit(res.value as boolean); + }, + () => { + this.event.emit(false); + }, + ); + } + + ngOnDestroy(): void { + this.bsModalRef.hide(); + } + + protected readonly STATUS_LINK = STATUS_LINK; +} diff --git a/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email.scss b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email.scss new file mode 100644 index 0000000000..a86e9ffc41 --- /dev/null +++ b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email.scss @@ -0,0 +1,25 @@ +.templates-container { + border: 1px solid #ccc; + padding: 10px; + background-color: #f9f9f9; +} + +.templates-list { + margin: 10px 0; + font-family: monospace; +} + +.valid-example { + border: 1px solid #ccc; + padding: 10px; + background-color: #f9f9f9; + margin-top: 10px; +} + +.valid-example-heading { + margin-bottom: 5px; +} + +.valid-example-content { + font-family: monospace; +} \ No newline at end of file diff --git a/src/app/shared/modal/email/project-email-modal/project-email-modal.component.html b/src/app/shared/modal/email/project-email-modal/project-email-modal.component.html index 5584431736..683f4adf5a 100644 --- a/src/app/shared/modal/email/project-email-modal/project-email-modal.component.html +++ b/src/app/shared/modal/email/project-email-modal/project-email-modal.component.html @@ -1,179 +1,187 @@ + +
+

+ The following keys were provided by the CSV file: {{ csvFile.name }} +

+
+ {{ '{' + template + '}' }} +
+
-
-

You can use the following keys as variables:

-
- {{ '{' + template + '}' }} -
-
+
+

You can use the following keys as variables:

+
+ {{ '{' + template + '}' }} +
+
-
- Please consider: In case any dates are part of the sent E-Mails, they will be formatted in the german - TT.MM.YYYY-format. -
+
+ Please consider: In case any dates are part of the sent E-Mails, they will be formatted in the german + TT.MM.YYYY-format. +
+ } diff --git a/src/app/shared/shared_modules/shared-module.module.ts b/src/app/shared/shared_modules/shared-module.module.ts index eab670b22f..6c985ba778 100644 --- a/src/app/shared/shared_modules/shared-module.module.ts +++ b/src/app/shared/shared_modules/shared-module.module.ts @@ -16,6 +16,9 @@ import { SharedDirectivesModule } from './shared_directives.module'; import { MaintenanceNotificationComponent } from './components/maintenance-notification/maintenance-notification.component'; import { PipeModuleModule } from '../../pipe-module/pipe-module.module'; import { MembersListModalComponent } from '../modal/members/members-list-modal.component'; +import { + ProjectCsvTemplatedEmailModalComponent, +} from '../modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component'; /** * Shared module. @@ -30,6 +33,7 @@ import { MembersListModalComponent } from '../modal/members/members-list-modal.c MigrationInformationComponent, ApplicationBadgesComponent, ProjectEmailModalComponent, + ProjectCsvTemplatedEmailModalComponent, TestimonialFormComponent, MaintenanceNotificationComponent, ], @@ -53,6 +57,7 @@ import { MembersListModalComponent } from '../modal/members/members-list-modal.c MigrationInformationComponent, ApplicationBadgesComponent, ProjectEmailModalComponent, + ProjectCsvTemplatedEmailModalComponent, TestimonialFormComponent, MaintenanceNotificationComponent, ], diff --git a/src/app/vo_manager/VoOverviewComponent.ts b/src/app/vo_manager/VoOverviewComponent.ts index 9a207966b7..3f392670e6 100644 --- a/src/app/vo_manager/VoOverviewComponent.ts +++ b/src/app/vo_manager/VoOverviewComponent.ts @@ -26,6 +26,9 @@ import { ConfirmationActions } from '../shared/modal/confirmation_actions'; import { MembersListModalComponent } from '../shared/modal/members/members-list-modal.component'; import { EmailService } from '../api-connector/email.service'; import { CsvMailTemplateModel } from '../shared/classes/csvMailTemplate.model'; +import { + ProjectCsvTemplatedEmailModalComponent, +} from '../shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component'; /** * Vo Overview component. @@ -122,21 +125,6 @@ export class VoOverviewComponent extends AbstractBaseClass implements OnInit, On this.subscription.unsubscribe(); } - onCsvFileSelected(event): void { - const inputElement = event.target as HTMLInputElement; - if (inputElement.files && inputElement.files.length > 0) { - this.emailService.sendCsvTemplate(inputElement.files[0]).subscribe( - (csvTemplate: CsvMailTemplateModel) => { - this.openProjectMailsModal(inputElement.files[0], csvTemplate); - }, - (error: CsvMailTemplateModel) => { - console.log(error['error']); - this.openProjectMailsModal(inputElement.files[0], error['error']); - }, - ); - } - } - getTSVInformation(timeout: number = this.checkTSVTimeout): void { this.stopCheckTSVTimer(); this.subscription.add( @@ -252,20 +240,9 @@ export class VoOverviewComponent extends AbstractBaseClass implements OnInit, On } } - openProjectMailsModal(csvFile: File = null, csvTemplate: CsvMailTemplateModel = null): void { - let initialState = {}; - - if (csvFile) { - initialState = { - selectedProjects: csvTemplate.valid_projects, - csvFile, - csvMailTemplate: csvTemplate, - }; - } else { - initialState = { selectedProjects: this.selectedEmailProjects }; - } + openProjectMailsModal(): void { - this.bsModalRef = this.modalService.show(ProjectEmailModalComponent, { initialState, class: 'modal-lg' }); + this.bsModalRef = this.modalService.show(ProjectCsvTemplatedEmailModalComponent, { class: 'modal-lg' }); this.bsModalRef.content.event.subscribe((sent_successfully: boolean) => { if (sent_successfully) { this.updateNotificationModal('Success', 'Mails were successfully sent', true, 'success'); diff --git a/src/app/vo_manager/voOverview.component.html b/src/app/vo_manager/voOverview.component.html index 439ddfcc7d..d70da89c96 100644 --- a/src/app/vo_manager/voOverview.component.html +++ b/src/app/vo_manager/voOverview.component.html @@ -34,8 +34,7 @@ {{ selectedEmailProjects?.length }} - -
- -
diff --git a/src/app/facility_manager/facilityprojectsoverview.component.ts b/src/app/facility_manager/facilityprojectsoverview.component.ts index bcade8d803..03910a2a8c 100644 --- a/src/app/facility_manager/facilityprojectsoverview.component.ts +++ b/src/app/facility_manager/facilityprojectsoverview.component.ts @@ -19,10 +19,12 @@ import { import { ProjectSortService } from '../shared/shared_modules/services/project-sort.service'; import { AbstractBaseClass } from '../shared/shared_modules/baseClass/abstract-base-class'; import { ProjectEmailModalComponent } from '../shared/modal/email/project-email-modal/project-email-modal.component'; -import { NotificationModalComponent } from '../shared/modal/notification-modal'; import { MembersListModalComponent } from '../shared/modal/members/members-list-modal.component'; import { EmailService } from '../api-connector/email.service'; import { CsvMailTemplateModel } from '../shared/classes/csvMailTemplate.model'; +import { + ProjectCsvTemplatedEmailModalComponent, +} from '../shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component'; /** * Facility Project overview component. @@ -43,9 +45,7 @@ export class FacilityProjectsOverviewComponent extends AbstractBaseClass impleme public memberFilter: string = ''; filteredMembers: object[] = []; selectedMember: object[] = []; - facility_members: object[] = []; - filterChanged: Subject = new Subject(); isLoaded: boolean = false; projects: Application[] = []; projectsCopy: Application[] = []; @@ -183,7 +183,12 @@ export class FacilityProjectsOverviewComponent extends AbstractBaseClass impleme ); } } + openProjectCSVMailModal(): void { + console.log('show'); + + this.bsModalRef = this.modalService.show(ProjectCsvTemplatedEmailModalComponent, { class: 'modal-lg' }); + } onSort({ column, direction }: SortEvent) { // resetting other headers this.headers.forEach(header => { @@ -512,24 +517,6 @@ export class FacilityProjectsOverviewComponent extends AbstractBaseClass impleme initialState = { selectedProjects: this.selectedEmailProjects }; } this.bsModalRef = this.modalService.show(ProjectEmailModalComponent, { initialState, class: 'modal-lg' }); - this.bsModalRef.content.event.subscribe((sent_successfully: boolean) => { - if (sent_successfully) { - const initialStateNotification = { - notificationModalTitle: 'Success', - notificationModalType: 'success', - notificationModalMessage: 'Mails were successfully sent', - }; - - this.modalService.show(NotificationModalComponent, { initialState: initialStateNotification }); - } else { - const initialStateNotification = { - notificationModalTitle: 'Failed', - notificationModalType: 'danger', - notificationModalMessage: 'Failed to send mails!', - }; - this.modalService.show(NotificationModalComponent, { initialState: initialStateNotification }); - } - }); } setFacilitySupportMails(supportMails: string): void { diff --git a/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html index 337d2c0538..50e8fc8a12 100644 --- a/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html +++ b/src/app/shared/modal/email/project-csv-templated-email-modal/project-csv-templated-email-modal.component.html @@ -10,7 +10,7 @@