From d8cffc8a8a1251b0d0858cde426dfcf6e4351322 Mon Sep 17 00:00:00 2001 From: Markus Edenhauser <1720843+maxmarkus@users.noreply.github.com> Date: Mon, 15 Oct 2018 12:46:20 +0200 Subject: [PATCH 1/6] tets --- core/examples/luigi-sample-angular/src/app/app.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/examples/luigi-sample-angular/src/app/app.component.ts b/core/examples/luigi-sample-angular/src/app/app.component.ts index 48b58e9afd..78dc87f0fd 100644 --- a/core/examples/luigi-sample-angular/src/app/app.component.ts +++ b/core/examples/luigi-sample-angular/src/app/app.component.ts @@ -12,9 +12,9 @@ import { }) export class AppComponent implements OnInit { public luigiClient: LuigiClient = LuigiClient; - public title = 'app'; + public title: string = 'app'; - constructor(private luigiService: LuigiContextService) {} + constructor(private luigiService: LuigiContextService) { } ngOnInit() { this.luigiClient.addInitListener(context => From 253913dcf8e0fc2174012798d9b24515f38e01dd Mon Sep 17 00:00:00 2001 From: Markus Edenhauser <1720843+maxmarkus@users.noreply.github.com> Date: Tue, 20 Nov 2018 12:12:24 +0100 Subject: [PATCH 2/6] Content is responsive again after going back. Slight refactoring. Fixes #223 --- client/luigi-client.js | 4 ++++ core/src/App.html | 2 +- core/src/services/routing.js | 22 ++++++++++------------ core/test/routing.spec.js | 10 +++++----- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/client/luigi-client.js b/client/luigi-client.js index 2bef10dcc4..01bbb00b06 100644 --- a/client/luigi-client.js +++ b/client/luigi-client.js @@ -127,6 +127,10 @@ } else if ('luigi.navigate' === e.data.msg) { setContext(e.data); + console.log( + '​currentContext.internal.isNavigateBack', + currentContext.internal.isNavigateBack + ); if (!currentContext.internal.isNavigateBack) { var hashRoutingModeActive = e.data.viewUrl.indexOf('#') !== -1 && diff --git a/core/src/App.html b/core/src/App.html index a51f59f209..2d700cbbca 100644 --- a/core/src/App.html +++ b/core/src/App.html @@ -214,7 +214,6 @@ if ('luigi.navigation.back' === e.data.msg) { // go back: context from the view - this.set({ isNavigateBack: false }); const preservedViews = this.get().preservedViews; if (preservedViews && preservedViews.length) { // remove current active iframe and data @@ -236,6 +235,7 @@ config ); } else { + this.set({ isNavigateBack: false }); console.error('goBack() not possible, no preserved views found.'); } } diff --git a/core/src/services/routing.js b/core/src/services/routing.js index 101701935a..5a30e674bb 100644 --- a/core/src/services/routing.js +++ b/core/src/services/routing.js @@ -217,8 +217,8 @@ const navigateIframe = (config, component, node) => { }, '*' ); - // clear goBackContext after sending it to the client - component.set({ goBackContext: undefined }); + // clear goBackContext and reset navigateBack after sending it to the client + component.set({ goBackContext: undefined, isNavigateBack: false }); /** * check if luigi responded @@ -389,16 +389,14 @@ export const matchPath = async path => { navigateTo used for navigation @param route string absolute path of the new route @param options object navi options, eg preserveView - @param windowElem object defaults to window - @param documentElem object defaults to document */ -export const navigateTo = (route, windowElem = window) => { +export const navigateTo = route => { if (LuigiConfig.getConfigValue('routing.useHashRouting')) { - windowElem.location.hash = route; + window.location.hash = route; return; } - windowElem.history.pushState( + window.history.pushState( { path: route }, @@ -417,17 +415,17 @@ export const navigateTo = (route, windowElem = window) => { event = new CustomEvent('popstate'); } - windowElem.dispatchEvent(event); + window.dispatchEvent(event); }; -export const handleRouteClick = (node, windowElem = window) => { +export const handleRouteClick = node => { if (node.externalLink && node.externalLink.url) { node.externalLink.sameWindow - ? (windowElem.location.href = node.externalLink.url) - : windowElem.open(node.externalLink.url).focus(); + ? (window.location.href = node.externalLink.url) + : window.open(node.externalLink.url).focus(); // externalLinkUrl property is provided so there's no need to trigger routing mechanizm return; } const route = buildRoute(node, `/${node.pathSegment}`); - navigateTo(route, windowElem); + navigateTo(route); }; diff --git a/core/test/routing.spec.js b/core/test/routing.spec.js index 7c3c9927e4..6ebe6c29b3 100644 --- a/core/test/routing.spec.js +++ b/core/test/routing.spec.js @@ -517,7 +517,7 @@ describe('Routing', () => { useHashRouting: true } }; - routing.handleRouteClick(nodeWithParent, window, document); + routing.handleRouteClick(nodeWithParent); // then assert.equal(window.location.hash, expectedRoute); @@ -534,7 +534,7 @@ describe('Routing', () => { } }; - routing.handleRouteClick(nodeWithoutParent, window); + routing.handleRouteClick(nodeWithoutParent); // then assert.equal(window.location.hash, expectedRoute); @@ -554,7 +554,7 @@ describe('Routing', () => { useHashRouting: false } }; - routing.handleRouteClick(nodeWithParent, window); + routing.handleRouteClick(nodeWithParent); // then const pushStateArgs = window.history.pushState.args[0]; @@ -578,7 +578,7 @@ describe('Routing', () => { useHashRouting: false } }; - routing.handleRouteClick(nodeWithoutParent, window, document); + routing.handleRouteClick(nodeWithoutParent); // then const pushStateArgs = window.history.pushState.args[0]; @@ -603,7 +603,7 @@ describe('Routing', () => { useHashRouting: false } }; - routing.handleRouteClick(nodeWithoutParent, window, document); + routing.handleRouteClick(nodeWithoutParent); // then const pushStateArgs = window.history.pushState.args[0]; From 07423053dc2718bde9ce7ec341ebb436c9567a61 Mon Sep 17 00:00:00 2001 From: Markus Edenhauser <1720843+maxmarkus@users.noreply.github.com> Date: Tue, 20 Nov 2018 12:29:49 +0100 Subject: [PATCH 3/6] removed console.log --- client/luigi-client.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/client/luigi-client.js b/client/luigi-client.js index 01bbb00b06..21d3b975ca 100644 --- a/client/luigi-client.js +++ b/client/luigi-client.js @@ -126,11 +126,6 @@ _callAllFns(_onInitFns, currentContext.context); } else if ('luigi.navigate' === e.data.msg) { setContext(e.data); - - console.log( - '​currentContext.internal.isNavigateBack', - currentContext.internal.isNavigateBack - ); if (!currentContext.internal.isNavigateBack) { var hashRoutingModeActive = e.data.viewUrl.indexOf('#') !== -1 && From f6a98e154b8927eae8a58a8aa89b28514c1b7180 Mon Sep 17 00:00:00 2001 From: Markus Edenhauser <1720843+maxmarkus@users.noreply.github.com> Date: Tue, 20 Nov 2018 16:22:56 +0100 Subject: [PATCH 4/6] fix tets --- core/test/services/routing.spec.js | 49 +----------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/core/test/services/routing.spec.js b/core/test/services/routing.spec.js index 010be00cdf..f768d25102 100644 --- a/core/test/services/routing.spec.js +++ b/core/test/services/routing.spec.js @@ -516,16 +516,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(true); // when -<<<<<<< HEAD:core/test/routing.spec.js - LuigiConfig.config = { - routing: { - useHashRouting: true - } - }; routing.handleRouteClick(nodeWithParent); -======= - routing.handleRouteClick(nodeWithParent, window, document); ->>>>>>> upstream/master:core/test/services/routing.spec.js // then assert.equal(window.location.hash, expectedRoute); @@ -537,17 +528,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(true); // when -<<<<<<< HEAD:core/test/routing.spec.js - LuigiConfig.config = { - routing: { - useHashRouting: true - } - }; - routing.handleRouteClick(nodeWithoutParent); -======= - routing.handleRouteClick(nodeWithoutParent, window); ->>>>>>> upstream/master:core/test/services/routing.spec.js // then assert.equal(window.location.hash, expectedRoute); @@ -564,16 +545,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(false); // when -<<<<<<< HEAD:core/test/routing.spec.js - LuigiConfig.config = { - routing: { - useHashRouting: false - } - }; routing.handleRouteClick(nodeWithParent); -======= - routing.handleRouteClick(nodeWithParent, window); ->>>>>>> upstream/master:core/test/services/routing.spec.js // then const pushStateArgs = window.history.pushState.args[0]; @@ -594,16 +566,7 @@ describe('Routing', () => { LuigiConfig.getConfigValue.returns(false); // when -<<<<<<< HEAD:core/test/routing.spec.js - LuigiConfig.config = { - routing: { - useHashRouting: false - } - }; routing.handleRouteClick(nodeWithoutParent); -======= - routing.handleRouteClick(nodeWithoutParent, window, document); ->>>>>>> upstream/master:core/test/services/routing.spec.js // then const pushStateArgs = window.history.pushState.args[0]; @@ -621,20 +584,10 @@ describe('Routing', () => { window.history.pushState = sinon.spy(); window.dispatchEvent = sinon.spy(); const dispatchCallsNum = window.dispatchEvent.callCount; + LuigiConfig.getConfigValue.returns(false); // when -<<<<<<< HEAD:core/test/routing.spec.js - LuigiConfig.config = { - routing: { - useHashRouting: false - } - }; routing.handleRouteClick(nodeWithoutParent); -======= - LuigiConfig.getConfigValue.returns(false); - - routing.handleRouteClick(nodeWithoutParent, window, document); ->>>>>>> upstream/master:core/test/services/routing.spec.js // then const pushStateArgs = window.history.pushState.args[0]; From 33cd6e55727dedc91422ef8ff54be66756269fb5 Mon Sep 17 00:00:00 2001 From: Markus Edenhauser <1720843+maxmarkus@users.noreply.github.com> Date: Tue, 20 Nov 2018 16:29:01 +0100 Subject: [PATCH 5/6] fix merge issue --- core/src/services/routing.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/core/src/services/routing.js b/core/src/services/routing.js index 03da4f7ef9..fe97f48ff2 100644 --- a/core/src/services/routing.js +++ b/core/src/services/routing.js @@ -17,7 +17,7 @@ const getLastNodeObject = pathData => { return lastElement ? lastElement : {}; }; -const getDefaultChildNode = function (pathData) { +const getDefaultChildNode = function(pathData) { const lastElement = pathData.navigationPath[pathData.navigationPath.length - 1]; @@ -34,7 +34,7 @@ const getDefaultChildNode = function (pathData) { } }; -const isExistingRoute = function (path, pathData) { +const isExistingRoute = function(path, pathData) { if (!path) { return true; } @@ -128,9 +128,9 @@ const replaceVars = (viewUrl, params, prefix, parenthesis = true) => { new RegExp( escapeRegExp( (parenthesis ? '{' : '') + - prefix + - entry[0] + - (parenthesis ? '}' : '') + prefix + + entry[0] + + (parenthesis ? '}' : '') ), 'g' ), @@ -349,9 +349,9 @@ export const handleRouteChange = async (path, component, node, config) => { isolateView, previousNodeValues: previousCompData ? { - viewUrl: previousCompData.viewUrl, - isolateView: previousCompData.isolateView - } + viewUrl: previousCompData.viewUrl, + isolateView: previousCompData.isolateView + } : {} }); @@ -412,10 +412,6 @@ export const matchPath = async path => { @param route string absolute path of the new route @param options object navi options, eg preserveView */ -<<<<<<< HEAD -======= - ->>>>>>> aa37a1ca933214a3d6db666d066f6356cf384cc5 export const navigateTo = async route => { if (LuigiConfig.getConfigValue('routing.useHashRouting')) { window.location.hash = route; From 11bbe096f14dc896e173b9d541684b4332b448b4 Mon Sep 17 00:00:00 2001 From: Markus Edenhauser <1720843+maxmarkus@users.noreply.github.com> Date: Tue, 20 Nov 2018 16:37:01 +0100 Subject: [PATCH 6/6] improvement on structure, component updates happen now in the component instead of service --- core/src/App.html | 6 +++--- core/src/services/routing.js | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/App.html b/core/src/App.html index 5b9ff8a0ee..f5f0f50226 100644 --- a/core/src/App.html +++ b/core/src/App.html @@ -217,7 +217,7 @@ if ('luigi.navigation.open' === e.data.msg) { this.set({ isNavigateBack: false }); - handleNavigation(this, e.data, config); + await handleNavigation(this, e.data, config); } if ('luigi.navigation.back' === e.data.msg) { @@ -237,13 +237,13 @@ }); // TODO: check if handleNavigation or history pop to update hash / path - handleNavigation( + await handleNavigation( this, { params: { link: previousActiveIframeData.path } }, config ); + this.set({ goBackContext: undefined, isNavigateBack: false }); } else { - this.set({ isNavigateBack: false }); console.error('goBack() not possible, no preserved views found.'); } } diff --git a/core/src/services/routing.js b/core/src/services/routing.js index fe97f48ff2..794c5fe2a1 100644 --- a/core/src/services/routing.js +++ b/core/src/services/routing.js @@ -218,8 +218,6 @@ const navigateIframe = (config, component, node) => { }, '*' ); - // clear goBackContext and reset navigateBack after sending it to the client - component.set({ goBackContext: undefined, isNavigateBack: false }); /** * check if luigi responded