Implemented dynamic load of activity records

Change-Id: I70bdd0b91ecdf8007de9ac9a5619a0d3b29c1426
This commit is contained in:
Ilya Shakhat
2013-08-15 14:47:37 +04:00
parent 822da253a4
commit 57ed3ecf80
2 changed files with 36 additions and 6 deletions

View File

@@ -6,6 +6,7 @@
{% set show_user_activity = (user_id) %}
{% set show_module_activity = (module) %}
{% set show_activity = (show_user_activity) or (show_module_activity) %}
{% set show_contribution = show_activity %}
{% set show_user_profile = (user_id) %}
{% block scripts %}
@@ -24,11 +25,18 @@
{% endif %}
{% if show_activity %}
$(document).ready(function () {
var page_size = 10;
var start_record = 0;
function load_activity() {
$.ajax({
url: make_uri("/data/activity.json"),
url: make_uri("/data/activity.json", {page_size: page_size, start_record: start_record}),
dataType: "json",
success: function (data) {
if (data["activity"].length < page_size) {
$('#activity_more').hide();
}
{% if metric == 'marks' %}
$("#review_activity_template").tmpl(data["activity"]).appendTo("#activity_container");
{% else %}
@@ -36,7 +44,17 @@
{% endif %}
}
});
}
$(document).ready(function () {
load_activity();
});
$(document).ready(function () {
$('#activity_more')
.click(function() {
start_record += page_size;
load_activity() });
});
{% endif %}
{% if show_user_profile %}
@@ -51,7 +69,7 @@
});
{% endif %}
{% if show_activity %}
{% if show_contribution %}
$(document).ready(function () {
$.ajax({
url: make_uri("/data/contribution.json"),
@@ -77,7 +95,7 @@
{%if correction_comment != "" %}
<div style='font-weight: bold; color: red;'>Commit corrected:
<span>${correction_comment}</span></div>
{%/if %}
{%/if%}
<div style='font-weight: bold;'>${subject}</div>
<div style='white-space: pre-wrap; '>{%html message %}</div>
<div><span style="color: green">+<span>${lines_added}</span></span>
@@ -113,7 +131,7 @@
<div>Company: {%html company_link %}</div>
{%if launchpad_id != '' %}
<div>Launchpad: <a href="https://launchpad.net/~${launchpad_id}">${launchpad_id}</a></div>
{%/if %}
{%/if%}
</div>
</div>
{% endraw %}
@@ -205,6 +223,12 @@
{% if show_user_activity %}
<h3>Activity log</h3>
<div id="activity_container"></div>
<div style="height: 44px;">
<div class="dataTables_paginate paging_full_numbers" id="activity_paginate">
<a class="last paginate_button" tabindex="0" id="activity_more">More...</a>
</div>
</div>
{% endif %}
{% endblock %}

View File

@@ -563,6 +563,9 @@ def extend_record(record):
@exception_handler()
@record_filter()
def get_activity_json(records):
start_record = int(flask.request.args.get('start_record') or 0)
page_size = int(flask.request.args.get('page_size') or
DEFAULT_RECORDS_LIMIT)
result = []
memory_storage_inst = get_memory_storage()
for record in records:
@@ -585,7 +588,10 @@ def get_activity_json(records):
result.append(review)
result.sort(key=lambda x: x['date'], reverse=True)
return json.dumps({'activity': result[0:DEFAULT_RECORDS_LIMIT]})
if start_record < 0:
start_record += len(result)
return json.dumps({'activity':
result[start_record:start_record + page_size]})
@app.route('/data/contribution.json')