@saltcorn/mobile-app 0.7.4-beta.0 → 0.7.4-beta.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saltcorn/mobile-app",
3
3
  "displayName": "Saltcorn mobile app",
4
- "version": "0.7.4-beta.0",
4
+ "version": "0.7.4-beta.1",
5
5
  "description": "Apache Cordova application with @saltcorn/markup",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/www/index.html CHANGED
@@ -1,9 +1,27 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
+ <meta
5
+ name="viewport"
6
+ content="width=device-width, initial-scale=1, maximum-scale=1"
7
+ />
4
8
  <script src="cordova.js"></script>
5
9
  <script src="js/utils/global_utils.js"></script>
6
10
  <script src="js/utils/iframe_view_utils.js"></script>
11
+ <script src="js/utils/file_helpers.js"></script>
12
+ <script src="js/utils/table_utils.js"></script>
13
+
14
+ <script src="js/mocks/request.js"></script>
15
+ <script src="js/mocks/response.js"></script>
16
+ <script src="js/routes/common.js"></script>
17
+ <script src="js/routes/auth.js"></script>
18
+ <script src="js/routes/delete.js"></script>
19
+ <script src="js/routes/edit.js"></script>
20
+ <script src="js/routes/error.js"></script>
21
+ <script src="js/routes/page.js"></script>
22
+ <script src="js/routes/view.js"></script>
23
+ <script src="js/routes/init.js"></script>
24
+
7
25
  <script src="js/mocks/response.js"></script>
8
26
  <script src="js/mocks/request.js"></script>
9
27
  <script src="npm_packages/jwt-decode.js"></script>
@@ -11,16 +29,7 @@
11
29
  <script src="npm_packages/axios.min.js"></script>
12
30
  <script src="npm_packages/i18next.min.js"></script>
13
31
  <script src="npm_packages/i18nextSprintfPostProcessor.min.js"></script>
14
- <script type="module">
15
- import { initRoutes } from "./js/routes/init.js";
16
- import {
17
- updateDb,
18
- getTableIds,
19
- dbUpdateNeeded,
20
- updateScPlugins,
21
- } from "./js/utils/table_utils.js";
22
- import { readJSON } from "./js/utils/file_helpers.js";
23
-
32
+ <script>
24
33
  const staticPlugins = ["base", "sbadmin2"];
25
34
 
26
35
  async function addScript(scriptObj) {
@@ -92,6 +101,14 @@
92
101
  }
93
102
  }
94
103
 
