57039d4b by acetousk

Create api and services (WIP), fix auth and urls for screen, add data

1 parent ed4848ef
...@@ -29,7 +29,7 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -29,7 +29,7 @@ along with this software (see the LICENSE.md file). If not, see
29 <!-- Artifact group for all of the Moqui Mjml REST API via the mjml resource (the root resource) --> 29 <!-- Artifact group for all of the Moqui Mjml REST API via the mjml resource (the root resource) -->
30 <moqui.security.ArtifactGroup artifactGroupId="MOQUI_MJML_API" description="Example REST API (via root resource)"/> 30 <moqui.security.ArtifactGroup artifactGroupId="MOQUI_MJML_API" description="Example REST API (via root resource)"/>
31 <moqui.security.ArtifactGroupMember artifactGroupId="MOQUI_MJML_API" artifactTypeEnumId="AT_REST_PATH" 31 <moqui.security.ArtifactGroupMember artifactGroupId="MOQUI_MJML_API" artifactTypeEnumId="AT_REST_PATH"
32 inheritAuthz="Y" artifactName="/example"/> 32 inheritAuthz="Y" artifactName="/moqui-mjml/mjml"/>
33 <!-- Full permissions for the ADMIN user group --> 33 <!-- Full permissions for the ADMIN user group -->
34 <moqui.security.ArtifactAuthz artifactAuthzId="MOQUI_MJML_API_AUTHZ_ALL" userGroupId="ADMIN" artifactGroupId="MOQUI_MJML_API" 34 <moqui.security.ArtifactAuthz artifactAuthzId="MOQUI_MJML_API_AUTHZ_ALL" userGroupId="ADMIN" artifactGroupId="MOQUI_MJML_API"
35 authzTypeEnumId="AUTHZT_ALWAYS" authzActionEnumId="AUTHZA_ALL"/> 35 authzTypeEnumId="AUTHZT_ALWAYS" authzActionEnumId="AUTHZA_ALL"/>
......
...@@ -20,6 +20,7 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -20,6 +20,7 @@ along with this software (see the LICENSE.md file). If not, see
20 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="50" resourceTypeEnumId="STRT_STYLESHEET" resourceValue="/mjmlstatic/css/grapes.min.css"/> 20 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="50" resourceTypeEnumId="STRT_STYLESHEET" resourceValue="/mjmlstatic/css/grapes.min.css"/>
21 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="52" resourceTypeEnumId="STRT_STYLESHEET" resourceValue="/mjmlstatic/css/grapesjs-mjml.css"/> 21 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="52" resourceTypeEnumId="STRT_STYLESHEET" resourceValue="/mjmlstatic/css/grapesjs-mjml.css"/>
22 22
23 <delete-moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="10" resourceTypeEnumId="STRT_SCRIPT" resourceValue="/js/MoquiLib.js"/>
23 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="51" resourceTypeEnumId="STRT_SCRIPT" resourceValue="/mjmlstatic/js/grapesjs.min.js"/> 24 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="51" resourceTypeEnumId="STRT_SCRIPT" resourceValue="/mjmlstatic/js/grapesjs.min.js"/>
24 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="52" resourceTypeEnumId="STRT_SCRIPT" resourceValue="/mjmlstatic/js/grapesjs-mjml.min.js"/> 25 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="52" resourceTypeEnumId="STRT_SCRIPT" resourceValue="/mjmlstatic/js/grapesjs-mjml.min.js"/>
25 26
...@@ -33,5 +34,7 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -33,5 +34,7 @@ along with this software (see the LICENSE.md file). If not, see
33 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="110" resourceTypeEnumId="STRT_HEADER_TITLE" 34 <moqui.screen.ScreenThemeResource screenThemeId="MJML_DEFAULT" sequenceNum="110" resourceTypeEnumId="STRT_HEADER_TITLE"
34 resourceValue="Email Editor"/> 35 resourceValue="Email Editor"/>
35 36
37 <moqui.resource.DbResource resourceId="GRAPESJS" filename="grapesjs" isFile="N"/>
38 <moqui.resource.DbResource resourceId="GRAPESJS_PROJECT" filename="project" isFile="N" parentResourceId="GRAPESJS"/>
36 39
37 </entity-facade-xml> 40 </entity-facade-xml>
......
...@@ -16,11 +16,30 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -16,11 +16,30 @@ along with this software (see the LICENSE.md file). If not, see
16 xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-3.xsd" 16 xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-3.xsd"
17 menu-image="fa fa-flash" menu-image-type="icon" standalone="true" screen-theme-type-enum-id="STT_MJML" > 17 menu-image="fa fa-flash" menu-image-type="icon" standalone="true" screen-theme-type-enum-id="STT_MJML" >
18 18
19 <parameter name="resourceId"/>
20
21 <transition name="handleGrapeJs" read-only="true" method="get">
22 <actions>
23 <log level="warn" message="context.toString() ${context.toString()}"/>
24 <service-call name="moqui.MjmlServices.get#GrapeJs" in-map="[resourceId:resourceId]" out-map="context"/>
25 </actions>
26 <default-response url="."/></transition>
27 <transition name="handleGrapeJs" read-only="true" method="post">
28 <actions>
29 <log level="warn" message="context.toString() ${context.toString()}"/>
30 <service-call name="moqui.MjmlServices.store#GrapeJs" in-map="context" out-map="context"/>
31 </actions>
32 <default-response url="."/></transition>
33
34 <actions>
35 <set field="baseLinkUrl" from="!'production'.equals(System.getProperty('instance_purpose')) ? 'http://localhost:8080' : ec.web.getWebappRootUrl(true,true)"/>
36 </actions>
37
19 <widgets> 38 <widgets>
20 <render-mode><text type="html" location="component://webroot/screen/includes/Header.html.ftl"/></render-mode> 39 <render-mode><text type="html" location="component://webroot/screen/includes/Header.html.ftl"/></render-mode>
21 40
22 41 <render-mode><text type="html"><![CDATA[
23 <render-mode><text type="html,vuet,qvt"><![CDATA[ 42 <input type="hidden" id="confMoquiSessionToken" value="${ec.web.sessionToken}">
24 <style> 43 <style>
25 body, 44 body,
26 html { 45 html {
...@@ -159,10 +178,37 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -159,10 +178,37 @@ along with this software (see the LICENSE.md file). If not, see
159 <script type="text/javascript"> 178 <script type="text/javascript">
160 // Wait for the plugin to be injected by the dev server 179 // Wait for the plugin to be injected by the dev server
161 window.onload = () => { 180 window.onload = () => {
181 const resourceId = new URLSearchParams(window.location.search).get('resourceId');
182
162 window.editor = grapesjs.init({ 183 window.editor = grapesjs.init({
163 height: '100%', 184 height: '100%',
164 noticeOnUnload: false, 185 noticeOnUnload: false,
165 storageManager: false, 186 // Default configurations
187 storageManager: {
188 type: 'remote', // Storage type. Available: local | remote
189 autosave: true, // Store data automatically
190 autoload: true, // Autoload stored data on init
191 stepsBeforeSave: 1, // If autosave is enabled, indicates how many changes are necessary before the store method is triggered
192 // ...
193 // Default storage options
194 options: {
195 remote: {
196 urlLoad: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + resourceId,
197 urlStore: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + resourceId,
198 headers: {
199 "X-CSRF-Token": document.getElementById('confMoquiSessionToken').value
200 },
201 // The `remote` storage uses the POST method when stores data but
202 // the json-server API requires PATCH.
203 // fetchOptions: opts => (opts.method === 'POST' ? { method: 'PATCH' } : {}),
204 // As the API stores projects in this format `{id: 1, data: projectData }`,
205 // we have to properly update the body before the store and extract the
206 // project data from the response result.
207 onStore: data => ({ resourceId: resourceId, data }),
208 onLoad: result => result.data,
209 },
210 }
211 },
166 fromElement: true, 212 fromElement: true,
167 container: '#gjs', 213 container: '#gjs',
168 214
......
...@@ -14,5 +14,47 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -14,5 +14,47 @@ along with this software (see the LICENSE.md file). If not, see
14 --> 14 -->
15 <services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-3.xsd"> 15 <services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-3.xsd">
16 16
17 <service verb="get" noun="GrapeJs">
18 <description>Create MJML</description>
19 <in-parameters>
20 <parameter name="resourceId"/>
21 </in-parameters>
22 <out-parameters>
23 <parameter name="data"/>
24 </out-parameters>
25 <actions>
26 <set field="file" from="ec.resource.getLocationReference('dbresource://grapesjs/project/'+resourceId)"/>
27 <set field="data" from="file.getText()"/>
28 </actions>
29 </service>
30 <service verb="store" noun="GrapeJs">
31 <description>Create MJML</description>
32 <in-parameters>
33 <parameter name="resourceId"/>
34 <parameter name="data" type="String"/>
35 </in-parameters>
36 <out-parameters>
37 <parameter name="resourceId"/>
38 </out-parameters>
39 <actions>
40 <!-- <log level="warn" message="context.toString() ${context.toString()}"/>-->
41 <!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters.data ${ec.web.secureRequestParameters.data}"/>-->
42
43 <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>
44 <log level="warn" message="store#GrapeJs data ${data} typeof data ${data.getClass().getName()}"/>
45
46 <!-- <set field="data" from="groovy.json.JsonOutput.toJson(data)"/>-->
47
48 <set field="project" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
49 <set field="file" from="project.makeFile(java.util.UUID.randomUUID().toString())"/>
50 <script><![CDATA[
51 file.putText(data)
52 file.move(project.location + "/" + file.dbResourceId)
53 ]]></script>
54 <set field="resourceId" from="context.resourceId"/>
55
56 </actions>
57 </service>
58
17 59
18 </services> 60 </services>
......