Skip to content

Commit

Permalink
search updated and working
Browse files Browse the repository at this point in the history
  • Loading branch information
bpiv400 committed Dec 3, 2017
1 parent e0041a4 commit 72eb257
Show file tree
Hide file tree
Showing 37 changed files with 1,190 additions and 104 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var create = require('./routes/create');
var view = require('./routes/view');
var images = require('./routes/images');
var search = require('./routes/search');
var results = require('./routes/results');


var handleError = require('./middlewares/handleError.js');

Expand All @@ -37,6 +39,7 @@ app.use('/create', create);
app.use('/view', view);
app.use('/images', images);
app.use('/search', search);
app.use('/results', results);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion data/db/WiredTiger.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ WiredTiger 2.9.2: (December 23, 2016)
WiredTiger version
major=2,minor=9,patch=2
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,block_allocation=best,block_compressor=,cache_resident=false,checkpoint=(WiredTigerCheckpoint.103=(addr="018981e49cbbaf348a81e44460bf888b81e489110c40808080e3010fc0e23fc0",order=103,time=1511925349,size=28672,write_gen=204)),checkpoint_lsn=(3,17018624),checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1)
access_pattern_hint=none,allocation_size=4KB,app_metadata=,block_allocation=best,block_compressor=,cache_resident=false,checkpoint=(WiredTigerCheckpoint.109=(addr="018981e4b43d4c448a81e44460bf888b81e489110c40808080e3010fc0e23fc0",order=109,time=1512204214,size=28672,write_gen=216)),checkpoint_lsn=(3,17271040),checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1)
Binary file modified data/db/WiredTiger.wt
Binary file not shown.
Binary file modified data/db/collection-0-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/collection-10-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/collection-8-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/index-1-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/index-11-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/index-9-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/journal/WiredTigerLog.0000000003
Binary file not shown.
Binary file modified data/db/sizeStorer.wt
Binary file not shown.
29 changes: 28 additions & 1 deletion data/listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,32 @@ module.exports = {
callback(error, listing, address, photos);
}
});
}
},
getSearchResults: function(constraints, callback) {
console.log(constraints.limit);
console.log(constraints.page);
console.log(constraints.sort);
mongo.Listings.find({}).
limit(constraints.limit).
skip(constraints.limit * (constraints.page - 1)).
sort(constraints.sort).
populate('address').
exec(function (error, listings) {
if (error) {
callback(error, listings, null);
} else {
var addresses = Array();
listings = listings.map(function(listing) {
var out = listing.toObject();
delete out.address.__v;
delete out.address._id;
addresses.push(out.address);
delete out.address;
delete out.__v;
return out;
});
callback(error, listings, addresses);
}
});
}
};
675 changes: 675 additions & 0 deletions data/log/mongod.log

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/mongo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://127.0.0.1:27017/penn-leases', function (err) {
if (err && err.message.includes('ECONNREFUSED')) {
console.log('Error connecting to mongodb database: %s.\nIs "mongod" running?', err.message);
Expand Down
30 changes: 30 additions & 0 deletions routes/results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var express = require('express');
var router = express.Router();
var listingDb = require('../data/listings');


/* GET home page. */
router.get('/', function(req, res, next) {
var constraints = {
page : parseInt(req.query.pg),
limit : parseInt(req.query.lim)
};
constraints.restrictions = {};
var sort ={};
sort[req.query.srt] = parseInt(req.query.ord);
constraints.sort = sort;
listingDb.getSearchResults(constraints,
function(error, listings, addresses) {
if (error) {
next(error);
} else {
res.json({
listings: listings,
addresses: addresses
});
}
}
);
});

module.exports = router;
10 changes: 10 additions & 0 deletions search/package-lock.json

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

4 changes: 3 additions & 1 deletion search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"private": true,
"dependencies": {
"axios": "^0.17.1",
"bootstrap": "^3.3.7",
"jquery": "^3.2.1",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-scripts": "1.0.17",
Expand All @@ -15,5 +17,5 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3000"
"proxy": "http://localhost:3001"
}
70 changes: 0 additions & 70 deletions search/public/components/Preview.js

This file was deleted.

8 changes: 0 additions & 8 deletions search/public/components/ResultsContainer.js

This file was deleted.

6 changes: 0 additions & 6 deletions search/public/initialState.js

This file was deleted.

File renamed without changes.
File renamed without changes.
75 changes: 75 additions & 0 deletions search/src/components/Preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';

export default class Preview extends React.Component {
constructor() {
super();
this.onPreviewClick = this.onPreviewClick.bind(this);
}

onPreviewClick() {
console.log('preview clicked');
}

render() {
let addressTitle = this.props.address.streetNumber + ' ' +
this.props.address.street;
if (this.props.address.unit) {
addressTitle = addressTitle + this.props.address.unit;
}
//TODO: Determine whether this needs to be changed when
// going to production -- understand how react is communicating
// with the server better
let imgSource = null;
if (this.props.photos) {
imgSource = "/images/?id=" + this.props.photos[0];
}
let viewLink = "/view/" + this.props.id;
let availability ="";
for (let i = 0; i < this.props.availability.length; i++) {
availability = availability + this.props.availability[i];
if (i < this.props.availability.length - 1) {
availability = availability + ', ';
}
}
let price = "$" + this.props.price;
let location = (this.props.buildingName) ? this.props.buildingName :
(this.props.housingType === 'House') ? 'House' : 'Apartment';
return (
<a href = {viewLink}>
<div className="panel panel-default container"
onClick = {(e) => this.onPreviewClick(e)}>
<div className="panel-heading">
<h3 className="panel-title">{addressTitle}</h3>
</div>
<div className="panel-body">
<div className='container'>
<div className="row">
<div className="col-xs-4">

{ this.props.photos
? <img src={imgSource} className = "img-fluid
img-thumbnail"
alt='preview of property'>
</img>
: null
}
</div>
<div className="col-xs-8">
<dl className="row">
<dt className="col-xs-3">Availability</dt>
<dd className="col-xs-9">{availability}</dd>

<dt className="col-xs-3">Price</dt>
<dd className="col-xs-9">{price}</dd>

<dt className="col-xs-3">Location</dt>
<dd className="col-xs-9">{location}</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
</a>);
}
}
48 changes: 48 additions & 0 deletions search/src/components/ResultsContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import Preview from './Preview';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
import * as initialState from '../initialState';

window.jQuery = window.$ = require('jquery');


export default class ResultsContainer extends React.Component {
constructor(props) {
super(props);
console.log(this.props.store.getState());
this.state = this.props.store.getState();
}


componentDidMount() {
this.props.store.subscribe(function () {
this.setState(this.props.store.getState());
}.bind(this));
}

render() {
var resultsArray = Array();
for (var i = 0; i < this.state.listings.length; i++) {
console.log(this.state.listings[i]);
const currResult = (<Preview
key = {i}
housingType = {this.state.listings[i].housingType}
address = {this.state.addresses[i]}
photos = {this.state.listings[i].photos}
availability = {this.state.listings[i].term}
buildingName = {this.state.listings[i].buildingName}
price = {this.state.listings[i].price}
id = {this.state.listings[i]._id}>
</Preview>);
resultsArray.push(currResult);
}
return (
<div className='results-container container'>
<div className='results'>
{resultsArray}
</div>
</div>
);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added search/src/fonts/glyphicons-halflings-regular.eot
Binary file not shown.
Loading

0 comments on commit 72eb257

Please sign in to comment.