API & Client: adding activity w/o gpx update
This commit is contained in:
parent
faefe18e04
commit
e6d2ad914f
@ -207,7 +207,7 @@ def post_activity_no_gpx(auth_user_id):
|
||||
user_id=auth_user_id,
|
||||
sport_id=activity_data.get('sport_id'),
|
||||
activity_date=datetime.strptime(
|
||||
activity_data.get('activity_date'), '%Y-%m-%d'),
|
||||
activity_data.get('activity_date'), '%Y-%m-%d %H:%M'),
|
||||
duration=timedelta(seconds=activity_data.get('duration'))
|
||||
)
|
||||
new_activity.moving = new_activity.duration
|
||||
|
@ -270,7 +270,7 @@ def test_add_an_activity_no_gpx(app):
|
||||
data=json.dumps(dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='2018-05-15',
|
||||
activity_date='2018-05-15 14:05',
|
||||
distance=10
|
||||
)),
|
||||
headers=dict(
|
||||
@ -285,7 +285,7 @@ def test_add_an_activity_no_gpx(app):
|
||||
assert 'created' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
assert data['data']['activities'][0]['activity_date'] == 'Tue, 15 May 2018 00:00:00 GMT' # noqa
|
||||
assert data['data']['activities'][0]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT' # noqa
|
||||
assert data['data']['activities'][0]['user_id'] == 1
|
||||
assert data['data']['activities'][0]['sport_id'] == 1
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
|
@ -31,11 +31,22 @@ function FormWithoutGpx (props) {
|
||||
<div className="form-group">
|
||||
<label>
|
||||
Activity Date:
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<input
|
||||
name="activity_date"
|
||||
className="form-control input-lg"
|
||||
className="form-control col-md"
|
||||
required
|
||||
type="date"
|
||||
/>
|
||||
<input
|
||||
name="activity_time"
|
||||
className="form-control col-md"
|
||||
required
|
||||
type="time"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
@ -43,7 +54,10 @@ function FormWithoutGpx (props) {
|
||||
Duration:
|
||||
<input
|
||||
name="duration"
|
||||
className="form-control input-lg"
|
||||
className="form-control col-xs-4"
|
||||
pattern="([0-2][0-3]):([0-5][0-9]):([0-5][0-9])"
|
||||
placeholder="hh:mm:ss"
|
||||
required
|
||||
type="text"
|
||||
/>
|
||||
</label>
|
||||
@ -54,6 +68,8 @@ function FormWithoutGpx (props) {
|
||||
<input
|
||||
name="distance"
|
||||
className="form-control input-lg"
|
||||
min={0}
|
||||
required
|
||||
type="number"
|
||||
/>
|
||||
</label>
|
||||
@ -78,18 +94,18 @@ export default connect(
|
||||
() => ({ }),
|
||||
dispatch => ({
|
||||
onAddSport: e => {
|
||||
const data = [].slice
|
||||
.call(e.target.form.elements)
|
||||
.reduce(function(map, obj) {
|
||||
if (obj.name) {
|
||||
if (obj.name === 'duration' || obj.name === 'distance') {
|
||||
map[obj.name] = +obj.value
|
||||
} else {
|
||||
map[obj.name] = obj.value
|
||||
const d = e.target.form.duration.value.split(':')
|
||||
const duration = +d[0] * 60 * 60 + +d[1] * 60 + +d[2]
|
||||
|
||||
const activityDate = `${e.target.form.activity_date.value
|
||||
} ${ e.target.form.activity_time.value}`
|
||||
|
||||
const data = {
|
||||
activity_date: activityDate,
|
||||
distance: +e.target.form.distance.value,
|
||||
duration,
|
||||
sport_id: +e.target.form.sport_id.value,
|
||||
}
|
||||
}
|
||||
return map
|
||||
}, {})
|
||||
dispatch(addActivityWithoutGpx(data))
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user