Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
the-AjK committed Apr 8, 2018
2 parents 03d3e2f + deea17e commit 638e82d
Show file tree
Hide file tree
Showing 71 changed files with 493 additions and 72 deletions.
9 changes: 6 additions & 3 deletions dashboard/src/components/GenericTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ const Table = inject("ctx")(

let options = {
className: this.props.highlightRows === false ? undefined : "-highlight",
showPagination: false,
defaultPageSize: 200,
loading: false,
noDataText: this.props.store.isLoading ? "Loading" : (this.props.store.error ? this.props.errorDataText : this.props.emptyDataText),
style: {
maxHeight: "400px"
//maxHeight: "400px"
},
minRows: 1,
defaultFilterMethod: (filter, row, column) => {
Expand Down Expand Up @@ -158,6 +156,11 @@ const Table = inject("ctx")(
filterable={this.filters_enabled}
data={this.props.data}
columns={this.props.columns}
showPagination={this.props.showPagination || false}
showPaginationBottom={true}
showPageSizeOptions={true}
pageSizeOptions={[5, 10, 20, 50, 100]}
defaultPageSize={5}
/>}
{this.props.checkbox && <CheckboxTable
{...options}
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { observer, inject } from "mobx-react";
import { withStyles } from "material-ui/styles";
import GridList, { GridListTile, GridListTileBar } from 'material-ui/GridList';
import Subheader from 'material-ui/List/ListSubheader';
import Autorenew from 'material-ui-icons/Autorenew';

const styles = theme => ({
root: {
Expand Down Expand Up @@ -89,7 +90,7 @@ const Home = inject("ctx")(
<div className={classes.root}>
<GridList cellHeight={180} cols={3} className={classes.gridList}>
<GridListTile key="Subheader" cols={3} style={{ height: 'auto' }}>
<Subheader component="div">BTB - Smart Menu Ordering System {this.props.ctx.stats.isLoading ? "[ updating... ]" : ""}</Subheader>
<Subheader component="div">BTB - Smart Menu Ordering System {this.props.ctx.stats.isLoading ? <Autorenew /> : ""}</Subheader>
</GridListTile>
{tileData.map(tile => (
<GridListTile key={tile.img} cols={tile.cols || 1}>
Expand Down
8 changes: 7 additions & 1 deletion dashboard/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const styles = theme => ({
const LoginError = class extends Component {
render() {
const { classes } = this.props;
let message;
try {
message = JSON.parse(this.props.message);
} catch (ex) {
message = this.props.message;
}
return (
<div>
<Card className={classes.card}>
Expand All @@ -61,7 +67,7 @@ const LoginError = class extends Component {
<Typography variant="headline" component="h2">
Are you kidding me!?
</Typography>
<Typography component="p">{this.props.message}</Typography>
<Typography component="p">{message.message ? message.message : message}</Typography>
</CardContent>
<CardActions>
<Button size="small" color="primary" onClick={this.props.action}>
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const Menus = inject("ctx")(
columns={columns}
data={this.props.ctx.menus.menus}
store={this.props.ctx.menus}
showPagination={true}
/>
<FloatingAddButton
onClick={() => this.props.ctx.history.push('/menus/new')}
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/components/Orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const Orders = inject("ctx")(
columns={dailyOrderColumns}
data={dailyOrders}
store={this.props.ctx.stats}
showPagination={false}
/>
</Grid>
<Grid item xs={12}>
Expand All @@ -189,6 +190,7 @@ const Orders = inject("ctx")(
columns={columns}
data={this.props.ctx.orders.orders}
store={this.props.ctx.orders}
showPagination={true}
/>
</Grid>
</Grid>
Expand Down
235 changes: 224 additions & 11 deletions dashboard/src/components/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,245 @@
// @flow
import React from "react";
import { observer, inject } from "mobx-react";
import { extendObservable, action } from "mobx";
import { withStyles } from "material-ui/styles";
import Avatar from 'material-ui/Avatar';
import FloatingSaveButton from "./buttons/FloatingSaveButton";
import Grid from "material-ui/Grid";
import TextField from 'material-ui/TextField';
import IconButton from 'material-ui/IconButton';
import Input, { InputLabel, InputAdornment } from 'material-ui/Input';
import Visibility from 'material-ui-icons/Visibility';
import VisibilityOff from 'material-ui-icons/VisibilityOff';
import { FormControl } from 'material-ui/Form';
import Validator from "validatorjs";

const styles = theme => ({
avatar: {
root: {
display: 'flex',
//flexWrap: 'wrap',
//height: "100em"
},
errorText: {
color: "red"
},
passwordText: {
width: "100%"
},
avatar: {
margin: 10,
width: 60,
height: 60,
},
},
});

const Profile = inject("ctx")(
observer(
class extends React.Component {

constructor(props) {
super(props);
extendObservable(this, {
username: this.props.ctx.auth.user.username,
email: this.props.ctx.auth.user.email,
errors: {
email: false,
username: false,
password: false
},
showPassword: false,
password: "",
password2: ""
});
}

showAlert = (title, description, onClose) => {
this.props.ctx.dialog.set({
open: true,
onClose: (response) => {
if(onClose)
onClose(response);
},
showCancel: false,
title: title,
description: description
})
}

profileUpdate = () => {
this.props.ctx.auth.updateProfile(this.username, this.email, this.password, (err) => {
if (err) {
this.showAlert("Error", err);
} else {
this.showAlert("Success", "Profile updated!\nPlease login again.", ()=>{
this.props.ctx.history.push('/login');
});
action(() => {
this.email = this.props.ctx.auth.user.email;
this.username = this.props.ctx.auth.user.username;
this.password = "";
})()
}
});
}

handleProfileUpdate = () => {
this.props.ctx.dialog.set({
open: true,
showCancel: true,
onClose: (response) => {
if (response) {
this.profileUpdate();
}
},
title: "Update profile",
description: "Are you sure to save the changes?"
})
}

handleMouseDownPassword = event => {
event.preventDefault();
};

handleClickShowPasssword = action(() => {
this.showPassword = !this.showPassword;
});

handleChangeField = action((field, event) => {
if (field == "password" && event.target.value == "")
this.password2 = "";
if (field == "password" && event.target.value != "" && event.target.value.length < 8) {
this.errors.password = "Password too short [min 8 chars]";
} else {
this.errors.password = false;
}
if (field == "email") {
let validation = new Validator(
{ email: event.target.value },
{ email: "required|email" }
);
validation.passes();
this.errors[field] = validation.errors.first(field)
}
if (field == "username") {
let validation = new Validator(
{ username: event.target.value },
{ username: "required" }
);
validation.passes();
this.errors[field] = validation.errors.first(field)
}
this[field] = event.target.value
});

render() {
const { classes, theme } = this.props;
return (
<div>
<h2>Profile</h2>
<Avatar
alt="Avatar"
src="/static/images/profile.jpg"
className={classes.avatar}
/>
<h3>{this.props.ctx.auth.user.email}</h3>
</div>
<Grid
className={classes.root}
container
direction={"row"}
justify={"center"}
alignItems={"stretch"}
>
<FloatingSaveButton disabled={this.props.ctx.auth.isLoading || this.errors.email !== false || this.errors.username !== false || this.password !== this.password2} onClick={this.handleProfileUpdate} />
<Grid item xs={12} md={6}>
<Grid
className={classes.root}
container
direction={"row"}
alignItems={"stretch"}
>
<Grid item xs={12}>
<h2>Profile</h2>
<Avatar
alt="Avatar"
src="/static/images/profile.jpg"
className={classes.avatar}
/>
</Grid>
<Grid item xs={12}>
<TextField
id="username"
label="Username"
value={this.username}
error={this.errors.username !== false}
placeholder="Username"
onChange={(e) => { this.handleChangeField("username", e) }}
fullWidth
margin="normal"
/>
</Grid>
<Grid item xs={12}>
<TextField
id="email"
label="Email"
type="email"
error={this.errors.email !== false}
value={this.email}
placeholder="Email"
onChange={(e) => { this.handleChangeField("email", e) }}
fullWidth
margin="normal"
/>
</Grid>
<Grid item xs={12}>
<FormControl className={classes.passwordText}>
<InputLabel htmlFor="password">Password
{this.errors.password !== false && <span className={classes.errorText}> {this.errors.password}</span>}
</InputLabel>
<Input
id="password"
type={this.showPassword ? 'text' : 'password'}
value={this.password}
autoComplete={false}
onChange={(e) => { this.handleChangeField("password", e) }}
error={this.password !== this.password2 || this.errors.password !== false}
fullWidth
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="Toggle password visibility"
onClick={this.handleClickShowPasssword}
onMouseDown={this.handleMouseDownPassword}
>
{this.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
</Grid>
{this.password.length > 0 && <Grid item xs={12}>
<FormControl className={classes.passwordText}>
<InputLabel htmlFor="password">Repeat Password
{this.password !== this.password2 && <span className={classes.errorText}> The passwords doesnt match!</span>}
</InputLabel>
<Input
id="password2"
type={this.showPassword ? 'text' : 'password'}
value={this.password2}
autoComplete={false}
onChange={(e) => { this.handleChangeField("password2", e) }}
error={this.password !== this.password2}
fullWidth
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="Toggle password visibility"
onClick={this.handleClickShowPasssword}
onMouseDown={this.handleMouseDownPassword}
>
{this.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
</Grid>}
</Grid>
</Grid>
</Grid>
);
}
}));
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/Tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const Tables = inject("ctx")(
columns={columns}
data={this.props.ctx.tables.tables}
store={this.props.ctx.tables}
showPagination={true}
/>
<FloatingAddButton
onClick={this.handleAddTable}
Expand Down
Loading

0 comments on commit 638e82d

Please sign in to comment.