@soleil-se/app-util 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import PortletContextUtil from 'PortletContextUtil';
2
2
  import VersionUtil from 'VersionUtil';
3
- import app from 'app';
3
+ import appInfo from 'appInfo';
4
4
  /* Underscore is provided by SiteVision */
5
5
  /* eslint-disable-next-line import/no-extraneous-dependencies */
6
6
  import _ from 'underscore';
@@ -8,7 +8,7 @@ import _ from 'underscore';
8
8
  /** If the webapp is running in offline mode or not. */
9
9
  export var isOffline = VersionUtil.getCurrentVersion() === VersionUtil.OFFLINE_VERSION;
10
10
 
11
- var portletId = app.portletId.replace('.', '_');
11
+ var portletId = PortletContextUtil.getCurrentPortlet().getIdentifier().replace('.', '_');
12
12
 
13
13
  /**
14
14
  * Get URI for a resource.
@@ -16,7 +16,7 @@ var portletId = app.portletId.replace('.', '_');
16
16
  * @returns {String} URI for a resource.
17
17
  */
18
18
  export function getResourceUri(resource) {
19
- return ("/webapp-files/" + (app.webAppId) + "/" + (app.webAppVersion) + "/" + resource);
19
+ return ("/webapp-files/" + (appInfo.appIdentifier) + "/" + (appInfo.appVersion) + "/" + resource);
20
20
  }
21
21
 
22
22
  /**
@@ -57,13 +57,13 @@ export function renderApp(name, data, ref) {
57
57
  var async = ref.async; if ( async === void 0 ) async = true;
58
58
  var defer = ref.defer; if ( defer === void 0 ) defer = false;
59
59
 
60
- var options = Object.assign({}, {webapp: app, isOffline: isOffline}, data);
60
+ var options = Object.assign({}, data, {isOffline: isOffline});
61
61
  var clientUri = getResourceUri('client/index.js');
62
62
 
63
63
  if (isOffline) {
64
- return ("\n<!-- Generated by WebappUtil." + (this.name) + "() -->\n<div data-portlet-id=\"" + portletId + "\">" + noScript + "</div>\n<script src=\"" + clientUri + "\"></script>\n<script> \n Soleil.webapps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n</script>\n");
64
+ return ("\n<!-- Generated by WebappUtil.renderApp() -->\n<div data-portlet-id=\"" + portletId + "\">" + noScript + "</div>\n<script src=\"" + clientUri + "?" + (appInfo.appImportDate) + "\"></script>\n<script> \n Soleil.webapps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n</script>\n");
65
65
  }
66
- return ("\n<!-- Generated by WebappUtil." + (this.name) + "() -->\n<div data-portlet-id=\"" + portletId + "\">" + noScript + "</div>\n<script>\n function renderApp" + portletId + "() {\n Soleil.webapps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n } \n</script>\n<script src=\"" + clientUri + "\" " + (async && !defer ? 'async' : '') + " " + (defer ? 'defer' : '') + " onload=\"renderApp" + portletId + "();\"></script>\n");
66
+ return ("\n<!-- Generated by WebappUtil.renderApp() -->\n<div data-portlet-id=\"" + portletId + "\">" + noScript + "</div>\n<script>\n function renderApp" + portletId + "() {\n Soleil.webapps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n } \n</script>\n<script src=\"" + clientUri + "?" + (appInfo.appImportDate) + "\" " + (async && !defer ? 'async' : '') + " " + (defer ? 'defer' : '') + " onload=\"renderApp" + portletId + "();\"></script>\n");
67
67
  }
68
68
 
69
69
  /**
@@ -72,7 +72,7 @@ export function renderApp(name, data, ref) {
72
72
  * @returns {String} URI for route.
73
73
  */
