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

Improve notion of 'App' in Hoist #387

Merged
merged 4 commits into from
Jun 15, 2018
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
214 changes: 157 additions & 57 deletions admin/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,172 @@
*
* Copyright © 2018 Extremely Heavy Industries Inc.
*/
import {XH, HoistApp} from '@xh/hoist/core';
import {action} from '@xh/hoist/mobx';
import {TabContainerModel} from '@xh/hoist/cmp/tab';

import {Component} from 'react';
import {button} from '@xh/hoist/kit/blueprint';
import {HoistComponent, XH} from '@xh/hoist/core';
import {lockoutPanel} from '@xh/hoist/app';
import {tabContainer, tabSwitcher} from '@xh/hoist/cmp/tab';
import {frame, panel} from '@xh/hoist/cmp/layout';
import {Icon} from '@xh/hoist/icon';
import {appBar} from '@xh/hoist/cmp/appbar';
import {AppComponent} from './AppComponent';
import {AboutPanel} from './tabs/about/AboutPanel';
import {ActivityPanel} from './tabs/activity/ActivityPanel';
import {ConfigPanel} from './tabs/configs/ConfigPanel';
import {ClientErrorPanel} from './tabs/clienterrors/ClientErrorPanel';
import {FeedbackPanel} from './tabs/feedback/FeedbackPanel';
import {EhCachePanel} from './tabs/ehcache/EhCachePanel';
import {LogLevelPanel} from './tabs/logging/LogLevelPanel';
import {LogViewer} from './tabs/logging/viewer/LogViewer';
import {MonitorResultsPanel} from './tabs/monitor/MonitorResultsPanel';
import {MonitorEditorPanel} from './tabs/monitor/MonitorEditorPanel';
import {PreferencePanel} from './tabs/preferences/PreferencePanel';
import {UserPreferencePanel} from './tabs/preferences/UserPreferencePanel';
import {ServicePanel} from './tabs/services/ServicePanel';
import {UserPanel} from './tabs/users/UserPanel';

