[virtualcommons-developer] commit/vcweb: alllee: adding progress modals for participant updates and
Status: Beta
Brought to you by:
alllee
|
From: <com...@bi...> - 2013-03-20 08:41:54
|
1 new commit in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/a1dd1c200888/ changeset: a1dd1c200888 user: alllee date: 2013-03-20 09:41:39 summary: adding progress modals for participant updates and starting to wire up experimenter->sockjs->client update cycle affected #: 7 files diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/boundaries/templates/boundaries/participate.html --- a/vcweb/boundaries/templates/boundaries/participate.html +++ b/vcweb/boundaries/templates/boundaries/participate.html @@ -7,6 +7,16 @@ {% block content %} <div data-bind='template: { name: templateName() }'></div> +<div id='progress-modal' class='modal hide fade'> + <div class='model-header'> + <h3>Updating experiment data</h3> + </div> + <div class='modal-body'> + <div class='progress progress-striped active'> + <div id='progress-bar' class='bar' style='width: 100%'></div> + </div> + </div> +</div> {% endblock content %} {% block sidebar %} @@ -433,9 +443,7 @@ 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); + //update($.parseJSON(jsonString.experimentModelJson)); model.secondsLeft(0); model.hasSubmit(true); model.clearCurrentInterval(); @@ -451,6 +459,14 @@ $('#chatText').focus(); } } + model.update = function() { + $.get('view-model', { participant_group_id: {{ participant_group_relationship.pk }} }, function(data) { + console.debug("retrieved view model successfully"); + console.debug(data); + ko.mapping.fromJS(data, model); + $('#progress-modal').modal('hide'); + }); + } model.disableChat = function() { $('#content').removeClass('span6').addClass('span9'); $('#sidebar').removeClass('span6').addClass('span3'); @@ -465,11 +481,6 @@ } return model; } - function update(experimentModel) { - return function(data) { - ko.mapping.fromJS(data, experimentModel); - } - } function initialize(experimentModelJson) { var experimentModel = new ExperimentModel(experimentModelJson); ko.applyBindings(experimentModel); @@ -483,17 +494,18 @@ experimentModel.chatMessages.unshift(data); console.debug("received chat message:" + json); break; + case 'update': + $('#progress-modal').modal('show'); + experimentModel.update(); default: console.debug("unhandled json message:" + json); break; } - update(json); }; $('#harvestDecision').keyup(function() { $('#harvestDecision').val(this.value.match(/\d+/)); }); } - //send the message when submit is clicked var experimentModelJson = $.parseJSON("{{ experimentModelJson|escapejs }}"); initialize(experimentModelJson); }); diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/boundaries/urls.py --- a/vcweb/boundaries/urls.py +++ b/vcweb/boundaries/urls.py @@ -1,10 +1,11 @@ from django.conf.urls.defaults import url, patterns -from vcweb.boundaries.views import (participate, submit_harvest_decision) +from vcweb.boundaries.views import (participate, submit_harvest_decision, get_view_model) urlpatterns = patterns('vcweb.boundaries.views', url(r'^$', 'index', name='index'), url(r'^(?P<experiment_id>\d+)/configure$', 'configure', name='configure'), url(r'^(?P<experiment_id>\d+)/experimenter$', 'monitor_experiment', name='monitor_experiment'), url(r'^(?P<experiment_id>\d+)/participate$', participate, name='participate'), + url(r'^(?P<experiment_id>\d+)/view-model$', get_view_model, name='view_model'), url(r'^(?P<experiment_id>\d+)/submit-harvest-decision$', submit_harvest_decision, name='submit_harvest_decision'), ) diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/boundaries/views.py --- a/vcweb/boundaries/views.py +++ b/vcweb/boundaries/views.py @@ -53,6 +53,11 @@ logger.debug("field %s had errors %s", field, field.errors) return JsonResponse(dumps({'success': False })) +@participant_required +def get_view_model(request, experiment_id=None): + experiment = get_object_or_404(Experiment.select_related('experiment_metadata', 'experiment_configuration'), pk=experiment_id) + pgr = experiment.get_participant_group_relationship(request.user.participant) + return JsonResponse(get_view_model_json(experiment, pgr)) # FIXME: need to distinguish between instructions / welcome rounds and practice/regular rounds def get_view_model_json(experiment, participant_group_relationship, **kwargs): diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/core/templates/experimenter/monitor.html --- a/vcweb/core/templates/experimenter/monitor.html +++ b/vcweb/core/templates/experimenter/monitor.html @@ -140,7 +140,7 @@ </div><div id='progress-modal' class='modal hide fade'><div class='model-header'> - <h3>Updating experiment status</h3> + <h3>Updating experiment data</h3></div><div class='modal-body'><div class='progress progress-striped active'> @@ -163,6 +163,7 @@ confirmExperimentControllerAction(evt.target, model, function(confirmed) { if (confirmed) { console.debug("advancing to next round, notify all participants"); + sendUpdateEvent(); } }); }; diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/core/templates/includes/experimenter.events.html --- a/vcweb/core/templates/includes/experimenter.events.html +++ b/vcweb/core/templates/includes/experimenter.events.html @@ -1,4 +1,7 @@ <script type="text/javascript"> +function createUpdateEvent() { + return createMessageEvent("Update all participants", "update_participants"); +} function createRefreshEvent() { return createMessageEvent("Refresh all clients", "refresh"); } @@ -29,6 +32,9 @@ function createChatEvent(message) { return createMessageEvent(message); } +function sendUpdateEvent() { + getWebSocket().send(createUpdateEvent()); +} function sendRefreshEvent() { var webSocket = getWebSocket(); if (webSocket) { diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/core/views.py --- a/vcweb/core/views.py +++ b/vcweb/core/views.py @@ -96,9 +96,10 @@ # FIXME: could also use collections.defaultdict or regroup template tag to # accomplish this.. experiment_dict = {} - for experiment in user.participant.experiments.exclude(status__in=(Experiment.INACTIVE, Experiment.PAUSED, Experiment.COMPLETED)): +# FIXME: this needs to be refactored + for experiment in user.participant.experiments.exclude(status__in=(Experiment.Status.INACTIVE, Experiment.Status.PAUSED, Experiment.Status.COMPLETED)): if not experiment.experiment_metadata in experiment_dict: - experiment_dict[experiment.experiment_metadata] = dict([(choice[0], list()) for choice in Experiment.STATUS]) + experiment_dict[experiment.experiment_metadata] = dict([(choice[0], list()) for choice in Experiment.Status]) experiment_dict[experiment.experiment_metadata][experiment.status].append(experiment) logger.info("experiment_dict %s", experiment_dict) return experiment_dict diff -r f51624f9cb1b3b6e07b2e47a3915fde1da36ae34 -r a1dd1c200888f982753d36439d02942166088b96 vcweb/vcweb-sockjs.py --- a/vcweb/vcweb-sockjs.py +++ b/vcweb/vcweb-sockjs.py @@ -188,6 +188,9 @@ connection.send(REFRESH_EVENT) return participant_connections + def send_update(self, experimenter, experiment): + pass + def send_goto(self, experimenter, experiment, url): notified_participants = [] message = json.dumps({'event_type': 'goto', 'url': url}) @@ -359,6 +362,10 @@ notified_participants = connection_manager.send_refresh(experimenter, experiment) self.send(create_message_event("Refreshed all connected participant pgr_ids=%s)" % notified_participants)) + def handle_update_participants(self, event, experiment, experimenter): + notified_participants = connection_manager.send_update(experimenter, experiment) + self.send(create_message_event("Updating all connected participants pgr_ids=%s)" % notified_participants)) + def on_close(self): #self.client.unsubscribe(self.default_channel) pass 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. |