define persisted body json structure

This commit is contained in:
mchouliara 2024-10-02 12:13:44 +03:00
parent 8c42b784ba
commit 3a93d006e1
2 changed files with 13 additions and 5 deletions

View File

@ -15,7 +15,7 @@
</button> </button>
</div> </div>
<div class="col-auto" *ngIf="canSave"> <div class="col-auto" *ngIf="canSave">
<button mat-button class="rounded-btn secondary" (click)="attemptSave()"> <button mat-button class="rounded-btn secondary" (click)="attemptSave()" [disabled]="!editorReady">
<mat-icon>save</mat-icon> <mat-icon>save</mat-icon>
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.ACTIONS.SAVE' | translate}} {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.ACTIONS.SAVE' | translate}}
</button> </button>
@ -147,7 +147,6 @@
<h4>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-TEXT' | translate}}</h4> <h4>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-TEXT' | translate}}</h4>
<mat-progress-spinner class="ml-auto mr-auto" *ngIf="!editorReady" mode="indeterminate" [diameter]="24"></mat-progress-spinner> <mat-progress-spinner class="ml-auto mr-auto" *ngIf="!editorReady" mode="indeterminate" [diameter]="24"></mat-progress-spinner>
<email-editor <email-editor
[maxWidth]="'800px'"
(ready)="onEditorReady($event)" (ready)="onEditorReady($event)"
></email-editor> ></email-editor>
<!-- <editor class="w-100 mt-2" [init]="{ <!-- <editor class="w-100 mt-2" [init]="{

View File

@ -37,6 +37,7 @@ import { NotificationTemplateEditorResolver } from './notification-template-edit
import { NotificationTemplateEditorService } from './notification-template-editor.service'; import { NotificationTemplateEditorService } from './notification-template-editor.service';
import { RouterUtilsService } from '@app/core/services/router/router-utils.service'; import { RouterUtilsService } from '@app/core/services/router/router-utils.service';
import { EmailEditorComponent } from 'angular-email-editor'; import { EmailEditorComponent } from 'angular-email-editor';
import { JSONTemplate } from 'angular-email-editor/types';
@Component({ @Component({
selector: 'app-notification-template-editor', selector: 'app-notification-template-editor',
@ -48,7 +49,6 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
@ViewChild(EmailEditorComponent) @ViewChild(EmailEditorComponent)
private emailEditor: EmailEditorComponent; private emailEditor: EmailEditorComponent;
editorReady = false; editorReady = false;
isNew = true; isNew = true;
isDeleted = false; isDeleted = false;
@ -200,7 +200,11 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
attemptSave(): void { attemptSave(): void {
if(this.emailEditor?.editor){ if(this.emailEditor?.editor){
this.emailEditor?.editor?.exportHtml((data) => { this.emailEditor?.editor?.exportHtml((data) => {
this.formGroup.get('value').get('bodyText').setValue(JSON.stringify(data)); const json: BodyTemplateJSON = {
design: data?.design,
html: data?.html
};
this.formGroup.get('value').get('bodyText').setValue(JSON.stringify(json));
this.formSubmit(); this.formSubmit();
}); });
}else { }else {
@ -328,10 +332,15 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
onEditorReady() { onEditorReady() {
const body = this.formGroup.get('value')?.get('bodyText')?.value; const body = this.formGroup.get('value')?.get('bodyText')?.value;
if(body){ if(body){
const design = JSON.parse(body)?.design; const design = JSON.parse(body)?.design as JSONTemplate;
this.emailEditor.loadDesign(design); this.emailEditor.loadDesign(design);
} }
this.editorReady = true; this.editorReady = true;
} }
} }
export interface BodyTemplateJSON {
design: JSONTemplate;
html: string;
}