import './App.scss';
@HoistApp
export class App {

@HoistComponent()
export class App extends Component {
render() {
if (!XH.getUser().isHoistAdmin) {
return lockoutPanel({message: 'Access to this area requires administrator permissions.'});
}
tabs = this.createTabContainer();

return panel({
tbar: this.renderAppBar(),
item: frame({
cls: 'xh-admin-app-frame',
item: tabContainer({model: XH.appModel.tabModel})
})
});
checkAccess(user) {
const role = 'HOIST_ADMIN',
hasAccess = user.hasRole(role),
message = hasAccess ? '' : `Admin console access requires the "${role}" role.`;
return {hasAccess, message};
}

//------------------
// Implementation
//------------------
renderAppBar() {
return appBar({
icon: Icon.gears({size: '2x', prefix: 'fal'}),
title: `${XH.appName} Admin`,
leftItems: [
tabSwitcher({model: this.model.tabModel})
],
rightItems: [
button({
icon: Icon.mail(),
text: 'Contact',
onClick: this.onContactClick
}),
button({
icon: Icon.openExternal(),
title: 'Open app...',
onClick: this.onOpenAppClick
})
],
hideAdminButton: true,
refreshButtonProps: {
onClick: this.onRefreshClick
get componentClass() {return AppComponent}

@action
requestRefresh() {
this.tabs.requestRefresh();
}

getRoutes() {
return [
{
name: 'default',
path: '/admin',
forwardTo: 'default.general',
children: this.getTabRoutes()
}
];
}

//------------------------
// Implementation
//------------------------
createTabContainer() {
return new TabContainerModel({
id: 'default',
useRoutes: true,
children: this.createTabs()
});
}

onContactClick = () => {
window.open('https://xh.io/contact');
};
//------------------------
// For override / extension
//------------------------
getTabRoutes() {
return [
{
name: 'general',
path: '/general',
forwardTo: 'default.general.about',
children: [
{name: 'about', path: '/about'},
{name: 'config', path: '/config'},
{name: 'services', path: '/services'},
{name: 'ehCache', path: '/ehCache'},
{name: 'users', path: '/users'}
]
},
{
name: 'logging',
path: '/logging',
forwardTo: 'default.logging.viewer',
children: [
{name: 'viewer', path: '/viewer'},
{name: 'levels', path: '/levels'}
]
},
{
name: 'monitor',
path: '/monitor',
forwardTo: 'default.monitor.status',
children: [
{name: 'status', path: '/status'},
{name: 'editMonitors', path: '/editMonitors'}
]
}, {
name: 'clientActivity',
path: '/clientActivity',
forwardTo: 'default.clientActivity.activity',
children: [
{name: 'activity', path: '/activity'},
{name: 'clientErrors', path: '/clientErrors'},
{name: 'feedback', path: '/feedback'}
]
},
{
name: 'preferences',
path: '/preferences',
forwardTo: 'default.preferences.prefs',
children: [
{name: 'prefs', path: '/prefs'},
{name: 'userPrefs', path: '/userPrefs'}
]
}
];
}

onOpenAppClick = () => {
window.open('/app');
};
createTabs() {
return [
{
id: 'general',
switcherPosition: 'left',
children: [
{id: 'about', component: AboutPanel},
{id: 'config', component: ConfigPanel},
{id: 'services', component: ServicePanel},
{id: 'ehCache', name: 'Caches', component: EhCachePanel},
{id: 'users', component: UserPanel}
]
}, {
id: 'logging',
switcherPosition: 'left',
children: [
{id: 'viewer', component: LogViewer},
{id: 'levels', component: LogLevelPanel}
]
},
{
id: 'monitor',
switcherPosition: 'left',
children: [
{id: 'status', component: MonitorResultsPanel},
{id: 'editMonitors', component: MonitorEditorPanel}
]
},
{
id: 'clientActivity',
switcherPosition: 'left',
children: [
{id: 'activity', component: ActivityPanel},
{id: 'clientErrors', component: ClientErrorPanel},
{id: 'feedback', component: FeedbackPanel}
]
},
{
id: 'preferences',
switcherPosition: 'left',
children: [
{id: 'prefs', component: PreferencePanel},
{id: 'userPrefs', component: UserPreferencePanel, reloadOnShow: true}
]
}
];
}

onRefreshClick = () => {
XH.appModel.requestRefresh();
};
}
destroy() {
XH.safeDestroy(this.tabs);
}
}
84 changes: 84 additions & 0 deletions admin/AppComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* Copyright © 2018 Extremely Heavy Industries Inc.
*/

import {Component} from 'react';
import {navbar, navbarGroup, navbarHeading, button} from '@xh/hoist/kit/blueprint';
import {XH, HoistComponent} from '@xh/hoist/core';
import {lockoutPanel} from '@xh/hoist/app';
import {tabContainer} from '@xh/hoist/cmp/tab';
import {frame, panel} from '@xh/hoist/cmp/layout';
import {logoutButton, themeToggleButton, refreshButton} from '@xh/hoist/cmp/button';
import {Icon} from '@xh/hoist/icon';

import './App.scss';

@HoistComponent()
export class AppComponent extends Component {
render() {
if (!XH.getUser().isHoistAdmin) {
return lockoutPanel({message: 'Access to this area requires administrator permissions.'});
}

return panel({
tbar: this.renderNavBar(),
item: frame({
cls: 'xh-admin-app-frame',
item: tabContainer({model: XH.app.tabs})
})
});
}

//------------------
// Implementation
//------------------
renderNavBar() {
return navbar({
items: [
navbarGroup({
align: 'left',
items: [
Icon.gears({size: '2x'}),
navbarHeading(`${XH.appName} Admin`)
]
}),
navbarGroup({
align: 'right',
items: [
button({
icon: Icon.mail(),
text: 'Contact',
onClick: this.onContactClick
}),
button({
icon: Icon.openExternal(),
title: 'Open app...',
onClick: this.onOpenAppClick
}),
themeToggleButton(),
logoutButton(),
refreshButton({
intent: 'success',
onClick: this.onRefreshClick
})
]
})
]
});
}

onContactClick = () => {
window.open('https://xh.io/contact');
}

onOpenAppClick = () => {
window.open('/app');
}

onRefreshClick = () => {
XH.app.requestRefresh();
}
}
Loading