diff --git a/irclogs/api.py b/irclogs/api.py index 13acabf..82e538d 100644 --- a/irclogs/api.py +++ b/irclogs/api.py @@ -1,4 +1,4 @@ from .core import api from .models import Message -api.create_api(Message, url_prefix='/api/v1') +api.create_api(Message, results_per_page=25, url_prefix='/api/v1') diff --git a/irclogs/static/js/app.js b/irclogs/static/js/app.js index f4d382f..5c94df0 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -11,6 +11,19 @@ app.config(['$routeProvider', function($routeProvider) { app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($scope, $http, $location) { $scope.searchQuery = $location.search().q || ''; + $scope.page_num = 1; + $scope.older = function() { + if ($scope.page_num !== $scope.total_pages) { + $scope.page_num++; + $scope.fetch(); + } + }; + $scope.newer = function() { + if ($scope.page_num !== 1) { + $scope.page_num--; + $scope.fetch(); + } + }; $scope.fetch = function() { if($scope.searchQuery.trim().length) { $location.search('q', $scope.searchQuery.trim()); @@ -19,14 +32,24 @@ app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($sco method: 'GET', url: '/api/v1/message', params: { - q: {filters:[{ - name: 'body', - op: 'like', - val: '%' + $scope.searchQuery + '%', - }]}, + q: { + filters:[{ + name: 'body', + op: 'like', + val: '%' + $scope.searchQuery + '%', + }], + order_by:[{ + field: 'created', + direction: 'desc', + }], + }, + page: $scope.page_num, }, }).success(function(data) { $scope.messages = data.objects; + $scope.total_pages = data.total_pages; }); }; }]); + + diff --git a/irclogs/templates/irclogs/index.html b/irclogs/templates/irclogs/index.html index 0b2d6a6..cfe1f44 100644 --- a/irclogs/templates/irclogs/index.html +++ b/irclogs/templates/irclogs/index.html @@ -21,16 +21,18 @@ Timestamp Nick Message - + {{ message.created | date:'yyyy-MM-dd HH:mm:ss' }} {{ message.nick }} {{ message.body }} + {{ message.page }} + + {% endraw %} - {% endblock %}