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>
</div>
<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>
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.ACTIONS.SAVE' | translate}}
</button>
@ -147,7 +147,6 @@
<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>
<email-editor
[maxWidth]="'800px'"
(ready)="onEditorReady($event)"
></email-editor>
<!-- <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 { RouterUtilsService } from '@app/core/services/router/router-utils.service';
import { EmailEditorComponent } from 'angular-email-editor';
import { JSONTemplate } from 'angular-email-editor/types';
@Component({
selector: 'app-notification-template-editor',
@ -48,7 +49,6 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
@ViewChild(EmailEditorComponent)
private emailEditor: EmailEditorComponent;
editorReady = false;
isNew = true;
isDeleted = false;
@ -200,7 +200,11 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
attemptSave(): void {
if(this.emailEditor?.editor){
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();
});
}else {
@ -328,10 +332,15 @@ export class NotificationTemplateEditorComponent extends BaseEditor<Notification
onEditorReady() {
const body = this.formGroup.get('value')?.get('bodyText')?.value;
if(body){
const design = JSON.parse(body)?.design;
const design = JSON.parse(body)?.design as JSONTemplate;
this.emailEditor.loadDesign(design);
}
this.editorReady = true;
}
}
export interface BodyTemplateJSON {
design: JSONTemplate;
html: string;
}