3fcb0754 by acetousk

Parse data fields JSON, get loading and storing data partially working, create default template

1 parent df6362cb
...@@ -36,5 +36,11 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -36,5 +36,11 @@ along with this software (see the LICENSE.md file). If not, see
36 36
37 <moqui.resource.DbResource resourceId="GRAPESJS" filename="grapesjs" isFile="N"/> 37 <moqui.resource.DbResource resourceId="GRAPESJS" filename="grapesjs" isFile="N"/>
38 <moqui.resource.DbResource resourceId="GRAPESJS_PROJECT" filename="project" isFile="N" parentResourceId="GRAPESJS"/> 38 <moqui.resource.DbResource resourceId="GRAPESJS_PROJECT" filename="project" isFile="N" parentResourceId="GRAPESJS"/>
39 <moqui.resource.DbResource resourceId="GRAPESJS_TEMPLATE" filename="template" isFile="N" parentResourceId="GRAPESJS"/>
39 40
41 <dbResources resourceId="GRAPESJS_TEMPLATE_DEFAULT" filename="default" isFile="Y" parentResourceId="GRAPESJS_TEMPLATE">
42 <file rootVersionName="01" mimeType="text/json" versionName="01">
43 <fileData><![CDATA[ewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGFnZXM6IFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBvbmVudDogYAogICAgICAgICAgICA8ZGl2IGNsYXNzPSJ0ZXN0Ij5Jbml0aWFsIGNvbnRlbnQ8L2Rpdj4KICAgICAgICAgICAgPHN0eWxlPi50ZXN0IHsgY29sb3I6IHJlZCB9PC9zdHlsZT4KICAgICAgICAgIGAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBdCiAgICAgICAgICAgICAgICAgICAgICAgIH0=]]></fileData>
44 </file>
45 </dbResources>
40 </entity-facade-xml> 46 </entity-facade-xml>
......
...@@ -179,9 +179,18 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -179,9 +179,18 @@ along with this software (see the LICENSE.md file). If not, see
179 // Wait for the plugin to be injected by the dev server 179 // Wait for the plugin to be injected by the dev server
180 window.onload = () => { 180 window.onload = () => {
181 const resourceId = new URLSearchParams(window.location.search).get('resourceId'); 181 const resourceId = new URLSearchParams(window.location.search).get('resourceId');
182 const projectEndpoint = `${baseLinkUrl}/mjml/handleGrapeJs?resourceId=${resourceId}`;
183 182
184 window.editor = grapesjs.init({ 183 window.editor = grapesjs.init({
184 // projectData: {
185 // pages: [
186 // {
187 // component: `
188 // <div class="test">Initial content</div>
189 // <style>.test { color: red }</style>
190 // `
191 // }
192 // ]
193 // },
185 height: '100%', 194 height: '100%',
186 noticeOnUnload: false, 195 noticeOnUnload: false,
187 // Default configurations 196 // Default configurations
...@@ -205,8 +214,21 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -205,8 +214,21 @@ along with this software (see the LICENSE.md file). If not, see
205 // As the API stores projects in this format `{id: 1, data: projectData }`, 214 // As the API stores projects in this format `{id: 1, data: projectData }`,
206 // we have to properly update the body before the store and extract the 215 // we have to properly update the body before the store and extract the
207 // project data from the response result. 216 // project data from the response result.
208 onStore: data => ({ resourceId: resourceId, data }), 217 onStore: data => {
209 onLoad: result => result.data, 218 console.log('onStore', ({ id: resourceId, data }))
219 console.log('resourceId', resourceId)
220 // const url = new URL(window.location.href)
221 // url.searchParams.set('resourceId', resourceId);
222 // window.history.pushState({}, '', url)
223 return { id: resourceId, data }
224 },
225 onLoad: result => {
226 const url = new URL(window.location.href)
227 url.searchParams.set('resourceId', result.resourceId);
228 window.history.pushState({}, '', url)
229 console.log('onLoad', result.data)
230 return result.data
231 },
210 }, 232 },
211 } 233 }
212 }, 234 },
......
...@@ -19,8 +19,8 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -19,8 +19,8 @@ along with this software (see the LICENSE.md file). If not, see
19 name="moqui-mjml" displayName="Mjml REST API" version="0.0.0"> 19 name="moqui-mjml" displayName="Mjml REST API" version="0.0.0">
20 20
21 <resource name="mjml"> 21 <resource name="mjml">
22 <method type="get"><service name="moqui.mjml.MjmlServices.get#GrapeJs"/></method> 22 <method type="get"><service name="mjml.MjmlServices.load#GrapeJs"/></method>
23 <method type="post"><service name="moqui.mjml.MjmlServices.store#GrapeJs"/></method> 23 <method type="post"><service name="mjml.MjmlServices.store#GrapeJs"/></method>
24 </resource> 24 </resource>
25 25
26 </resource> 26 </resource>
......
...@@ -24,15 +24,19 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -24,15 +24,19 @@ along with this software (see the LICENSE.md file). If not, see
24 <parameter name="data"/> 24 <parameter name="data"/>
25 </out-parameters> 25 </out-parameters>
26 <actions> 26 <actions>
27 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
28 <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>
27 <log level="warn" message="load context.toString() ${context.toString()}"/> 29 <log level="warn" message="load context.toString() ${context.toString()}"/>
28 30
29 <if condition="!resourceId"> 31 <if condition="!resourceId">
30 <then> 32 <then>
31 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs')"/> 33 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
32 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> 34 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
33 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/> 35 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/>
34 <set field="versionName" value="01"/> 36 <set field="versionName" value="01"/>
35 <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:null]"/> 37 <set field="defaultFile" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default')"/>
38 <set field="data" from="defaultFile.getText()"/>
39 <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
36 <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/> 40 <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
37 <set field="resourceId" from="dbResource.resourceId"/> 41 <set field="resourceId" from="dbResource.resourceId"/>
38 </then> 42 </then>
...@@ -77,18 +81,23 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -77,18 +81,23 @@ along with this software (see the LICENSE.md file). If not, see
77 <description>Create MJML</description> 81 <description>Create MJML</description>
78 <in-parameters> 82 <in-parameters>
79 <parameter name="resourceId"/> 83 <parameter name="resourceId"/>
80 <parameter name="data"> 84 <parameter name="data"></parameter>
81 </parameter>
82 </in-parameters> 85 </in-parameters>
83 <out-parameters> 86 <out-parameters>
84 <parameter name="resourceId"/> 87 <parameter name="resourceId"/>
85 </out-parameters> 88 </out-parameters>
86 <actions> 89 <actions>
87 <log level="warn" message="store context.toString() ${context.toString()}"/> 90 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
91 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
92 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
93 <!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>-->
94 <set field="data" from="new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data.toString()"/>
95
96 <!-- <log level="warn" message="store context.toString() ${context.toString()}"/>-->
88 <if condition="!resourceId"> 97 <if condition="!resourceId">
89 <then> 98 <then>
90 <!-- <log level="warn" message="resourceId is null"/>--> 99 <!-- <log level="warn" message="resourceId is null"/>-->
91 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs')"/> 100 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
92 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> 101 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
93 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/> 102 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/>
94 <set field="versionName" value="01"/> 103 <set field="versionName" value="01"/>
......