Skip to content

Commit

Permalink
Merge pull request #51 from edu-xored/WEBUI-12
Browse files Browse the repository at this point in the history
PageHeader (connected #12)
  • Loading branch information
sergeyt authored Nov 1, 2016
2 parents c110110 + 050dd4c commit 11ebfd8
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 43 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<link rel="stylesheet" type="text/css" href="/semantic/semantic.css">
</head>
<body>
<div id="header">
</div>
<div id="root">
</div>
<script src="/dist/vendor.bundle.js"></script>
Expand Down
18 changes: 9 additions & 9 deletions semantic/semantic.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ input[type="password"] {
*/

/*******************************
Page
PageHeader
*******************************/

html,
Expand Down Expand Up @@ -4780,7 +4780,7 @@ i.flag:not(.icon):before {
*******************************/

/*--------------
Page
PageHeader
---------------*/

h1.ui.header {
Expand Down Expand Up @@ -16950,7 +16950,7 @@ ol.ui.horizontal.list li:before,
*******************************/

/*-----------------------
Page Grid
PageHeader Grid
-------------------------*/

@media only screen and (max-width: 767px) {
Expand Down Expand Up @@ -17162,7 +17162,7 @@ ol.ui.horizontal.list li:before,
width: 6.25% !important;
}

/* Celled Page */
/* Celled PageHeader */

.ui.celled.page.grid {
box-shadow: none;
Expand Down Expand Up @@ -23143,7 +23143,7 @@ Floated Menu / Item
height: 280px;
}

/* Half Page */
/* Half PageHeader */

.ui[class*="half page"].ad {
width: 300px;
Expand Down Expand Up @@ -27120,7 +27120,7 @@ a.ui.card:hover,
*******************************/

/*--------------
Page
PageHeader
---------------*/

.ui.page.dimmer {
Expand Down Expand Up @@ -31829,13 +31829,13 @@ a.ui.nag {
padding: 0em !important;
}

/* Whole Page */
/* Whole PageHeader */

body.pushable {
background: #333333 !important;
}

/* Page Context */
/* PageHeader Context */

.pushable:not(body) {
-webkit-transform: translate3d(0, 0, 0);
Expand Down Expand Up @@ -31865,7 +31865,7 @@ body.pushable {
}

/*--------------
Page
PageHeader
---------------*/

.pushable > .pusher {
Expand Down
2 changes: 2 additions & 0 deletions src/client/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as React from 'react';
import { render } from 'react-dom';
import Routes from './routes';
import PageHeader from './pageheader';

class Root extends React.Component<{}, {}> {
render() {
return Routes;
}
}

render(<PageHeader/>, document.getElementById('header'));
render(<Root/>, document.getElementById('root'));
163 changes: 163 additions & 0 deletions src/client/pageheader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import * as React from 'react';
import {Input, Menu, Dropdown, Container} from 'semantic-ui-react';
import {User} from '../lib/model';

interface PageState {
activeItem: string;
}

interface MenuItem {
name: string;
text: string;
role: boolean | string;
parent: boolean | string;
rightSide: boolean;
}

export default class PageHeader extends React.Component<{}, PageState> {
state: PageState = {
activeItem: 'home',
};

handleItemClick = (name) => this.setState({activeItem: name});
handleMenuItemClick = (e, {name}) => this.handleItemClick(name);
handleDropdownItemClick = (e, {value}) => this.handleItemClick(value);

user: User = {
id: '1',
login: '%username%',
name: '%username%',
pwdhash: '%username%', // password hash
avatar: '', // URL to avatar image, e.g. it could be a gravatar URL or URL to uploaded image
role: 'admin',
position: '213',
place: 's',
}; // TODO fetch real logged in user's information

menu: MenuItem[] = [
{
name: 'home',
text: 'Home',
role: false,
parent: false,
rightSide: false,
},
{
name: 'calendars',
text: '',
role: false,
parent: false,
rightSide: false,
},
{
name: 'reports',
text: 'Reports',
role: false,
parent: false,
rightSide: false,
},
{
name: 'teams',
text: 'Teams',
role: false,
parent: false,
rightSide: false,
},
{
name: 'admin',
text: 'Admin',
role: 'admin',
parent: false,
rightSide: false,
},
{
name: 'user',
text: this.user.name,
role: true,
parent: false,
rightSide: false,
},
{
name: 'account',
text: 'My account',
role: true,
parent: 'user',
rightSide: false,
},
{
name: 'logout',
text: 'Logout',
role: true,
parent: 'user',
rightSide: false,
},
];

showItem(item, child = false) {
if (item.parent === item.name)
return;
if ((item.role === true && +(this.user.id) <= 0) || (item.role && item.role === this.user.role)) // TODO normal check for rights
return;
let dropdown = [];
for (let tmpitem of this.menu)
if (tmpitem.parent === item.name)
dropdown.push(this.showItem(tmpitem));
if (dropdown.length > 0) {
return (
<Dropdown as={(child) ? Dropdown.Item : Menu.Item} text={item.text}>
<Dropdown.Menu>
{dropdown}
</Dropdown.Menu>
</Dropdown>
);
} else {
if (child)
return (
<Dropdown.Item value={item.name} text={item.text} active={this.state.activeItem === item.name}
onClick={this.handleDropdownItemClick}/>
);
else
return (
<Menu.Item name={item.name} active={this.state.activeItem === item.name} onClick={this.handleMenuItemClick}/>
);
}
}

render() {
let container = [];
for (let item of this.menu)
if (item.parent === false && !item.rightSide)
container.push(this.showItem(item));
container.push(
<Menu.Item position='right'>
<Input icon='search' placeholder='Search...'/>
</Menu.Item>
);
for (let item of this.menu)
if (item.parent === false && item.rightSide)
container.push(this.showItem(item));
return (
<Menu><Container>{container}</Container></Menu>
);
/*
<Container>
<Menu.Item name='home' active={this.state.activeItem === 'home'} onClick={this.handleMenuItemClick} />
<Menu.Item name='calendars' active={this.state.activeItem === 'calendars'} onClick={this.handleMenuItemClick} />
<Menu.Item name='reports' active={this.state.activeItem === 'reports'} onClick={this.handleMenuItemClick}/>
<Menu.Item name='teams' active={this.state.activeItem === 'teams'} onClick={this.handleMenuItemClick}/>
{this.user.role === 'admin' &&
<Menu.Item name='admin' active={this.state.activeItem === 'admin'} onClick={this.handleMenuItemClick}/>
}
<Menu.Item position='right'>
<Input icon='search' placeholder='Search...' />
</Menu.Item>
<Dropdown as={Menu.Item} text={this.user.name}>
<Dropdown.Menu>
<Dropdown.Item value='options' text="My account" active={this.state.activeItem === 'options'} onClick={this.handleDropdownItemClick} />
<Dropdown.Item value='logout' text="Log Out" active={this.state.activeItem === 'logout'} onClick={this.handleDropdownItemClick} />
</Dropdown.Menu>
</Dropdown>
</Container>
*/
}
}
32 changes: 0 additions & 32 deletions src/client/pages/sui-example.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/client/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { Router, Route, IndexRoute, RouterState } from 'react-router';
import history from './history';
import Home from './pages/home';
import Blank from './pages/blank';
import SuiExamplePage from './pages/sui-example';

const Routes = (
<Router history={history}>
<Route path="/" component={Home}/>
<Route path="/sui" component={SuiExamplePage} />
<Route path="*" component={Blank}/>
</Router>
);
Expand Down

0 comments on commit 11ebfd8

Please sign in to comment.