# HG changeset patch # User Lennard de Rijk # Date 1237924175 0 # Node ID 4d9e41c947fd54d6802f63d01fbbac26b7f5e6f3 # Parent ed24a0bd19d98e1696099d7a61e97c35c389bdb0 Added JS to the duplicate proposals page. TODO's: Caching Fix the recalculate to properly clear the previous iteration. Patch by: Mario Ferraro Reviewed by: Lennard de Rijk diff -r ed24a0bd19d9 -r 4d9e41c947fd app/soc/content/js/duplicate-slots-090324.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/content/js/duplicate-slots-090324.js Tue Mar 24 19:49:35 2009 +0000 @@ -0,0 +1,182 @@ +//http://www.digital-web.com/articles/scope_in_javascript/ +var duplicateSlots = new function() { + // this variable will contain all the org details, and filled + // incrementally + var orgs_details = {}; + // this variable will contain all student/proposal data details, + // filled incrementally + var assigned_proposals = new Array(); + + // public function to begin iterating load of JSONs and then call printing + // of duplicates + + this.showDuplicatesInit = function() { + + // Remember this object for Javascript scoping + var this_object = this; + var NUMBER_OF_ORGS = number_of_orgs; + var OFFSET_LENGTH = offset_length; + // Variables to handle progress bar updating + var ITERATIONS = (number_of_orgs % offset_length)==0 ? Math.floor(number_of_orgs/offset_length) : Math.floor(number_of_orgs/offset_length)+1; + var successful_calls = 0; + + $("#id_button_duplicate_slots").fadeOut("slow", + function() { + $("#duplicates_progress_bar").progressBar(0); + $("#description_done").html(""); + // For every ajax success, bind this function to update user feedback + $(this).bind("ajaxSuccess", function() { + successful_calls++; + var percentage = Math.floor(100 * (successful_calls) / (ITERATIONS)); + $("#duplicates_progress_bar").progressBar(percentage); + $("#description_progressbar").html(" Processed orgs chunk " + (successful_calls) + "/" + ITERATIONS); + // If this is the last call, feedback the user and print the duplicates data + if (successful_calls==ITERATIONS) { + $("#applications_progress_bar").fadeOut("slow", + function() { + $("#duplicates_progress_bar").progressBar(0); + $("#id_button_duplicate_slots").fadeIn("slow"); + } + ); + $("#description_progressbar").html(""); + $("#description_done").html(" Done!"); + $("#duplicates_progress_bar").fadeOut("slow", + function() { + $("#id_button_duplicate_slots").val("Recalculate").fadeIn("slow", + function() { + // Call printing to HTML function with correct scope + printDuplicatesAndSendJSON.call(this_object); + } + ); + } + ); + } + }); + // Call the showDuplicates function for the first time with correct scope + $("#duplicates_progress_bar").fadeIn("slow", showDuplicates.apply(this_object,[url_to_query,OFFSET_LENGTH,NUMBER_OF_ORGS])); + } + ); + } + + function showDuplicates(url_to_query,OFFSET_LENGTH,NUMBER_OF_ORGS) { + var current_offset = 0; + + // Here Ajax call is handled + setTimeout(function() { + $.ajax({ + cache:false, + mode: "sync", + type: "POST", + timeout: 1000000, + dataType: "json", + url: "/program/assigned_proposals/"+url_to_query+"?limit="+OFFSET_LENGTH+"&offset="+current_offset+"&_="+(new Date().getTime()), + success: function (data, textStatus) { + if (data) { + // Load JSON data + loadSingleJSONData(data); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + // if there is an error return the button and leave a try again message + if (XMLHttpRequest!=undefined) { + $("#id_button_duplicate_slots").fadeIn("slow", function() { + $("#description_done").html(" Error encountered, try again"); + }); + } + } + }); + current_offset+=OFFSET_LENGTH; + if (current_offsetNo duplicate slots found"); + } + // at the end, send the JSON for caching purposes + $.ajax({ + url: location.href, + type: 'POST', + processData: true, + data: {result: JSON.stringify(to_json)}, + contentType: 'application/json', + dataType: 'json', + }); + } + + // public function to output actual HTML out of the data (cached or not) + this.showDuplicatesHtml = function(orgs_details,student,student_key,proposals) { + if (html_string==='') { + html_string=''; + $("#div_duplicate_slots").html(html_string); + } +} diff -r ed24a0bd19d9 -r 4d9e41c947fd app/soc/templates/soc/base.html --- a/app/soc/templates/soc/base.html Tue Mar 24 18:43:22 2009 +0000 +++ b/app/soc/templates/soc/base.html Tue Mar 24 19:49:35 2009 +0000 @@ -98,6 +98,9 @@ {% if uses_slot_allocator %} {% endif %} + {% if uses_duplicates %} + + {% endif %} {% endblock %} diff -r ed24a0bd19d9 -r 4d9e41c947fd app/soc/templates/soc/program/show_duplicates.html --- a/app/soc/templates/soc/program/show_duplicates.html Tue Mar 24 18:43:22 2009 +0000 +++ b/app/soc/templates/soc/program/show_duplicates.html Tue Mar 24 19:49:35 2009 +0000 @@ -19,6 +19,43 @@ {% endblock %} {% block body %} -{{ info }}
-{{ duplicate_cache_content }} + + + + + +

+
{% endblock %} diff -r ed24a0bd19d9 -r 4d9e41c947fd app/soc/views/models/program.py --- a/app/soc/views/models/program.py Tue Mar 24 18:43:22 2009 +0000 +++ b/app/soc/views/models/program.py Tue Mar 24 19:49:35 2009 +0000 @@ -380,6 +380,8 @@ context = helper.responses.getUniversalContext(request) helper.responses.useJavaScript(context, params['js_uses_all']) + context['uses_duplicates'] = True + context['uses_json'] = True context['page_name'] = page_name # get all orgs for this program who are active and have slots assigned @@ -397,6 +399,7 @@ # TODO(ljvderijk) cache the result of the duplicate calculation context['duplicate_cache_content'] = simplejson.dumps({}) + context['offset_length'] = 10 template = 'soc/program/show_duplicates.html' @@ -460,7 +463,6 @@ 'status': 'accepted'} query = student_proposal_logic.logic.getQueryForFields(fields) - test = query.count() slots_left_to_assign = max(0, org.slots - query.count())