API & Client: fix
This commit is contained in:
parent
76b2d5aad2
commit
e7e0a20f89
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from fittrackee_api import appLog, db
|
from fittrackee_api import appLog, db
|
||||||
from flask import Blueprint, current_app, jsonify, request, send_file
|
from flask import Blueprint, current_app, jsonify, request, send_file
|
||||||
@ -41,8 +41,9 @@ def get_activities(auth_user_id):
|
|||||||
Activity.sport_id == sport_id if sport_id else True,
|
Activity.sport_id == sport_id if sport_id else True,
|
||||||
Activity.activity_date >= datetime.strptime(date_from, '%Y-%m-%d')
|
Activity.activity_date >= datetime.strptime(date_from, '%Y-%m-%d')
|
||||||
if date_from else True,
|
if date_from else True,
|
||||||
Activity.activity_date <= datetime.strptime(date_to, '%Y-%m-%d')
|
Activity.activity_date < (
|
||||||
if date_to else True,
|
datetime.strptime(date_to, '%Y-%m-%d') + timedelta(days=1)
|
||||||
|
) if date_to else True,
|
||||||
Activity.distance >= int(distance_from) if distance_from else True,
|
Activity.distance >= int(distance_from) if distance_from else True,
|
||||||
Activity.distance <= int(distance_to) if distance_to else True,
|
Activity.distance <= int(distance_to) if distance_to else True,
|
||||||
Activity.duration >= convert_in_duration(duration_from)
|
Activity.duration >= convert_in_duration(duration_from)
|
||||||
|
@ -43,8 +43,9 @@ def get_activities(user_id, type):
|
|||||||
Activity.user_id == user_id,
|
Activity.user_id == user_id,
|
||||||
Activity.activity_date >= datetime.strptime(date_from, '%Y-%m-%d')
|
Activity.activity_date >= datetime.strptime(date_from, '%Y-%m-%d')
|
||||||
if date_from else True,
|
if date_from else True,
|
||||||
Activity.activity_date <= datetime.strptime(date_to, '%Y-%m-%d')
|
Activity.activity_date < (
|
||||||
if date_to else True,
|
datetime.strptime(date_to, '%Y-%m-%d') + timedelta(days=1)
|
||||||
|
) if date_to else True,
|
||||||
Activity.sport_id == sport_id if sport_id else True,
|
Activity.sport_id == sport_id if sport_id else True,
|
||||||
).order_by(
|
).order_by(
|
||||||
Activity.activity_date.asc()
|
Activity.activity_date.asc()
|
||||||
|
@ -87,6 +87,9 @@ class User(db.Model):
|
|||||||
nb_activity = Activity.query.filter(
|
nb_activity = Activity.query.filter(
|
||||||
Activity.user_id == self.id
|
Activity.user_id == self.id
|
||||||
).count()
|
).count()
|
||||||
|
sports = []
|
||||||
|
total = (None, None)
|
||||||
|
if nb_activity > 0:
|
||||||
sports = db.session.query(
|
sports = db.session.query(
|
||||||
func.count(Activity.sport_id)
|
func.count(Activity.sport_id)
|
||||||
).group_by(
|
).group_by(
|
||||||
|
@ -135,9 +135,9 @@ export const getMoreActivities = params => dispatch => FitTrackeeGenericApi
|
|||||||
})
|
})
|
||||||
.catch(error => dispatch(setError(`activities: ${error}`)))
|
.catch(error => dispatch(setError(`activities: ${error}`)))
|
||||||
|
|
||||||
export const getMonthActivities = (start, end) => dispatch =>
|
export const getMonthActivities = (from, to) => dispatch =>
|
||||||
FitTrackeeGenericApi
|
FitTrackeeGenericApi
|
||||||
.getData('activities', { start, end, order: 'asc', per_page: 100 })
|
.getData('activities', { from, to, order: 'asc', per_page: 100 })
|
||||||
.then(ret => {
|
.then(ret => {
|
||||||
if (ret.status === 'success') {
|
if (ret.status === 'success') {
|
||||||
if (ret.data.activities.length > 0) {
|
if (ret.data.activities.length > 0) {
|
||||||
@ -146,8 +146,8 @@ export const getMonthActivities = (start, end) => dispatch =>
|
|||||||
ret.data.activities[i].activity_date
|
ret.data.activities[i].activity_date
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
dispatch(updateCalendar(ret.data.activities))
|
|
||||||
}
|
}
|
||||||
|
dispatch(updateCalendar(ret.data.activities))
|
||||||
} else {
|
} else {
|
||||||
dispatch(setError(`activities: ${ret.message}`))
|
dispatch(setError(`activities: ${ret.message}`))
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,10 @@ function FormWithoutGpx (props) {
|
|||||||
const { activity, onAddOrEdit, sports } = props
|
const { activity, onAddOrEdit, sports } = props
|
||||||
let activityDate, activityTime, sportId = ''
|
let activityDate, activityTime, sportId = ''
|
||||||
if (activity) {
|
if (activity) {
|
||||||
const activityDateTime = formatActivityDate(activity.activity_date)
|
const activityDateTime = formatActivityDate(
|
||||||
|
activity.activity_date,
|
||||||
|
'YYYY-MM-DD'
|
||||||
|
)
|
||||||
activityDate = activityDateTime.activity_date
|
activityDate = activityDateTime.activity_date
|
||||||
activityTime = activityDateTime.activity_time
|
activityTime = activityDateTime.activity_time
|
||||||
sportId = activity.sport_id
|
sportId = activity.sport_id
|
||||||
|
@ -302,7 +302,6 @@ input, textarea {
|
|||||||
height: 3em;
|
height: 3em;
|
||||||
border-right: 1px solid var(--border-color);
|
border-right: 1px solid var(--border-color);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: pointer;
|
|
||||||
background: var(--neutral-color);
|
background: var(--neutral-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ export default connect(
|
|||||||
loadMonthActivities: (userId, start, end) => {
|
loadMonthActivities: (userId, start, end) => {
|
||||||
const dateFormat = 'YYYY-MM-DD'
|
const dateFormat = 'YYYY-MM-DD'
|
||||||
const params = {
|
const params = {
|
||||||
start: format(start, dateFormat),
|
from: format(start, dateFormat),
|
||||||
end: format(end, dateFormat),
|
to: format(end, dateFormat),
|
||||||
time: 'week'
|
time: 'week'
|
||||||
}
|
}
|
||||||
dispatch(getStats(userId, 'by_time', params))
|
dispatch(getStats(userId, 'by_time', params))
|
||||||
|
@ -3,6 +3,13 @@ import React from 'react'
|
|||||||
|
|
||||||
export default function UserStatistics (props) {
|
export default function UserStatistics (props) {
|
||||||
const { user } = props
|
const { user } = props
|
||||||
|
const days = user.totalDuration.match(/day/g)
|
||||||
|
? `${user.totalDuration.split(',')[0]},`
|
||||||
|
: '0 days,'
|
||||||
|
let duration = user.totalDuration.match(/day/g)
|
||||||
|
? user.totalDuration.split(', ')[1]
|
||||||
|
: user.totalDuration
|
||||||
|
duration = `${duration.split(':')[0]}h ${duration.split(':')[1]}min`
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col">
|
<div className="col">
|
||||||
@ -26,7 +33,7 @@ export default function UserStatistics (props) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="col-9 text-right">
|
<div className="col-9 text-right">
|
||||||
<div className="huge">
|
<div className="huge">
|
||||||
{Math.round(user.totalDistance * 100) / 100}
|
{Number(user.totalDistance).toFixed(2)}
|
||||||
</div>
|
</div>
|
||||||
<div>km</div>
|
<div>km</div>
|
||||||
</div>
|
</div>
|
||||||
@ -40,8 +47,8 @@ export default function UserStatistics (props) {
|
|||||||
<i className="fa fa-clock-o fa-3x fa-color" />
|
<i className="fa fa-clock-o fa-3x fa-color" />
|
||||||
</div>
|
</div>
|
||||||
<div className="col-9 text-right">
|
<div className="col-9 text-right">
|
||||||
<div className="huge">{user.totalDuration}</div>
|
<div className="huge">{days}</div>
|
||||||
<div>total duration</div>
|
<div>{duration}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,10 +10,19 @@ class Logout extends React.Component {
|
|||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="container dashboard">
|
||||||
<p className="App-center">
|
<div className="row">
|
||||||
|
<div className="col-2" />
|
||||||
|
<div className="card col-8">
|
||||||
|
<div className="card-body">
|
||||||
|
<div className="text-center">
|
||||||
You are now logged out.
|
You are now logged out.
|
||||||
Click <Link to="/login">here</Link> to log back in.</p>
|
Click <Link to="/login">here</Link> to log back in.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-2" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,14 @@ export const getGeoJson = gpxContent => {
|
|||||||
return { jsonData }
|
return { jsonData }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const formatActivityDate = activityDateTime => {
|
export const formatActivityDate = (activityDateTime, dateFormat = null) => {
|
||||||
if (activityDateTime) {
|
if (activityDateTime) {
|
||||||
const dateTime = parse(activityDateTime)
|
const dateTime = parse(activityDateTime)
|
||||||
return {
|
return {
|
||||||
activity_date: format(dateTime, 'DD/MM/YYYY'),
|
activity_date: format(
|
||||||
|
dateTime,
|
||||||
|
dateFormat ? dateFormat : 'DD/MM/YYYY'
|
||||||
|
),
|
||||||
activity_time: activityDateTime.match(/[0-2][0-9]:[0-5][0-9]/)[0]
|
activity_time: activityDateTime.match(/[0-2][0-9]:[0-5][0-9]/)[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user