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
<moqui.resource.DbResource resourceId="GRAPESJS" filename="grapesjs" isFile="N"/>
<moqui.resource.DbResource resourceId="GRAPESJS_PROJECT" filename="project" isFile="N" parentResourceId="GRAPESJS"/>
<moqui.resource.DbResource resourceId="GRAPESJS_TEMPLATE" filename="template" isFile="N" parentResourceId="GRAPESJS"/>
<dbResources resourceId="GRAPESJS_TEMPLATE_DEFAULT" filename="default" isFile="Y" parentResourceId="GRAPESJS_TEMPLATE">
<file rootVersionName="01" mimeType="text/json" versionName="01">
<fileData><![CDATA[ewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGFnZXM6IFsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBvbmVudDogYAogICAgICAgICAgICA8ZGl2IGNsYXNzPSJ0ZXN0Ij5Jbml0aWFsIGNvbnRlbnQ8L2Rpdj4KICAgICAgICAgICAgPHN0eWxlPi50ZXN0IHsgY29sb3I6IHJlZCB9PC9zdHlsZT4KICAgICAgICAgIGAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBdCiAgICAgICAgICAgICAgICAgICAgICAgIH0=]]></fileData>
</file>
</dbResources>
</entity-facade-xml>
......
......@@ -179,9 +179,18 @@ along with this software (see the LICENSE.md file). If not, see
// Wait for the plugin to be injected by the dev server
window.onload = () => {
const resourceId = new URLSearchParams(window.location.search).get('resourceId');
const projectEndpoint = `${baseLinkUrl}/mjml/handleGrapeJs?resourceId=${resourceId}`;
window.editor = grapesjs.init({
// projectData: {
// pages: [
// {
// component: `
// <div class="test">Initial content</div>
// <style>.test { color: red }</style>
// `
// }
// ]
// },
height: '100%',
noticeOnUnload: false,
// Default configurations
......@@ -205,8 +214,21 @@ along with this software (see the LICENSE.md file). If not, see
// As the API stores projects in this format `{id: 1, data: projectData }`,
// we have to properly update the body before the store and extract the
// project data from the response result.
onStore: data => ({ resourceId: resourceId, data }),
onLoad: result => result.data,
onStore: data => {
console.log('onStore', ({ id: resourceId, data }))
console.log('resourceId', resourceId)
// const url = new URL(window.location.href)
// url.searchParams.set('resourceId', resourceId);
// window.history.pushState({}, '', url)
return { id: resourceId, data }
},
onLoad: result => {
const url = new URL(window.location.href)
url.searchParams.set('resourceId', result.resourceId);
window.history.pushState({}, '', url)
console.log('onLoad', result.data)
return result.data
},
},
}
},
......
......@@ -19,8 +19,8 @@ along with this software (see the LICENSE.md file). If not, see
name="moqui-mjml" displayName="Mjml REST API" version="0.0.0">
<resource name="mjml">
<method type="get"><service name="moqui.mjml.MjmlServices.get#GrapeJs"/></method>
<method type="post"><service name="moqui.mjml.MjmlServices.store#GrapeJs"/></method>
<method type="get"><service name="mjml.MjmlServices.load#GrapeJs"/></method>
<method type="post"><service name="mjml.MjmlServices.store#GrapeJs"/></method>
</resource>
</resource>
......
......@@ -24,15 +24,19 @@ along with this software (see the LICENSE.md file). If not, see
<parameter name="data"/>
</out-parameters>
<actions>
<if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
<log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>
<log level="warn" message="load context.toString() ${context.toString()}"/>
<if condition="!resourceId">
<then>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs')"/>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/>
<set field="versionName" value="01"/>
<service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:null]"/>
<set field="defaultFile" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default')"/>
<set field="data" from="defaultFile.getText()"/>
<service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
<service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
<set field="resourceId" from="dbResource.resourceId"/>
</then>
......@@ -77,18 +81,23 @@ along with this software (see the LICENSE.md file). If not, see
<description>Create MJML</description>
<in-parameters>
<parameter name="resourceId"/>
<parameter name="data">
</parameter>
<parameter name="data"></parameter>
</in-parameters>
<out-parameters>
<parameter name="resourceId"/>
</out-parameters>
<actions>
<log level="warn" message="store context.toString() ${context.toString()}"/>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>-->
<set field="data" from="new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data.toString()"/>
<!-- <log level="warn" message="store context.toString() ${context.toString()}"/>-->
<if condition="!resourceId">
<then>
<!-- <log level="warn" message="resourceId is null"/>-->
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs')"/>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/>
<set field="versionName" value="01"/>
......