Skip to content

Commit

Permalink
Merge pull request #51 from Unitie-FAC/deleteprompt
Browse files Browse the repository at this point in the history
#44 #50 #7 #3 #9 added prompt when selecting delete button, also MULT…
  • Loading branch information
thegsi committed Jan 8, 2016
2 parents cefc2dd + 3d04ffd commit 76902ad
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 25 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions hello.js
Original file line number Diff line number Diff line change
@@ -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();
});
4 changes: 3 additions & 1 deletion lib/companyredis.js
Original file line number Diff line number Diff line change
@@ -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) {

Expand Down
8 changes: 5 additions & 3 deletions lib/deletedata.js
Original file line number Diff line number Diff line change
@@ -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([{
Expand All @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions lib/redis.js
Original file line number Diff line number Diff line change
@@ -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();
13 changes: 7 additions & 6 deletions lib/societydashboard.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -19,7 +21,6 @@ var template = require('./dashboardhandlebars.js');
var object = [];

var callback = function(){
client.quit();

var quoteData = {
object:object
Expand Down
51 changes: 51 additions & 0 deletions lib/societydashboardsearch.js
Original file line number Diff line number Diff line change
@@ -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'
};
19 changes: 11 additions & 8 deletions lib/societyredis.js
Original file line number Diff line number Diff line change
@@ -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) {

Expand All @@ -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);
Expand All @@ -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");
Expand Down
51 changes: 48 additions & 3 deletions test/server.test.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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"
Expand All @@ -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();
//
// });
//
// });
63 changes: 62 additions & 1 deletion views/societydashboard.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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>

0 comments on commit 76902ad

Please sign in to comment.