diff --git a/controllers/prototype/views/user_study.jade b/controllers/prototype/views/user_study.jade index 30c9807..d413401 100644 --- a/controllers/prototype/views/user_study.jade +++ b/controllers/prototype/views/user_study.jade @@ -2,6 +2,17 @@ extends ../../../views/base.jade block extrahead link(rel="stylesheet", href="/static/css/signin.css") + link(rel="stylesheet", href="/static/css/star-rating.min.css") + +block extrajs + script(src="/static/js/star-rating.min.js") + script. + $('#3dgames').rating({ + showClear: false, + showCaption: false, + size: 'xs' + }); + $('#3dgames').rating('update', 3); block extrabody if identificationFailed @@ -16,16 +27,44 @@ block content h2 Please sign in label(for='inputId').sr-only Id input#inputId.form-control(name="inputId", type="text", placeholder='Id', required, autofocus) - label(for='inputAge').sr-only Age - input#inputAge.form-control(name="inputAge", type="number", placeholder='Age', min="18", required) - div(style={'text-align': 'center', 'margin-top':'10px', 'margin-bottom':'10px'}) - label.radio-inline - input(type='radio', name='inputGender', value="male", checked) - | Male - label.radio-inline - input(type='radio', name='inputGender', value="female") - | Female + .form-group + label Gender + .form-group + label.radio-inline + input(type='radio', name='inputGender', value="male", checked) + | Male + label.radio-inline + input(type='radio', name='inputGender', value="female") + | Female + + .form-group + label(for='sel1') How old are you ? + select.form-control#sel1(name="inputAge") + option(value='-20') Less than 20 + option(value='20-25') Between 20 and 25 + option(value='25-30') Between 25 and 30 + option(value='30-35') Between 30 and 35 + option(value='35-40') Between 35 and 40 + option(value='40-45') Between 40 and 45 + option(value='45-50') Between 45 and 50 + option(value='50-55') Between 50 and 55 + option(value='55-60') Between 55 and 60 + option(value='60-') More than 60 + + label(for='3dgames') Rate your 3D game skills (1 star if you never played) + input#3dgames(type='number', class='rating', min='0', max='5', step='1', default='3', name='input3dskills') + + .form-group + label(for='se21') When is the last time you played a 3D video game ? + select.form-control#sel2(name="inputLastTime") + option(value='3') This week + option(value='2') This month + option(value='1') This year + option(value='0') I never played a 3D video game + + + button.btn.btn-lg.btn-primary.btn-block(type='submit') Sign in diff --git a/js/Makefile b/js/Makefile index c773437..c4fb629 100644 --- a/js/Makefile +++ b/js/Makefile @@ -6,7 +6,10 @@ else CLOSURE=../utils/simple-compiler/compiler.sh endif -all: L3D L3DP Socket Three Stats Bouncing Multisphere StreamingSimulator PrototypeReplay PrototypeInteractive Tutorial TestList CoinCreator CoinViewer +all: L3D L3DP Socket Three Stats Bouncing Multisphere StreamingSimulator PrototypeReplay PrototypeInteractive Tutorial TestList CoinCreator CoinViewer StarRating + +StarRating: + cp star-rating.min.js ../static/js/ L3D: $(CLOSURE) $(OPT) \ diff --git a/js/star-rating.min.js b/js/star-rating.min.js new file mode 100644 index 0000000..237e5a9 --- /dev/null +++ b/js/star-rating.min.js @@ -0,0 +1,10 @@ +/*! + * @copyright © Kartik Visweswaran, Krajee.com, 2013 - 2015 + * @version 3.5.3 + * + * A simple yet powerful JQuery star rating plugin that allows rendering + * fractional star ratings and supports Right to Left (RTL) input. + * + * For more JQuery plugins visit http://plugins.krajee.com + * For more Yii related demos visit http://demos.krajee.com + */!function(t){"use strict";String.prototype.replaceAll=function(t,e){return this.split(t).join(e)};var e=0,a=5,n=.5,r=function(e,a){return null===e||void 0===e||0===e.length||a&&""===t.trim(e)},i=function(t,e){t.removeClass(e).addClass(e)},l=function(t,e,a){var n=r(t.data(e))?t.attr(e):t.data(e);return n?n:a[e]},o=function(t){var e=(""+t).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return e?Math.max(0,(e[1]?e[1].length:0)-(e[2]?+e[2]:0)):0},s=function(t,e){return parseFloat(t.toFixed(e))},c=function(e,a){this.$element=t(e),this.init(a)};c.prototype={constructor:c,_parseAttr:function(t,i){var o=this,s=o.$element;if("range"===s.attr("type")||"number"===s.attr("type")){var c,u,g=l(s,t,i);switch(t){case"min":c=e;break;case"max":c=a;break;default:c=n}return u=r(g)?c:g,parseFloat(u)}return parseFloat(i[t])},listenClick:function(t,e){t.on("click touchstart",function(t){return t.stopPropagation(),t.preventDefault(),t.handled===!0?!1:(e(t),void(t.handled=!0))})},setDefault:function(t,e){var a=this;r(a[t])&&(a[t]=e)},getPosition:function(t){var e=t.pageX||t.originalEvent.touches[0].pageX;return e-this.$rating.offset().left},listen:function(){var e,a,n=this;n.initTouch(),n.listenClick(n.$rating,function(t){return n.inactive?!1:(e=n.getPosition(t),n.setStars(e),n.$element.trigger("change").trigger("rating.change",[n.$element.val(),n.$caption.html()]),void(n.starClicked=!0))}),n.$rating.on("mousemove",function(t){n.hoverEnabled&&!n.inactive&&(n.starClicked=!1,e=n.getPosition(t),a=n.calculate(e),n.toggleHover(a),n.$element.trigger("rating.hover",[a.val,a.caption,"stars"]))}),n.$rating.on("mouseleave",function(){!n.hoverEnabled||n.inactive||n.starClicked||(a=n.cache,n.toggleHover(a),n.$element.trigger("rating.hoverleave",["stars"]))}),n.$clear.on("mousemove",function(){if(n.hoverEnabled&&!n.inactive&&n.hoverOnClear){n.clearClicked=!1;var t=''+n.clearCaption+"",e=n.clearValue,r=n.getWidthFromValue(e);a={caption:t,width:r,val:e},n.toggleHover(a),n.$element.trigger("rating.hover",[e,t,"clear"])}}),n.$clear.on("mouseleave",function(){n.hoverEnabled&&!n.inactive&&!n.clearClicked&&n.hoverOnClear&&(a=n.cache,n.toggleHover(a),n.$element.trigger("rating.hoverleave",["clear"]))}),n.listenClick(n.$clear,function(){n.inactive||(n.clear(),n.clearClicked=!0)}),t(n.$element[0].form).on("reset",function(){n.inactive||n.reset()})},destroy:function(){var e=this,a=e.$element;r(e.$container)||e.$container.before(a).remove(),t.removeData(a.get(0)),a.off("rating").removeClass("hide")},create:function(t){var e=this,a=e.$element;t=t||e.options||{},e.destroy(),a.rating(t)},setTouch:function(t,e){var a=this,n="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch;if(n&&!a.inactive){var r=t.originalEvent,i=r.touches||r.changedTouches,l=a.getPosition(i[0]);if(e)a.setStars(l),a.$element.trigger("change").trigger("rating.change",[a.$element.val(),a.$caption.html()]),a.starClicked=!0;else{var o=a.calculate(l),s=o.val<=a.clearValue?a.fetchCaption(a.clearValue):o.caption,c=a.getWidthFromValue(a.clearValue),u=o.val<=a.clearValue?a.rtl?100-c+"%":c+"%":o.width;a.$caption.html(s),a.$stars.css("width",u)}}},initTouch:function(){var t=this;t.$rating.on("touchstart touchmove touchend",function(e){var a="touchend"===e.type;t.setTouch(e,a)})},initSlider:function(t){var i=this;r(i.$element.val())&&i.$element.val(0),i.initialValue=i.$element.val(),i.setDefault("min",i._parseAttr("min",t)),i.setDefault("max",i._parseAttr("max",t)),i.setDefault("step",i._parseAttr("step",t)),(isNaN(i.min)||r(i.min))&&(i.min=e),(isNaN(i.max)||r(i.max))&&(i.max=a),(isNaN(i.step)||r(i.step)||0===i.step)&&(i.step=n),i.diff=i.max-i.min},init:function(e){var a,n,l,o=this,s=o.$element;o.options=e,t.each(e,function(t,e){o[t]=e}),o.starClicked=!1,o.clearClicked=!1,o.initSlider(e),o.checkDisabled(),o.setDefault("rtl",s.attr("dir")),o.rtl&&s.attr("dir","rtl"),a=o.glyphicon?"":"★",o.setDefault("symbol",a),o.setDefault("clearButtonBaseClass","clear-rating"),o.setDefault("clearButtonActiveClass","clear-rating-active"),o.setDefault("clearValue",o.min),i(s,"form-control hide"),o.$clearElement=r(e.clearElement)?null:t(e.clearElement),o.$captionElement=r(e.captionElement)?null:t(e.captionElement),void 0===o.$rating&&void 0===o.$container&&(o.$rating=t(document.createElement("div")).html('
'),o.$container=t(document.createElement("div")),o.$container.before(o.$rating).append(o.$rating),s.before(o.$container).appendTo(o.$rating)),o.$stars=o.$rating.find(".rating-stars"),o.generateRating(),o.$clear=r(o.$clearElement)?o.$container.find("."+o.clearButtonBaseClass):o.$clearElement,o.$caption=r(o.$captionElement)?o.$container.find(".caption"):o.$captionElement,o.setStars(),o.listen(),o.showClear&&o.$clear.attr({"class":o.getClearClass()}),n=s.val(),l=o.getWidthFromValue(n),o.cache={caption:o.$caption.html(),width:(o.rtl?100-l:l)+"%",val:n},s.removeClass("rating-loading")},checkDisabled:function(){var t=this;t.disabled=l(t.$element,"disabled",t.options),t.readonly=l(t.$element,"readonly",t.options),t.inactive=t.disabled||t.readonly},getClearClass:function(){return this.clearButtonBaseClass+" "+(this.inactive?"":this.clearButtonActiveClass)},generateRating:function(){var t=this,e=t.renderClear(),a=t.renderCaption(),n=t.rtl?"rating-container-rtl":"rating-container",l=t.getStars();n+=t.glyphicon?(""===t.symbol?" rating-gly-star":" rating-gly")+t.ratingClass:r(t.ratingClass)?" rating-uni":" "+t.ratingClass,t.$rating.attr("class",n),t.$rating.attr("data-content",l),t.$stars.attr("data-content",l),n=t.rtl?"star-rating-rtl":"star-rating",t.$container.attr("class",n+" rating-"+t.size),t.$container.removeClass("rating-active rating-disabled"),t.$container.addClass(t.inactive?"rating-disabled":"rating-active"),r(t.$caption)&&(t.rtl?t.$container.prepend(a):t.$container.append(a)),r(t.$clear)&&(t.rtl?t.$container.append(e):t.$container.prepend(e)),r(t.containerClass)||i(t.$container,t.containerClass)},getStars:function(){var t,e=this,a=e.stars,n="";for(t=1;a>=t;t++)n+=e.symbol;return n},renderClear:function(){var t,e=this;return e.showClear?(t=e.getClearClass(),r(e.$clearElement)?'
'+e.clearButton+"
":(i(e.$clearElement,t),e.$clearElement.attr({title:e.clearButtonTitle}).html(e.clearButton),"")):""},renderCaption:function(){var t,e=this,a=e.$element.val();return e.showCaption?(t=e.fetchCaption(a),r(e.$captionElement)?'
'+t+"
":(i(e.$captionElement,"caption"),e.$captionElement.html(t),"")):""},fetchCaption:function(t){var e,a,n,i,l,o=this,s=parseFloat(t),c=o.starCaptions,u=o.starCaptionClasses;return i="function"==typeof u?u(s):u[s],n="function"==typeof c?c(s):c[s],a=r(n)?o.defaultCaption.replaceAll("{rating}",s):n,e=r(i)?o.clearCaptionClass:i,l=s===o.clearValue?o.clearCaption:a,''+l+""},getWidthFromValue:function(t){var e=this,a=e.min,n=e.max;return a>=t||a===n?0:t>=n?100:100*(t-a)/(n-a)},getValueFromPosition:function(t){var e,a,n=this,r=o(n.step),i=n.$rating.width();return a=n.diff*t/(i*n.step),a=n.rtl?Math.floor(a):Math.ceil(a),e=s(parseFloat(n.min+a*n.step),r),e=Math.max(Math.min(e,n.max),n.min),n.rtl?n.max-e:e},toggleHover:function(t){var e,a,n,r=this;r.hoverChangeCaption&&(n=t.val<=r.clearValue?r.fetchCaption(r.clearValue):t.caption,r.$caption.html(n)),r.hoverChangeStars&&(e=r.getWidthFromValue(r.clearValue),a=t.val<=r.clearValue?r.rtl?100-e+"%":e+"%":t.width,r.$stars.css("width",a))},calculate:function(t){var e=this,a=r(e.$element.val())?0:e.$element.val(),n=arguments.length?e.getValueFromPosition(t):a,i=e.fetchCaption(n),l=e.getWidthFromValue(n);return e.rtl&&(l=100-l),l+="%",{caption:i,width:l,val:n}},setStars:function(t){var e=this,a=arguments.length?e.calculate(t):e.calculate();e.$element.val(a.val),e.$stars.css("width",a.width),e.$caption.html(a.caption),e.cache=a},clear:function(){var t=this,e=''+t.clearCaption+"";t.$stars.removeClass("rated"),t.inactive||t.$caption.html(e),t.$element.val(t.clearValue),t.setStars(),t.$element.trigger("rating.clear")},reset:function(){var t=this;t.$element.val(t.initialValue),t.setStars(),t.$element.trigger("rating.reset")},update:function(t){var e=this;arguments.length&&(e.$element.val(t),e.setStars())},refresh:function(e){var a=this;arguments.length&&(a.$rating.off("rating"),void 0!==a.$clear&&a.$clear.off(),a.init(t.extend(a.options,e)),a.showClear?a.$clear.show():a.$clear.hide(),a.showCaption?a.$caption.show():a.$caption.hide(),a.$element.trigger("rating.refresh"))}},t.fn.rating=function(e){var a=Array.apply(null,arguments);return a.shift(),this.each(function(){var n=t(this),r=n.data("rating"),i="object"==typeof e&&e;r||n.data("rating",r=new c(this,t.extend({},t.fn.rating.defaults,i,t(this).data()))),"string"==typeof e&&r[e].apply(r,a)})},t.fn.rating.defaults={stars:5,glyphicon:!0,symbol:null,ratingClass:"",disabled:!1,readonly:!1,rtl:!1,size:"md",showClear:!0,showCaption:!0,defaultCaption:"{rating} Stars",starCaptions:{.5:"Half Star",1:"One Star",1.5:"One & Half Star",2:"Two Stars",2.5:"Two & Half Stars",3:"Three Stars",3.5:"Three & Half Stars",4:"Four Stars",4.5:"Four & Half Stars",5:"Five Stars"},starCaptionClasses:{.5:"label label-danger",1:"label label-danger",1.5:"label label-warning",2:"label label-warning",2.5:"label label-info",3:"label label-info",3.5:"label label-primary",4:"label label-primary",4.5:"label label-success",5:"label label-success"},clearButton:'',clearButtonTitle:"Clear",clearButtonBaseClass:"clear-rating",clearButtonActiveClass:"clear-rating-active",clearCaption:"Not Rated",clearCaptionClass:"label label-default",clearValue:null,captionElement:null,clearElement:null,containerClass:null,hoverEnabled:!0,hoverChangeCaption:!0,hoverChangeStars:!0,hoverOnClear:!0},t.fn.rating.Constructor=c,t("input.rating").addClass("rating-loading"),t(document).ready(function(){var e=t("input.rating"),a=Object.keys(e).length;a>0&&e.rating()})}(window.jQuery); \ No newline at end of file diff --git a/posts/identification/index.js b/posts/identification/index.js index 06a78a0..c18825a 100644 --- a/posts/identification/index.js +++ b/posts/identification/index.js @@ -4,6 +4,11 @@ var db = require('../../controllers/prototype/dbrequests.js'); var Log = require('../../lib/NodeLog.js'); module.exports.index = function(req, res) { + + for (var key in req.body) { + console.log(key, req.body[key]); + } + db.checkUserName(req.body.inputId, function(ok) { if (!ok) { db.tryUser(req.session.user_id, function(id) { @@ -12,8 +17,15 @@ module.exports.index = function(req, res) { pg.connect(secret.url, function(err, client, release) { client.query( - "UPDATE Users SET worker_id = $1, age = $2, male = $3 WHERE id = $4;", - [req.body.inputId, req.body.inputAge, req.body.inputGender === 'male', req.session.user_id], + "UPDATE Users SET worker_id = $1, age = $2, male = $3, rating = $5, lasttime = $6 WHERE id = $4;", + [ + req.body.inputId, + req.body.inputAge, + req.body.inputGender === 'male', + req.session.user_id, + req.body.input3dskills, + req.body.inputLastTime + ], function(err, result) { if (err !== null) Log.dberror(err + ' in identfication'); diff --git a/sql/backup.pgsql b/sql/backup.pgsql index 6d0853e..1025564 100644 --- a/sql/backup.pgsql +++ b/sql/backup.pgsql @@ -36,8 +36,10 @@ CREATE TYPE CAMERA AS( -- Base tables CREATE TABLE Users( id SERIAL PRIMARY KEY, - worker_id varchar(50), - age INTEGER, + worker_id VARCHAR(50), + age VARCHAR(10), + rating INT, + lasttime INT, male BOOLEAN ); diff --git a/static/css/signin.css b/static/css/signin.css index 198aac2..ebd2332 100644 --- a/static/css/signin.css +++ b/static/css/signin.css @@ -5,7 +5,7 @@ body { } .form-signin { - max-width: 330px; + max-width: 500px; padding: 15px; margin: 0 auto; } @@ -34,6 +34,6 @@ body { } .form-signin label { - margin-right: 50px; - margin-left: 50px; + margin-right: 0px; + margin-left: 0px; } diff --git a/static/css/star-rating.min.css b/static/css/star-rating.min.css new file mode 100644 index 0000000..4e768fc --- /dev/null +++ b/static/css/star-rating.min.css @@ -0,0 +1,10 @@ +/*! + * @copyright © Kartik Visweswaran, Krajee.com, 2013 - 2015 + * @version 3.5.3 + * + * A simple yet powerful JQuery star rating plugin that allows rendering + * fractional star ratings and supports Right to Left (RTL) input. + * + * For more JQuery/Bootstrap plugins and demos visit http://plugins.krajee.com + * For more Yii related demos visit http://demos.krajee.com + */.rating-loading{width:25px;height:25px;font-size:0;color:#fff;background:transparent url(../img/loading.gif) top left no-repeat;border:none}.rating-fa{font-family:FontAwesome;padding-left:1px}.rating-fa .rating-stars:before{padding-left:1px}.rating-gly{font-family:'Glyphicons Halflings'}.rating-gly-star{font-family:'Glyphicons Halflings';padding-left:2px}.rating-gly-star .rating-stars:before{padding-left:2px}.rating-lg .rating-gly-star,.rating-lg .rating-gly-star .rating-stars:before{padding-left:4px}.rating-xl .rating-gly-star,.rating-xl .rating-gly-star .rating-stars:before{padding-left:2px}.rating-active{cursor:default}.rating-disabled{cursor:not-allowed}.rating-uni{font-size:1.2em;margin-top:-5px}.rating-container{position:relative;vertical-align:middle;display:inline-block;color:#e3e3e3;overflow:hidden}.rating-container:before{content:attr(data-content)}.rating-container .rating-stars{position:absolute;left:0;top:0;white-space:nowrap;overflow:hidden;color:#fde16d;transition:all .25s ease-out;-o-transition:all .25s ease-out;-moz-transition:all .25s ease-out;-webkit-transition:all .25s ease-out}.rating-container .rating-stars:before{content:attr(data-content);text-shadow:0 0 1px rgba(0,0,0,.7)}.rating-container-rtl{position:relative;vertical-align:middle;display:inline-block;overflow:hidden;color:#fde16d}.rating-container-rtl:before{content:attr(data-content);text-shadow:0 0 1px rgba(0,0,0,.7)}.rating-container-rtl .rating-stars{position:absolute;left:0;top:0;white-space:nowrap;overflow:hidden;color:#e3e3e3;transition:all .25s ease-out;-o-transition:all .25s ease-out;-moz-transition:all .25s ease-out;-webkit-transition:all .25s ease-out}.rating-container-rtl .rating-stars:before{content:attr(data-content)}.rating-xl{font-size:4.89em}.rating-lg{font-size:3.91em}.rating-md{font-size:3.13em}.rating-sm{font-size:2.5em}.rating-xs{font-size:2em}.star-rating .clear-rating,.star-rating-rtl .clear-rating{color:#aaa;cursor:not-allowed;display:inline-block;vertical-align:middle;font-size:60%}.clear-rating-active{cursor:pointer!important}.clear-rating-active:hover{color:#843534}.star-rating .clear-rating{padding-right:5px}.star-rating .caption,.star-rating-rtl .caption{color:#999;display:inline-block;vertical-align:middle;font-size:55%}.star-rating .caption{padding-left:5px}.star-rating-rtl .caption{padding-right:5px} \ No newline at end of file