Skip to content

Commit

Permalink
(FatalBadgers#1) Search by language. Show username and profile pic.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrice10 committed Feb 4, 2015
1 parent 805249a commit 19701f7
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 44 deletions.
36 changes: 16 additions & 20 deletions client/app/search/search.controller.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
'use strict';

angular.module('tikrApp')
.controller('SearchCtrl', function ($scope, $http, $q, User) {
$scope.users = [];
$scope.skills = [];
$scope.hasAllSkills = false;
.controller('SearchCtrl', function($scope, $http, $q, User) {
$scope.users = [];
$scope.skill = 'javascript';
$scope.searchStarted = false;

// returns a promise
$scope.fetchUsers = function(){
return $q(function(resolve, reject){
$scope.users = User.search({'skills': $scope.skills,
'hasAllSkills': $scope.hasAllSkills});
if(!$scope.users){
reject('failed');
} else{
resolve($scope.users);
}
});
};
// returns a promise
$scope.fetchUsers = function() {

$scope.fetchUsers()
.then(function(users){
$scope.users = users;
});
User.search({
skill: $scope.skill
}, function(data) {
$scope.searchStarted = true;
$scope.data = data[0];
$scope.users = $scope.data.items;
});
};

//init
$scope.fetchUsers();
});
17 changes: 17 additions & 0 deletions client/app/search/search.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.odd {
background-color: transparent;
margin-bottom: 12px;
margin-top: 12px;
}

.even {
background-color: #f2f2f2;
border-bottom: 1px solid #dddddd;
border-top: 1px solid #dddddd;
margin-bottom: 12px;
margin-top: 12px;
}

.profile-img {
height: 100px;
}
56 changes: 48 additions & 8 deletions client/app/search/search.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
<div ng-include="'components/navbar/navbar.html'"></div>

<div style='text-align: center;'>
<input type='radio' ng-model='hasAllSkills' ng-value='true'>has all skills</input>
<input type='radio' ng-model='hasAllSkills' ng-value='false'>has at least one of the following skills</input>
<br>
search by skills (comma seperated list)
<input type='text' ng-model='skills' ng-list></input>
Search by language:
<input type='text' ng-model='skill'>
<button ng-click='fetchUsers()'>search</button>
<div>
<div ng-repeat='user in users'>
{{ user.name }}
</div>

<div class="container-fluid app-font">
<div class="row"></div>

<div class="row" style="margin-top:20px;">
<div class="col-sm-2 col-md-2 sidebar left-nav colorBg" style="padding-top: 20px;"></div>

<div class="col-sm-8 col-md-8 col-md-offset-0 main">

<div class="row-fluid" ng-if="(users.length <= 0 || data.errors.length > 0) && searchStarted">
<span>
Your search for<b> {{skill}} </b>did not match any documents...
<br/><br/>
* Suggestions: Make sure all words are spelled correctly.</br>
* Use similar words or synonyms.</br>
* Try more general keywords.
</span>
</div>

<div class="row-fluid main-section" style="min-height:500px" ng-if="users.length > 0 && searchStarted">
<div ng-bind="(data.total_count ? (data.total_count | number) : 0) + ' results found'"></div>

<div class="col-fluid" ng-repeat="user in users track by $index" ng-class-odd="'odd'" ng-class-even="'even'">

<div class="container">
<a href="{{user.html_url}}" target="_blank">
<img class="img-rounded profile-img pull-left" src="{{user.avatar_url}}">
</a>
<div class="text-left">
<label>
<dl class="lead dl-horizontal">

<dt>Username</dt>
<dd><a href="{{user.html_url}}" target="_blank"><b>{{user.login}}</b></a></dd>
</dl>
</label>
</div>
</div>

</div>
</div>

</div>
</div>
</div>



3 changes: 2 additions & 1 deletion client/components/auth/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ angular.module('tikrApp')
isArray: true,
params: {
id: 'me',
controller: 'search'
controller: 'search',
skill: null
}
}
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"passport-github": "^0.1.5",
"passport-local": "~0.1.6",
"passport-twitter": "latest",
"request": "*",
"serve-favicon": "~2.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion server/api/message/message.model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Message Model', function () {
message.should.have.property('content');
message.should.have.property('read');
message.should.have.property('starred');
})
});

it('should begin with no messages', function (done) {
Message.find({}, function (err, messages) {
Expand Down
4 changes: 4 additions & 0 deletions server/api/user/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "application-name",
"version": "0.0.1"
}
35 changes: 21 additions & 14 deletions server/api/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var User = require('./user.model');
var passport = require('passport');
var config = require('../../config/environment');
var jwt = require('jsonwebtoken');
var request = require('request');

var validationError = function(res, err) {
return res.json(422, err);
Expand Down Expand Up @@ -84,22 +85,28 @@ exports.changePassword = function(req, res, next) {
* Query for users by skills
*/
exports.search = function(req, res, next) {
var options = {
url: 'https://api.github.com/search/users?q=+language:' + encodeURIComponent(req.body.skill),
headers: {
'User-Agent': 'scottrice10'
}
};

// return users who have all of the specified skills
if(req.body.hasAllSkills){
User.find({'skills': { $all: req.body.skills}}, '-salt -hashedPassword',
function(err, users) {
if (err) return next(err);
if (!users) return res.json(401);
res.json(users);
});
} else { // return users who have at least one of the skills
User.find({'skills': { $in: req.body.skills }}, '-salt -hashedPassword',
function(err, users) {
if (err) return next(err);
if (!users) return res.json(401);
res.json(users);
});
if(req.body.hasAllSkills && req.body.skill){
//nothing now
} else if(req.body.skill) { // return users who have at least one of the skills
//nothing now
}

request(options , function (error, response, body) {
if (!error) {
res.send([JSON.parse(decodeURIComponent(response.body))]);
} else {
console.log(error);
res.send(500);
}
})
};

/**
Expand Down

0 comments on commit 19701f7

Please sign in to comment.