Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/preserve view #102

Merged
merged 21 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
41bb5f8
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Jul 31, 2018
4349a3e
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 1, 2018
7cafa4b
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 7, 2018
f8a6a28
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 8, 2018
0ab8b3a
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 8, 2018
9e4e1f0
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 14, 2018
0d886e5
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 22, 2018
c0edce7
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 28, 2018
21fa6a4
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 30, 2018
63c3a61
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Aug 31, 2018
c0d06bc
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Sep 4, 2018
282ddcc
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Sep 5, 2018
7623ae3
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Sep 6, 2018
db5803f
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Sep 10, 2018
ab060d9
Merge remote-tracking branch 'upstream/master'
maxmarkus Sep 11, 2018
a8be44f
Merge branch 'master' of github.com:kyma-project/luigi
maxmarkus Sep 18, 2018
f7b37bc
Merge remote-tracking branch 'upstream/master'
maxmarkus Sep 21, 2018
e70f781
refactored preserve view to be able to route to everywhere and back, …
maxmarkus Sep 21, 2018
41e27d9
removed console.logs
maxmarkus Sep 25, 2018
a60a37f
Add example for preserve view feature for nested nodes
kwiatekus Sep 25, 2018
59f159c
Remove example for preserve view feature for nested nodes
kwiatekus Sep 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RestrictedComponent } from './restricted/restricted.component';

const routes: Routes = [
{ path: 'overview', component: OverviewComponent },
{ path: 'settings', component: SettingsComponent },
{ path: 'restricted', component: RestrictedComponent },
{ path: 'projects/:projectId', component: ProjectComponent },
{ path: 'projects/:projectId/users', component: UsersComponent },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ <h1 class="fd-section__title">Project {{ projectId }}</h1>
<app-code-snippet data="luigiClient.linkManager().fromContext('FOOMARK').navigate('/settings')"></app-code-snippet>
</li>
<li class="fd-list-group__item">
<a href="javascript:void(0)" (click)="luigiClient.linkManager().fromContext('project').navigate('/settings', null, true)">with preserved view: project to settings and back</a>
<app-code-snippet data="luigiClient.linkManager().fromContext('project').navigate('/settings', null, true)"></app-code-snippet>
<a href="javascript:void(0)" (click)="luigiClient.linkManager().navigate('/settings', null, true)">with preserved view: project to settings and back</a>
<app-code-snippet data="luigiClient.linkManager().navigate('/settings', null, true)"></app-code-snippet>
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

<section class="fd-section">
<div class="fd-section__header">
<h1 class="fd-section__title">Settings of {{ projectId }}</h1>
<h1 *ngIf="projectId" class="fd-section__title">Settings of {{ projectId }}</h1>
<h1 *ngIf="!projectId" class="fd-section__title">Global Settings</h1>
</div>

<div class="fd-panel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ export class SettingsComponent implements OnInit {
constructor(
private activatedRoute: ActivatedRoute,
private cdr: ChangeDetectorRef
) {}
) { }

ngOnInit() {
this.activatedRoute.params.subscribe((params: Params) => {
this.projectId = params['projectId'];
});
this.luigiClient = LuigiClient;
LuigiClient.addInitListener(() => {
LuigiClient.addInitListener((init) => {
this.hasBack = LuigiClient.linkManager().hasBack();
this.nodeParams =
Object.keys(LuigiClient.getNodeParams()).length > 0
? LuigiClient.getNodeParams()
: null;
this.nodeParams = Object.keys(LuigiClient.getNodeParams()).length > 0
? LuigiClient.getNodeParams()
: null;
this.cdr.detectChanges();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ Luigi.setConfig({
viewUrl: '/sampleapp.html#/restricted',
constraints: ['unicorns']
},
{
pathSegment: 'settings',
label: 'Settings',
viewUrl: '/sampleapp.html#/settings'
},
{
pathSegment: 'ext',
label: 'External Page',
Expand Down
43 changes: 25 additions & 18 deletions core/src/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,7 @@
Routing.handleRouteChange(trimLeadingSlash(window.location.pathname), component, node, config);
};

const addPreserveView = (component, data, config, node) => {
if (data.params.preserveView) {
const pv = component.get().preservedViews;
pv.push({
path: Routing.getNodePath(component.get().currentNode),
nextPath: Routing.getNodePath(component.get().currentNode) + data.params.link,
context: component.get().context
});
component.set({preservedViews: pv});

// Resetting iframe config to null, since Routing.navigateTo will then create a new iframe
// instead of using the existing instance for route.
config.iframe = null;
}
};

const handleNavigation = async (component, data, config, node) => {
const buildPath = (component, data) => {
let path = data.params.link;
if (data.params.fromClosestContext) { // from the closest navigation context
const node = [...component.get().navigationPath].reverse().find((n) => n.navigationContext && n.navigationContext.length > 0);
Expand All @@ -76,13 +60,36 @@
path = Routing.concatenatePath(Routing.getNodePath(component.get().currentNode), data.params.link);
}

if (data.params.nodeParams) {
if (data.params.nodeParams && Object.keys(data.params.nodeParams).length) {
path += '?';
Object.entries(data.params.nodeParams).forEach(entry => {
path += (encodeURIComponent(Routing.getContentViewParamPrefix() + entry[0]) + '=' + encodeURIComponent(entry[1]) + '&');
});
}
return path;
};

const addPreserveView = (component, data, config, node) => {
if (data.params.preserveView) {
console.log('TCL: addPreserveView -> data', data, node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please get rid of console logs

const pv = component.get().preservedViews;
const nextPath = buildPath(component, data);
pv.push({
path: Routing.getNodePath(component.get().currentNode),
nextPath: nextPath.startsWith('/') ? nextPath : '/' + nextPath,
context: component.get().context
});
console.log('pv', pv);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please get rid of console logs

component.set({preservedViews: pv});

// Resetting iframe config to null, since Routing.navigateTo will then create a new iframe
// instead of using the existing instance for route.
config.iframe = null;
}
};

const handleNavigation = async (component, data, config, node) => {
const path = buildPath(component, data);
const matchedPath = await Routing.matchPath(path);
if (matchedPath !== null) {
addPreserveView(component, data, config, node);
Expand Down