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

Navigation node as a link to an external page #121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions core/examples/luigi-sample-angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export class OverviewComponent {
link: '/projects/pr1/users/groups',
text: 'dynamic Nodes',
description:
'navigation Node configuration to set a specific Node as dynamic'
'navigation Node configuration to set a specific node as dynamic'
},
{
link: '/projects/pr1',
text: 'external URL node',
description:
'navigation Node configuration to direct to an external website'
},
{
link: '/projects/pr1/avengers',
Expand Down
117 changes: 83 additions & 34 deletions core/examples/luigi-sample-angular/src/assets/sampleconfig.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
var navigationPermissionChecker = function (nodeToCheckPermissionFor, parentNode, currentContext) {
var navigationPermissionChecker = function(
nodeToCheckPermissionFor,
parentNode,
currentContext
) {
// depending on the current path and context returns true or false
// true means the current node is accessible, false the opposite
var mockCurrentUserGroups = ['admins'];
if (nodeToCheckPermissionFor.constraints) {
// check if user has required groups
return nodeToCheckPermissionFor.constraints.filter(
function (c) {
return (
nodeToCheckPermissionFor.constraints.filter(function(c) {
return mockCurrentUserGroups.indexOf(c) !== -1;
}
).length !== 0;
}).length !== 0
);
}

return true;
};

function toTitleCase(str) {
return str.replace(/\w\S*/g, function (txt) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}

var getAllProjects = function () {
return new Promise(function (resolve) {
var getAllProjects = function() {
return new Promise(function(resolve) {
resolve([
{
id: 'pr1',
Expand All @@ -35,8 +39,8 @@ var getAllProjects = function () {
});
};

var getProjectPlugins = function (projectId) {
return new Promise(function (resolve) {
var getProjectPlugins = function(projectId) {
return new Promise(function(resolve) {
if (projectId === 'pr2') {
resolve([
{
Expand Down Expand Up @@ -74,8 +78,8 @@ var getProjectPlugins = function (projectId) {
});
};

var projectDetailNavProviderFn = function (context) {
return new Promise(function (resolve) {
var projectDetailNavProviderFn = function(context) {
return new Promise(function(resolve) {
var projectId = context.currentProject;
var children = [
{
Expand Down Expand Up @@ -169,17 +173,33 @@ var projectDetailNavProviderFn = function (context) {
{
pathSegment: 'avengers',
label: 'Keep Selected Example',
viewUrl:
'/sampleapp.html#/projects/' +
projectId +
'/dynamic/avengers',
viewUrl: '/sampleapp.html#/projects/' + projectId + '/dynamic/avengers',
keepSelectedForChildren: true,
context: {
label: 'Avengers',
links: ['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye', 'Loki']
links: [
'Captain America',
'Iron Man',
'Thor',
'Hulk',
'Black Widow',
'Hawkeye',
'Loki'
]
},
children: ['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye', 'Loki'].map(name => ({
pathSegment: name.toLowerCase().split(' ').join('-'),
children: [
'Captain America',
'Iron Man',
'Thor',
'Hulk',
'Black Widow',
'Hawkeye',
'Loki'
].map(name => ({
pathSegment: name
.toLowerCase()
.split(' ')
.join('-'),
label: name,
context: {
label: name,
Expand All @@ -188,7 +208,11 @@ var projectDetailNavProviderFn = function (context) {
viewUrl:
'/sampleapp.html#/projects/' +
projectId +
'/dynamic/' + name.toLowerCase().split(' ').join('-'),
'/dynamic/' +
name
.toLowerCase()
.split(' ')
.join('-'),
children: [
{
label: 'Super Power',
Expand Down Expand Up @@ -218,10 +242,26 @@ var projectDetailNavProviderFn = function (context) {
}
]
}))
},
{
label: 'Open Github in new tab',
category: 'Super useful Github links',
externalLink: {
url: 'http://github.com',
sameWindow: false
}
},
{
label: 'Open Github in this tab',
category: 'Super useful Github links',
externalLink: {
url: 'http://github.com',
sameWindow: true
}
}
];
getProjectPlugins(projectId).then(function (result) {
result.forEach(function (plugin) {
getProjectPlugins(projectId).then(function(result) {
result.forEach(function(plugin) {
children.push({
category: plugin.category,
pathSegment: plugin.viewId,
Expand All @@ -235,11 +275,11 @@ var projectDetailNavProviderFn = function (context) {
});
};

var projectsNavProviderFn = function (context) {
return new Promise(function (resolve) {
getAllProjects().then(function (result) {
var projectsNavProviderFn = function(context) {
return new Promise(function(resolve) {
getAllProjects().then(function(result) {
var children = [];
result.forEach(function (project) {
result.forEach(function(project) {
children.push({
/**
* navigationContext:
Expand Down Expand Up @@ -280,7 +320,9 @@ Luigi.setConfig({
auth: {
use: 'mockAuth',
mockAuth: {
authorizeUrl: `${window.location.origin}/assets/auth-mock/login-mock.html`,
authorizeUrl: `${
window.location.origin
}/assets/auth-mock/login-mock.html`,
logoutUrl: `${window.location.origin}/assets/auth-mock/logout-mock.html`,
post_logout_redirect_uri: '/logout.html',
authorizeMethod: 'GET',
Expand All @@ -292,7 +334,7 @@ Luigi.setConfig({
authority: 'https://example-authority.com',
client_id: 'client',
scope: 'audience:server:client_id:client openid profile email groups',
logoutUrl: 'https://example-url.com/logout',
logoutUrl: 'https://example-url.com/logout'
// optional parameters
// redirect_uri: '',
// post_logout_redirect_uri: '/logout.html',
Expand Down Expand Up @@ -344,24 +386,24 @@ Luigi.setConfig({
},

events: {
onLogout: function () {
onLogout: function() {
console.log('onLogout');
},
onAuthSuccessful: function (data) {
onAuthSuccessful: function(data) {
console.log('onAuthSuccessful', data);
},
onAuthExpired: function () {
onAuthExpired: function() {
console.log('onAuthExpired');
},
// TODO: define luigi-client api for getting errors
onAuthError: function (err) {
onAuthError: function(err) {
console.log('authErrorHandler 1', err);
}
}
},
navigation: {
nodeAccessibilityResolver: navigationPermissionChecker,
nodes: function () {
nodes: function() {
return [
{
pathSegment: 'overview',
Expand Down Expand Up @@ -391,6 +433,13 @@ Luigi.setConfig({
label: 'Settings',
viewUrl: '/sampleapp.html#/settings'
},
{
label: 'Open Google in this tab',
externalLink: {
url: 'http://google.com',
sameWindow: true
}
},
{
pathSegment: 'ext',
label: 'External Page',
Expand All @@ -417,7 +466,7 @@ Luigi.setConfig({
}
]
}
]
];
}
},

Expand Down
10 changes: 8 additions & 2 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading