@saltcorn/mobile-app 0.9.0 → 0.9.1-beta.0

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.9.0",
4
+ "version": "0.9.1-beta.0",
5
5
  "description": "Apache Cordova application with @saltcorn/markup",
6
6
  "main": "index.js",
7
7
  "scripts": {
@@ -3,9 +3,10 @@
3
3
  // post/page/:pagename/action/:rndid
4
4
  const postPageAction = async (context) => {
5
5
  const state = saltcorn.data.state.getState();
6
+ const req = new MobileRequest({ xhr: context.xhr });
6
7
  const { page_name, rndid } = context.params;
7
8
  const page = await saltcorn.data.models.Page.findOne({ name: page_name });
8
- const req = new MobileRequest({ xhr: context.xhr });
9
+ if (!page) throw new Error(req.__("Page %s not found", page_name));
9
10
  if (state.mobileConfig.role_id > page.min_role) {
10
11
  throw new saltcorn.data.utils.NotAuthorized(req.__("Not authorized"));
11
12
  }
@@ -26,9 +27,10 @@ const postPageAction = async (context) => {
26
27
  // get/page/pagename
27
28
  const getPage = async (context) => {
28
29
  const state = saltcorn.data.state.getState();
30
+ const req = new MobileRequest({ xhr: context.xhr });
29
31
  const { page_name } = context.params;
30
32
  const page = await saltcorn.data.models.Page.findOne({ name: page_name });
31
- const req = new MobileRequest({ xhr: context.xhr });
33
+ if (!page) throw new Error(req.__("Page %s not found", page_name));
32
34
  if (state.mobileConfig.role_id > page.min_role) {
33
35
  throw new saltcorn.data.utils.NotAuthorized(req.__("Not authorized"));
34
36
  }
@@ -12,9 +12,6 @@ const postView = async (context) => {
12
12
  body[k] = v;
13
13
  if (k === "redirect") redirect = v;
14
14
  }
15
- const view = await saltcorn.data.models.View.findOne({
16
- name: context.params.viewname,
17
- });
18
15
  const refererRoute =
19
16
  routingHistory?.length > 1
20
17
  ? routingHistory[routingHistory.length - 2]
@@ -24,6 +21,11 @@ const postView = async (context) => {
24
21
  files: context.files,
25
22
  refererRoute,
26
23
  });
24
+ const view = await saltcorn.data.models.View.findOne({
25
+ name: context.params.viewname,
26
+ });
27
+ if (!view)
28
+ throw new Error(req.__("No such view: %s", context.params.viewname));
27
29
  const res = new MobileResponse();
28
30
  const state = saltcorn.data.state.getState();
29
31
  const mobileCfg = state.mobileConfig;
@@ -44,7 +46,18 @@ const postView = async (context) => {
44
46
  view.isRemoteTable()
45
47
  );
46
48
  if (mobileCfg.isOfflineMode) await offlineHelper.setHasOfflineData(true);
47
- return res.getJson();
49
+ const wrapped = res.getWrapHtml();
50
+ if (wrapped) {
51
+ return wrapContents(
52
+ wrapped,
53
+ res.getWrapViewName() || "viewname",
54
+ context,
55
+ req
56
+ );
57
+ }
58
+ const json = res.getJson();
59
+ if (json) return json;
60
+ throw new Error(req.__("%s finished without a result", `POST ${view.name}`));
48
61
  };
49
62
 
50
63
  /**
@@ -52,9 +65,6 @@ const postView = async (context) => {
52
65
  * @param {*} context
53
66
  */
54
67
  const postViewRoute = async (context) => {
55
- const view = await saltcorn.data.models.View.findOne({
56
- name: context.params.viewname,
57
- });
58
68
  const query = context.query ? parseQuery(context.query) : {};
59
69
  const refererRoute =
60
70
  routingHistory?.length > 1
@@ -65,6 +75,11 @@ const postViewRoute = async (context) => {
65
75
  query,
66
76
  refererRoute,
67
77
  });
78
+ const view = await saltcorn.data.models.View.findOne({
79
+ name: context.params.viewname,
80
+ });
81
+ if (!view)
82
+ throw new Error(req.__("No such view: %s", context.params.viewname));
68
83
  const res = new MobileResponse();
69
84
  const state = saltcorn.data.state.getState();
70
85
  const { role_id, isOfflineMode } = state.mobileConfig;
@@ -86,7 +101,14 @@ const postViewRoute = async (context) => {
86
101
  context,
87
102
  req
88
103
  );
89
- else return res.getJson();
104
+ const json = res.getJson();
105
+ if (json) return json;
106
+ throw new Error(
107
+ req.__(
108
+ "%s finished without a result",
109
+ `POST ${view.name}: ${context.params.route}`
110
+ )
111
+ );
90
112
  };
91
113
 
92
114
  /**
@@ -97,13 +119,14 @@ const postViewRoute = async (context) => {
97
119
  const getView = async (context) => {
98
120
  const state = saltcorn.data.state.getState();
99
121
  const query = context.query ? parseQuery(context.query) : {};
100
- const { viewname } = context.params;
101
- const view = saltcorn.data.models.View.findOne({ name: viewname });
102
122
  const refererRoute =
103
123
  routingHistory?.length > 1
104
124
  ? routingHistory[routingHistory.length - 2]
105
125
  : undefined;
106
126
  const req = new MobileRequest({ xhr: context.xhr, query, refererRoute });
127
+ const { viewname } = context.params;
128
+ const view = saltcorn.data.models.View.findOne({ name: viewname });
129
+ if (!view) throw new Error(req.__("No such view: %s", viewname));
107
130
  const res = new MobileResponse();
108
131
  if (
109
132
  state.mobileConfig.role_id > view.min_role &&
@@ -1,4 +1,4 @@
1
- /*global window, $, offlineHelper, axios, write, cordova, router, getDirEntry, saltcorn, document, FileReader, navigator, splashConfig*/
1
+ /*global window, $, offlineHelper, axios, write, cordova, router, getDirEntry, saltcorn, document, FileReader, navigator, splashConfig, i18next*/
2
2
 
3
3
  let routingHistory = [];
4
4
 
@@ -271,13 +271,26 @@ async function handleRoute(route, query, files, data) {
271
271
  } else if (page.content) {
272
272
  if (!page.replaceIframe) await replaceIframeInnerContent(page.content);
273
273
  else await replaceIframe(page.content);
274
+ } else {
275
+ showAlerts([
276
+ {
277
+ type: "warning",
278
+ msg: i18next.t("%s finished without a result", {
279
+ postProcess: "sprintf",
280
+ sprintf: [safeRoute],
281
+ }),
282
+ },
283
+ ]);
274
284
  }
275
285
  }
276
286
  } catch (error) {
277
287
  showAlerts([
278
288
  {
279
289
  type: "error",
280
- msg: error.message ? error.message : "An error occured.",
290
+ msg: `${i18next.t("In %s", {
291
+ postProcess: "sprintf",
292
+ sprintf: [route],
293
+ })}: ${error.message ? error.message : i18next.t("An error occurred")}`,
281
294
  },
282
295
  ]);
283
296
  }