104
+ const prepareHeader = (header) => {
105
+ let result = Object.assign({}, header);
106
+ if (result.script?.startsWith("/")) {
107
+ result.script = result.script.substring(1);
108
+ }
109
+ return result;
110
+ };
111
+
95
112
  /*
96
113
  A plugin exports headers either as array, as key values object, or
97
114
  as a function with a configuration parameter that returns an Array.
@@ -104,17 +121,17 @@
104
121
  if (pluginHeaders) {
105
122
  if (Array.isArray(pluginHeaders))
106
123
  for (const header of pluginHeaders) {
107
- config.pluginHeaders.push(header);
124
+ config.pluginHeaders.push(prepareHeader(header));
108
125
  }
109
126
  else if (typeof pluginHeaders === "function") {
110
127
  const headerResult = pluginHeaders(row.configuration);
111
128
  if (Array.isArray(headerResult)) {
112
129
  for (const header of headerResult)
113
- config.pluginHeaders.push(header);
130
+ config.pluginHeaders.push(prepareHeader(header));
114
131
  }
115
132
  } else
116
133
  for (const [key, value] of Object.entries(pluginHeaders)) {
117
- config.pluginHeaders.push(value);
134
+ config.pluginHeaders.push(prepareHeader(value));
118
135
  }
119
136
  }
120
137
  }
@@ -1,5 +1,3 @@
1
- import { sbAdmin2Layout } from "./common.js";
2
-
3
1
  const prepareAuthForm = () => {
4
2
  return new saltcorn.data.models.Form({
5
3
  class: "login",
@@ -69,7 +67,7 @@ const renderSignupView = (entryPoint, versionTag) => {
69
67
  });
70
68
  };
71
69
 
72
- export const getLoginView = async () => {
70
+ const getLoginView = async () => {
73
71
  const config = saltcorn.data.state.getState().mobileConfig;
74
72
  return {
75
73
  content: renderLoginView(config.entry_point, config.version_tag),
@@ -77,7 +75,7 @@ export const getLoginView = async () => {
77
75
  };
78
76
  };
79
77
 
80
- export const getSignupView = async () => {
78
+ const getSignupView = async () => {
81
79
  const config = saltcorn.data.state.getState().mobileConfig;
82
80
  return {
83
81
  content: renderSignupView(config.entry_point, config.version_tag),
@@ -85,7 +83,7 @@ export const getSignupView = async () => {
85
83
  };
86
84
  };
87
85
 
88
- export const logout = async () => {
86
+ const logoutAction = async () => {
89
87
  const config = saltcorn.data.state.getState().mobileConfig;
90
88
  const response = await apiCall({ method: "GET", path: "/auth/logout" });
91
89
  if (response.data.success) {
@@ -1,4 +1,4 @@
1
- export const getHeaders = () => {
1
+ const getHeaders = () => {
2
2
  const config = saltcorn.data.state.getState().mobileConfig;
3
3
  const versionTag = config.version_tag;
4
4
  const stdHeaders = [
@@ -9,7 +9,7 @@ export const getHeaders = () => {
9
9
  return [...stdHeaders, ...config.pluginHeaders];
10
10
  };
11
11
 
12
- export const parseQuery = (queryStr) => {
12
+ const parseQuery = (queryStr) => {
13
13
  let result = {};
14
14
  const parsedQuery =
15
15
  typeof queryStr === "string" ? new URLSearchParams(queryStr) : undefined;
@@ -21,16 +21,16 @@ export const parseQuery = (queryStr) => {
21
21
  return result;
22
22
  };
23
23
 
24
- export const layout = () => {
24
+ const layout = () => {
25
25
  const state = saltcorn.data.state.getState();
26
26
  return state.getLayout({ role_id: state.mobileConfig.role_id });
27
27
  };
28
28
 
29
- export const sbAdmin2Layout = () => {
29
+ const sbAdmin2Layout = () => {
30
30
  return saltcorn.data.state.getState().layouts["sbadmin2"];
31
31
  };
32
32
 
33
- export const getMenu = () => {
33
+ const getMenu = () => {
34
34
  const state = saltcorn.data.state.getState();
35
35
  const allowSignup = state.getConfig("allow_signup");
36
36
  const mobileCfg = saltcorn.data.state.getState().mobileConfig;
@@ -67,11 +67,11 @@ export const getMenu = () => {
67
67
  ];
68
68
  };
69
69
 
70
- export const prepareAlerts = (context, req) => {
70
+ const prepareAlerts = (context, req) => {
71
71
  return [...(context.alerts || []), ...req.flashMessages()];
72
72
  };
73
73
 
74
- export const wrapContents = (contents, title, context, req) => {
74
+ const wrapContents = (contents, title, context, req) => {
75
75
  const state = saltcorn.data.state.getState();
76
76
  const wrappedContent = context.fullWrap
77
77
  ? layout().wrap({
@@ -1,5 +1,5 @@
1
1
  // post/delete/:name/:id
2
- export const deleteRows = async (context) => {
2
+ const deleteRows = async (context) => {
3
3
  const { name, id } = context.params;
4
4
  const table = await saltcorn.data.models.Table.findOne({ name });
5
5
  const mobileConfig = saltcorn.data.state.getState().mobileConfig;
@@ -1,5 +1,5 @@
1
1
  // /toggle/:name/:id/:field_name
2
- export const postToggleField = async (context) => {
2
+ const postToggleField = async (context) => {
3
3
  const { name, id, field_name } = context.params;
4
4
  const table = await saltcorn.data.models.Table.findOne({ name });
5
5
  const mobileConfig = saltcorn.data.state.getState().mobileConfig;
@@ -1,6 +1,4 @@
1
- import { getHeaders, layout } from "./common.js"
2
-
3
- export const getErrorView = async (context) => {
1
+ const getErrorView = async (context) => {
4
2
  const state = saltcorn.data.state.getState();
5
3
  const wrappedContent = layout().wrap({
6
4
  title: "Error",
@@ -1,11 +1,4 @@
1
- import { deleteRows } from "./delete.js";
2
- import { getView, postView, postViewRoute } from "./view.js";
3
- import { postToggleField } from "./edit.js";
4
- import { postPageAction, getPage } from "./page.js";
5
- import { getLoginView, getSignupView, logout } from "./auth.js";
6
- import { getErrorView } from "./error.js";
7
-
8
- export const initRoutes = async () => {
1
+ const initRoutes = async () => {
9
2
  const routes = [
10
3
  {
11
4
  path: "post/view/:viewname",
@@ -41,7 +34,7 @@ export const initRoutes = async () => {
41
34
  },
42
35
  {
43
36
  path: "get/auth/logout",
44
- action: logout,
37
+ action: logoutAction,
45
38
  },
46
39
  {
47
40
  path: "get/auth/signup",
@@ -1,7 +1,5 @@
1
- import { parseQuery, wrapContents } from "./common.js";
2
-
3
1
  // post/page/:pagename/action/:rndid
4
- export const postPageAction = async (context) => {
2
+ const postPageAction = async (context) => {
5
3
  const state = saltcorn.data.state.getState();
6
4
  const { page_name, rndid } = context.params;
7
5
  const page = await saltcorn.data.models.Page.findOne({ name: page_name });
@@ -24,7 +22,7 @@ export const postPageAction = async (context) => {
24
22
  };
25
23
 
26
24
  // get/page/pagename
27
- export const getPage = async (context) => {
25
+ const getPage = async (context) => {
28
26
  const state = saltcorn.data.state.getState();
29
27
  const { page_name } = context.params;
30
28
  const page = await saltcorn.data.models.Page.findOne({ name: page_name });
@@ -1,11 +1,9 @@
1
- import { parseQuery, wrapContents } from "./common.js";
2
-
3
1
  /**
4
2
  *
5
3
  * @param {*} context
6
4
  * @returns
7
5
  */
