Changeset 4678c5e in OpenWorkouts-current


Ignore:
Timestamp:
Apr 23, 2019, 6:41:11 PM (4 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
e57b2df
Parents:
9f3c353
Message:

(#71) Keep the "distance/time/elevation" filter when clicking on bars
in the profile yearly stats chart

Location:
ow
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ow/static/js/ow.js

    r9f3c353 r4678c5e  
    403403                })
    404404                .on('click', function(d) {
    405                     window.location.href = d.url;
     405                    window.location.href = d.url+'&filter_by='+filter_by;
    406406                });
    407407
  • ow/templates/profile.pt

    r9f3c353 r4678c5e  
    111111            <div class="center">
    112112              <ul class="workout-options filters js-filters">
    113                 <li><a href="#" class="js-distance is-active" i18n:translate="">distance</a></li>
    114                 <li><a href="#" class="js-time" i18n:translate="">time</a></li>
    115                 <li><a href="#" class="js-elevation" i18n:translate="">elevation</a></li>
     113                <li>
     114                  <a href="#" class="js-distance is-active"
     115                     tal:attributes="class 'js-distance is-active' if filter_by == 'distance' else 'js-distance'"
     116                     i18n:translate="">distance</a>
     117                </li>
     118                <li>
     119                  <a href="#" class="js-time"
     120                     tal:attributes="class 'js-time is-active' if filter_by == 'time' else 'js-time'"
     121                     i18n:translate="">time</a>
     122                </li>
     123                <li>
     124                  <a href="#" class="js-elevation"
     125                     tal:attributes="class 'js-elevation is-active' if filter_by == 'elevation' else 'js-elevation'"
     126                     i18n:translate="">elevation</a>
     127                </li>
    116128              </ul>
    117129
     
    520532         current_week: "${current_week}",
    521533         y_axis_labels: y_axis_labels,
    522          filter_by: "distance",
     534         filter_by: "${filter_by}",
    523535         url: "${'monthly' if current_week is None else 'weekly'}",
    524536     });
    525      year_chart.render("distance", "${'monthly' if current_week is None else 'weekly'}");
     537     year_chart.render("${filter_by}", "${'monthly' if current_week is None else 'weekly'}");
    526538     year_chart.filters_setup();
    527539     year_chart.switcher_setup();
  • ow/tests/views/test_user.py

    r9f3c353 r4678c5e  
    414414        # profile page for the current day (no workouts avalable)
    415415        response = user_views.profile(john, request)
    416         assert len(response.keys()) == 7
     416        assert len(response.keys()) == 8
    417417        current_month = datetime.now(timezone.utc).strftime('%Y-%m')
    418418        assert response['user'] == john
     
    432432            'current_sport': 'cycling'
    433433        }
     434        assert response['filter_by'] == 'distance'
    434435        # profile page for a previous date, that has workouts
    435436        request.GET['year'] = 2015
    436437        request.GET['month'] = 6
    437438        response = user_views.profile(john, request)
    438         assert len(response.keys()) == 7
     439        assert len(response.keys()) == 8
    439440        assert response['user'] == john
    440441        assert response['user_gender'] == 'Robot'
     
    448449            'elevation': Decimal(0)
    449450        }
    450         # same, passing a week, first on a week without workouts
     451        assert response['filter_by'] == 'distance'
     452        # same request, but passing a filter_by value
     453        request.GET['filter_by'] = 'time'
     454        response = user_views.profile(john, request)
     455        assert len(response.keys()) == 8
     456        assert response['filter_by'] == 'time'
     457        # same, passing a week, first on a week without workouts,
     458        # keeping the modified filter_by GET param
    451459        request.GET['year'] = 2015
    452460        request.GET['month'] = 6
    453461        request.GET['week'] = 25
    454462        response = user_views.profile(john, request)
    455         assert len(response.keys()) == 7
     463        assert len(response.keys()) == 8
    456464        assert response['user'] == john
    457465        assert response['user_gender'] == 'Robot'
     
    464472            'elevation': Decimal(0)
    465473        }
    466         # now in a week with workouts
     474        assert response['filter_by'] == 'time'
     475        # now in a week with workouts, changing the filter_by again
    467476        request.GET['year'] = 2015
    468477        request.GET['month'] = 6
    469478        request.GET['week'] = 26
     479        request.GET['filter_by'] = 'elevation'
    470480        response = user_views.profile(john, request)
    471         assert len(response.keys()) == 7
     481        assert len(response.keys()) == 8
    472482        assert response['user'] == john
    473483        assert response['user_gender'] == 'Robot'
     
    481491            'elevation': Decimal(0)
    482492        }
     493        assert response['filter_by'] == 'elevation'
    483494
    484495    def test_profile_with_nickname(self, dummy_request, john):
  • ow/views/user.py

    r9f3c353 r4678c5e  
    284284    month = int(request.GET.get('month', now.month))
    285285    week = request.GET.get('week', None)
     286    # filter_by can be 'distance', 'time' or 'elevation', defaults to
     287    # 'distance' if no value is provided
     288    filter_by = request.GET.get('filter_by', 'distance')
    286289    workouts = user.workouts(year, month, week)
    287290    totals = {
     
    321324        'current_week': week,
    322325        'totals': totals,
    323         'profile_stats': profile_stats
     326        'profile_stats': profile_stats,
     327        'filter_by': filter_by
    324328    }
    325329
Note: See TracChangeset for help on using the changeset viewer.