-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserController.js
More file actions
43 lines (34 loc) · 1.28 KB
/
userController.js
File metadata and controls
43 lines (34 loc) · 1.28 KB
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
(function () {
var app = angular.module('githubViewer');
var userControlller = function ($scope, $http, $log,
$location, $routeParams, github, httpTest) {
var onReposComplete = function (response) {
$log.log('Got repos');
$scope.repos = response;
};
var onUserComplete = function (response) {
$log.log(response);
$scope.user = response;
githubmod.getRepos($scope.username)
.then(onReposComplete, onError);
// $http.get("https://api.github.com/users/" + username +"/repos");
// $log.log('get repos');
// httpTest.getRepos($scope.username)
// .then(onReposComplete, onError);
};
var onError = function (reason) {
$log.log(reason);
$scope.error = "Could not fetch the data: " + reason;
};
// httpTest returns mock data
// use github to get the actual data
var githubmod = github; // httpTest; // or github
console.log('search for user: ', $routeParams.username);
$scope.username = $routeParams.username;
githubmod.getUser($scope.username).then(onUserComplete, onError);
$scope.sortOrder = "-stargazers_count";
console.log('Executing user controller');
};
console.log('Adding user controller');
app.controller('userController', userControlller);
})();