@saltcorn/mobile-app 1.4.0 → 1.4.1-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 +1 -1
- package/src/init.js +33 -10
package/package.json
CHANGED
package/src/init.js
CHANGED
|
@@ -253,6 +253,7 @@ const isPublicJwt = (jwt) => {
|
|
|
253
253
|
};
|
|
254
254
|
|
|
255
255
|
const isPublicEntryPoint = async (entryPoint) => {
|
|
256
|
+
if (!entryPoint) return false;
|
|
256
257
|
try {
|
|
257
258
|
const tokens = entryPoint.split("/");
|
|
258
259
|
if (tokens.length < 3) throw new Error("The format is incorrect");
|
|
@@ -354,6 +355,17 @@ const readSiteLogo = async (state) => {
|
|
|
354
355
|
}
|
|
355
356
|
};
|
|
356
357
|
|
|
358
|
+
// fixed entry point or by role
|
|
359
|
+
const getEntryPoint = (roleId, state, mobileConfig) => {
|
|
360
|
+
let entryPoint = null;
|
|
361
|
+
if (mobileConfig.entryPointType === "byrole") {
|
|
362
|
+
const homepageByRole = state.getConfig("home_page_by_role", {})[roleId];
|
|
363
|
+
if (homepageByRole) entryPoint = `get/page/${homepageByRole}`;
|
|
364
|
+
} else entryPoint = mobileConfig.entry_point;
|
|
365
|
+
|
|
366
|
+
return entryPoint;
|
|
367
|
+
};
|
|
368
|
+
|
|
357
369
|
// device is ready
|
|
358
370
|
export async function init(mobileConfig) {
|
|
359
371
|
try {
|
|
@@ -400,7 +412,6 @@ export async function init(mobileConfig) {
|
|
|
400
412
|
mobileConfig.localUserTables
|
|
401
413
|
);
|
|
402
414
|
await state.setConfig("base_url", mobileConfig.server_path);
|
|
403
|
-
const entryPoint = mobileConfig.entry_point;
|
|
404
415
|
await initI18Next();
|
|
405
416
|
state.mobileConfig.encodedSiteLogo = await readSiteLogo();
|
|
406
417
|
state.mobileConfig.networkState = (
|
|
@@ -469,6 +480,12 @@ export async function init(mobileConfig) {
|
|
|
469
480
|
if (shareData && notEmpty(shareData)) return await postShare(shareData);
|
|
470
481
|
}
|
|
471
482
|
let page = null;
|
|
483
|
+
const entryPoint = getEntryPoint(
|
|
484
|
+
mobileConfig.user.role_id,
|
|
485
|
+
state,
|
|
486
|
+
mobileConfig
|
|
487
|
+
);
|
|
488
|
+
if (!entryPoint) throw new Error("No entry point defined for this role.");
|
|
472
489
|
if (!lastLocation) {
|
|
473
490
|
addRoute({ route: entryPoint, query: undefined });
|
|
474
491
|
page = await router.resolve({
|
|
@@ -494,15 +511,21 @@ export async function init(mobileConfig) {
|
|
|
494
511
|
config.user = { role_id: 100, email: "public", language: "en" };
|
|
495
512
|
config.isPublicUser = true;
|
|
496
513
|
i18next.changeLanguage(config.user.language);
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
514
|
+
const entryPoint = getEntryPoint(100, state, state.mobileConfig);
|
|
515
|
+
if (!entryPoint) await showLogin(alerts);
|
|
516
|
+
else {
|
|
517
|
+
addRoute({ route: entryPoint, query: undefined });
|
|
518
|
+
const page = await router.resolve({
|
|
519
|
+
pathname: entryPoint,
|
|
520
|
+
fullWrap: true,
|
|
521
|
+
alerts,
|
|
522
|
+
});
|
|
523
|
+
if (page.content) await replaceIframe(page.content, page.isFile);
|
|
524
|
+
}
|
|
504
525
|
} else if (
|
|
505
|
-
(await isPublicEntryPoint(
|
|
526
|
+
(await isPublicEntryPoint(
|
|
527
|
+
getEntryPoint(100, state, state.mobileConfig)
|
|
528
|
+
)) &&
|
|
506
529
|
state.mobileConfig.autoPublicLogin
|
|
507
530
|
) {
|
|
508
531
|
if (networkDisabled)
|
|
@@ -510,7 +533,7 @@ export async function init(mobileConfig) {
|
|
|
510
533
|
"No internet connection or previous login is available. " +
|
|
511
534
|
"Please go online and reload, the public login is not yet supported."
|
|
512
535
|
);
|
|
513
|
-
await publicLogin(
|
|
536
|
+
await publicLogin(getEntryPoint(100, state, state.mobileConfig));
|
|
514
537
|
} else await showLogin(alerts);
|
|
515
538
|
} catch (error) {
|
|
516
539
|
if (typeof saltcorn === "undefined" || typeof router === "undefined") {
|