-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
55 lines (47 loc) · 1.66 KB
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var fitnessApp = angular.module('fitnessApp', [ 'ngResource','ui.router' ]);
fitnessApp.config(function($stateProvider){
$stateProvider.state('exercise', {
url: '/exercise?userId',
templateUrl: 'exercises.html',
controller: 'FitnessController',
});
$stateProvider.state('fat', {
url: '/fat?userId',
templateUrl: 'fat.html',
controller: 'FitnessController',
});
})
fitnessApp.controller('FitnessController', ['$scope', '$stateParams','$http', '$timeout', function($scope, $stateParams, $http, $timeout) {
var json;
var userResourceUrl =
"https://raw.githubusercontent.com/FreeFitness/fitness-log-users/master/users.json";
$scope.$on('$viewContentLoaded',
function(event){
$timeout(function () {
drawExerciseChart();
}, 100);
});
$http({
url: userResourceUrl,
method: "GET"
}).success(function(data, status, headers, config) {
if ($stateParams.userId === undefined) {
$scope.userData = data['henry'];
} else {
$scope.userData = data[$stateParams.userId];
}
$scope.users = data;
$http({
url: $scope.userData['resource'] + 'strength.json',
method: "GET"
}).success(function(data, status, headers, config) {
$scope.strengths = data;
$scope.id = $stateParams.userId;
}).error(function(data, status, headers, config) {
$scope.status = status;
});
}).error(function(data, status, headers, config) {
$scope.status = status;
});
$scope.foo = "bar";
}]);