Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
moqui
/
moqui-mjml
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3fcb0754
authored
2024-05-03 12:46:26 -0600
by
acetousk
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Parse data fields JSON, get loading and storing data partially working, create default template
1 parent
df6362cb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
11 deletions
data/MjmlSetupData.xml
screen/MjmlApp.xml
service/mjml.rest.xml
service/mjml/MjmlServices.xml
data/MjmlSetupData.xml
View file @
3fcb075
...
...
@@ -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>
...
...
screen/MjmlApp.xml
View file @
3fcb075
...
...
@@ -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
},
},
}
},
...
...
service/mjml.rest.xml
View file @
3fcb075
...
...
@@ -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=
"m
oqui.mjml.MjmlServices.get
#GrapeJs"
/></method>
<method
type=
"post"
><service
name=
"m
oqui.m
jml.MjmlServices.store#GrapeJs"
/></method>
<method
type=
"get"
><service
name=
"m
jml.MjmlServices.load
#GrapeJs"
/></method>
<method
type=
"post"
><service
name=
"mjml.MjmlServices.store#GrapeJs"
/></method>
</resource>
</resource>
...
...
service/mjml/MjmlServices.xml
View file @
3fcb075
...
...
@@ -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"
/>
...
...
Please
register
or
sign in
to post a comment