[virtualcommons-developer] commit/vcweb: dieg...@gmail.com: setting up round transitions and partic
Status: Beta
Brought to you by:
alllee
1 new commit in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/941832738911/ Changeset: 941832738911 User: di...@gm... Date: 2013-03-22 22:07:10 Summary: setting up round transitions and participant / experimenter synchronization and wiring up submit decision and conservation decisions Affected #: 3 files diff -r 4d70504fa520013746cd744640e5525c32005f57 -r 9418327389116cb15600c3e1ba52cf76ccd0cb8a vcweb/broker/templates/broker/participate.html --- a/vcweb/broker/templates/broker/participate.html +++ b/vcweb/broker/templates/broker/participate.html @@ -369,12 +369,13 @@ <td><div><div class='control-group'> - <div class='controls'> - <input id='participantGroupId' type='hidden' name='participant_group_id'/> + <div class='controls input-append'> + <input id='participantGroupId' type='hidden' name='participant_group_id' value="{{ participant_group_relationship.pk }}"/><input id='harvestDecisionId' type="number" size="1" maxlength="1" - name='harvest_decision' - class='required' min="0" + name='integer_decision' + class='required input-mini' min="0" data-bind="value: harvestDecision, attr: { max: maxHarvestDecision }"/> + <span class='add-on'>hrs</span><button id='submitDecision' data-bind='click: submitDecision' type='submit' class='btn'> @@ -390,10 +391,11 @@ <td><div> - <div class='controls'> + <div class='input-append'><input id='conservationDecision' type="number" size="1" maxlength="1" - name='conservation_decision' class='disabled' min="0" + name='conservation_decision' class='input-mini disabled' disabled min="0" data-bind="value: conservationDecision"/> + <span class='add-on'>hrs</span></div> @@ -469,6 +471,7 @@ var self = this; var model = ko.mapping.fromJS(experimentModelJson); + model.isTimeOut = ko.observable(0) model.hasSubmit = ko.observable(0) model.secondsLeft = ko.observable(0); @@ -513,7 +516,6 @@ } }); }; - model.templateName = ko.observable("WELCOME"); // activate instructions click bindings model.activateInstructionsPageOne = function () { model.templateName('GENERAL_INSTRUCTIONS'); @@ -540,19 +542,17 @@ model.networkStructure = ko.observable("{{STATIC_URL}}images/broker/SES.jpg"); model.networkStructureImageWidth = ko.observable("600px"); model.networkStructureImageHeight = ko.observable("80px"); - model.finishedInstructions = function () { - {% comment %}console.debug("instructions were finished, notifying experimenter"); + model.participantReady = function () { $.post('/experiment/participant-ready', { participant_group_id: {{ participant_group_relationship.pk }} }, function (response) { console.debug("successfully posted to server, notifying sockjs: " + response); - getWebSocket().send(createMessageEvent("Instructions completed", "client_ready"));{% endcomment %} - model.templateName("PRACTICE"); - - } + getWebSocket().send(createMessageEvent("Participant ready", "client_ready")); + }); + }; model.chatEnabled = ko.observable(false); // round configurations model.chatOptionEnabled = ko.observable(false); // round configurations model.harvestDecision = ko.observable(0); model.conservationDecision = ko.computed(function () { - return model.conservationDecision == model.maxHarvestDecision() - model.harvestDecision(); + return model.maxHarvestDecision() - model.harvestDecision(); }); // model.numberOfTreesPerRow = ko.observable(10); // model.isResourceEmpty = ko.computed(function() { @@ -603,21 +603,20 @@ }, 1000)); }; - // model.submitDecision = function(data, evt) { -// if (evt) { -// evt.preventDefault(); -// } -// var formData = $('#vcweb-form').serialize(); -// $.post('submit-harvest-decision', formData, function(jsonString) { -// console.log(jsonString); -// // FIXME: should probably update the entire model after we remove the test panel -// // update(data.experimentModelJson); -// // ko.mapping.fromJSON(data.experimentModelJson, model); -// model.secondsLeft(0); -// model.hasSubmit(true); -// model.clearCurrentInterval(); -// }); -// } + model.submitDecision = function(data, evt) { + var formData = $('#vcweb-form').serialize(); + $.post('submit-decision', formData, function(response) { + console.log(response); + if (response.success) { + console.debug("updating view model"); + ko.mapping.fromJSON(response.experimentModelJson, model); + getWebSocket().send() + } + // model.secondsLeft(0); + // model.hasSubmit(true); + // model.clearCurrentInterval(); + }); + }; // model.submitChatMessage = function(data, evt) { // evt.preventDefault(); // console.log("clicking chat message"); @@ -654,6 +653,7 @@ function initialize(experimentModelJson) { var experimentModel = new ExperimentModel(experimentModelJson); ko.applyBindings(experimentModel); + console.debug("CURRENT TEMPLATE: " + experimentModel.templateName()); var s = connect(); s.onmessage = function (json) { console.debug(json); @@ -664,7 +664,7 @@ experimentModel.chatMessages.unshift(data); console.debug("received chat message:" + json); break; - case 'update_view_model': + case 'update': console.debug("updating view model"); experimentModel.update(); break; @@ -784,6 +784,7 @@ var experimentModelJson = $.parseJSON("{{ experimentModelJson|escapejs }}"); initialize(experimentModelJson); + }); </script> {% endblock %} diff -r 4d70504fa520013746cd744640e5525c32005f57 -r 9418327389116cb15600c3e1ba52cf76ccd0cb8a vcweb/broker/urls.py --- a/vcweb/broker/urls.py +++ b/vcweb/broker/urls.py @@ -3,7 +3,7 @@ urlpatterns = patterns('vcweb.broker.views', url(r'^(?P<experiment_id>\d+)?/participate/?$', participate, name='participate'), - url(r'^(?P<experiment_id>\d+)/submit-harvest-decision$', submit_decision, name='submit_decision'), + url(r'^(?P<experiment_id>\d+)/submit-decision$', submit_decision, name='submit_decision'), url(r'^(?P<experiment_id>\d+)/view-model$', get_view_model, name='get_view_model'), ) diff -r 4d70504fa520013746cd744640e5525c32005f57 -r 9418327389116cb15600c3e1ba52cf76ccd0cb8a vcweb/broker/views.py --- a/vcweb/broker/views.py +++ b/vcweb/broker/views.py @@ -5,7 +5,7 @@ from vcweb.core.forms import ParticipantGroupIdForm, SingleIntegerDecisionForm from vcweb.core.http import JsonResponse from vcweb.core.models import (is_participant, is_experimenter, Experiment, ParticipantGroupRelationship, - ParticipantExperimentRelationship, ChatMessage, ParticipantRoundDataValue) + ParticipantExperimentRelationship, RoundConfiguration, ChatMessage, ParticipantRoundDataValue) from vcweb.broker.models import get_max_harvest_hours, get_harvest_decision_parameter, get_conservation_hours_parameter @@ -47,6 +47,7 @@ return render(request, 'broker/participate.html', { 'experiment': experiment, + 'participant_experiment_relationship': experiment.get_participant_experiment_relationship(participant), 'participant_group_relationship': participant_group_relationship, 'experimentModelJson': get_view_model_json(experiment, participant_group_relationship), }) @@ -76,7 +77,9 @@ experiment_model_dict['networkStructure'] = 10 practice_round = round_configuration.is_practice_round experiment_model_dict['practiceRound'] = practice_round - + experiment_model_dict['templateName'] = round_configuration.round_type + if practice_round: + experiment_model_dict['templateName'] = RoundConfiguration.RoundType.REGULAR if practice_round and round_configuration.sequence_number == 3: experiment_model_dict['isFirstPracticeRound'] = True experiment_model_dict['isSecondPracticeRound'] = False Repository URL: https://bitbucket.org/virtualcommons/vcweb/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |