Skip to content

Commit

Permalink
#212 Infiniscroll on project activities
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Jan 2, 2014
1 parent ed2a0de commit d8580d8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
4 changes: 2 additions & 2 deletions djangoproject/core/services/activity_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
__author__ = 'tony'


def get_latest_activity(project_id):
def get_latest_activity(project_id, offset):
query = ActionLog.objects.all()
if project_id:
query = query.filter(Q(project__id=project_id) & (~Q(action__in=['ADD_ISSUE_COMMENT', 'EDIT_ISSUE_COMMENT'])))
query = query.order_by('-creationDate')
return query[0:10]
return query[offset: offset + 10], query.count()
10 changes: 7 additions & 3 deletions djangoproject/core/views/json_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def get_offers(request):


def list_issue_cards(request):

project_id = None
if 'project_id' in request.GET:
project_id = int(request.GET.get('project_id'))
Expand Down Expand Up @@ -109,8 +108,13 @@ def toggle_watch(request):

def latest_activity(request):
project_id = int(request.GET.get('project_id')) if 'project_id' in request.GET else None
activities = activity_services.get_latest_activity(project_id)
return HttpResponse(json.dumps([activity.to_dict_json() for activity in activities]))
offset = int(request.GET.get('offset'))
activities, count = activity_services.get_latest_activity(project_id, offset)
result = {
'count': count,
'activities': [activity.to_dict_json() for activity in activities],
}
return HttpResponse(json.dumps(result))


def _convert_offers_to_dict(offers):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</div>
<div ng-switch-when="CHANGE_OFFER">
<span title="{[{ activity.creationDate }]}"> {[{ activity.when }]}</span><br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
has changed his offer on issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
<a href="#">More...</a>
</div>
Expand Down Expand Up @@ -73,4 +74,8 @@
</div>
</div>
</div>
<div ng-show="loading"><img src="/static/img2/ajax-loader.gif"></div>
<div ng-show="show_more()">
<button ng-click="more()">More...</button>
</div>
</div>
31 changes: 22 additions & 9 deletions djangoproject/statfiles/static/js/activitylist/activitylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ mod.directive('activitylist', function() {
templateUrl: '/static/js/activitylist/activitylist.html',
controller: function ($scope, FSApi) {

$scope.activities = [];

var instrument = function(activity){
try{
activity.new_dic = JSON.parse(activity.new_json);
Expand All @@ -40,16 +42,27 @@ mod.directive('activitylist', function() {
}
};

FSApi.get_latest_activity($scope.projectId).onResult(function(result){
$scope.activities=result;
for(var i=0; i < $scope.activities.length; i++){
instrument($scope.activities[i])
}
$scope.$digest();
});
var more = function(){
$scope.loading = true;
FSApi.get_latest_activity($scope.projectId, $scope.activities.length).onResult(function(result){
$scope.loading = false;
$scope.activities = $scope.activities.concat(result.activities);
$scope.count = result.count;
for(var i=0; i < $scope.activities.length; i++){
instrument($scope.activities[i])
}
$scope.$digest();
});
};

more();

$scope.show_more = function(){
return $scope.activities.length < $scope.count;
};

$scope.describe = function(activity){
return 'Action = ' + activity.action + '/ Entity = ' + activity.entity + '/ Old Value = ' + activity.old_json + '/ New Value = ' + activity.new_json;
$scope.more = function(){
more();
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions djangoproject/statfiles/static/js/fsapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ fsapi_mod.factory('FSApi', function(){
return fs_ajax_async_result($.get, '/core/json/list_issue_cards', params)
}

function get_latest_activity(project_id){
function get_latest_activity(project_id, offset){
var params = {
project_id: project_id
project_id: project_id,
offset: offset
};
return fs_ajax_async_result($.get, '/core/json/latest_activity', params)
}
Expand Down
4 changes: 2 additions & 2 deletions djangoproject/statfiles/static/js/fsapi_mock.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d8580d8

Please sign in to comment.