summaryrefslogtreecommitdiff
path: root/public/bundle.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/bundle.js')
-rw-r--r--public/bundle.js76
1 files changed, 43 insertions, 33 deletions
diff --git a/public/bundle.js b/public/bundle.js
index d347c49..f66d737 100644
--- a/public/bundle.js
+++ b/public/bundle.js
@@ -12054,7 +12054,9 @@ var App = function (_React$Component) {
});
}).catch(function (error) {
_this.setState({ ready: true });
- console.error(error);
+ if (!error.message.match(/stored JWT/)) {
+ console.error(error);
+ }
});
return _this;
}
@@ -12859,6 +12861,7 @@ var MealList = function (_React$Component) {
value: function render() {
var _this2 = this;
+ var canEdit = canEditUserMeals(this.props.currentUser, this.props.user);
var groups = groupByDate(this.state.data);
var items = Object.keys(groups).sort().reverse().map(function (date) {
var group = groups[date];
@@ -12866,6 +12869,7 @@ var MealList = function (_React$Component) {
return _react2.default.createElement(MealItem, {
key: meal.id,
meal: meal,
+ canEdit: canEdit,
onClick: _this2.pickMeal,
onDelete: _this2.handleDelete });
});
@@ -12899,6 +12903,7 @@ var MealList = function (_React$Component) {
'div',
null,
_react2.default.createElement(MealForm, { user: this.props.user,
+ currentUser: this.props.currentUser,
ref: function ref(mealForm) {
_this2.mealForm = mealForm;
},
@@ -12937,11 +12942,19 @@ var MealItem = function (_React$Component2) {
var _this3 = _possibleConstructorReturn(this, (MealItem.__proto__ || Object.getPrototypeOf(MealItem)).call(this));
+ _this3.handleClick = _this3.handleClick.bind(_this3);
_this3.remove = _this3.remove.bind(_this3);
return _this3;
}
_createClass(MealItem, [{
+ key: 'handleClick',
+ value: function handleClick() {
+ if (this.props.canEdit) {
+ this.props.onClick(this.props.meal);
+ }
+ }
+ }, {
key: 'remove',
value: function remove(e) {
var _this4 = this;
@@ -12959,18 +12972,14 @@ var MealItem = function (_React$Component2) {
}, {
key: 'render',
value: function render() {
- var _this5 = this;
-
var meal = this.props.meal;
// const canEdit = this.props.meal.userid === this.props.currentUser.id ? 'canEdit' : ''
- var canEdit = 'canEdit';
+ var canEdit = this.props.canEdit ? 'canEdit' : '';
var date = parseDate(meal.date);
var time = parseTime(meal.date);
return _react2.default.createElement(
'div',
- { className: 'meal row ' + canEdit, onClick: function onClick() {
- return _this5.props.onClick(meal);
- } },
+ { className: 'meal row ' + canEdit, onClick: this.handleClick },
_react2.default.createElement(
'div',
{ className: 'name' },
@@ -13010,18 +13019,18 @@ var MealForm = function (_React$Component3) {
function MealForm(props) {
_classCallCheck(this, MealForm);
- var _this6 = _possibleConstructorReturn(this, (MealForm.__proto__ || Object.getPrototypeOf(MealForm)).call(this));
+ var _this5 = _possibleConstructorReturn(this, (MealForm.__proto__ || Object.getPrototypeOf(MealForm)).call(this));
- _this6.state = {
+ _this5.state = {
id: '',
userid: props.user.id,
name: '',
calories: '',
date: new Date()
};
- _this6.updateState = _this6.updateState.bind(_this6);
- _this6.handleSubmit = _this6.handleSubmit.bind(_this6);
- return _this6;
+ _this5.updateState = _this5.updateState.bind(_this5);
+ _this5.handleSubmit = _this5.handleSubmit.bind(_this5);
+ return _this5;
}
_createClass(MealForm, [{
@@ -13071,17 +13080,17 @@ var MealForm = function (_React$Component3) {
}, {
key: 'create',
value: function create() {
- var _this7 = this;
+ var _this6 = this;
var mealsService = _client2.default.service('meals');
var params = { query: { token: _client2.default.get('token') } };
mealsService.create(this.state, params).then(function (result) {
- _this7.props.onCreate(result);
- _this7.reset();
+ _this6.props.onCreate(result);
+ _this6.reset();
}).catch(function (error) {
console.error(error);
- _this7.setState({
+ _this6.setState({
error: error.toString()
});
});
@@ -13089,17 +13098,17 @@ var MealForm = function (_React$Component3) {
}, {
key: 'update',
value: function update() {
- var _this8 = this;
+ var _this7 = this;
var mealsService = _client2.default.service('meals');
var params = { query: { token: _client2.default.get('token') } };
mealsService.update(this.state.id, this.state, params).then(function (result) {
- _this8.props.onUpdate(result);
- _this8.reset();
+ _this7.props.onUpdate(result);
+ _this7.reset();
}).catch(function (error) {
console.error(error);
- _this8.setState({
+ _this7.setState({
error: error.toString()
});
});
@@ -13107,10 +13116,14 @@ var MealForm = function (_React$Component3) {
}, {
key: 'render',
value: function render() {
- var _this9 = this;
+ var _this8 = this;
var id = this.state.id;
var action = id ? 'update' : 'create';
+ var canEdit = canEditUserMeals(this.props.currentUser, this.props.user);
+ if (!canEdit) {
+ return _react2.default.createElement('div', null);
+ }
var date = parseDate(this.state.date);
var time = parseTime(this.state.date);
@@ -13127,7 +13140,7 @@ var MealForm = function (_React$Component3) {
_react2.default.createElement(
'span',
{ className: 'clear', onClick: function onClick() {
- return _this9.reset();
+ return _this8.reset();
} },
'cancel'
),
@@ -13143,6 +13156,11 @@ var MealForm = function (_React$Component3) {
return MealForm;
}(_react2.default.Component);
+function canEditUserMeals(currentUser, user) {
+ var isValidRole = currentUser.role === 'admin';
+ return user.id == currentUser.id || isValidRole;
+}
+
function groupByDate(a) {
return a.reduce(function (rv, x) {
var date = parseDate(x.date);
@@ -47997,17 +48015,9 @@ var Menu = function (_React$Component) {
));
switch (currentUser.role) {
case 'admin':
- if (this.props.user.id !== this.props.currentUser.id) {
- items.push(_react2.default.createElement(
- 'li',
- { key: 'resetUser' },
- _react2.default.createElement(
- 'a',
- { href: '#', onClick: this.resetUser },
- 'Reset User'
- )
- ));
- }
+ // if (this.props.user.id !== this.props.currentUser.id) {
+ // items.push( <li key='resetUser'><a href='#' onClick={this.resetUser}>Stop viewing</a></li> )
+ // }
items.push(_react2.default.createElement(
'li',
{ key: 'userlist' },