Skip to content

Commit

Permalink
(FatalBadgers#1) Display repo information in user search results.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrice10 committed Feb 4, 2015
1 parent 19de986 commit 85db8ed
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 77 deletions.
18 changes: 0 additions & 18 deletions client/app/main/main.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@

angular.module('tikrApp')
.controller('MainCtrl', function ($scope, $http, $window, Auth) {
$scope.awesomeThings = [];

$http.get('/api/things').success(function(awesomeThings) {
$scope.awesomeThings = awesomeThings;
});

$scope.isLoggedIn = Auth.isLoggedIn;

$scope.addThing = function() {
if($scope.newThing === '') {
return;
}
$http.post('/api/things', { name: $scope.newThing });
$scope.newThing = '';
};

$scope.loginOauth = function(provider) {
$window.location.href = '/auth/' + provider;
};

$scope.deleteThing = function(thing) {
$http.delete('/api/things/' + thing._id);
};
});
9 changes: 1 addition & 8 deletions client/app/main/main.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ describe('Controller: MainCtrl', function () {
beforeEach(module('tikrApp'));

var MainCtrl,
scope,
$httpBackend;
scope;

// Initialize the controller and a mock scope
beforeEach(inject(function (_$httpBackend_, $controller, $rootScope) {
$httpBackend = _$httpBackend_;
$httpBackend.expectGET('/api/things')
.respond(['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express']);

scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl', {
$scope: scope
});
}));

it('should attach a list of things to the scope', function () {
$httpBackend.flush();
expect(scope.awesomeThings.length).toBe(4);
});
});
9 changes: 5 additions & 4 deletions client/app/search/search.controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

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

