-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
591 additions
and
5,233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
components | ||
_dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
app.controller('HubSearchController', function($scope, $routeParams, $location, debug) { | ||
var log = debug('app:hubSearch'); | ||
$scope.query = $routeParams.query; | ||
$scope.language = $routeParams.lang; | ||
|
||
$scope.updateQuery = function(lang, query) { | ||
lang = lang || 'all'; | ||
$location.path('/'+lang+'/'+query); | ||
}; | ||
|
||
$scope.$on('$routeChangeSuccess', function(event, route, previousRoute) { | ||
log('route changed', route); | ||
$scope.query = route.params.query; | ||
$scope.language = $routeParams.lang; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
app.controller('SearchResultsController', function($scope, github, debug) { | ||
var log = debug('app:searchResults'); | ||
|
||
$scope.sortKey = '-forks'; | ||
$scope.searching = false; | ||
$scope.repos = []; | ||
|
||
$scope.$watch('query', function() { | ||
search($scope.query, $scope.language); | ||
}); | ||
$scope.$watch('language', function() { | ||
search($scope.query, $scope.language); | ||
}); | ||
|
||
var search = function(query, lang) { | ||
log('query', query); | ||
$scope.searching = true; | ||
github | ||
.search(query, lang) | ||
.then(function(response) { | ||
log('results', response); | ||
$scope.repos = response; | ||
$scope.searching = false; | ||
}); | ||
}; | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
app.controller('SearchBoxController', function($rootScope, $scope, debug) { | ||
var log = debug('app:searchBox'); | ||
|
||
$scope.languages = _languages; | ||
$scope.inputLanguage = localStorage.getItem('lang') || _languages[0]; | ||
|
||
$scope.$watch('query', function() { | ||
$scope.inputQuery = $scope.query; | ||
}); | ||
|
||
$scope.$watch('language', function() { | ||
if (!$scope.language) { | ||
return; | ||
} | ||
$scope.inputLanguage = $scope.language; | ||
}); | ||
|
||
$scope.onSubmit = function() { | ||
log('submit', $scope.inputLanguage, $scope.inputQuery); | ||
localStorage.setItem('lang', $scope.inputLanguage); | ||
$scope.updateQuery($scope.inputLanguage, $scope.inputQuery); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
window.app = angular.module('hubSearch', ['ui']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
app.factory('debug', function() { | ||
return function() { | ||
return debug.apply(debug, arguments); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
app.factory('github', ['$http', 'score', 'utils', function($http, score, utils) { | ||
return { | ||
search: function(query, language) { | ||
if (language) { | ||
language = '&language='+language; | ||
} else { | ||
language = ''; | ||
} | ||
return $http | ||
//.get('/fixtures/results.json') | ||
.jsonp('https://api.github.com/legacy/repos/search/'+query+'?callback=JSON_CALLBACK'+language) | ||
.then(function(response) { | ||
var repos = response.data.data.repositories; | ||
utils.each(repos, function(repo, index) { | ||
var result = score(repo, index); | ||
repo.score = result.value; | ||
repo.githubRank = index+1; | ||
}); | ||
return repos; | ||
}); | ||
} | ||
}; | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
app.config(function($routeProvider, $locationProvider) { | ||
$routeProvider | ||
.when('/:lang/:query', { | ||
controller: 'SearchResultsController', | ||
templateUrl: 'searchResults.html' | ||
}) | ||
.otherwise({ redirectTo: '' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
app.factory('utils', function() { | ||
return { | ||
each: function(arr, cb) { | ||
for (var i = 0, c = arr.length; i < c; i++) { | ||
var item = arr[i]; | ||
cb(item, i); | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "hubsearch", | ||
"dependencies": { | ||
"angular": "*", | ||
"jquery": "1.8.3", | ||
"angular-ui": "~0.3.1", | ||
"select2": "~3.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.