Skip to content

Commit

Permalink
Improved next/last session functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
travhow99 committed Jun 3, 2020
1 parent 0e16875 commit ffae9b2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
20 changes: 13 additions & 7 deletions app/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ public function nextSession()
// Create a new DateTime object
$date = new DateTime();

if (new DateTime($this->lastSession()->session_date) >= $date) {
if ($this->lastSession() && new DateTime($this->lastSession()->session_date) >= $date) {
return $this->lastSession();
}

if ($this->session_day && $this->start_date) {
} else if ($this->session_day && $this->start_date) {
// Modify the date it contains
$date->modify("next " . $this->session_day);

// Output
return $date->format('m-d-Y');
$nextSession = new Session(['session_date' => $date->format('m-d-Y')]);
return $nextSession;
} else {
return "Session not available";
}
Expand Down Expand Up @@ -100,7 +98,15 @@ public function getNextSessionAttribute()
*/
public function lastSession()
{
return $this->sessions()->orderBy('session_date', 'DESC')->first();
$date = new DateTime();

// dd($date->format('H:m:s'));

// TODO: account for timezone

dd($this->sessions()->where('session_date', '<=', $date->format('Y-m-d'))->where('session_time', '<=', $date->format('H:m:s'))->orderBy('session_date', 'DESC')->first());

return $this->sessions()->where('session_date', '<=', $date->format('Y-m-d'))->where('session_time', '<=', $date->format('H:m:s'))->orderBy('session_date', 'DESC')->first();
}

/**
Expand Down
23 changes: 17 additions & 6 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -184858,7 +184858,7 @@ var Home = /*#__PURE__*/function (_Component) {
return client.next_session !== 'Session not available' && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["Card"], {
key: index,
className: "text-center mb-2"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["CardBody"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["CardTitle"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("h3", null, client.name)), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["CardText"], null, days[new Date(client.next_session).getDay()], /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("br", null), Object(_helpers_functions__WEBPACK_IMPORTED_MODULE_4__["toLocalTime"])(client.session_time)), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"], {
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["CardBody"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["CardTitle"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("h3", null, client.name)), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_3__["CardText"], null, days[new Date(client.next_session).getDay()] || days[new Date(client.next_session.session_date).getDay()], /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("br", null), Object(_helpers_functions__WEBPACK_IMPORTED_MODULE_4__["toLocalTime"])(client.session_time)), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"], {
to: "/clients/".concat(client.id)
}, "Manage Client")));
}))));
Expand Down Expand Up @@ -185308,11 +185308,11 @@ var ClientOverview = function ClientOverview(props) {
className: "d-flex flex-column flex-half px-1"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(_utilities_AgendaItem__WEBPACK_IMPORTED_MODULE_2__["default"], {
title: "Next Session",
date: props.client.next_session,
date: props.client.next_session.session_date,
time: props.client.session_time,
detail: "Therapy Session" // TODO: determine if session exists already
,
href: "/clients/".concat(props.client.id, "/sessions/new")
href: "/clients/".concat(props.client.id, "/sessions/").concat(props.client.next_session.session_id || 'new')
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(_utilities_AgendaItem__WEBPACK_IMPORTED_MODULE_2__["default"], {
title: "Last Session",
date: props.client.last_session.session_date,
Expand Down Expand Up @@ -186178,6 +186178,9 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var reactstrap__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! reactstrap */ "./node_modules/reactstrap/es/index.js");


/**
* @todo Functional checkboxes
*/

var GoalNote = function GoalNote(props) {
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react__WEBPACK_IMPORTED_MODULE_0___default.a.Fragment, null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Row"], {
Expand All @@ -186200,13 +186203,15 @@ var GoalNote = function GoalNote(props) {
}, "+")))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Row"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Col"], {
className: "form-check"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Input"], {
type: "checkbox"
type: "checkbox",
onChange: props.updateStatus
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Label"], {
className: "form-check-label"
}, "Did not meet objective")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Col"], {
className: "form-check"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Input"], {
type: "checkbox"
type: "checkbox",
onChange: props.updateStatus
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(reactstrap__WEBPACK_IMPORTED_MODULE_1__["Label"], {
className: "form-check-label"
}, "Met objective"))));
Expand Down Expand Up @@ -187793,6 +187798,11 @@ var SessionGoal = /*#__PURE__*/function (_Component) {
goal: _objectSpread({}, this.state.goal, _defineProperty({}, name, value))
});
}
}, {
key: "updateGoalProgress",
value: function updateGoalProgress(e) {
console.log(e.target.checked);
}
}, {
key: "updateGoal",
value: function updateGoal(e) {
Expand Down Expand Up @@ -187843,7 +187853,8 @@ var SessionGoal = /*#__PURE__*/function (_Component) {
}, this.state.takingNote ? 'Close Note' : 'Add Note'))), !this.props.master && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react__WEBPACK_IMPORTED_MODULE_0___default.a.Fragment, null, this.state.takingNote && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(_goals_GoalNote__WEBPACK_IMPORTED_MODULE_3__["default"], {
save: this.saveNote,
goal: this.state.goal,
adjustCount: this.adjustCount
adjustCount: this.adjustCount,
updateStatus: this.updateGoalProgress
})));
}
}]);
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Home extends Component {
<h3>{client.name}</h3>
</CardTitle>
<CardText>
{days[new Date(client.next_session).getDay()]}
{days[new Date(client.next_session).getDay()] || days[new Date(client.next_session.session_date).getDay()]}
<br />
{toLocalTime(client.session_time)}
</CardText>
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/clients/ClientOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const ClientOverview = (props) => {
<div className="d-flex flex-column flex-half px-1">
<AgendaItem
title={"Next Session"}
date={props.client.next_session}
date={props.client.next_session.session_date}
time={props.client.session_time}
detail={"Therapy Session"}
// TODO: determine if session exists already
href={`/clients/${props.client.id}/sessions/new`}
href={`/clients/${props.client.id}/sessions/${props.client.next_session.session_id || 'new'}`}
/>
<AgendaItem
title={"Last Session"}
Expand Down
7 changes: 5 additions & 2 deletions resources/js/components/goals/GoalNote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { Row, Col, Input, Label, Button } from 'reactstrap';

/**
* @todo Functional checkboxes
*/
const GoalNote = (props) => {
return (
<React.Fragment>
Expand All @@ -21,11 +24,11 @@ const GoalNote = (props) => {
</Row>
<Row>
<Col className="form-check">
<Input type="checkbox" />
<Input type="checkbox" onChange={props.updateStatus} />
<Label className="form-check-label">Did not meet objective</Label>
</Col>
<Col className="form-check">
<Input type="checkbox" />
<Input type="checkbox" onChange={props.updateStatus} />
<Label className="form-check-label">Met objective</Label>
</Col>
</Row>
Expand Down
7 changes: 6 additions & 1 deletion resources/js/components/sessions/SessionGoal.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class SessionGoal extends Component {
this.setState({goal: {...this.state.goal, [name]: value}});
}

updateGoalProgress(e) {
console.log(e.target.checked);
}

updateGoal(e) {
axios.put(`/api/clients/${this.props.client_id}/goals/${this.state.goal.id}`, this.state.goal)
.then((response) => {
Expand Down Expand Up @@ -137,7 +141,8 @@ class SessionGoal extends Component {
<GoalNote
save={this.saveNote}
goal={this.state.goal}
adjustCount={this.adjustCount}
adjustCount={this.adjustCount}
updateStatus={this.updateGoalProgress}
/>
}
</React.Fragment>
Expand Down

0 comments on commit ffae9b2

Please sign in to comment.