diff options
| -rw-r--r-- | f/images/delete.jpg | bin | 0 -> 1307 bytes | |||
| -rw-r--r-- | f/scripts/client.js | 19 | ||||
| -rw-r--r-- | f/styles/style.css | 5 | ||||
| -rw-r--r-- | f/templates/index.html | 4 | ||||
| -rw-r--r-- | index.js | 31 | ||||
| -rw-r--r-- | package.json | 3 |
6 files changed, 53 insertions, 9 deletions
diff --git a/f/images/delete.jpg b/f/images/delete.jpg Binary files differnew file mode 100644 index 0000000..1ae7bfa --- /dev/null +++ b/f/images/delete.jpg diff --git a/f/scripts/client.js b/f/scripts/client.js index fb612ed..546aa57 100644 --- a/f/scripts/client.js +++ b/f/scripts/client.js @@ -2,13 +2,16 @@ var ioc = angular.module('ioc',[]); ioc.controller('ioctrl',function($scope){ var soc= io(); + var pw =0; + + $scope.uid =0; $scope.que=[]; $scope.row=""; $scope.name=""; $scope.qsize=0; $scope.submit = function(){ - soc.emit("queadd",{"row":$scope.row,"name":$scope.name}); + soc.emit("queadd",{"row":$scope.row,"name":$scope.name,"uid":$scope.uid}); $scope.row=""; $scope.name=""; }; @@ -19,8 +22,20 @@ ioc.controller('ioctrl',function($scope){ $scope.$apply(); }); + soc.on("userinfo",function(data){ + $scope.uid = data.uid; + pw= data.pw; + }); + + soc.on("err",function(err){ + console.log("error! msg: "+err.msg); + }); + $scope.popfirst = function(){ soc.emit("quepopfirst",""); }; - + $scope.querm = function(qid){ + data = {"qid":qid,"pw":pw}; + soc.emit("quedelete",data); + }; }); diff --git a/f/styles/style.css b/f/styles/style.css index 246a201..ae909c8 100644 --- a/f/styles/style.css +++ b/f/styles/style.css @@ -4,7 +4,7 @@ body{ }
#container_main{
font-size:24px;
- width:200px;
+ width:400px;
margin-top:40px;
margin-left:auto;
margin-right:auto;
@@ -26,6 +26,9 @@ td:first-child{ #que tr:nth-child(2){
background-color:darkgreen;
}
+#que td:nth-child(3){
+ text-align: center;
+}
#addform{
}
diff --git a/f/templates/index.html b/f/templates/index.html index b75ee8a..b02d4b8 100644 --- a/f/templates/index.html +++ b/f/templates/index.html @@ -27,10 +27,12 @@ <tr><td></td><td> <button id="addbutton" ng-click="submit();">Lisää</button></td></tr> </table> <table id="que"> -<tr><th>Rivi</th><th>Nimi</th></tr> +<tr><th>Rivi</th><th>Nimi</th><th>Poista</th></tr> <tr ng-repeat="person in que"> <td >Rivi {{person.row}}</td> <td >{{person.name}}</td> + <td ng-if="person.uid == uid" ng-click="querm(person.qid);"><img src="/f/images/delete.jpg"></td> + <td ng-if="person.uid != uid"></td> </tr> </table> </div> @@ -2,7 +2,8 @@ var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); -var que = [] +var que = []; +var pws = {}; app.get('/', function(req, res){ res.sendFile(__dirname + '/f/templates/index.html'); @@ -18,10 +19,19 @@ app.get('/f/*', function(req, res){ io.on('connection', function(socket){ + var uid = Date.now(); + var pw = Math.random()*10000000 + Math.random()*10000000 -1; + pws[uid] = pw; + + + socket.emit("userinfo",{"uid":uid,"pw":pw}); socket.emit("quedata",que); + socket.on("queadd",function(data){ - console.log("adding new que entry"); + console.log("adding new que entry with user :" ); + data.qid= Date.now(); + que.push(data); io.emit("quedata",que); }); @@ -29,9 +39,22 @@ io.on('connection', function(socket){ console.log("deleting first from que"); que.shift(); io.emit("quedata",que); - }); - + }); + socket.on("quedelete",function(data){ + for (var i=0;i<que.length;i++){ + if (que[i].qid == data.qid){ + if (data.pw != pws[que[i].uid]){ + socket.emit("err",{"msg":"you're not allowed to remove this entry"}); + break; + } + console.log("deleting: "+ que[i].name); + que.splice(i,1); + io.emit("quedata",que); + break; + } + } + }); }); diff --git a/package.json b/package.json index 62f9309..1d28a46 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "express": "^4.12.1", "socket.io": "^1.3.4", - "angular": "~1.3.14" + "angular": "~1.3.14", + "crypto": "0.0.3" } } |
