diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/hello.js b/hello.js new file mode 100644 index 0000000..d88bf9d --- /dev/null +++ b/hello.js @@ -0,0 +1,6 @@ +var redisClient = require('redis-connection')(); +redisClient.set('hello', 'world'); +redisClient.get('hello', function (err, reply) { + console.log('hello', reply.toString()); // hello world + redisClient.quit(); +}); diff --git a/lib/companyredis.js b/lib/companyredis.js index 14c18b1..c4ad60c 100644 --- a/lib/companyredis.js +++ b/lib/companyredis.js @@ -1,7 +1,9 @@ //var redisClient = require('redis'); -var redisClient = require('redis-connection')(); +// var redisClient = require('redis-connection')(); //var env = require('env2')('.env'); //var client = redisClient.createClient(process.env.REDIS_URL); +var client = require('./redis.js'); + exports.register = function (server, options, next) { diff --git a/lib/deletedata.js b/lib/deletedata.js index a53dd89..e5fc70f 100644 --- a/lib/deletedata.js +++ b/lib/deletedata.js @@ -1,15 +1,17 @@ // var bluebird = require('bluebird'); -var redisClient = require('redis-connection')(); +//var redisClient = require('redis-connection')(); // var redisClient = require('redis'); // var client = redisClient.createClient(); // bluebird.promisifyAll(redisClient.RedisClient.prototype); // bluebird.promisifyAll(redisClient.Multi.prototype); +var client = require('./redis.js'); + exports.register = function(server, options, next) { function deleteFromSet(key, value, hashID) { var keyValue = key + ":" + value; - redisClient.srem(keyValue, hashID); + client.srem(keyValue, hashID); } server.route([{ @@ -19,7 +21,7 @@ exports.register = function(server, options, next) { description: 'return home page', handler: function(request, reply) { var id = request.params.id; - var hashToDelete = redisClient.hgetall(request.params.id, function(err,reply){ + var hashToDelete = client.hgetall(request.params.id, function(err,reply){ console.log(reply); console.log(id); deleteFromSet('university', reply.university,id); diff --git a/lib/index.js b/lib/index.js index a0ec0ee..ad98f7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,12 +2,17 @@ var Hapi = require('hapi'); var Inert = require('inert'); var Vision = require('vision'); var Handlebars = require('handlebars'); -var Home = require('./home.js'); -var Assets = require('./assets.js'); + +var Home = require('./home.js'); +var Assets = require('./assets.js'); +var Societydashboardsearch = require('./societydashboardsearch.js'); var Companyredis = require('./companyredis.js'); var Societyredis = require('./societyredis.js'); + + +// Societyredis.bind(client); var Societydashboard = require('./societydashboard.js'); var Admin = require('./admin.js'); var Autocomplete =require('./autocomplete.js'); @@ -19,7 +24,8 @@ exports.init = function (port, next) { var server = new Hapi.Server(); server.connection({port: port}); - server.register([Inert, Vision, Assets, Home, Companyredis, Societyredis, Autocomplete, Admin, Societydashboard, Delete], function (err) { + + server.register([Inert, Vision, Assets, Home, Companyredis, Societyredis, Autocomplete, Admin, Societydashboard, Delete, Societydashboardsearch], function (err) { if (err) { return next(err); diff --git a/lib/redis.js b/lib/redis.js new file mode 100644 index 0000000..f293532 --- /dev/null +++ b/lib/redis.js @@ -0,0 +1,6 @@ +var bluebird = require('bluebird'); +var redisClient = require('redis'); +bluebird.promisifyAll(redisClient.RedisClient.prototype); +bluebird.promisifyAll(redisClient.Multi.prototype); + +module.exports = redisClient.createClient(); diff --git a/lib/societydashboard.js b/lib/societydashboard.js index 6b71d3e..e4f2645 100644 --- a/lib/societydashboard.js +++ b/lib/societydashboard.js @@ -1,9 +1,11 @@ -var bluebird = require('bluebird'); +//var bluebird = require('bluebird'); // var redisClient = require('redis-connection')(); -var redisClient = require('redis'); -var client = redisClient.createClient(); -bluebird.promisifyAll(redisClient.RedisClient.prototype); -bluebird.promisifyAll(redisClient.Multi.prototype); +// var redisClient = require('redis'); +// var client = redisClient.createClient(); +// bluebird.promisifyAll(redisClient.RedisClient.prototype); +// bluebird.promisifyAll(redisClient.Multi.prototype); +var client = require('./redis.js'); + exports.register = function (server, options, next) { var template = require('./dashboardhandlebars.js'); @@ -19,7 +21,6 @@ var template = require('./dashboardhandlebars.js'); var object = []; var callback = function(){ - client.quit(); var quoteData = { object:object diff --git a/lib/societydashboardsearch.js b/lib/societydashboardsearch.js new file mode 100644 index 0000000..241d40d --- /dev/null +++ b/lib/societydashboardsearch.js @@ -0,0 +1,51 @@ +// var bluebird = require('bluebird'); +// var client = require('redis-connection')(); +// var redisClient = require('redis'); +// var client = redisClient.createClient(); + +var client = require('./redis.js'); +// bluebird.promisifyAll(redisClient.RedisClient.prototype); +// bluebird.promisifyAll(redisClient.Multi.prototype); + +exports.register = function (server, options, next) { + + server.route([ + { + method: 'POST', + path: '/societydashboardsearch', + config: { + description: 'return home page', + handler: function(request,reply){ + var requestPayload = request.payload; + var arrayOfFilters = []; + var requestPayloadKeys = Object.keys(requestPayload); + + var arrayOfSetNames = function(requestPayload,requestPayloadKeys){ + requestPayloadKeys.forEach(function(elem){ + if(requestPayload[elem] !== '' && requestPayload[elem] !== null && requestPayload[elem] !== undefined && elem.length !== 0){ + var setName = elem+ ':' + requestPayload[elem]; + arrayOfFilters.push(setName); + } + }); + }; + + arrayOfSetNames(requestPayload,requestPayloadKeys); + client.sinterAsync.apply(client, arrayOfFilters) + .then(function(filteredlist){ + console.log(filteredlist); + }); + return reply('You have searched'); + + + } + } + } + + ]); + + return next(); +}; + +exports.register.attributes = { + name: 'Societydashboardsearch' +}; diff --git a/lib/societyredis.js b/lib/societyredis.js index 5545113..82c63e7 100644 --- a/lib/societyredis.js +++ b/lib/societyredis.js @@ -1,7 +1,10 @@ -var redisClient = require('redis-connection')(); -//var redisClient = require('redis'); -//var env = require('env2')('.env'); -//var client = redisClient.createClient(process.env.REDIS_URL); +// var redisClient = require('redis-connection')(); +// var redisClient = require('redis'); +// var client = redisClient.createClient(); +// var env = require('env2')('.env'); + +var client = require('./redis.js'); + exports.register = function(server, options, next) { @@ -13,8 +16,8 @@ exports.register = function(server, options, next) { console.log('BOOM',request.payload); - redisClient.incr('id'); - var thisId = redisClient.get('id', function(err,reply){ + client.incr('id'); + var thisId = client.get('id', function(err,reply){ addHashToDatabase(reply); addToSet('university', societyFormObject.university, reply); addToSet('region', societyFormObject.region, reply); @@ -26,12 +29,12 @@ exports.register = function(server, options, next) { }); function addHashToDatabase(reply){ - redisClient.hmset(reply, 'id', reply, 'timestamp', timeNow, 'date', date, 'societyName', societyFormObject.societyName, 'university', societyFormObject.university, 'region', societyFormObject.region, 'typeSociety', societyFormObject.typeSociety, 'memberSize', societyFormObject.memberSize, 'email', societyFormObject.email,'phone',societyFormObject.phone,'aboutus', societyFormObject.aboutus,'societyLogo', societyFormObject.societyLogo, function(err,reply){}); + client.hmset(reply, 'id', reply, 'timestamp', timeNow, 'date', date, 'societyName', societyFormObject.societyName, 'university', societyFormObject.university, 'region', societyFormObject.region, 'typeSociety', societyFormObject.typeSociety, 'memberSize', societyFormObject.memberSize, 'email', societyFormObject.email,'phone',societyFormObject.phone,'aboutus', societyFormObject.aboutus,'societyLogo', societyFormObject.societyLogo, function(err,reply){}); } function addToSet (key, value, hashID){ var keyValue = key + ":" + value; - redisClient.sadd(keyValue, hashID); + client.sadd(keyValue, hashID); } return reply("society-redis reply"); diff --git a/test/server.test.js b/test/server.test.js index e9195eb..3949585 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -1,18 +1,26 @@ var test = require('tape'); var path = require('path'); -var redisClient = require('redis-connection')(); // var env = require('env2')('.env'); +// var redisClient = require('redis-connection')(); +// redisClient.set('hello', 'world'); +// redisClient.get('hello', function (err, reply) { +// console.log('hello', reply.toString()); // hello world +// }); + //var client = redisClient.createClient(process.env.REDIS_URL); // var redisClient = require('redis'); // var client = redisClient.createClient(); + var dir = __dirname.split('/')[__dirname.split('/').length-1]; var file = dir + __filename.replace(__dirname, '') + ' ->'; var start = require('../lib/start.js'); var server = require('../lib/index.js'); +var client = require('../lib/redis.js'); + test(file + " GET / returns status 200", function(t) { var options = { @@ -25,12 +33,13 @@ test(file + " GET / returns status 200", function(t) { setTimeout(function(){ server.stop(t.end); },700); - redisClient.end(); + //client.quit(); + }); }); -test(file + " GET / returns status 200", function(t) { +test.only(file + " GET / returns status 200", function(t) { var options = { method : "GET", url : "/societydashboard" @@ -42,5 +51,41 @@ test(file + " GET / returns status 200", function(t) { server.stop(t.end); },700); + //client.quit(); + }); +}); + + +test(file + " GET / returns status 200", function(t) { + var options = { + method : "GET", + url : "/societyredis" + }; + server.inject(options, function (res) { + t.equal(res.statusCode, 404, 'server loads ok'); + + setTimeout(function(){ + server.stop(t.end); + },700); + client.quit(); + }); }); + +// test(file + " POST / returns status 200", function(t) { +// var options = { +// method : "POST", +// url : "/societydashboardsearch" +// }; +// server.inject(options, function (res) { +// t.equal(res.statusCode, 200, 'server loads ok'); +// +// setTimeout(function(){ +// server.stop(t.end); +// },700); +// +// client.quit(); +// +// }); +// +// }); diff --git a/views/societydashboard.html b/views/societydashboard.html index 86dee9b..1db5b0c 100644 --- a/views/societydashboard.html +++ b/views/societydashboard.html @@ -1,6 +1,66 @@ <h1> Society dashboard</h1> +<form role="form" action="/societydashboardsearch" method="POST" id="societyForm"> + +<label for="University">University Name</label> +<input type="text" id="university" name="university" placeholder="university auto/comp" value="University of Glasgow" > +<output id="universityAcList"></output> +<br> +<label for="Region">Region </label> +<select name="region" id="region" > + <option value="" selected>Select region</option> + <option value="East" selected="selected">East</option> + <option value="East Midlands">East Midlands</option> + <option value="London">London</option> + <option value="North East">North East</option> + <option value="North West">North West</option> + <option value="Northern Ireland">Northern Ireland</option> + <option value="Scotland">Scotland</option> + <option value="South East">South East</option> + <option value="South West">South West</option> + <option value="Wales">Wales</option> + <option value="West Midlands">West Midlands</option> + <option value="Yorkshire and the Humber">Yorkshire and the Humber</option> +</select> +<br> +<label for="Type of society">Type of society </label> +<select name="typeSociety" id="typeSociety" > + <option value="" selected>Select society type</option> + <option value="Academic & Employability" selected="selected">Academic & Employability</option> + <option value="Arts & Culture">Arts & Culture</option> + <option value="Faith & Worldview">Faith & Worldview</option> + <option value="Fitness & Wellbeing">Fitness & Wellbeing</option> + <option value="International">International</option> + <option value="Media">Media</option> + <option value="Music">Music</option> + <option value="Outdoor and Adventure">Outdoor and Adventure</option> + <option value="Political, Campaigning & Causes">Political, Campaigning & Causes</option> + <option value="Recreational">Recreational</option> + <option value="Volunteering">Volunteering</option> + <option value="Committee Resources">Committee Resources</option> + <option value="Other">Other</option> +</select> +<br> +<label for="Member size">Member Size</label> +<select name="memberSize" id="region" > + <option value="" selected>Select size</option> + <option value="0-50" selected="selected">0-50</option> + <option value="51-100">51-100</option> + <option value="101-150">101-150</option> + <option value="151-200">151-200</option> + <option value="200+">200 +</option> +</select> +<br> + +<button type="submit">Submit</button> + +</form> + + + + + <table> <tr> <th>ID</th> @@ -29,7 +89,8 @@ <h1> Society dashboard</h1> <td>{{this.phone}}</td> <td>{{this.aboutus}}</td> <td>{{this.societyLogo}}</td> - <td><button type="button" name="button"><a href="/delete/{{this.id}}" >Delete</a></button></td> + <td><button type="button" name="button" id="deleteSociety"><a href="/delete/{{this.id}}" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a> +</button></td> </tr> {{/each}} </table>