Skip to content

Commit

Permalink
adding support for Kong 0.6.1 + pagintation of filtered resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwannRobin committed Jan 2, 2017
1 parent 0e9bb3d commit eccc8a6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/html/apis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3 class="header">APIs</h3>
<p class="right" ng-show="next" style="margin-top:50px;">
<a href="#/apis?offset={{offset}}&size={{size}}" class="waves-effect waves-light btn">
<i class="material-icons left">navigate_next</i>
Go to next page
Go to next page
</a>
</p>

Expand Down
2 changes: 1 addition & 1 deletion src/html/consumers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3 class="header">Consumers</h3>
<p class="right" ng-show="next" style="margin-top:50px;">
<a href="#/consumers?offset={{offset}}&size={{size}}" class="waves-effect waves-light btn">
<i class="material-icons left">navigate_next</i>
Go to next page
Go to next page
</a>
</p>

Expand Down
6 changes: 3 additions & 3 deletions src/html/plugins/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ <h3 class="header" ng-show="owner_type==='Consumer'">
</p>

<p class="right" ng-show="next" style="margin-top:50px;">
<a href="#/plugins?offset={{offset}}&size={{size}}" class="waves-effect waves-light btn">
<a href="#{{location.path()}}?offset={{offset}}&size={{size}}" class="waves-effect waves-light btn">
<i class="material-icons left">navigate_next</i>
Go to next page
Go to next page
</a>
</p>

Expand All @@ -44,7 +44,7 @@ <h3 class="header" ng-show="owner_type==='Consumer'">
</p>

<p class="center" ng-show="plugins.length == 0 && total > 0">
<a href="#/plugins?size={{size}}" class="waves-effect waves-light btn">
<a href="#{{location.path()}}?size={{size}}" class="waves-effect waves-light btn">
<i class="material-icons left">skip_previous</i>
Go to first page
</a>
Expand Down
27 changes: 20 additions & 7 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
controller: 'PluginsController',
resolve: {
isAppReady: isAppReady,
pluginsCollection: ['Kong', '$route', function (Kong, $route) {
pluginsCollection: ['Kong', '$route', '$location', function (Kong, $route, $location) {
var api_id = $route.current.params.api_id;
return Kong.get('/apis/' + api_id + '/plugins');
var url = '/apis/' + api_id + '/plugins?';
if ($route.current.params.offset) {
url += '&offset=' + encodeURIComponent($route.current.params.offset);
}
if ($route.current.params.size) {
url += '&size=' + $route.current.params.size;
}
return Kong.get(url);
}],
owner: ['Kong', '$route', function(Kong, $route) {
var api_id = $route.current.params.api_id;
Expand All @@ -80,9 +87,15 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
controller: 'PluginsController',
resolve: {
isAppReady: isAppReady,
pluginsCollection: ['Kong', '$route', function (Kong, $route) {
var consumer_id = $route.current.params.consumer_id;
return Kong.get('/plugins?consumer_id=' + consumer_id);
pluginsCollection: ['Kong', '$route', '$location', function (Kong, $route, $location) {
var url = '/plugins?consumer_id=' + $route.current.params.consumer_id;
if ($route.current.params.offset) {
url += '&offset=' + encodeURIComponent($route.current.params.offset);
}
if ($route.current.params.size) {
url += '&size=' + $route.current.params.size;
}
return Kong.get(url);
}],
owner: ['Kong', '$route', function(Kong, $route) {
var consumer_id = $route.current.params.consumer_id;
Expand All @@ -95,7 +108,7 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
controller: 'PluginsController',
resolve: {
isAppReady: isAppReady,
pluginsCollection: ['Kong', '$route', function (Kong, $route) {
pluginsCollection: ['Kong', '$route', '$location', function (Kong, $route, $location) {
var url = '/plugins?';
if ($route.current.params.offset) {
url += 'offset=' + encodeURIComponent($route.current.params.offset);
Expand Down Expand Up @@ -123,7 +136,7 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
return Kong.get('/apis');
}],
consumers: ['Kong', '$location', function(Kong) {
return Kong.get('/consumers?size=-1');
return Kong.get('/consumers?size=1000');
}]
}
})
Expand Down
3 changes: 2 additions & 1 deletion src/js/controllers/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ angular.module('app').controller("ApisController", ["initialData", "$scope", "Ko
$scope.total = initialData.total;
$scope.next = initialData.next;
$scope.size = $route.current.params.size;
$scope.offset = encodeURIComponent(initialData.offset);
$scope.offset = initialData.next ? /offset=([^&]+)/.exec(initialData.next)[1] : null;

$scope.showDeleteModal = function (name, id) {
$scope.current = {name: name, id: id};
$('#deleteAPI').openModal();
Expand Down
3 changes: 2 additions & 1 deletion src/js/controllers/consumers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ angular.module('app').controller("ConsumersController", ["consumersCollection",
$scope.total = consumersCollection.total;
$scope.next = consumersCollection.next;
$scope.size = $route.current.params.size;
$scope.offset = encodeURIComponent(consumersCollection.offset);
$scope.offset = consumersCollection.next ? /offset=([^&]+)/.exec(consumersCollection.next)[1] : null;
//$scope.offset = encodeURIComponent(consumersCollection.offset);
$scope.gelato = Kong.config.gelato;
$scope.showDeleteModal = function (username, id) {
$scope.current = {username: username, id: id};
Expand Down
5 changes: 3 additions & 2 deletions src/js/controllers/plugins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('app').controller("PluginsController", ["pluginsCollection", "$scope", "Kong", "$route", "$routeParams", "owner", "Alert", function (pluginsCollection, $scope, Kong, $route, $routeParams, $owner, Alert) {
angular.module('app').controller("PluginsController", ["pluginsCollection", "$scope", "Kong", "$route", "$location", "$routeParams", "owner", "Alert", function (pluginsCollection, $scope, Kong, $route, $location, $routeParams, $owner, Alert) {
if ($routeParams.api_id) {
$scope.owner_type = 'API';
} else if ($routeParams.consumer_id) {
Expand All @@ -12,7 +12,8 @@ angular.module('app').controller("PluginsController", ["pluginsCollection", "$sc
$scope.total = pluginsCollection.total;
$scope.next = pluginsCollection.next;
$scope.size = $route.current.params.size;
$scope.offset = encodeURIComponent(pluginsCollection.offset);
$scope.offset = pluginsCollection.next ? /offset=([^&]+)/.exec(pluginsCollection.next)[1] : null;
$scope.location = $location;

angular.forEach($scope.plugins, function(plugin) {
Kong.get('/apis/' + plugin.api_id).then(function(api) {
Expand Down

0 comments on commit eccc8a6

Please sign in to comment.