@saltcorn/mobile-app 1.3.1-beta.10 → 1.3.1-beta.12
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 +2 -2
- package/src/helpers/auth.js +29 -18
- package/src/helpers/offline_mode.js +3 -3
- package/src/init.js +6 -0
- package/src/routing/routes/view.js +46 -39
- package/www/index.html +0 -3
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.
|
|
4
|
+
"version": "1.3.1-beta.12",
|
|
5
5
|
"description": "Saltcorn mobile app for Android and iOS",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"universal-router": "9.2.1",
|
|
21
|
-
"axios": "^
|
|
21
|
+
"axios": "^0.29.0",
|
|
22
22
|
"jwt-decode": "4.0.0",
|
|
23
23
|
"i18next": "24.2.2",
|
|
24
24
|
"i18next-sprintf-postprocessor": "0.2.2",
|
package/src/helpers/auth.js
CHANGED
|
@@ -19,27 +19,27 @@ async function loginRequest({ email, password, isSignup, isPublic }) {
|
|
|
19
19
|
path: "/auth/login-with/jwt",
|
|
20
20
|
}
|
|
21
21
|
: isSignup
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
? {
|
|
23
|
+
method: "POST",
|
|
24
|
+
path: "/auth/signup",
|
|
25
|
+
body: {
|
|
26
|
+
email,
|
|
27
|
+
password,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
: {
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: "/auth/login-with/jwt",
|
|
33
|
+
params: {
|
|
34
|
+
email,
|
|
35
|
+
password,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
38
|
const response = await apiCall(opts);
|
|
39
39
|
return response.data;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export async function login({ email, password,
|
|
42
|
+
export async function login({ email, password, isSignup }) {
|
|
43
43
|
const loginResult = await loginRequest({
|
|
44
44
|
email,
|
|
45
45
|
password,
|
|
@@ -48,7 +48,8 @@ export async function login({ email, password, entryPoint, isSignup }) {
|
|
|
48
48
|
if (typeof loginResult === "string") {
|
|
49
49
|
// use it as a token
|
|
50
50
|
const decodedJwt = jwtDecode(loginResult);
|
|
51
|
-
const
|
|
51
|
+
const state = saltcorn.data.state.getState();
|
|
52
|
+
const config = state.mobileConfig;
|
|
52
53
|
config.user = decodedJwt.user;
|
|
53
54
|
config.isPublicUser = false;
|
|
54
55
|
config.isOfflineMode = false;
|
|
@@ -86,6 +87,16 @@ export async function login({ email, password, entryPoint, isSignup }) {
|
|
|
86
87
|
sprintf: [config.user.email],
|
|
87
88
|
}),
|
|
88
89
|
});
|
|
90
|
+
|
|
91
|
+
let entryPoint = null;
|
|
92
|
+
if (config.entryPointType === "byrole") {
|
|
93
|
+
const homepageByRole = state.getConfig("home_page_by_role", {})[
|
|
94
|
+
config.user.role_id
|
|
95
|
+
];
|
|
96
|
+
if (homepageByRole) entryPoint = `get/page/${homepageByRole}`;
|
|
97
|
+
else throw new Error("No homepage defined for this role.");
|
|
98
|
+
} else entryPoint = config.entry_point;
|
|
99
|
+
|
|
89
100
|
addRoute({ route: entryPoint, query: undefined });
|
|
90
101
|
const page = await router.resolve({
|
|
91
102
|
pathname: entryPoint,
|
|
@@ -224,8 +224,8 @@ const loadOfflineChanges = async (synchedTbls) => {
|
|
|
224
224
|
from "${saltcorn.data.db.sqlsanitize(
|
|
225
225
|
synchedTbl
|
|
226
226
|
)}_sync_info" as info_tbl left join "${saltcorn.data.db.sqlsanitize(
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
synchedTbl
|
|
228
|
+
)}" as data_tbl
|
|
229
229
|
on info_tbl.ref = data_tbl."${saltcorn.data.db.sqlsanitize(pkName)}"
|
|
230
230
|
where info_tbl.modified_local = true`
|
|
231
231
|
);
|
|
@@ -562,7 +562,7 @@ export async function clearLocalData(inTransaction) {
|
|
|
562
562
|
const { synchedTables } = saltcorn.data.state.getState().mobileConfig;
|
|
563
563
|
for (const tblName of synchedTables) {
|
|
564
564
|
const table = saltcorn.data.models.Table.findOne({ name: tblName });
|
|
565
|
-
await table.deleteRows();
|
|
565
|
+
await table.deleteRows({});
|
|
566
566
|
await saltcorn.data.db.deleteWhere(`${table.name}_sync_info`, {});
|
|
567
567
|
}
|
|
568
568
|
if (!inTransaction) await saltcorn.data.db.query("COMMIT");
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
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
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
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
|
}
|