Skip to content

Commit

Permalink
Enhanced exports.trader and edited trader view page
Browse files Browse the repository at this point in the history
  • Loading branch information
DSRoden committed Aug 31, 2014
1 parent 5349c5b commit 3b93fc7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 16 deletions.
5 changes: 2 additions & 3 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ exports.edit = function(req, res){

exports.update = function(req, res){
res.locals.user.save(req.body, function(){
console.log(req.body);
res.redirect('/profile');
});
};
Expand All @@ -66,9 +65,9 @@ exports.index = function(req, res){
};

exports.trader = function(req, res){
User.findOne({email:req.params.email}, function(err, trader){
User.findOneAndItems({email:req.params.email}, function(err, trader, biddableItems, saleItems){
if(trader){
res.render('users/trader', {trader:trader});
res.render('users/trader', {trader:trader, biddableItems:biddableItems, saleItems:saleItems});
}else{
res.redirect('/users');
}
Expand Down
12 changes: 10 additions & 2 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ User.findAll = function(cb){
User.collection.find().toArray(cb);
};

User.findOne = function(filter, cb){
User.collection.findOne(filter, cb);
User.findOneAndItems = function(filter, cb){
User.collection.findOne(filter, function(err, trader){
console.log(filter);
console.log(trader);
require('./item').collection.find({ownerId:trader._id, isBiddable: true}).toArray(function(err, traderBiddableItems){
require('./item').collection.find({ownerId:trader._id, onSale: true}).toArray(function(err2, traderOnSaleItems){
cb(null, trader, traderBiddableItems, traderOnSaleItems);
});
});
});
};

User.prototype.messages = function(cb){
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/static/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
background-color: white;
}

table#ItemsOnSale.table.table-stribed.table-hover.table-bordered {
border: 3px solid #0f1c3c;
}



41 changes: 34 additions & 7 deletions app/views/users/trader.jade
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,42 @@ extends ../shared/template
block content
.row
.col-xs-12
h2= user.name
h2= trader.name
.row
.col-xs-3
a.thumbnail(href='#')
img(src=user.photo)
img(src=trader.photo)

.row
.col-xs-6
table.table.table-stribed.table-hover.table-bordered Items on Sale
thead
tr
th Photo
th Name
th Something
tbody
each saleItem in saleItems
tr
td
.sale-item-photo(style='background-image: url("#{saleItem.photo}");')
td: a(href='/bid/#{saleItem._id}')=saleItem.name
td
.row
.col-xs-6
table.table.table-stribed.table-hover.table-bordered Items Available
thead
tr
th Photo
th Name
th Something
tbody
each bidItem in biddableItems
tr
td
td= bidItem.name
td

.row
.col-xs-6
table.table.table-striped.table-hover.table-bordered
Expand All @@ -26,15 +57,11 @@ block content
form(role='form', method='post', action='/messages/#{trader._id}')
.row
.col-xs-12
.radio
label
input(type='radio' name='mtype' value='internal')
span Send Internal Message
.form-group
label(for='message') Message:
textarea.form-control#message(name='message', autofocus=true)
input(type='hidden' name='mtype' value='internal')
.form-group
button.btn.btn-info.btn-sm(type='submit') Send Message
.col-xs-12

block scripts
2 changes: 2 additions & 0 deletions test/acceptance/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ describe('users', function(){
.set('cookie', cookie)
.end(function(err, res){
expect(res.status).to.equal(200);
expect(res.text).to.include('Red Wine');
expect(res.text).to.include('White Wine');
done();
});
});
Expand Down
8 changes: 5 additions & 3 deletions test/unit/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ describe('User', function(){
});
});

describe('.findOne', function(){
describe('.findOneAndItems', function(){
it('should find a specific user', function(done){
User.findOne({email:'nodeapptest+bob@gmail.com'}, function(err, user){
expect(user.email).to.equal('nodeapptest+bob@gmail.com');
User.findOneAndItems({email:'nodeapptest+bob@gmail.com'}, function(err, trader, biddableItems, saleItems){
expect(trader.email).to.equal('nodeapptest+bob@gmail.com');
expect(biddableItems).to.have.length(1);
expect(saleItems).to.have.length(1);
done();
});
});
Expand Down

0 comments on commit 3b93fc7

Please sign in to comment.