b0231d7f by acetousk

Save mjml rendered html and render the html with ftl in the current context of t…

…he parameters passed in through the service.
1 parent 88f3e150
...@@ -224,7 +224,7 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -224,7 +224,7 @@ along with this software (see the LICENSE.md file). If not, see
224 // we have to properly update the body before the store and extract the 224 // we have to properly update the body before the store and extract the
225 // project data from the response result. 225 // project data from the response result.
226 onStore: data => { 226 onStore: data => {
227 return { id: window.resourceId, data } 227 return { id: window.resourceId, data, html:window.editor.runCommand('mjml-code-to-html')?.html }
228 }, 228 },
229 onLoad: result => { 229 onLoad: result => {
230 if (result.resourceId !== null) { 230 if (result.resourceId !== null) {
......
...@@ -28,6 +28,15 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -28,6 +28,15 @@ along with this software (see the LICENSE.md file). If not, see
28 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if> 28 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
29 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>--> 29 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
30 <!-- <log level="warn" message="load context.toString() ${context.toString()}"/>--> 30 <!-- <log level="warn" message="load context.toString() ${context.toString()}"/>-->
31 <if condition="emailTemplateId">
32 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
33 <if condition="!resourceId"><set field="resourceId" from="emailTemplate?.resourceId"/></if>
34 <if condition="resourceId != emailTemplate?.resourceId">
35 <!-- This should almost never happen, but if it does it basically creates a resource leak for the previously used resource -->
36 <log message="Changing resource id from ${resourceId} to ${emailTemplate?.resourceId} for email template ${emailTemplateId}"/>
37 <service-call name="update#moqui.basic.email.EmailTemplate" in-map="[emailTemplateId:emailTemplateId,resourceId:resourceId]"/>
38 </if>
39 </if>
31 40
32 <if condition="!resourceId"> 41 <if condition="!resourceId">
33 <then> 42 <then>
...@@ -88,23 +97,18 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -88,23 +97,18 @@ along with this software (see the LICENSE.md file). If not, see
88 <description>Create MJML</description> 97 <description>Create MJML</description>
89 <in-parameters> 98 <in-parameters>
90 <parameter name="resourceId"/> 99 <parameter name="resourceId"/>
91 <parameter name="data"></parameter> 100 <parameter name="data"/>
101 <parameter name="html" allow-html="any"/>
92 </in-parameters> 102 </in-parameters>
93 <out-parameters> 103 <out-parameters>
94 <parameter name="resourceId"/> 104 <parameter name="resourceId"/>
95 </out-parameters> 105 </out-parameters>
96 <actions> 106 <actions>
97 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
98 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if> 107 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
99 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
100 <!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>-->
101 <set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/> 108 <set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/>
102 <!-- <log level="warn" message="store#GrapeJs data ${data}"/>-->
103 109
104 <!-- <log level="warn" message="store context.toString() ${context.toString()}"/>-->
105 <if condition="!resourceId"> 110 <if condition="!resourceId">
106 <then> 111 <then>
107 <!-- <log level="warn" message="resourceId is null"/>-->
108 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/> 112 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
109 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> 113 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
110 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/> 114 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/>
...@@ -112,25 +116,23 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -112,25 +116,23 @@ along with this software (see the LICENSE.md file). If not, see
112 <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/> 116 <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
113 <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/> 117 <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
114 <set field="resourceId" from="dbResource.resourceId"/> 118 <set field="resourceId" from="dbResource.resourceId"/>
119
120 <set field="htmlFile" from="grapesJsResource.makeFile(resourceId.toString()+'.html')"/>
121 <script><![CDATA[htmlFile.putText(html)]]></script>
115 </then> 122 </then>
116 <else> 123 <else>
117 <!-- <log level="warn" message="resourceId is ${resourceId}"/>-->
118 <entity-find-one entity-name="moqui.resource.DbResource" value-field="dbResource" auto-field-map="[resourceId:resourceId]"/> 124 <entity-find-one entity-name="moqui.resource.DbResource" value-field="dbResource" auto-field-map="[resourceId:resourceId]"/>
119 <!-- <log level="warn" message="dbResource ${dbResource}"/>-->
120 <if condition="!dbResource"> 125 <if condition="!dbResource">
121 <return error="true" message="Resource not found"/> 126 <return error="true" message="Resource not found"/>
122 </if> 127 </if>
123 <set field="actualDbResourcePath" from="null"/> 128 <set field="actualDbResourcePath" from="null"/>
124 <set field="dbResourcePath" from="dbResource.filename"/> 129 <set field="dbResourcePath" from="dbResource.filename"/>
125 <set field="lastDbResource" from="dbResource"/> 130 <set field="lastDbResource" from="dbResource"/>
126 <!-- <log level="warn" message="lastDbResource ${lastDbResource}"/>-->
127 <script> 131 <script>
128 while (actualDbResourcePath == null) { 132 while (actualDbResourcePath == null) {
129 // ec.logger.warn('dbResourcePath: '+dbResourcePath)
130 if (lastDbResource.parentResourceId == null) { 133 if (lastDbResource.parentResourceId == null) {
131 dbResourcePath = 'dbresource://'+dbResourcePath 134 dbResourcePath = 'dbresource://'+dbResourcePath
132 actualDbResourcePath = dbResourcePath 135 actualDbResourcePath = dbResourcePath
133 // ec.logger.warn('actualDbResourcePath: '+actualDbResourcePath)
134 } else { 136 } else {
135 lastDbResource = ec.entity.fastFindOne("moqui.resource.DbResource", true, false, lastDbResource.parentResourceId) 137 lastDbResource = ec.entity.fastFindOne("moqui.resource.DbResource", true, false, lastDbResource.parentResourceId)
136 dbResourcePath = lastDbResource.filename+'/'+dbResourcePath 138 dbResourcePath = lastDbResource.filename+'/'+dbResourcePath
...@@ -142,6 +144,10 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -142,6 +144,10 @@ along with this software (see the LICENSE.md file). If not, see
142 putDbResource.putText(data) 144 putDbResource.putText(data)
143 </script> 145 </script>
144 146
147 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
148 <set field="htmlFile" from="grapesJsResource.findChildFile(resourceId.toString()+'.html') ?: grapesJsResource.makeFile(resourceId.toString()+'.html')"/>
149 <script><![CDATA[htmlFile.putText(html)]]></script>
150
145 </else> 151 </else>
146 </if> 152 </if>
147 </actions> 153 </actions>
......