From 3c6e53372b3aa50255c126d8545326bfe52f688a Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Mon, 24 Mar 2014 18:13:49 -0400 Subject: [PATCH 1/7] some updates, working on pagignation --- irclogs/static/js/app.js | 11 +++++++++++ irclogs/templates/irclogs/index.html | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/irclogs/static/js/app.js b/irclogs/static/js/app.js index f4d382f..88931bf 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -26,6 +26,17 @@ app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($sco }]}, }, }).success(function(data) { + $scope.range = function(start, end) { + var ret = []; + if (!end) { + end = start; + start = 0; + } + for (var i = start; i < end; i++){ + ret.push(i); + } + return ret + }; $scope.messages = data.objects; }); }; diff --git a/irclogs/templates/irclogs/index.html b/irclogs/templates/irclogs/index.html index 0b2d6a6..866187d 100644 --- a/irclogs/templates/irclogs/index.html +++ b/irclogs/templates/irclogs/index.html @@ -21,16 +21,17 @@ Timestamp Nick Message - + {{ message.created | date:'yyyy-MM-dd HH:mm:ss' }} {{ message.nick }} {{ message.body }} + {{ message.page }} + {% endraw %} - {% endblock %} From fb4a25957352f3254af60085311236e375c67983 Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Tue, 25 Mar 2014 16:32:15 -0400 Subject: [PATCH 2/7] removed my bad ideas --- irclogs/static/js/app.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/irclogs/static/js/app.js b/irclogs/static/js/app.js index 88931bf..20427fc 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -26,18 +26,9 @@ app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($sco }]}, }, }).success(function(data) { - $scope.range = function(start, end) { - var ret = []; - if (!end) { - end = start; - start = 0; - } - for (var i = start; i < end; i++){ - ret.push(i); - } - return ret - }; $scope.messages = data.objects; }); }; }]); + + From ff195c6d2118e683635393cfa876164fcd7cbdfd Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Tue, 25 Mar 2014 17:54:59 -0400 Subject: [PATCH 3/7] change message number to 25 per page, attempt at pagination almost complete --- irclogs/api.py | 2 +- irclogs/static/js/app.js | 19 +++++++++++++++++++ irclogs/templates/irclogs/index.html | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) 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 20427fc..604efa2 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -11,6 +11,23 @@ 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.next_page = function() { + if ($scope.page_num == $scope.total_pages) + return undefined; + else { + $scope.page_num++; + $scope.fetch(); + } + }; + $scope.last_page = function() { + if ($scope.page_num == 1) + return undefined; + else { + $scope.page_num--; + $scope.fetch(); + } + }; $scope.fetch = function() { if($scope.searchQuery.trim().length) { $location.search('q', $scope.searchQuery.trim()); @@ -24,9 +41,11 @@ app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($sco op: 'like', val: '%' + $scope.searchQuery + '%', }]}, + 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 866187d..d945dca 100644 --- a/irclogs/templates/irclogs/index.html +++ b/irclogs/templates/irclogs/index.html @@ -29,8 +29,9 @@ {{ message.page }} + + - {% endraw %} {% endblock %} From 6ebcf48179d8e61854855992d9e9ba47b8f1c4dd Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Tue, 25 Mar 2014 20:39:35 -0400 Subject: [PATCH 4/7] newest convos load first --- irclogs/static/js/app.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/irclogs/static/js/app.js b/irclogs/static/js/app.js index 604efa2..812eae5 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -36,12 +36,18 @@ app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($sco method: 'GET', url: '/api/v1/message', params: { - q: {filters:[{ - name: 'body', - op: 'like', - val: '%' + $scope.searchQuery + '%', - }]}, - page: $scope.page_num, + 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; From 5b14dc3ea2b824c1e0d8f8fe7703470df0cd9129 Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Tue, 25 Mar 2014 21:04:26 -0400 Subject: [PATCH 5/7] update the buttons for newer and older --- irclogs/static/js/app.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/irclogs/static/js/app.js b/irclogs/static/js/app.js index 812eae5..865d783 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -12,18 +12,14 @@ 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.next_page = function() { - if ($scope.page_num == $scope.total_pages) - return undefined; - else { + $scope.older = function() { + if ($scope.page_num != $scope.total_pages) { $scope.page_num++; $scope.fetch(); } }; - $scope.last_page = function() { - if ($scope.page_num == 1) - return undefined; - else { + $scope.newer = function() { + if ($scope.page_num != 1) { $scope.page_num--; $scope.fetch(); } From 9472dd900383316c56712cf974098c9cbb4c8fef Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Tue, 25 Mar 2014 23:20:18 -0400 Subject: [PATCH 6/7] Update app.js != changed to !== --- irclogs/static/js/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/irclogs/static/js/app.js b/irclogs/static/js/app.js index 865d783..5c94df0 100644 --- a/irclogs/static/js/app.js +++ b/irclogs/static/js/app.js @@ -13,13 +13,13 @@ app.controller('MessageListCtrl', ['$scope', '$http', '$location', function($sco $scope.searchQuery = $location.search().q || ''; $scope.page_num = 1; $scope.older = function() { - if ($scope.page_num != $scope.total_pages) { + if ($scope.page_num !== $scope.total_pages) { $scope.page_num++; $scope.fetch(); } }; $scope.newer = function() { - if ($scope.page_num != 1) { + if ($scope.page_num !== 1) { $scope.page_num--; $scope.fetch(); } From fd165c0cf5123417fcd0f5d5dbfdbc56536d2959 Mon Sep 17 00:00:00 2001 From: Dean Silfen Date: Fri, 4 Apr 2014 14:39:36 -0400 Subject: [PATCH 7/7] rename functions and buttons for clarity --- irclogs/templates/irclogs/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/irclogs/templates/irclogs/index.html b/irclogs/templates/irclogs/index.html index d945dca..cfe1f44 100644 --- a/irclogs/templates/irclogs/index.html +++ b/irclogs/templates/irclogs/index.html @@ -29,8 +29,8 @@ {{ message.page }} - - + + {% endraw %}