Skip to content

Commit

Permalink
Merge pull request #5 from YURAresearch/master
Browse files Browse the repository at this point in the history
get all changes
  • Loading branch information
Surya Dutta authored Nov 12, 2017
2 parents 8cdc39c + 5f66352 commit 4a0d59d
Show file tree
Hide file tree
Showing 46 changed files with 22,595 additions and 11,831 deletions.
8 changes: 6 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var config = require('./bin/config');
var depts = require('./bin/departments');
var cas = require('./bin/cas');
var session = require('express-session')
var ua = require('universal-analytics');
//var ua = require('universal-analytics');

var app = express();

Expand Down Expand Up @@ -51,7 +51,7 @@ app.use(session({

var user = "";
var auth = cas(config.host, config.port);
app.use(ua.middleware("UA-63178606-6", {cookieName: '_ga'}));
//app.use(ua.middleware("UA-63178606-6", {cookieName: '_ga'}));

app.get('/logout', function(req, res) {
req.session.destroy(function(err) {
Expand All @@ -61,6 +61,10 @@ app.get('/logout', function(req, res) {
});
});

app.get('/database',function(req,res){
res.redirect('/');
});

app.get('/users', auth.bounce, users);

app.get('/listings', auth.bounce, listings);
Expand Down
2 changes: 0 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"name": "YURAResearchDatabase",
"description": "",
"scripts": {
},
"env": {
Expand Down
7 changes: 4 additions & 3 deletions bin/departments.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var social_sciences = [
'Environmental Studies',
'Ethics, Politics, and Economics',
'Global Affairs',
'Linguistings',
'Linguistics',
'Political Science',
'Psychology',
'Sociology',
Expand All @@ -43,7 +43,7 @@ var humanities = [
'History',
'Humanities',
'Philosophy',
'Religious Studies'
'Religious Studies',
];

var languages_cultures = [
Expand Down Expand Up @@ -92,7 +92,8 @@ var graduate_professional_schools = [
'Biostatistics (School of Public Health)',
'Environmental Health Studies (School of Public Health)',
'Epidemiology of Microbial Diseases (School of Public Health)',
'School of Forestry and Environmental Studies'
'School of Forestry and Environmental Studies',
'Divinity School'
];

var depts = {
Expand Down
21 changes: 11 additions & 10 deletions models/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,40 @@ function callbackData(query, callback) {
//listing functions

function searchHandler(searchString) {
searchString = searchString.replace(/[^a-zA-Z0-9 ]/g, '');
var searchArray = searchString.split(' ');
var searchQuery = "";
for (var i = 0; i < searchArray.length; i++) {
searchQuery = searchQuery + searchArray[i] + '&';
searchQuery = searchQuery + searchArray[i].replace(/'/g, '"') + '&';
}
searchQuery = searchQuery.substring(0, searchQuery.length-1);
return searchQuery;
}

function escapeRegExp(str) {
function escapeRegExpDept(str) {
return str = str.replace(/\(/g, "\\\\(").replace(/\)/g, "\\\\)");
}

function saveSearch(searchQuery, deptFilter){
db.query("INSERT INTO searches (search_query, department_filter, datetime) VALUES ('" + searchQuery + "', '" + deptFilter + "', CURRENT_TIMESTAMP);");
function saveSearch(searchQuery, deptFilter, countListings, netIDhash){
db.query("INSERT INTO searches (search_query, department_filter, datetime, listing_count, netid_hash) VALUES ('" + searchQuery + "', '" + deptFilter + "', CURRENT_TIMESTAMP, "+countListings+",'"+netIDhash+"');");
}

//(to_tsvector(coalesce(listings.name, '')) || to_tsvector(coalesce(listings.description, '')) || to_tsvector(coalesce(listings.keywords, '')) || to_tsvector(coalesce(listings.departments, '')))

function getAllListings(netID, callback) {
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),name,departments", callback);
}

function searchListings(searchString, netID, callback) {
saveSearch(searchString, "");
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings WHERE (to_tsvector(listings.name) @@ to_tsquery('"+searchHandler(searchString)+"') OR to_tsvector(listings.description) @@ to_tsquery('"+searchHandler(searchString)+"') OR to_tsvector(listings.keywords) @@ to_tsquery('"+searchHandler(searchString)+"')) ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),(SELECT CASE WHEN (ts_rank(to_tsvector(listings.departments), to_tsquery('"+searchHandler(searchString)+"'))) > 0 THEN 1 ELSE 0 END) DESC, listings.custom_desc DESC,(SELECT ts_rank(to_tsvector(listings.name), to_tsquery('"+searchHandler(searchString)+"'))) DESC,(SELECT ts_rank(to_tsvector(listings.description), to_tsquery('"+searchHandler(searchString)+"'))) DESC, (SELECT ts_rank(to_tsvector(listings.keywords), to_tsquery('"+searchHandler(searchString)+"'))) DESC,name,departments", callback);
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings WHERE ((to_tsvector(coalesce(listings.name, '')) || to_tsvector(coalesce(listings.description, '')) || to_tsvector(coalesce(listings.keywords, '')) || to_tsvector(coalesce(listings.departments, ''))) @@ to_tsquery('"+searchHandler(searchString)+"')) ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),(SELECT CASE WHEN (ts_rank(to_tsvector(listings.departments), to_tsquery('"+searchHandler(searchString)+"'))) > 0 THEN 1 ELSE 0 END) DESC, listings.custom_desc DESC,(SELECT ts_rank(to_tsvector(listings.name), to_tsquery('"+searchHandler(searchString)+"'))) DESC,(SELECT ts_rank(to_tsvector(listings.description), to_tsquery('"+searchHandler(searchString)+"'))) DESC, (SELECT ts_rank(to_tsvector(listings.keywords), to_tsquery('"+searchHandler(searchString)+"'))) DESC,name,departments", callback);
}

function filterDepts(deptString, netID, callback) {
saveSearch("",deptString);
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings WHERE departments ~* E'" + escapeRegExp(deptString) + ";' ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),listings.custom_desc DESC,name,departments", callback);
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings WHERE departments ~* E'" + escapeRegExpDept(deptString) + ";' ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),listings.custom_desc DESC,name,departments", callback);
}

function searchANDfilter(searchString, deptString, netID, callback) {
saveSearch(searchString, deptString);
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings WHERE departments ~* E'" + escapeRegExp(deptString) + ";' AND (to_tsvector(listings.name) @@ to_tsquery('"+searchHandler(searchString)+"') OR to_tsvector(listings.description) @@ to_tsquery('"+searchHandler(searchString)+"') OR to_tsvector(listings.keywords) @@ to_tsquery('"+searchHandler(searchString)+"')) ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),(SELECT CASE WHEN (ts_rank(to_tsvector(listings.departments), to_tsquery('"+searchHandler(searchString)+"'))) > 0 THEN 1 ELSE 0 END) DESC, listings.custom_desc DESC,(SELECT ts_rank(to_tsvector(listings.name), to_tsquery('"+searchHandler(searchString)+"'))) DESC,(SELECT ts_rank(to_tsvector(listings.description), to_tsquery('"+searchHandler(searchString)+"'))) DESC, (SELECT ts_rank(to_tsvector(listings.keywords), to_tsquery('"+searchHandler(searchString)+"'))) DESC,name,departments", callback);
callbackData("SELECT *, exists(SELECT 1 FROM favorites WHERE favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "') AS isFavorite FROM listings WHERE departments ~* E'" + escapeRegExpDept(deptString) + ";' AND ((to_tsvector(coalesce(listings.name, '')) || to_tsvector(coalesce(listings.description, '')) || to_tsvector(coalesce(listings.keywords, '')) || to_tsvector(coalesce(listings.departments, ''))) @@ to_tsquery('"+searchHandler(searchString)+"')) ORDER BY (SELECT favorites.listingid FROM favorites WHERE (favorites.listingid = listings.list_id AND favorites.netid = '" + netID + "')),(SELECT CASE WHEN (ts_rank(to_tsvector(listings.departments), to_tsquery('"+searchHandler(searchString)+"'))) > 0 THEN 1 ELSE 0 END) DESC, listings.custom_desc DESC,(SELECT ts_rank(to_tsvector(listings.name), to_tsquery('"+searchHandler(searchString)+"'))) DESC,(SELECT ts_rank(to_tsvector(listings.description), to_tsquery('"+searchHandler(searchString)+"'))) DESC, (SELECT ts_rank(to_tsvector(listings.keywords), to_tsquery('"+searchHandler(searchString)+"'))) DESC,name,departments", callback);
}

//user functions
Expand Down Expand Up @@ -117,6 +117,7 @@ function getListingCount(callback){

module.exports = {
callbackData: callbackData,
saveSearch: saveSearch,
getAllListings: getAllListings,
searchListings: searchListings,
filterDepts: filterDepts,
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"cookie-parser": "~1.4.3",
"debug": "~2.6.0",
"express": "~4.14.1",
"express-admin": "^1.3.2",
"express-session": "^1.15.2",
"handlebars-paginate": "^0.1.0",
"hbs": "^4.0.1",
"json-query": "^2.2.2",
"mailgun": "^0.5.0",
"morgan": "~1.7.0",
"pg-promise": "^5.5.8",
Expand All @@ -26,6 +28,8 @@
"readmore-js": "^2.1.0",
"request": "^2.79.0",
"serve-favicon": "~2.3.2",
"short-hash": "^1.0.0",
"underscore": "^1.8.3",
"universal-analytics": "^0.4.15"
}
}
Binary file added public/images/RDB-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/Shield-White-Small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 0 additions & 41 deletions public/images/favicon/manifest.json

This file was deleted.

Binary file added public/images/learnmore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4a0d59d

Please sign in to comment.