@saltcorn/mobile-app 1.3.1-beta.10 → 1.3.1-beta.11

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": "1.3.1-beta.10",
4
+ "version": "1.3.1-beta.11",
5
5
  "description": "Saltcorn mobile app for Android and iOS",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/init.js CHANGED
@@ -30,6 +30,7 @@ import i18nextSprintfPostProcessor from "i18next-sprintf-postprocessor";
30
30
  import { jwtDecode } from "jwt-decode";
31
31
 
32
32
  import { Network } from "@capacitor/network";
33
+ import { App } from '@capacitor/app';
33
34
 
34
35
  import { defineCustomElements } from "jeep-sqlite/loader";
35
36
 
@@ -357,6 +358,11 @@ export async function init(mobileConfig) {
357
358
  document.body.appendChild(jeepSqlite);
358
359
  await jeepSqlite.componentOnReady();
359
360
  }
361
+
362
+ App.addListener('backButton', async ({ canGoBack }) => {
363
+ await saltcorn.mobileApp.navigation.goBack(1, true);
364
+ });
365
+
360
366
  const lastLocation = takeLastLocation();
361
367
  document.addEventListener("resume", onResume, false);
362
368
  await addScripts(mobileConfig.version_tag);
@@ -148,7 +148,6 @@ export const getView = async (context) => {
148
148
  const { viewname } = context.params;
149
149
  const view = saltcorn.data.models.View.findOne({ name: viewname });
150
150
  if (!view) throw new Error(req.__("No such view: %s", viewname));
151
- const res = new MobileResponse();
152
151
  if (
153
152
  state.mobileConfig.user.role_id > view.min_role &&
154
153
  !(await view.authorise_get({ query, req, ...view }))
@@ -158,45 +157,53 @@ export const getView = async (context) => {
158
157
  req.__("Not authorized") + additionalInfos
159
158
  );
160
159
  }
161
- state.queriesCache = {};
162
160
  let contents0 = null;
163
- try {
164
- contents0 = await view.run_possibly_on_page(
165
- query,
166
- req,
167
- res,
168
- view.isRemoteTable()
169
- );
170
- } finally {
171
- state.queriesCache = null;
161
+ if (!view.renderLocally()) {
162
+ const response = await apiCall({
163
+ method: "GET",
164
+ path: `/view/${encodeURIComponent(viewname)}${context.query ? `?${context.query}` : ""}`,
165
+ });
166
+ const data = response.data;
167
+ contents0 = data;
168
+ } else {
169
+ const res = new MobileResponse();
170
+ state.queriesCache = {};
171
+ try {
172
+ contents0 = await view.run_possibly_on_page(
173
+ query,
174
+ req,
175
+ res,
176
+ view.isRemoteTable()
177
+ );
178
+ } finally {
179
+ state.queriesCache = null;
180
+ }
181
+ const wrapped = res.getWrapHtml();
182
+ if (wrapped)
183
+ return await wrapContents(
184
+ wrapped,
185
+ res.getWrapViewName() || "viewname",
186
+ context,
187
+ req
188
+ );
172
189
  }
173
- const wrapped = res.getWrapHtml();
174
- if (wrapped)
175
- return await wrapContents(
176
- wrapped,
177
- res.getWrapViewName() || "viewname",
178
- context,
179
- req
180
- );
181
- else {
182
- const contents =
183
- typeof contents0 === "string"
184
- ? saltcorn.markup.div(
185
- {
186
- class: "d-inline",
187
- "data-sc-embed-viewname": view.name,
188
- "data-sc-view-source": `/view/${context.params.viewname}${
189
- context.query
190
- ? context.query.startsWith("?")
191
- ? context.query
192
- : `?${context.query}`
193
- : ""
194
- }`,
195
- },
196
- contents0
197
- )
198
- : contents0;
190
+ const contents =
191
+ typeof contents0 === "string"
192
+ ? saltcorn.markup.div(
193
+ {
194
+ class: "d-inline",
195
+ "data-sc-embed-viewname": view.name,
196
+ "data-sc-view-source": `/view/${context.params.viewname}${
197
+ context.query
198
+ ? context.query.startsWith("?")
199
+ ? context.query
200
+ : `?${context.query}`
201
+ : ""
202
+ }`,
203
+ },
204
+ contents0
205
+ )
206
+ : contents0;
199
207
 
200
- return await wrapContents(contents, viewname, context, req);
201
- }
208
+ return await wrapContents(contents, viewname, context, req);
202
209
  };
package/www/index.html CHANGED
@@ -20,9 +20,6 @@
20
20
  document.addEventListener("deviceready", () => {
21
21
  saltcorn.mobileApp.init(_sc_mobile_config);
22
22
  });
23
- document.addEventListener("backbutton", async () => {
24
- await saltcorn.mobileApp.navigation.goBack(1, true);
25
- });
26
23
  } else {
27
24
  saltcorn.mobileApp.init(_sc_mobile_config);
28
25
  }