fitness-panel.js

angular.module('homepage').
directive('fitnessPanel', function () {
	return {
		controller: 'fitnessPanelController',
		restrict: 'E',
		replace: true,
		scope: {
			fitness: '='
		},
		templateUrl: 'components/feature-components/fitness/fitness-panel.html'
	}
}).
controller('fitnessPanelController', function ($scope) {
	function Set() {
		return {
			repetition: '',
			weight: '',
			time: '',
			distance: ''
		}
	}

	function setItem() {
		return {
			workouttitle: '',
			sets: [
				new Set()
			]
		}
	}

	// Initialize list of fitness and its sets list
	$scope.fitness.list = [
		setItem()
	];

	/**
	 * Remove the item from zeroth index and add it to list end and empty zeroth index
	 */
	$scope.addNewItem = function () {
		var length = $scope.fitness.list.length;
		$scope.fitness.list[length] = $scope.fitness.list[0];
		$scope.fitness.list[0] = setItem();
	};
});