Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion irclogs/api.py
Original file line number Diff line number Diff line change
@@ -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')
33 changes: 28 additions & 5 deletions irclogs/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
});
};
}]);


6 changes: 4 additions & 2 deletions irclogs/templates/irclogs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
<th>Timestamp</th>
<th>Nick</th>
<th>Message</th>
</thead>
</thead>
<tr ng-repeat="message in messages">
<td>{{ message.created | date:'yyyy-MM-dd HH:mm:ss' }}</td>
<td>{{ message.nick }}</td>
<td>{{ message.body }}</td>
<td>{{ message.page }}</td>
</tr>
</table>
<button ng-click="newer()">Newer Posts</button>
<button ng-click="older()">Older Posts</button>
</div>
{% endraw %}

</script>
{% endblock %}

Expand Down