Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/odpi/egeria-ui into relea…
Browse files Browse the repository at this point in the history
…se-3-2
  • Loading branch information
Ljupcho Palashevski committed Nov 29, 2021
2 parents 0db6cac + 22aa53e commit 0aa54ac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 54 deletions.
74 changes: 28 additions & 46 deletions new/egeria-app.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ class EgeriaApp extends PolymerElement {
constructor() {
super();

this.isLoading = false;
let path = window.location.pathname.substr(1);

if( !['login', 'forbidden', 'error', 'empty'].includes(path) ) {
//except for the pages not using the this data
//especially login is not need this calls
this._initialRequiredAuthenticatedRequest();
this._getCurrentUser();
}
}

Expand All @@ -50,7 +49,6 @@ class EgeriaApp extends PolymerElement {
appInfo: { type: Object, value: {} },
roles: { type: Array, value: [] },

isLoading: { type: Boolean, value: true },
isLoggedIn: { type: Boolean, value: false },

queryParams: {},
Expand All @@ -70,35 +68,35 @@ class EgeriaApp extends PolymerElement {
}

/**
* performes requests needed by authenticated page
* process token
* @private
*/
_initialRequiredAuthenticatedRequest() {
Promise.all([
egeriaFetch(`/api/public/app/info`),
egeriaFetch(`/api/users/components`),
egeriaFetch(`/api/users/current`),
egeriaFetch(`/api/users/roles`)
]).then((responses) => {
let [ appInfo, components, currentUser, roles ] = responses;

this.components = components;
this.currentUser = currentUser;
this.roles = roles;
this.appInfo = appInfo;

this.isLoggedIn = currentUser !== null && currentUser.status === 200;

const hasComponents = components !== null && components.status === 200;
const hasCurrentUser = currentUser !== null && currentUser.status === 200;
const hasRoles = roles !== null && roles.status === 200;
const hasAppInfo = appInfo !== null && appInfo.status === 200;

this.isLoading = ![hasComponents, hasCurrentUser, hasRoles, hasAppInfo].includes(false);

});
_getCurrentUser() {

const jwtClaims = this._parseJwtClaims();
if ( jwtClaims ) {
let tokenUser = JSON.parse(jwtClaims.sub);
if (tokenUser) {

this.currentUser = tokenUser;
this.components = tokenUser.visibleComponents;
this.roles = tokenUser.roles;

this.isLoggedIn = this.currentUser !== null;
}
}
}

_parseJwtClaims () {
const token = getCookie('token');
if(token !== undefined && token !== null){
const base64User = token.split('.')[1];
if( base64User !== undefined ) {
return JSON.parse( atob( base64User ) );
}
}
};

_pagesChanged(newPages) {
if(newPages && newPages.length >= 0) {
const [removed, ...newArr] = this.pages;
Expand Down Expand Up @@ -146,12 +144,7 @@ class EgeriaApp extends PolymerElement {

switch(route) {
case '':
if(components.length) {
this.pages = ['homepage'];
} else {
this.pages = !getCookie('token') ? ['empty'] : ['forbidden'];
}

this.pages = ['homepage'];
break;
case 'login':
this.pages = route.split('/');
Expand Down Expand Up @@ -194,9 +187,6 @@ class EgeriaApp extends PolymerElement {
data="{{ routeData }}"
tail="{{ tail }}"></app-route>
<template is="dom-if" if="[[ !isLoading ]]">
<template is="dom-if" if="[[ _isEqualTo(page, 'empty') ]]"></template>
<template is="dom-if" if="[[ _isEqualTo(page, 'login') ]]">
<egeria-login query-params="[[ queryParams ]]"></egeria-login>
</template>
Expand All @@ -210,8 +200,7 @@ class EgeriaApp extends PolymerElement {
</template>
<template is="dom-if" if="[[ _isEqualTo(page, 'homepage') ]]">
<egeria-home title="[[ appInfo.title ]]"
description="[[ appInfo.description ]]"
<egeria-home
components="[[ components ]]"></egeria-home>
</template>
Expand All @@ -223,13 +212,6 @@ class EgeriaApp extends PolymerElement {
is-logged-in="[[ isLoggedIn ]]"
pages="[[ pages ]]"></egeria-single-page>
</template>
</template>
<template is="dom-if" if="[[ isLoading ]]">
<div class="is-loading">
Loading...
</div>
</template>
<egeria-error-handling></egeria-error-handling>
`;
Expand Down
29 changes: 21 additions & 8 deletions new/egeria-home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ import { setCookie } from './commons/local-storage';
import { RoleComponentsBehavior } from '../old/common/role-components';

class EgeriaHome extends mixinBehaviors(RoleComponentsBehavior, PolymerElement) {

constructor() {
super();
egeriaFetch(`/api/public/app/info`)
.then(response => {
this.title = response.title;
this.description = response.description;
this.titleChunks = !['', undefined].includes(this.title) ? this.title.split('|') : [];

this.descriptionChunks = !['', undefined].includes(this.description) ? this.description.split('@@').map(d => {
let [ title, description ] = d.split('||');

return {
title: title,
description: description
}
}) : [];
});
}

static get properties() {
return {
title: { type: String, value: '' },
Expand All @@ -27,16 +47,9 @@ class EgeriaHome extends mixinBehaviors(RoleComponentsBehavior, PolymerElement)
ready() {
super.ready();

this.titleChunks = !['', undefined].includes(this.title) ? this.title.split('|') : [];

this.descriptionChunks = !['', undefined].includes(this.description) ? this.description.split('@@').map(d => {
let [ title, description ] = d.split('||');

return {
title: title,
description: description
}
}) : [];


egeriaFetch(`/api/assets/types`)
.then(data => {
Expand Down

0 comments on commit 0aa54ac

Please sign in to comment.