[virtualcommons-developer] commit/vcweb: alllee: fixing click bindings / refactoring experiment mon
Status: Beta
Brought to you by:
alllee
|
From: <com...@bi...> - 2013-03-21 23:21:19
|
1 new commit in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/c01f18439b84/ Changeset: c01f18439b84 User: alllee Date: 2013-03-22 00:21:17 Summary: fixing click bindings / refactoring experiment monitor confirmations Affected #: 2 files diff -r 02909e4e92ea99ac360cb0d0354605d9f7bca9c8 -r c01f18439b84d0036ea4d6a43086c16fc962acfc vcweb/boundaries/models.py --- a/vcweb/boundaries/models.py +++ b/vcweb/boundaries/models.py @@ -2,9 +2,10 @@ from vcweb.core import signals, simplecache from vcweb.core.models import ExperimentMetadata, Parameter, ParticipantRoundDataValue from vcweb.forestry.models import (get_harvest_decision_parameter, get_harvest_decision, get_regrowth_rate, - get_group_harvest_parameter, get_reset_resource_level_parameter, get_resource_level, get_initial_resource_level - as forestry_initial_resource_level, set_resource_level, get_regrowth_parameter, get_resource_level_parameter, - has_resource_level, get_resource_level_dv, get_harvest_decisions, set_group_harvest, set_regrowth) + get_group_harvest_parameter, get_reset_resource_level_parameter, get_resource_level, + get_initial_resource_level as forestry_initial_resource_level, set_resource_level, get_regrowth_parameter, + get_resource_level_parameter, has_resource_level, get_resource_level_dv, get_harvest_decisions, + set_group_harvest, set_regrowth) import logging @@ -37,7 +38,7 @@ @simplecache def get_max_harvest_decision_parameter(): - return Parameter.objects.for_round(name='max_harvest_decision') + return Parameter.objects.for_experiment(name='max_harvest_decision') @simplecache def get_cost_of_living_parameter(): @@ -64,6 +65,9 @@ def get_initial_resource_level(round_configuration, default=MAX_RESOURCE_LEVEL): return forestry_initial_resource_level(round_configuration, default) +def get_max_harvest(experiment): + return experiment.get_parameter_value(parameter=get_max_harvest_decision_parameter(), default=10).int_value + def get_cost_of_living(current_round): return current_round.get_parameter_value(get_cost_of_living_parameter(), default=5).int_value @@ -104,11 +108,11 @@ group_parameters=(get_regrowth_parameter(), get_group_harvest_parameter(), get_resource_level_parameter()), participant_parameters=[get_harvest_decision_parameter(), get_storage_parameter(), get_player_status_parameter()] ) + ''' - during a practice or regular round, set up resource levels and participant - harvest decision parameters + during a practice or regular round, set up resource levels, participant harvest decision parameters, and possibly + group formation ''' - if should_reset_resource_level(round_configuration): initial_resource_level = get_initial_resource_level(round_configuration) logger.debug("Resetting resource level for %s to %d", round_configuration, initial_resource_level) diff -r 02909e4e92ea99ac360cb0d0354605d9f7bca9c8 -r c01f18439b84d0036ea4d6a43086c16fc962acfc vcweb/core/templates/experimenter/monitor.html --- a/vcweb/core/templates/experimenter/monitor.html +++ b/vcweb/core/templates/experimenter/monitor.html @@ -12,11 +12,15 @@ <li><div class='btn-toolbar'><div class='btn-group'> - <a class='btn btn-success' data-bind="click: confirmExperimentAction, css: { disabled: isRoundInProgress }" data-action='start_round' data-content='Starts the round.'><i class='icon-play'></i> start</a> - <a class='btn btn-success' data-bind='click: advanceToNextRound' data-action='advance_to_next_round' data-content='Advances to and starts the next round.'><i class='icon-step-forward'></i> next round</a> - <a class='btn btn-success' data-bind='click: updateParticipants' data-content='Updates all connected participants.' ><i class='icon-exchange'></i> update</a> - <a class='btn btn-primary' data-bind='click: update' data-content='Update this page and pull the latest data from the server.' ><i class='icon-refresh'></i></a> - <a class='btn btn-danger' data-bind='click: confirmExperimentAction' data-action='deactivate' data-content='Deactivates this experiment.'><i class='icon-off'></i></a> + <a class='btn btn-success' data-bind="click: confirmExperimentControllerAction.bind($data, true), css: { disabled: isRoundInProgress }" data-action='start_round' data-content='Starts the round.'><i class='icon-play'></i> start</a> + <a class='btn btn-success' data-bind='click: confirmExperimentControllerAction.bind($data, true)' data-action='advance_to_next_round' data-content='Advances to and starts the next round.'><i class='icon-step-forward'></i> next round</a> + </div> + </div> + <div class='btn-toolbar'> + <div class='btn-group'> + <a class='btn btn-success' data-bind='click: updateParticipants' data-content='Updates all connected participants.' ><i class='icon-exchange'></i> update participants</a> + <a class='btn btn-primary' data-bind='click: update' data-content='Update this page and pull the latest data from the server.' ><i class='icon-refresh'></i> refresh data</a> + <a class='btn btn-danger' data-bind='click: confirmExperimentControllerAction.bind($data, false)' data-action='deactivate' data-content='Deactivates this experiment.'><i class='icon-off'></i> deactivate</a></div></div></li> @@ -45,7 +49,7 @@ <p class='text-error'>NOTE: activating an experiment <b>will delete all existing data</b></p><a data-content='Starts this experiment, assigns participants to groups, etc.' - class='btn btn-success' data-bind='click: confirmExperimentAction' data-action='activate'><i class='icon-off'></i> activate</a> + class='btn btn-success' data-bind='click: confirmExperimentControllerAction.bind($data, false)' data-action='activate'><i class='icon-off'></i> activate</a></div></div></div> @@ -68,7 +72,7 @@ <li><a href='export/configuration.xml'><i class='icon-cog'></i>xml</a></li><li><a href='export/configuration.json'><i class='icon-pencil'></i>json</a></li></ul> - <a class='btn btn-danger' data-bind='css: { disabled: isArchived}, click: confirmExperimentAction' data-action='complete' data-content='Mark this experiment as completed and archive it.'><i class='icon-save'></i> archive</a> + <a class='btn btn-danger' data-bind='css: { disabled: isArchived}, click: confirmExperimentControllerAction.bind($data, false)' data-action='complete' data-content='Mark this experiment as completed and archive it.'><i class='icon-save'></i> archive</a></div></div><div class='span6'> @@ -182,27 +186,30 @@ }, { experiment_id: {{ experiment.pk }}, notes: notes }); } -// FIXME: code duplication here, prime candidate for refactoring + // FIXME: factor out the code duplication with this and confirmExperimentControllerAction for + // showing the modal and invoking the ajax call if possible model.update = function(localModel, evt) { $('#progress-modal').modal('show'); Dajaxice.vcweb.core.get_experiment_model(function (data) { ko.mapping.fromJS(data, model); $('#progress-modal').modal('hide');}, {pk: {{experiment.pk}}}); } - model.confirmExperimentAction = function(m, evt) { + model.confirmExperimentControllerAction = function(updateParticipants, localModel, evt) { element = evt.target; + console.debug(element); if ($(element).hasClass('disabled')) { - console.debug("aborting."); - return; + console.debug("aborting disabled action: " + element); + return false; } - confirmExperimentControllerAction(element, model); + confirmAction(element, function(confirmed, action) { + $('#progress-modal').modal('show'); + Dajaxice.vcweb.core.experiment_controller(function(data) { + ko.mapping.fromJS(data, experimentModel); + if (updateParticipants) { + sendUpdateEvent(); + } + $('#progress-modal').modal('hide'); + }, {pk: {{experiment.pk}}, 'action':action}); + }); } - model.advanceToNextRound = function(m, evt) { - confirmExperimentControllerAction(evt.target, m, function(confirmed) { - if (confirmed) { - console.debug("advancing to next round, notify all participants"); - sendUpdateEvent(); - } - }); - }; model.updateParticipants = function(m, evt) { confirmAction(evt.target, function(confirmed, action) { if (confirmed) { @@ -219,18 +226,6 @@ }); return model; } - function confirmExperimentControllerAction(element, experimentModel, callback) { - confirmAction(element, function(confirmed, action) { - $('#progress-modal').modal('show'); - Dajaxice.vcweb.core.experiment_controller(function(data) { - ko.mapping.fromJS(data, experimentModel); - if (callback) { - callback(confirmed, action); - } - $('#progress-modal').modal('hide'); - }, {pk: {{experiment.pk}}, 'action':action}); - }); - } function confirmAction(element, callback) { var self = $(element); var description = self.attr("data-content"); 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. |