8
- export const postView = async (context) => {
6
+ const postView = async (context) => {
9
7
  let body = {};
10
8
  let redirect = undefined;
11
9
  for (const [k, v] of new URLSearchParams(context.query).entries()) {
@@ -41,7 +39,7 @@ export const postView = async (context) => {
41
39
  *
42
40
  * @param {*} context
43
41
  */
44
- export const postViewRoute = async (context) => {
42
+ const postViewRoute = async (context) => {
45
43
  const view = await saltcorn.data.models.View.findOne({
46
44
  name: context.params.viewname,
47
45
  });
@@ -66,7 +64,7 @@ export const postViewRoute = async (context) => {
66
64
  * @param {*} context
67
65
  * @returns
68
66
  */
69
- export const getView = async (context) => {
67
+ const getView = async (context) => {
70
68
  const state = saltcorn.data.state.getState();
71
69
  const query = parseQuery(context.query);
72
70
  const { viewname } = context.params;
@@ -1,4 +1,4 @@
1
- export async function fileExists(path) {
1
+ async function fileExists(path) {
2
2
  try {
3
3
  await getDirEntry(path);
4
4
  return true;
@@ -7,7 +7,7 @@ export async function fileExists(path) {
7
7
  }
8
8
  }
9
9
 
10
- export function getDirEntry(directory) {
10
+ function getDirEntry(directory) {
11
11
  return new Promise((resolve, reject) => {
12
12
  window.resolveLocalFileSystemURL(
13
13
  directory,
@@ -21,7 +21,7 @@ export function getDirEntry(directory) {
21
21
  });
22
22
  }
23
23
 
24
- export async function readJSON(fileName, dirName) {
24
+ async function readJSON(fileName, dirName) {
25
25
  const dirEntry = await getDirEntry(dirName);
26
26
  return new Promise((resolve, reject) => {
27
27
  dirEntry.getFile(
@@ -45,7 +45,7 @@ export async function readJSON(fileName, dirName) {
45
45
  });
46
46
  }
47
47
 
48
- export async function write(fileName, dirName, content) {
48
+ async function write(fileName, dirName, content) {
49
49
  const dirEntry = await getDirEntry(dirName);
50
50
  return new Promise((resolve, reject) => {
51
51
  dirEntry.getFile(
@@ -72,6 +72,6 @@ export async function write(fileName, dirName, content) {
72
72
  });
73
73
  }
74
74
 
75
- export async function writeJSON(fileName, dirName, content) {
75
+ async function writeJSON(fileName, dirName, content) {
76
76
  await write(fileName, dirName, JSON.stringify(content));
77
77
  }
@@ -1,5 +1,3 @@
1
- import { fileExists, readJSON, writeJSON } from "./file_helpers.js";
2
-
3
1
  const historyFile = "update_history";
4
2
 
5
3
  /**
@@ -28,7 +26,7 @@ async function updateScTables(tablesJSON, skipScPlugins = true) {
28
26
  saltcorn.data.db.query("PRAGMA foreign_keys = ON;");
29
27
  }
30
28
 
31
- export async function updateScPlugins(tablesJSON) {
29
+ async function updateScPlugins(tablesJSON) {
32
30
  const { table, rows } = tablesJSON.sc_tables.find(
33
31
  ({ table }) => table === "_sc_plugins"
34
32
  );
@@ -66,14 +64,14 @@ async function tablesUptodate(tables, historyFile) {
66
64
  return tables.created_at.valueOf() < history.updated_at.valueOf();
67
65
  }
68
66
 
69
- export async function dbUpdateNeeded(tablesJSON) {
67
+ async function dbUpdateNeeded(tablesJSON) {
70
68
  return (
71
69
  !(await fileExists(`${cordova.file.dataDirectory}${historyFile}`)) ||
72
70
  !(await tablesUptodate(tablesJSON, historyFile))
73
71
  );
74
72
  }
75
73
 
76
- export async function updateDb(tablesJSON) {
74
+ async function updateDb(tablesJSON) {
77
75
  await updateScTables(tablesJSON);
78
76
  await saltcorn.data.state.getState().refresh_tables();
79
77
  await updateUserDefinedTables();
@@ -82,7 +80,7 @@ export async function updateDb(tablesJSON) {
82
80
  });
83
81
  }
84
82
 
85
- export async function getTableIds(tableNames) {
83
+ async function getTableIds(tableNames) {
86
84
  return (await saltcorn.data.models.Table.find())
87
85
  .filter((table) => tableNames.indexOf(table.name) > -1)
88
86
  .map((table) => table.id);