Newer
Older
import { Component } from 'react';
import { Redirect, BrowserRouter as Router } from 'react-router-dom';
import AppTopbar from './layout/components/AppTopbar';
import AppMenu from './layout/components/AppMenu';
import { RoutedContent } from './routes';
import AppBreadcrumb from "./layout/components/AppBreadcrumb";

Ramesh Kumar
committed
import handleResponse from "./response.handler"

Ramesh Kumar
committed
import 'primeicons/primeicons.css';
import 'primereact/resources/primereact.css';
import 'primereact/resources/themes/nova/theme.css';
import './layout/layout.scss';

Ramesh Kumar
committed
import './App.scss';
import './App.css';
import Auth from './authenticate/auth';
import pubsub from './utils/pubSub';
import { CustomDialog } from './layout/components/CustomDialog';
import AuthStore from './authenticate/auth.store';
import { Provider } from "react-redux";

Ramesh Kumar
committed
import AuthComponent from './components/AuthComponent';

Ramesh Kumar
committed
const { publish, subscribe } = pubsub();
class App extends Component {
super();
this.state = {
layoutMode: 'static',
currentMenu: '',
currentPath: '/',
PageTitle: '',
isBreadCrumbVisible: false,
staticMenuInactive: localStorage.getItem('staticMenuInactive') === 'true',
overlayMenuActive: localStorage.getItem('overlayMenuActive') === 'true',
mobileMenuActive: localStorage.getItem('mobileMenuActive') === 'true',
authenticated: true,
findObjectPlaceholder: 'Sub Task',
redirect: window.location.pathname === '/' ? '/su/timelineview/week' : window.location.pathname,
isLogin: true
this.onToggleMenu = this.onToggleMenu.bind(this);
this.onMenuItemClick = this.onMenuItemClick.bind(this);
this.logout = this.logout.bind(this);
this.validateAndLogout = this.validateAndLogout.bind(this);
this.setSearchField = this.setSearchField.bind(this);
{ label: 'Failure ', icon: 'pi pi-fw pi-chart-bar', to: '/reports/failure', section: 'reports', isBreadCrumbVisible: false, isDateTimeVisible: false },
{ label: 'Cycle ', icon: 'pi pi-fw pi-history', to: '/reports/cycle', section: 'reports', isBreadCrumbVisible: false, isDateTimeVisible: false },
{ label: 'Project ', icon: 'pi pi-fw pi-table', to: '/reports/project', section: 'reports', isBreadCrumbVisible: false, isDateTimeVisible: false }
{ label: 'Calendar', icon: 'pi pi-fw pi-calendar-times', to: '/su/timelineview/week', section: 'su/timelineview/week', isBreadCrumbVisible: false, isDateTimeVisible: true },
{ label: 'Cycle', icon: 'pi pi-fw pi-spinner', to: '/cycle', section: 'cycle', isBreadCrumbVisible: true, isDateTimeVisible: false },
{ label: 'Daily Schedule', icon: 'pi pi-fw pi-sun', to: '/constraint/view', section: 'system', isBreadCrumbVisible: false, isDateTimeVisible: true },
{ label: 'Project', icon: 'pi pi-fw pi-compass', to: '/project', section: 'project', isBreadCrumbVisible: true, isDateTimeVisible: false },
{ label: 'Reservations', icon: 'pi pi-fw pi-book', to: '/reservation/list', section: 'system', isBreadCrumbVisible: false, isDateTimeVisible: true },
{ label: 'Reports', icon: 'pi pi-fw pi-chart-bar', to: '/reports/failure', section: 'reports', isBreadCrumbVisible: false, isDateTimeVisible: false, items: this.ReportSubMenu },
{ label: 'Scheduling Units', icon: 'pi pi-fw pi-calendar', to: '/schedulingunit', section: 'schedulingunit', isBreadCrumbVisible: true, isDateTimeVisible: false },
{ label: 'Stations', icon: 'pi pi-fw pi-wifi pi-rotate', to: '/station/list', section: 'system', isBreadCrumbVisible: false, isDateTimeVisible: true },
{ label: 'System Events', icon: 'pi pi-fw pi-bolt', to: '/systemevent/list', section: 'system', isBreadCrumbVisible: false, isDateTimeVisible: true },
{ label: 'Tasks', icon: 'pi pi-fw pi-check-square', to: '/task', isBreadCrumbVisible: true, isDateTimeVisible: false },
{ label: 'Workflow', icon: 'pi pi-fw pi-sitemap', to: '/su/workflow', section: 'workflow', isBreadCrumbVisible: true, isDateTimeVisible: false },
onToggleMenu(event) {
this.menuClick = true;
if (this.isDesktop()) {
this.setState(prevState => ({
staticMenuInactive: !prevState.staticMenuInactive
}), () => {
localStorage.setItem('staticMenuInactive', !this.state.staticMenuInactive);
});
} else {
this.setState(prevState => ({
mobileMenuActive: !prevState.mobileMenuActive
}), () => {
localStorage.setItem('mobileMenuActive', this.state.mobileMenuActive);
onMenuItemClick(event) {
this.setState({ currentMenu: event.item.label, currentPath: event.item.path, isBreadCrumbVisible: event.item.isBreadCrumbVisible, isDateTimeVisible: event.item.isDateTimeVisible });
setPageTitle(PageTitle) {
if (PageTitle !== this.state.PageTitle) {
this.setState({ PageTitle })
/**
* Logout and redirect to login page.
*/
logout() {
Auth.logout();
this.setState({ redirect: "/login", isLogin: false });
/**
* Get confirmation if any of the page has unsaved data and then logout.
* @returns
*/
validateAndLogout() {
if (this.state.isEditDirty) {
this.toggleDirtyDialog(this.logout);
this.setState(prevState => ({
showEditDialog: !prevState.showEditDialog
}));
subscribe('edit-dirty', (flag) => {
this.setState({ isEditDirty: flag }, () => {
if (flag) {
window.addEventListener("beforeunload", reloadDirty);
window.history.pushState(null, document.title, window.location.href);
window.addEventListener('popstate', this.onBackButtonEvent);
window.removeEventListener("beforeunload", reloadDirty);
let reloadDirty = function (e) {
(e).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage;
};
if (window.location.pathname === '/') {
this.setState({ redirect: '/su/timelineview/week', isBreadCrumbVisible: false, isDateTimeVisible: true })

Nithya Santhanam
committed
}
}
const leavePage = window.confirm("Do you want to discard your changes? Your changes may not be saved.");
if (leavePage) {
this.setState({ isEditDirty: false });
window.history.back();
window.history.pushState(null, document.title, window.location.href);
close = () => {
this.setState({ showDirtyDialog: false });
this.setState({ isEditDirty: false, showDirtyDialog: false });
this.state.toPathCallback();
this.setState({ showDirtyDialog: true, toPathCallback: callback });
}
onBreadcrumbClick = (callback) => {
if (this.state.isEditDirty) {
/**
* Set search param
* @param {*} key
* @param {*} value
*/
setSearchField(key, value) {
objectType: key,
findObjectId: value,
redirect: "/find/object/" + key + "/" + value
render() {
const wrapperClass = classNames('layout-wrapper', {
'layout-static': this.state.layoutMode === 'static',
'layout-static-sidebar-inactive': this.state.staticMenuInactive ,
'layout-mobile-sidebar-active': this.state.mobileMenuActive
});
return (
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<div className="App">
<Provider store={AuthStore}>
<div className={wrapperClass}>
{/* Load main routes and application only if the application is authenticated */}
{this.state.redirect &&
<AuthComponent>
<AppTopbar
onToggleMenu={this.onToggleMenu}
isLoggedIn={this.state.authenticated}
onLogout={this.validateAndLogout}
setSearchField={this.setSearchField}
isDateTimeVisible={this.state.isDateTimeVisible}
/>
<Router basename={this.state.currentPath}>
<AppMenu model={this.menu} toggleDirtyDialog={this.toggleDirtyDialog} isEditDirty={this.state.isEditDirty} onMenuItemClick={this.onMenuItemClick} active={this.state.menuActive} />
<div className="layout-main">
{(this.state.redirect || this.state.redirect === "/login") &&
<Redirect to={{ pathname: this.state.redirect === "/login" ? "/su/timelineview/week" : this.state.redirect, state: { userrole: this.state.userrole } }} />}
{(this.state.isBreadCrumbVisible) &&
<AppBreadcrumb setPageTitle={this.setPageTitle} section={this.state.currentMenu} onBreadcrumbClick={this.onBreadcrumbClick} />
}
<RoutedContent />
</div>
</Router>
</AuthComponent>
}
<CustomDialog type="confirmation" visible={this.state.showDirtyDialog} width="40vw"
header={'Confirmation'} message={'Do you want to discard your changes? Your changes may not be saved.'}
content={''} onClose={this.close}
actions={[{ id: "yes", title: 'Discard', callback: this.cancelEdit, className: 'act-btn-dispose' },
{ id: "no", title: 'Cancel', className: 'act-btn-cancel', callback: this.close }]}>
</CustomDialog>
</div>
</Provider>
</div>
);
}
}
export default handleResponse(App);