74
74
  export function getRouteUri(route) {
75
- var currentPageId = PortletContextUtil.getCurrentPage().getIdentifier();
75
+ var currentPageId = PortletContextUtil.getCurrentPage().getIdentifier().replace('_sitePage', '');
76
76
  var currentPortletId = PortletContextUtil.getCurrentPortlet().getIdentifier();
77
77
  return ("/appresource/" + currentPageId + "/" + currentPortletId + "/" + route).replace(/\/\//g, '/');
78
78
  }
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@soleil-se/app-util",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Utility functions for Webapps.",
5
5
  "main": "./dist/index.js",
6
6
  "author": "Soleil AB",
7
+ "contributors": [
8
+ "Kimmy Monassar"
9
+ ],
7
10
  "license": "UNLICENSED",
8
11
  "private": false,
9
12
  "homepage": "https://github.com/soleilit/server-monorepo/tree/master/packages/app-util",
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import PortletContextUtil from 'PortletContextUtil';
2
2
  import VersionUtil from 'VersionUtil';
3
- import app from 'app';
3
+ import appInfo from 'appInfo';
4
4
  /* Underscore is provided by SiteVision */
5
5
  /* eslint-disable-next-line import/no-extraneous-dependencies */
6
6
  import _ from 'underscore';
@@ -8,7 +8,7 @@ import _ from 'underscore';
8
8
  /** If the webapp is running in offline mode or not. */
9
9
  export const isOffline = VersionUtil.getCurrentVersion() === VersionUtil.OFFLINE_VERSION;
10
10
 
11
- const portletId = app.portletId.replace('.', '_');
11
+ const portletId = PortletContextUtil.getCurrentPortlet().getIdentifier().replace('.', '_');
12
12
 
13
13
  /**
14
14
  * Get URI for a resource.
@@ -16,7 +16,7 @@ const portletId = app.portletId.replace('.', '_');
16
16
  * @returns {String} URI for a resource.
17
17
  */
18
18
  export function getResourceUri(resource) {
19
- return `/webapp-files/${app.webAppId}/${app.webAppVersion}/${resource}`;
19
+ return `/webapp-files/${appInfo.appIdentifier}/${appInfo.appVersion}/${resource}`;
20
20
  }
21
21
 
22
22
  /**
@@ -54,14 +54,14 @@ export function renderApp(name, data, {
54
54
  async = true,
55
55
  defer = false,
56
56
  } = {}) {
57
- const options = { webapp: app, isOffline, ...data };
57
+ const options = { ...data, isOffline };
58
58
  const clientUri = getResourceUri('client/index.js');
59
59
 
60
60
  if (isOffline) {
61
61
  return `
62
62
  <!-- Generated by WebappUtil.renderApp() -->
63
63
  <div data-portlet-id="${portletId}">${noScript}</div>
64
- <script src="${clientUri}"></script>
64
+ <script src="${clientUri}?${appInfo.appImportDate}"></script>
65
65
  <script>
66
66
  Soleil.webapps['${name}'].render('${name}', '${selector}', ${JSON.stringify(options)});
67
67
  </script>
@@ -75,7 +75,7 @@ export function renderApp(name, data, {
75
75
  Soleil.webapps['${name}'].render('${name}', '${selector}', ${JSON.stringify(options)});
76
76
  }
77
77
  </script>
78
- <script src="${clientUri}" ${async && !defer ? 'async' : ''} ${defer ? 'defer' : ''} onload="renderApp${portletId}();"></script>
78
+ <script src="${clientUri}?${appInfo.appImportDate}" ${async && !defer ? 'async' : ''} ${defer ? 'defer' : ''} onload="renderApp${portletId}();"></script>
79
79
  `;
80
80
  }
81
81
 
@@ -85,7 +85,7 @@ export function renderApp(name, data, {
85
85
  * @returns {String} URI for route.
86
86
  */
87
87
  export function getRouteUri(route) {
88
- const currentPageId = PortletContextUtil.getCurrentPage().getIdentifier();
88
+ const currentPageId = PortletContextUtil.getCurrentPage().getIdentifier().replace('_sitePage', '');
89
89
  const currentPortletId = PortletContextUtil.getCurrentPortlet().getIdentifier();
90
90
  return `/appresource/${currentPageId}/${currentPortletId}/${route}`.replace(/\/\//g, '/');
91
91
  }