[virtualcommons-developer] commit/vcweb: 2 new changesets
Status: Beta
Brought to you by:
alllee
From: <com...@bi...> - 2013-03-27 04:53:20
|
2 new commits in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/5cb16c9dbc4f/ Changeset: 5cb16c9dbc4f User: alllee Date: 2013-03-27 05:01:02 Summary: styling chat sidebar Affected #: 4 files diff -r 65cdbed51c4e01ece5079179a5a58fad5c27c07c -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 vcweb/boundaries/models.py --- a/vcweb/boundaries/models.py +++ b/vcweb/boundaries/models.py @@ -294,6 +294,7 @@ player_status_dv = get_player_status_dv(pgr, round_data) player_alive = player_status_dv.boolean_value if not player_alive: + logger.debug("Skipping deceased participant %s", pgr) continue harvest_decision = get_harvest_decision(pgr, round_data) storage_dv = get_storage_dv(pgr, round_data) diff -r 65cdbed51c4e01ece5079179a5a58fad5c27c07c -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 vcweb/boundaries/templates/boundaries/participate.html --- a/vcweb/boundaries/templates/boundaries/participate.html +++ b/vcweb/boundaries/templates/boundaries/participate.html @@ -21,17 +21,16 @@ {% endblock content %} {% block sidebar %} -<h3>Chat</h3> -<div class='chat-sidebar well'> - <form id="chat-form" class='form-inline'> - <div class='input-prepend input-append'> - <span class='add-on'><i class='text-info icon-comment'></i></span> - <input class='chat-action input-block-level' id='chatText' type="text" placeholder="Enter a chat message"> - <button class='btn' data-bind='click: submitChatMessage'>Send</button> - </div> - </form> +<form id="chat-form" class='form-inline'> + <div class='input-prepend input-append'> + <span class='add-on'><i class='text-info icon-comment'></i></span> + <input id='chatMessage' type="text" placeholder="Enter a chat message"> + <button class='btn btn-primary' data-bind='click: submitChatMessage'>Send</button> + </div> +</form> +<div class='chat-sidebar'><div id='chat-div'> - <div data-bind='foreach: chatMessages'> + <div class='chat-messages' data-bind='foreach: chatMessages'><i class='icon-user muted'></i><strong>Participant <span data-bind='text: participant_number'></strong><b class='pull-right muted' data-bind='text: date_created'></b><p><small><i class='icon-double-angle-right'></i></small><span data-bind='text: message'></span> @@ -436,7 +435,6 @@ model.resourceImageHeight = ko.observable("79px"); model.startRound = function() { model.enableChat(); - model.setFormDisabled("#vcweb-form", true); model.secondsLeft(model.roundDuration()); model.setCurrentInterval( setInterval(function() { @@ -457,21 +455,24 @@ model.setFormDisabled("#vcweb-form", true); model.setFormDisabled("#chat-form", true); console.debug(formData); - $.post('submit-harvest-decision', formData, function(jsonString) { - console.log(jsonString); - //update($.parseJSON(jsonString.experimentModelJson)); - model.secondsLeft(0); + $.post('submit-harvest-decision', formData, function(response) { + console.log(response); + model.update($.parseJSON(response.experimentModelJson)); + // FIXME: forward the response message to the chat window should be handled completely on the server + // side instead of ping-ponging to the client side back to the real time server back out to all + // clients in this group + getWebSocket().send(createMessageEvent(response.message)); model.clearCurrentInterval(); }); } model.submitChatMessage = function(data, evt) { evt.preventDefault(); console.log("clicking chat message"); - var message = $('#chatText').val(); + var message = $('#chatMessage').val(); if (message) { - $('#chatText').val(''); + $('#chatMessage').val(''); getWebSocket().send(createMessageEvent(message)); - $('#chatText').focus(); + $('#chatMessage').focus(); } } model.update = function() { @@ -494,19 +495,21 @@ // $('#content').removeClass('span6').addClass('span9'); // $('#sidebar').removeClass('span6').addClass('span3'); model.setFormDisabled("#chat-form", true); - model.chatEnabled(false); } model.enableChat = function() { // $('#content').removeClass('span9').addClass('span6'); // $('#sidebar').removeClass('span3').addClass('span6'); + model.setFormDisabled("#vcweb-form", true); model.setFormDisabled("#chat-form", false); - model.chatEnabled(true); } model.afterRenderTemplate = function(elements) { - if (model.submitted()) { + if (model.submitted() || ! model.alive()) { model.setFormDisabled("#vcweb-form", true); model.setFormDisabled("#chat-form", true); } + else { + model.setFormDisabled("#vcweb-form", false); + } if (model.roundType() === "REGULAR") { model.startRound() } diff -r 65cdbed51c4e01ece5079179a5a58fad5c27c07c -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 vcweb/boundaries/views.py --- a/vcweb/boundaries/views.py +++ b/vcweb/boundaries/views.py @@ -40,7 +40,10 @@ pgr = get_object_or_404(ParticipantGroupRelationship, pk=participant_group_id) harvest_decision = form.cleaned_data['integer_decision'] set_harvest_decision(pgr, harvest_decision, experiment.current_round_data, submitted=True) - return JsonResponse(dumps({ 'success': True, 'experimentModelJson': get_view_model_json(experiment, pgr)})) + message = "harvested %s trees" % harvest_decision + experiment.log(message) + return JsonResponse(dumps({ 'success': True, 'experimentModelJson': get_view_model_json(experiment, pgr), + 'message': message})) else: logger.debug("form was invalid: %s", form) for field in form: @@ -64,6 +67,7 @@ 'warningCountdownTime': 10, 'maxHarvestDecision': 10, 'harvestDecision': 0, + 'chatMessages': [], } # FIXME: need to distinguish between instructions / welcome rounds and practice/regular rounds def get_view_model_json(experiment, participant_group_relationship, **kwargs): @@ -124,6 +128,7 @@ 'message': cm.string_value, 'date_created': cm.date_created.strftime("%I:%M:%S") } for cm in ChatMessage.objects.for_group(own_group)] + logger.debug("chat messages: %s", experiment_model_dict['chatMessages']) experiment_model_dict['canObserveOtherGroup'] = can_observe_other_group(current_round) if not current_round.is_practice_round and experiment_model_dict['canObserveOtherGroup']: gr = GroupRelationship.objects.select_related('cluster').get(group=own_group) diff -r 65cdbed51c4e01ece5079179a5a58fad5c27c07c -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 vcweb/static/css/boundaries/style.css --- a/vcweb/static/css/boundaries/style.css +++ b/vcweb/static/css/boundaries/style.css @@ -1,6 +1,19 @@ .chat-sidebar { - height: 600px; - padding: 10px; + background-color: #f5f5f5; + border: 1px solid #e3e3e3; + padding: 0px 0px 0px 0px; + margin: 0px; + height: 520px; +} +.chat-messages { + padding: 5px; +} +#chat-div { + overflow: auto; + height: inherit; +} +#chatMessage { + width: auto; } .boundaries-status-dashboard p { padding-top: 15px; https://bitbucket.org/virtualcommons/vcweb/commits/be61831f5354/ Changeset: be61831f5354 User: alllee Date: 2013-03-27 05:53:02 Summary: switching to get_max_allowed_harvest_decision and using KO to render the select options instead of django Affected #: 3 files diff -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 -r be61831f5354003e211ca1bec17819b94e61c97a vcweb/boundaries/models.py --- a/vcweb/boundaries/models.py +++ b/vcweb/boundaries/models.py @@ -90,8 +90,13 @@ return round_configuration.get_parameter_value(get_cost_of_living_parameter(), default=5).int_value -def get_max_harvest(experiment): - return experiment.experiment_configuration.get_parameter_value(parameter=get_max_harvest_decision_parameter(), default=10).int_value +def get_max_harvest_decision(experiment_configuration): + return experiment_configuration.get_parameter_value(parameter=get_max_harvest_decision_parameter(), default=10).int_value + +def get_max_allowed_harvest_decision(participant_group_relationship, round_data=None, experiment_configuration=None): + group = participant_group_relationship.group + resource_level = get_resource_level(group, round_data) + return min(get_max_harvest_decision(experiment_configuration), resource_level / group.size) ''' group data accessors ''' diff -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 -r be61831f5354003e211ca1bec17819b94e61c97a vcweb/boundaries/templates/boundaries/participate.html --- a/vcweb/boundaries/templates/boundaries/participate.html +++ b/vcweb/boundaries/templates/boundaries/participate.html @@ -21,6 +21,12 @@ {% endblock content %} {% block sidebar %} +<h3>Chat</h3> +<div data-bind='ifnot: chatEnabled'> + <div class='alert alert-info'> + <i class='icon-info-sign'></i> Chat is disabled until the next round begins. + </div> +</div><form id="chat-form" class='form-inline'><div class='input-prepend input-append'><span class='add-on'><i class='text-info icon-comment'></i></span> @@ -339,9 +345,9 @@ <input id='participantGroupId' type='hidden' name='participant_group_id' data-bind='value: participantGroupId'/><input id='harvestDecisionTextInput' type='hidden' name='integer_decision' data-bind='value: harvestDecision'><select id='harvestDecisionSelect' required="required" form="vcweb-form" data-bind='value: harvestDecision'> - {% for i in harvest_decision_choices %} - <option>{{i}}</option> - {% endfor %} + <!-- ko foreach: ko.utils.range(0, maxHarvestDecision()) --> + <option data-bind='value: $data, text: $data'></option> + <!-- /ko --></select></div> diff -r 5cb16c9dbc4ff9758c1ac7cc88415442d4ac48b9 -r be61831f5354003e211ca1bec17819b94e61c97a vcweb/boundaries/views.py --- a/vcweb/boundaries/views.py +++ b/vcweb/boundaries/views.py @@ -5,7 +5,7 @@ from vcweb.core.http import JsonResponse from vcweb.core.models import (Experiment, ParticipantGroupRelationship, ChatMessage, GroupRelationship) from vcweb.boundaries.forms import SingleIntegerDecisionForm -from vcweb.boundaries.models import (get_experiment_metadata, get_regrowth_rate, get_max_harvest, +from vcweb.boundaries.models import (get_experiment_metadata, get_regrowth_rate, get_max_allowed_harvest_decision, get_cost_of_living, get_resource_level, get_initial_resource_level, get_total_storage, get_storage, get_last_harvest_decision, get_harvest_decision_dv, set_harvest_decision, can_observe_other_group, get_player_status) @@ -20,12 +20,9 @@ pgr = experiment.get_participant_group_relationship(participant) if experiment.experiment_metadata != get_experiment_metadata() or pgr.participant != request.user.participant: raise Http404 - -# FIXME: should limit harvest_decision_choices by min(max_harvest, resource_level / group.size) return render(request, 'boundaries/participate.html', { 'auth_token': participant.authentication_token, 'experiment': experiment, - 'harvest_decision_choices': range(get_max_harvest(experiment) + 1), 'participant_experiment_relationship': experiment.get_participant_experiment_relationship(participant), 'participant_group_relationship': pgr, 'experimentModelJson': get_view_model_json(experiment, pgr), @@ -65,7 +62,6 @@ 'maxEarnings': 20.00, 'maximumResourcesToDisplay': 20, 'warningCountdownTime': 10, - 'maxHarvestDecision': 10, 'harvestDecision': 0, 'chatMessages': [], } @@ -83,6 +79,7 @@ regrowth_rate = get_regrowth_rate(current_round) cost_of_living = get_cost_of_living(current_round) experiment_model_dict['costOfLiving'] = cost_of_living + experiment_model_dict['maxHarvestDecision'] = get_max_allowed_harvest_decision(participant_group_relationship, current_round_data, ec) # instructions round parameters if current_round.is_instructions_round: experiment_model_dict['participantsPerGroup'] = ec.max_group_size 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. |