Changeset 778d53d in OpenWorkouts-current for ow/static/js/ow.js


Ignore:
Timestamp:
Mar 5, 2019, 11:45:32 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
aa6dcaf
Parents:
35953eb
Message:

(#7) Show per-sport stats in the profile page:

  • Show a dropdown list of sports for which the user has activities. By default we choose the sport with most activities.
  • Show a dropdown list of years for which the user has activities. By default we show stats for the current year. If the user picks up a different year, we show the totals (distance, time, elevation, number of workouts) for that year.
  • Show the totals of all time for the chosen sport
File:
1 edited

Legend:

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

    r35953eb r778d53d  
    486486
    487487};
     488
     489
     490owjs.sport_stats = function(spec) {
     491
     492    "use strict";
     493
     494    var link_selector = spec.link_selector;
     495    var stats_selector = spec.stats_selector;
     496    var selected = spec.selected;
     497    var dropdown_selector = spec.dropdown_selector;
     498    var current_year = spec.current_year;
     499    var year_link_selector = spec.year_link_selector;
     500
     501    var setup = function setup() {
     502        // Hide all sports stats by default
     503        $(stats_selector).hide();
     504        // Show the pre-selected one
     505        $(selected).show();
     506
     507        $(link_selector).on('click', function(e) {
     508            e.preventDefault();
     509            var selected = $(this).attr('class').split(' ')[1];
     510            var sport = selected.split('-')[1]
     511            // Hide them all
     512            $(stats_selector).hide();
     513            // Show the selected one
     514            $(stats_selector + '.' + selected).show();
     515            // Update the sport on the sports selector widget
     516            $(dropdown_selector + ' strong').html(sport);
     517            // finally "click" on the proper year to be displayed for this sport
     518            $(year_link_selector + sport + '-' + current_year).click();
     519        });
     520    };
     521
     522    var that = {}
     523    that.setup = setup;
     524    return that
     525
     526};
     527
     528
     529owjs.year_stats = function(spec) {
     530
     531    "use strict";
     532
     533    var link_selector = spec.link_selector;
     534    var stats_selector = spec.stats_selector;
     535    var selected = spec.selected;
     536    var dropdown_selector = spec.dropdown_selector;
     537
     538    var setup = function setup() {
     539        // Hide all years stats by default
     540        $(stats_selector).hide();
     541        // Show the pre-selected one
     542        $(selected).show();
     543
     544        $(link_selector).on('click', function(e) {
     545            e.preventDefault();
     546            var selected = $(this).attr('class').split(' ')[1];
     547            var sport = selected.split('-')[1]
     548            var year = selected.split('-')[2]
     549            // Hide them all
     550            $(stats_selector).hide();
     551            // Show the selected one
     552            $(stats_selector + '.' + selected).show();
     553            // Update the year on the years selector widget
     554            $(dropdown_selector + sport + ' strong').html(year);
     555        });
     556    };
     557
     558    var that = {}
     559    that.setup = setup;
     560    return that
     561
     562};
Note: See TracChangeset for help on using the changeset viewer.