@saltcorn/mobile-app 0.9.6-beta.0 → 0.9.6-beta.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/config.xml CHANGED
@@ -3,6 +3,7 @@
3
3
  <name>SaltcornMobileApp</name>
4
4
  <description>Apache Cordova application with @saltcorn/markup</description>
5
5
  <platform name="android">
6
+ <preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/screen/android/splash-icon.png"/>
6
7
  <icon density="ldpi" foreground="res/icon/android/icon.png" background="res/icon/android/icon.png" />
7
8
  <edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application" mode="merge">
8
9
  <application android:usesCleartextTraffic="true"/>
@@ -17,6 +18,7 @@
17
18
  </platform>
18
19
  <platform name="ios">
19
20
  <preference name="deployment-target" value="12.0"/>
21
+ <splash src="res/screen/ios/Default@2x~universal~anyany.png" />
20
22
  </platform>
21
23
  <content src="index.html"/>
22
24
  <access origin="*"/>
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.9.6-beta.0",
4
+ "version": "0.9.6-beta.2",
5
5
  "description": "Apache Cordova application with @saltcorn/markup",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/www/index.html CHANGED
@@ -292,70 +292,70 @@
292
292
 
293
293
  // device is ready
294
294
  const init = async () => {
295
- document.addEventListener("resume", onResume, false);
296
- const config = await readJSON(
297
- "config",
298
- `${cordova.file.applicationDirectory}www`
299
- );
300
- const { created_at } = await readJSON(
301
- "tables_created_at.json",
302
- `${cordova.file.applicationDirectory}${"www"}`
303
- );
304
- let tablesJSON = null;
305
- await addScripts(config.version_tag);
306
- saltcorn.data.db.connectObj.version_tag = config.version_tag;
307
- await saltcorn.data.db.init();
308
- const updateNeeded = await dbUpdateNeeded(created_at);
309
- if (updateNeeded) {
310
- tablesJSON = await readJSON(
311
- "tables.json",
295
+ try {
296
+ document.addEventListener("resume", onResume, false);
297
+ const config = await readJSON(
298
+ "config",
299
+ `${cordova.file.applicationDirectory}www`
300
+ );
301
+ const { created_at } = await readJSON(
302
+ "tables_created_at.json",
312
303
  `${cordova.file.applicationDirectory}${"www"}`
313
304
  );
314
- // update '_sc_plugins' first because of loadPlugins()
315
- await updateScPlugins(tablesJSON);
316
- }
317
- saltcorn.data.state.features.version_plugin_serve_path = false;
318
- const state = saltcorn.data.state.getState();
319
- state.mobileConfig = config;
320
- state.registerPlugin("base", saltcorn.base_plugin);
321
- state.registerPlugin("sbadmin2", saltcorn.sbadmin2);
322
- collectPluginHeaders(await loadPlugins(state));
323
- if (updateNeeded) {
324
- if (!tablesJSON)
305
+ let tablesJSON = null;
306
+ await addScripts(config.version_tag);
307
+ saltcorn.data.db.connectObj.version_tag = config.version_tag;
308
+ await saltcorn.data.db.init();
309
+ const updateNeeded = await dbUpdateNeeded(created_at);
310
+ if (updateNeeded) {
325
311
  tablesJSON = await readJSON(
326
312
  "tables.json",
327
313
  `${cordova.file.applicationDirectory}${"www"}`
328
314
  );
329
- await updateDb(tablesJSON);
330
- }
331
- await createSyncInfoTables(config.synchedTables);
332
- await initJwt();
333
- await state.refresh_tables();
334
- await state.refresh_views();
335
- await state.refresh_pages();
336
- await state.refresh_page_groups();
337
- state.mobileConfig.localTableIds = await getTableIds(
338
- config.localUserTables
339
- );
340
- await state.setConfig("base_url", config.server_path);
341
- await initRoutes();
342
- const entryPoint = config.entry_point;
343
- await initI18Next();
344
- await readSiteLogo(state);
345
- state.mobileConfig.networkState = navigator.connection.type;
346
- document.addEventListener(
347
- "offline",
348
- offlineHelper.offlineCallback,
349
- false
350
- );
351
- document.addEventListener(
352
- "online",
353
- offlineHelper.onlineCallback,
354
- false
355
- );
356
- const networkDisabled = state.mobileConfig.networkState === "none";
357
- const jwt = state.mobileConfig.jwt;
358
- try {
315
+ // update '_sc_plugins' first because of loadPlugins()
316
+ await updateScPlugins(tablesJSON);
317
+ }
318
+ saltcorn.data.state.features.version_plugin_serve_path = false;
319
+ const state = saltcorn.data.state.getState();
320
+ state.mobileConfig = config;
321
+ state.registerPlugin("base", saltcorn.base_plugin);
322
+ state.registerPlugin("sbadmin2", saltcorn.sbadmin2);
323
+ collectPluginHeaders(await loadPlugins(state));
324
+ if (updateNeeded) {
325
+ if (!tablesJSON)
326
+ tablesJSON = await readJSON(
327
+ "tables.json",
328
+ `${cordova.file.applicationDirectory}${"www"}`
329
+ );
330
+ await updateDb(tablesJSON);
331
+ }
332
+ await createSyncInfoTables(config.synchedTables);
333
+ await initJwt();
334
+ await state.refresh_tables();
335
+ await state.refresh_views();
336
+ await state.refresh_pages();
337
+ await state.refresh_page_groups();
338
+ state.mobileConfig.localTableIds = await getTableIds(
339
+ config.localUserTables
340
+ );
341
+ await state.setConfig("base_url", config.server_path);
342
+ await initRoutes();
343
+ const entryPoint = config.entry_point;
344
+ await initI18Next();
345
+ await readSiteLogo(state);
346
+ state.mobileConfig.networkState = navigator.connection.type;
347
+ document.addEventListener(
348
+ "offline",
349
+ offlineHelper.offlineCallback,
350
+ false
351
+ );
352
+ document.addEventListener(
353
+ "online",
354
+ offlineHelper.onlineCallback,
355
+ false
356
+ );
357
+ const networkDisabled = state.mobileConfig.networkState === "none";
358
+ const jwt = state.mobileConfig.jwt;
359
359
  const alerts = [];
360
360
  if ((networkDisabled && jwt) || (await checkJWT(jwt))) {
361
361
  const mobileConfig = state.mobileConfig;
@@ -445,8 +445,19 @@
445
445
  await publicLogin(entryPoint);
446
446
  } else await showLogin(alerts);
447
447
  } catch (error) {
448
- if (error.httpCode === 401) await showLogin([]);
449
- else await showErrorPage(error);
448
+ if (
449
+ typeof saltcorn === "undefined" ||
450
+ typeof router === "undefined"
451
+ ) {
452
+ const msg = `An error occured: ${
453
+ error.message ? error.message : "Unknown error"
454
+ }`;
455
+ console.log(msg);
456
+ alert(msg);
457
+ } else {
458
+ if (error.httpCode === 401) await showLogin([]);
459
+ else await showErrorPage(error);
460
+ }
450
461
  }
451
462
  };
452
463
 
@@ -21,28 +21,37 @@ async function dropDeletedTables(incomingTables) {
21
21
  }
22
22
  }
23
23
 
24
+ /**
25
+ * pick fields that really exist
26
+ * @param {*} table
27
+ * @param {*} rows
28
+ * @returns
29
+ */
30
+ async function safeRows(table, rows) {
31
+ const existingFields = (
32
+ await saltcorn.data.db.query(
33
+ `PRAGMA table_info('${saltcorn.data.db.sqlsanitize(table)}')`
34
+ )
35
+ ).rows.map((row) => row.name);
36
+ return rows.map((row) => {
37
+ const insertRow = {};
38
+ for (const safeField of existingFields) {
39
+ const fromRow = row[safeField];
40
+ if (fromRow !== null && fromRow !== undefined) {
41
+ insertRow[safeField] = fromRow;
42
+ }
43
+ }
44
+ return insertRow;
45
+ });
46
+ }
47
+
24
48
  async function updateScTables(tablesJSON, skipScPlugins = true) {
25
49
  await saltcorn.data.db.query("PRAGMA foreign_keys = OFF;");
26
50
  for (const { table, rows } of tablesJSON.sc_tables) {
27
51
  if (skipScPlugins && table === "_sc_plugins") continue;
28
52
  if (table === "_sc_tables") await dropDeletedTables(rows);
29
53
  await saltcorn.data.db.deleteWhere(table);
30
- const existingFields = (
31
- await saltcorn.data.db.query(
32
- `PRAGMA table_info('${saltcorn.data.db.sqlsanitize(table)}')`
33
- )
34
- ).rows.map((row) => row.name);
35
- for (const row of rows) {
36
- // pick fields that really exist
37
- const insertRow = {};
38
- for (const safeField of existingFields) {
39
- const fromRow = row[safeField];
40
- if (fromRow !== null && fromRow !== undefined) {
41
- insertRow[safeField] = fromRow;
42
- }
43
- }
44
- await saltcorn.data.db.insert(table, insertRow);
45
- }
54
+ await saltcorn.data.db.insertRows(table, await safeRows(table, rows));
46
55
  }
47
56
  await saltcorn.data.db.query("PRAGMA foreign_keys = ON;");
48
57
  }
@@ -66,18 +75,18 @@ async function updateUserDefinedTables() {
66
75
  table.name !== "users" &&
67
76
  !existingTables.find((row) => row.name === sanitized)
68
77
  ) {
69
- // CREATE TABLE without inserting into _sc_tables
70
- await saltcorn.data.models.Table.create(table.name, {}, table.id);
71
- }
72
- const existingFields = (
73
- await saltcorn.data.db.query(`PRAGMA table_info('${sanitized}')`)
74
- ).rows.map((row) => row.name);
75
- for (const field of table.getFields()) {
76
- if (
77
- existingFields.indexOf(saltcorn.data.db.sqlsanitize(field.name)) < 0
78
- ) {
79
- // field is new
80
- await saltcorn.data.models.Field.create(field, false, field.id);
78
+ await saltcorn.data.models.Table.createInDb(table);
79
+ } else {
80
+ const existingFields = (
81
+ await saltcorn.data.db.query(`PRAGMA table_info('${sanitized}')`)
82
+ ).rows.map((row) => row.name);
83
+ for (const field of table.getFields()) {
84
+ if (
85
+ existingFields.indexOf(saltcorn.data.db.sqlsanitize(field.name)) < 0
86
+ ) {
87
+ // field is new
88
+ await saltcorn.data.models.Field.create(field, false, field.id);
89
+ }
81
90
  }
82
91
  }
83
92
  }