fitness-widget.js

angular.module('homepage').
directive('fitnessWidget', function () {
    return {
        restrict: 'E',
        replace: true,
        scope: {
        	data: '='
        },
        transclude: true,
        templateUrl: 'components/feature-components/fitness/fitness-widget.html'
    };
}).
filter('workoutSummary', function () {
    function getWorkoutSummary(workout) {
        var text = "";
        if(workout.sets) {
            for (var index in workout.sets) {
                var set = workout.sets[index];
                if(set.repetition !== "") {
                    text += set.repetition;
                    if(set.weight !== "") {
                        text += "(" + set.weight + ")";
                    }
                    else if(set.distance !== "") {
                        text += "(" + set.distance + ")";
                    }
                    else if(set.time !== "") {
                        text += "(" + set.time + ")";
                    }
                }
                else if(set.distance !== "") {
                    text += set.distance;
                    if(set.time !== "") {
                        text += "(" + set.time + ")";
                    }
                }
                else if(set.weight !== "") {
                    text += set.weight;
                    if(set.time !== "") {
                        text += "(" + set.time + ")";
                    }
                }
                else if(set.time !== "") {
                    text += set.time;
                }

                if(index < (workout.sets.length - 1)) {
                    text += ", ";
                }
            }
        }
        return text;
    }
    return getWorkoutSummary;
});