// returns a promise
$scope.fetchUsers = function(language) {
User.search({
skill: language
skill: language,
username: $scope.TEST_USER || Auth.getCurrentUser().github.login
}, function(data) {
$scope.searchStarted = true;
$scope.data = data[0];
Expand All @@ -22,7 +23,7 @@ angular.module('tikrApp')
$scope.languages = [];
$http.get('/api/languages').success(function(data) {
data.forEach(function(language) {
$scope.languages.push(language.Name + " ");
$scope.languages.push(language.Name);
});

if(!input){
Expand All @@ -32,7 +33,7 @@ angular.module('tikrApp')
var filtered = [];
$scope.languages.forEach(function(language) {
if(language.toLowerCase().indexOf(input.toLowerCase()) !== -1) {
filtered.push(language + " ");
filtered.push(language);
}
});

Expand Down
1 change: 1 addition & 0 deletions client/app/search/search.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Controller: SearchCtrl', function() {
}));

it('should be able to fetch all users by language = javascript', function() {
$scope.TEST_USER = 'scottrice10';
createController();
var searchInput = null;

Expand Down
14 changes: 13 additions & 1 deletion client/app/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@
<dl class="lead dl-horizontal">

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

<dt>Sample work</dt>
<dd>
<a ng-repeat="repo in user.repos" href="{{repo.html_url}}" target="_blank">
<b>{{repo.name}}{{$last ? '' : ', '}} </b>
</a>
</dd>

</dl>
</label>
</div>
Expand Down
18 changes: 9 additions & 9 deletions client/app/skills/skills.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ Note: This is a template copied from main

angular.module('tikrApp')
.controller('SkillsCtrl', function ($scope, $http, Auth) {
$scope.awesomeThings = [];
$scope.awesomekills = [];

$http.get('/api/things').success(function(awesomeThings) {
$scope.awesomeThings = awesomeThings;
$http.get('/api/skills').success(function(awesomeSkills) {
$scope.awesomeSkills = awesomeSkills;
});

$scope.isCollapsed = true;
$scope.isLoggedIn = Auth.isLoggedIn;
$scope.isAdmin = Auth.isAdmin;
$scope.getCurrentUser = Auth.getCurrentUser;

$scope.addThing = function() {
if($scope.newThing === '') {
$scope.addSkill = function() {
if($scope.newSkill === '') {
return;
}
$http.post('/api/things', { name: $scope.newThing });
$scope.newThing = '';
$http.post('/api/skills', { name: $scope.newSkills });
$scope.newSkill = '';
};

$scope.loginOauth = function(provider) {
$window.location.href = '/auth/' + provider;
};

$scope.deleteThing = function(thing) {
$http.delete('/api/things/' + thing._id);
$scope.deleteSkill = function(skill) {
$http.delete('/api/skills/' + skill._id);
};
});
13 changes: 5 additions & 8 deletions client/app/skills/skills.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ describe('Controller: SkillsCtrl', function () {
// load the controller's module
beforeEach(module('tikrApp'));

var MainCtrl,
scope,
$httpBackend;
var scope, $httpBackend, SkillsCtrl;

// Initialize the controller and a mock scope
beforeEach(inject(function (_$httpBackend_, $controller, $rootScope) {
$httpBackend = _$httpBackend_;
$httpBackend.expectGET('/api/things')
$httpBackend.expectGET('/api/skills')
.respond(['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express']);

scope = $rootScope.$new();
Expand All @@ -24,8 +22,7 @@ describe('Controller: SkillsCtrl', function () {
});
}));

// it('should attach a list of things to the scope', function () {
// $httpBackend.flush();
// expect(scope.awesomeThings.length).toBe(4);
// });
it('should attach a list of skills to the scope', function () {

});
});
3 changes: 2 additions & 1 deletion client/components/auth/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ angular.module('tikrApp')
params: {
id: 'me',
controller: 'search',
skill: null
skill: null,
username: null
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function(config) {
preprocessors: {
'**/*.jade': 'ng-jade2js',
'**/*.html': 'html2js',
'**/*.coffee': 'coffee',
'**/*.coffee': 'coffee'
},

ngHtml2JsPreprocessor: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"passport-local": "~0.1.6",
"passport-twitter": "latest",
"request": "*",
"serve-favicon": "~2.0.1"
"serve-favicon": "~2.0.1",
"bluebird": "*"
},
"devDependencies": {
"connect-livereload": "~0.4.0",
Expand Down
16 changes: 16 additions & 0 deletions server/api/skills/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var express = require('express');
var controller = require('./skills.controller');

var router = express.Router();

router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);

module.exports = router;

13 changes: 13 additions & 0 deletions server/api/skills/skill.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var SkillSchema = new Schema({
name: String,
info: String,
active: Boolean
});

module.exports = mongoose.model('Skill', SkillSchema);

68 changes: 68 additions & 0 deletions server/api/skills/skills.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Using Rails-like standard naming convention for endpoints.
* GET /skills -> index
* POST /skills -> create
* GET /skills/:id -> show
* PUT /skills/:id -> update
* DELETE /skills/:id -> destroy
*/

'use strict';

var _ = require('lodash');
var Skill = require('./skill.model');

// Get list of skills
exports.index = function(req, res) {
Skill.find(function (err, skills) {
if(err) { return handleError(res, err); }
return res.json(200, skills);
});
};

// Get a single skill
exports.show = function(req, res) {
Skill.findById(req.params.id, function (err, skill) {
if(err) { return handleError(res, err); }
if(!skill) { return res.send(404); }
return res.json(skill);
});
};

// Creates a new skill in the DB.
exports.create = function(req, res) {
Skill.create(req.body, function(err, skill) {
if(err) { return handleError(res, err); }
return res.json(201, skill);
});
};

// Updates an existing skill in the DB.
exports.update = function(req, res) {
if(req.body._id) { delete req.body._id; }
Skill.findById(req.params.id, function (err, skill) {
if (err) { return handleError(res, err); }
if(!skill) { return res.send(404); }
var updated = _.merge(skill, req.body);
updated.save(function (err) {
if (err) { return handleError(res, err); }
return res.json(200, skill);
});
});
};

// Deletes a skill from the DB.
exports.destroy = function(req, res) {
Skill.findById(req.params.id, function (err, skill) {
if(err) { return handleError(res, err); }
if(!skill) { return res.send(404); }
skill.remove(function(err) {
if(err) { return handleError(res, err); }
return res.send(204);
});
});
};

function handleError(res, err) {
return res.send(500, err);
}
20 changes: 20 additions & 0 deletions server/api/skills/skills.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var should = require('should');
var app = require('../../app');
var request = require('supertest');

describe('GET /api/skills', function() {

it('should respond with JSON array', function(done) {
request(app)
.get('/api/skills')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
done();
});
});
});
Loading

0 comments on commit 85db8ed

Please sign in to comment.