diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2016-01-20 18:48:43 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2016-01-20 19:17:47 +0200 |
| commit | 09b2d3ba6bd282982b609ff84410e2bb0e2f9d49 (patch) | |
| tree | eb06d5f1cf7ea9d3188135fdc35f5b01f2e09fea | |
| parent | a9c558fba0a839e45597dcf4bda225a857467295 (diff) | |
Add error message if the input is not sane
| -rw-r--r-- | f/images/delete.jpg | bin | 1307 -> 0 bytes | |||
| -rw-r--r-- | f/scripts/client.js | 99 | ||||
| -rw-r--r-- | f/styles/style.css | 9 | ||||
| -rw-r--r-- | f/templates/index.html | 4 | ||||
| -rw-r--r-- | index.js | 116 |
5 files changed, 133 insertions, 95 deletions
diff --git a/f/images/delete.jpg b/f/images/delete.jpg Binary files differdeleted file mode 100644 index 1ae7bfa..0000000 --- a/f/images/delete.jpg +++ /dev/null diff --git a/f/scripts/client.js b/f/scripts/client.js index b02123f..8cef12a 100644 --- a/f/scripts/client.js +++ b/f/scripts/client.js @@ -1,48 +1,69 @@ -var ioc = angular.module('ioc',[]); +var ioc = angular.module('ioc', []); -ioc.controller('ioctrl',function($scope){ - var soc= io(); - var pw =0; +ioc.controller('ioctrl', function($scope) { + var soc = io(); + var pw = 0; - $scope.uid =0; - $scope.que=[]; - $scope.row=""; - $scope.name=""; - $scope.qsize=0; + $scope.uid = 0; + $scope.que = []; + $scope.row = ""; + $scope.name = ""; + $scope.qsize = 0; $scope.outdated = true; - - $scope.submit = function(){ - soc.emit("queadd",{"row":$scope.row,"name":$scope.name,"uid":$scope.uid}); - $scope.row=""; - $scope.name=""; - }; - - soc.on("quedata",function(data){ - $scope.que=data; - $scope.qsize=data.length; + $scope.error_message = ""; + + $scope.submit = function() { + if ($scope.row == "") + $scope.error_message = "Valitse rivi ennen lisäämistä!"; + else if ($scope.name == "") + $scope.error_message = "Kirjoita nimesi ennen lisäämistä!"; + else { + soc.emit("queadd", { + "row": $scope.row, + "name": $scope.name, + "uid": $scope.uid + }); + $scope.error_message = ""; + $scope.row = ""; + $scope.name = ""; + } + }; + + soc.on("quedata", function(data) { + $scope.que = data; + $scope.qsize = data.length; $scope.outdated = false; - $scope.$apply(); - }); + $scope.$apply(); + }); - soc.on("userinfo",function(data){ - $scope.uid = data.uid; - pw= data.pw; - }); + soc.on("userinfo", function(data) { + $scope.uid = data.uid; + pw = data.pw; + }); - soc.on("disconnect",function(data){ - setTimeout(function(){console.log("blblbl");$scope.uid = data.uid;pw= data.pw;$scope.$apply();},1000) - }); + soc.on("disconnect", function(data) { + setTimeout(function() { + console.log("blblbl"); + $scope.uid = data.uid; + pw = data.pw; + $scope.$apply(); + }, 1000); + }); - soc.on("err",function(err){ - console.log("error! msg: "+err.msg); - }); + soc.on("err", function(err) { + console.log("error! msg: " + err.msg); + }); - $scope.popfirst = function(){ + $scope.popfirst = function() { $scope.outdated = true; - soc.emit("quepopfirst",""); - }; - $scope.querm = function(qid){ - data = {"qid":qid,"pw":pw}; - soc.emit("quedelete",data); - }; -}); + soc.emit("quepopfirst", ""); + }; + + $scope.querm = function(qid) { + data = { + "qid": qid, + "pw": pw + }; + soc.emit("quedelete", data); + }; +});
\ No newline at end of file diff --git a/f/styles/style.css b/f/styles/style.css index 3209cef..1d5df84 100644 --- a/f/styles/style.css +++ b/f/styles/style.css @@ -15,6 +15,13 @@ body{ font-style: italic;
}
+#add-error {
+ margin-top: 10px;
+ color: #c0392b;
+ font-style: italic;
+ font-weight: 700;
+}
+
.form-name {
font-weight: 700;
}
@@ -90,7 +97,7 @@ td { text-decoration:none;
}
.removeButton:hover {
- background-color:#408c99;
+ background-color: #a53a2b;
}
.removeButton:active {
position:relative;
diff --git a/f/templates/index.html b/f/templates/index.html index 81e2b7c..488f6b9 100644 --- a/f/templates/index.html +++ b/f/templates/index.html @@ -42,6 +42,10 @@ <a href="#" class="addButton" ng-click="submit();">Lisää</a> + <div ng-if='error_message != ""' id="add-error"> + {{error_message}} + </div> + <div ng-repeat="person in que"> <div ng-if="person.uid == uid" ng-click="querm(person.qid);"> <a href="#" class="removeButton">Poista {{person.name}}</a> @@ -4,85 +4,91 @@ var io = require('socket.io')(http); var port = (process.env.PORT || 5000); var LOGBROADCAST = true; //get port from commandline parameteres -if (process.argv.length== 3){ - port = process.argv[2]; +if (process.argv.length == 3) { + port = process.argv[2]; } var que = []; var pws = {}; -app.get('/', function(req, res){ - res.sendFile(__dirname + '/f/templates/index.html'); +app.get('/', function(req, res) { + res.sendFile(__dirname + '/f/templates/index.html'); }); -app.get('/adm', function(req, res){ - res.sendFile(__dirname + '/f/templates/adm.html'); +app.get('/adm', function(req, res) { + res.sendFile(__dirname + '/f/templates/adm.html'); }); -app.get('/log', function(req, res){ - res.sendFile(__dirname + '/f/templates/log.html'); +app.get('/log', function(req, res) { + res.sendFile(__dirname + '/f/templates/log.html'); }); //route all paths beginning with /f/ to real files -app.get('/f/*', function(req, res){ - res.sendFile(__dirname + req.path); +app.get('/f/*', function(req, res) { + res.sendFile(__dirname + req.path); }); -io.on('connection', function(socket){ - var uid = Date.now(); - var pw = Math.random()*10000000 + Math.random()*10000000 -1; - pws[uid] = pw; +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("logsubscribe",function(data){ - log("User "+data.uid+ " has subscribed in logging"); - socket.join("log"); - }); - - socket.on("queadd",function(data){ - log("User " +data.name+ " on row " +data.row+" added to queue"); - data.qid= Date.now(); + socket.emit("userinfo", { + "uid": uid, + "pw": pw + }); - que.push(data); - io.emit("quedata",que); - }); - socket.on("quepopfirst",function(data){ - var deleted = que.shift(); - log("admin deleted "+ deleted.name +" from queue"); - io.emit("quedata",que); + socket.emit("quedata", que); + socket.on("logsubscribe", function(data) { + log("User " + data.uid + " has subscribed in logging"); + socket.join("log"); + }); - }); - 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; - } - log(que[i].name+" deleted himself from queue"); - que.splice(i,1); - io.emit("quedata",que); - break; - } - } - }); + socket.on("queadd", function(data) { + log("User " + data.name + " on row " + data.row + " added to queue"); + data.qid = Date.now(); + + que.push(data); + io.emit("quedata", que); + }); + + socket.on("quepopfirst", function(data) { + var deleted = que.shift(); + log("admin deleted " + deleted.name + " from queue"); + 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; + } + log(que[i].name + " deleted himself from queue"); + que.splice(i, 1); + io.emit("quedata", que); + break; + } + } + }); }); -function getTimeString() -{ +function getTimeString() { return Date().toLocaleString(); } -function log(msg){ - var logmsg=getTimeString()+": "+msg; +function log(msg) { + var logmsg = getTimeString() + ": " + msg; console.log(logmsg); - if(LOGBROADCAST){ - io.to("log").emit("logmessage",logmsg); + if (LOGBROADCAST) { + io.to("log").emit("logmessage", logmsg); } } -http.listen(port, function(){ - log('listening on port '+port); -}); +http.listen(port, function() { + log('listening on port ' + port); +});
\ No newline at end of file |
