Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inifinite scrolling for pages displaying collections #93

Merged
merged 1 commit into from
Apr 15, 2017
Merged
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
1 change: 1 addition & 0 deletions lib/kong-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var compile_js = function() {
"./node_modules/angular-animate/angular-animate.min.js",
"./node_modules/angular-sanitize/angular-sanitize.min.js",
"./node_modules/materialize-css/dist/js/materialize.min.js",
"./node_modules/ng-infinite-scroll/build/ng-infinite-scroll.min.js",
];
filenames = filenames.concat(app_filenames);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"koa-static": "^2.0.0",
"materialize-css": "0.97.7",
"minimist": "^1.2.0",
"ng-infinite-scroll": "^1.3.0",
"node-sass": "^4.1.1",
"rimraf": "^2.5.4",
"uglify-js": "^2.7.5"
Expand Down
47 changes: 15 additions & 32 deletions src/html/apis/index.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
<div class="container">
<div class="container" infinite-scroll="loadMore()" infinite-scroll-distance="5" infinite-scroll-use-document-bottom="true">
<a href="#/apis/add" class="btn-floating btn-large waves-effect waves-light right" ng-show="apis.length >= 1">
<i class="material-icons">add</i>
</a>

<h3 class="header">APIs</h3>

<p class="flow-text center" ng-show="total == 0" style="margin-top:50px;">
You haven't created any API in Kong yet.
<p class="flow-text center" ng-show="total === null" style="margin-top:50px;">
<app-loader></app-loader>
</p>

<p class="flow-text center" ng-show="apis.length == 0 && total > 0" style="margin-top:50px;">
You have reached the end of the list.
</p>

<p class="flow-text left" ng-show="apis.length > 0" style="margin-top:50px;">
Showing {{apis.length}} Apis / {{total}}
</p>

<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
</a>
</p>

<p class="center" ng-show="total == 0">
<a href="#/apis/add" class="waves-effect waves-light btn">
<i class="material-icons left">add_box</i>
Add API
</a>
</p>

<p class="center" ng-show="apis.length == 0 && total > 0">
<a href="#/apis?size={{size}}" class="waves-effect waves-light btn">
<i class="material-icons left">skip_previous</i>
Go to first page
</a>
</p>
<div class ng-show="total === 0">
<p class="flow-text center">
You haven't created any API in Kong yet.
</p>
<p class="center">
<a href="#/apis/add" class="waves-effect waves-light btn">
<i class="material-icons left">add_box</i>
Add API
</a>
</p>
</div>

<table class="bordered" ng-show="apis.length >= 1">
<table class="bordered" ng-show="total > 0">
<thead>
<tr>
<th>Name</th>
Expand Down
47 changes: 15 additions & 32 deletions src/html/consumers/index.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
<div class="container">
<div class="container" infinite-scroll="loadMore()" infinite-scroll-distance="5" infinite-scroll-use-document-bottom="true">
<a href="#/consumers/add" class="btn-floating btn-large waves-effect waves-light right" ng-show="consumers.length >= 1">
<i class="material-icons">add</i>
</a>

<h3 class="header">Consumers</h3>

<p class="flow-text center" ng-show="total == 0" style="margin-top:50px;">
You haven't defined any Consumers in Kong yet.
<p class="flow-text center" ng-show="total === null" style="margin-top:50px;">
<app-loader></app-loader>
</p>

<p class="flow-text center" ng-show="consumers.length == 0 && total > 0" style="margin-top:50px;">
You have reached the end of the list.
</p>

<p class="flow-text left" ng-show="consumers.length > 0" style="margin-top:50px;">
Showing {{consumers.length}} Consumers / {{total}}
</p>

<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
</a>
</p>

<p class="center" ng-show="total == 0">
<a href="#/consumers/add" class="waves-effect waves-light btn">
<i class="material-icons left">add_box</i>
Add Consumer
</a>
</p>

<p class="center" ng-show="consumers.length == 0 && total > 0">
<a href="#/consumers?size={{size}}" class="waves-effect waves-light btn">
<i class="material-icons left">skip_previous</i>
Go to first page
</a>
</p>
<div class ng-show="total === 0">
<p class="flow-text center">
You haven't defined any Consumers in Kong yet.
</p>
<p class="center">
<a href="#/consumers/add" class="waves-effect waves-light btn">
<i class="material-icons left">add_box</i>
Add Consumer
</a>
</p>
</div>

<table class="bordered" ng-show="consumers.length >= 1">
<table class="bordered" ng-show="total > 0">
<thead>
<tr>
<th>Username</th>
Expand Down
59 changes: 21 additions & 38 deletions src/html/plugins/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="container">
<div class="container" infinite-scroll="loadMore()" infinite-scroll-distance="5" infinite-scroll-use-document-bottom="true">
<a href="#/plugins/add" class="btn-floating btn-large waves-effect waves-light right" ng-show="plugins.length >= 1">
<i class="material-icons">add</i>
</a>
Expand All @@ -11,46 +11,29 @@ <h3 class="header" ng-show="owner_type==='Consumer'">
Plugins of consumer "<a href="#/consumers/{{owner.id}}">{{owner.username}}</a>"
</h3>

<p class="flow-text center" ng-show="total == 0 && !owner_type" style="margin-top:50px;">
There are no plugin configured yet.
</p>
<p class="flow-text center" ng-show="total == 0 && owner_type=='API'" style="margin-top:50px;">
This API doesn't have any plugin configured yet.
</p>
<p class="flow-text center" ng-show="total == 0 && owner_type=='Consumer'" style="margin-top:50px;">
This Consumer doesn't have any plugin configured yet.
</p>

<p class="flow-text center" ng-show="plugins.length == 0 && total > 0" style="margin-top:50px;">
You have reached the end of the list.
</p>

<p class="flow-text left" ng-show="plugins.length > 0" style="margin-top:50px;">
Showing {{plugins.length}} Plugins / {{total}}
<p class="flow-text center" ng-show="total === null" style="margin-top:50px;">
<app-loader></app-loader>
</p>

<p class="right" ng-show="next" style="margin-top:50px;">
<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
</a>
</p>

<p class="center" ng-show="total == 0">
<a href="#/plugins/add" class="waves-effect waves-light btn">
<i class="material-icons left">add_box</i>
Add Plugin
</a>
</p>

<p class="center" ng-show="plugins.length == 0 && total > 0">
<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>
</p>
<div class ng-show="total === 0" style="margin-top:50px;">
<p class="flow-text center" ng-show="!owner_type">
There are no plugin configured yet.
</p>
<p class="flow-text center" ng-show="owner_type=='API'">
This API doesn't have any plugin configured yet.
</p>
<p class="flow-text center" ng-show="owner_type=='Consumer'">
This Consumer doesn't have any plugin configured yet.
</p>
<p class="center" ng-show="total == 0">
<a href="#/plugins/add" class="waves-effect waves-light btn">
<i class="material-icons left">add_box</i>
Add Plugin
</a>
</p>
</div>

<table class="bordered" ng-show="plugins.length >= 1">
<table class="bordered" ng-show="total > 0">
<thead>
<tr>
<th>Name</th>
Expand Down
59 changes: 4 additions & 55 deletions src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitize'])
var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitize', 'infinite-scroll'])
.config(['$routeProvider', function ($routeProvider) {

var appStarted = false;
Expand Down Expand Up @@ -29,17 +29,7 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
templateUrl: 'html/apis/index.html',
controller: 'ApisController',
resolve: {
isAppReady: isAppReady,
initialData: ['Kong', '$route', function (Kong, $route) {
var url = '/apis?';
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);
}]
isAppReady: isAppReady
}
})
.when('/apis/add', {
Expand All @@ -66,17 +56,6 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
controller: 'PluginsController',
resolve: {
isAppReady: isAppReady,
pluginsCollection: ['Kong', '$route', '$location', function (Kong, $route, $location) {
var api_id = $route.current.params.api_id;
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;
return Kong.get('/apis/' + api_id);
Expand All @@ -88,16 +67,6 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
controller: 'PluginsController',
resolve: {
isAppReady: isAppReady,
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;
return Kong.get('/consumers/' + consumer_id);
Expand All @@ -107,18 +76,8 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
.when('/plugins', {
templateUrl: 'html/plugins/index.html',
controller: 'PluginsController',
resolve: {
resolve: {
isAppReady: isAppReady,
pluginsCollection: ['Kong', '$route', '$location', function (Kong, $route, $location) {
var url = '/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: function() { return {};}
}
})
Expand Down Expand Up @@ -165,17 +124,7 @@ var app = angular.module('app', ['ngRoute', 'ngCookies', 'ngAnimate', 'ngSanitiz
templateUrl: 'html/consumers/index.html',
controller: 'ConsumersController',
resolve: {
isAppReady: isAppReady,
consumersCollection: ['Kong', '$route', function (Kong, $route) {
var url = '/consumers?';
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);
}]
isAppReady: isAppReady
}
})
.when('/consumers/add', {
Expand Down
45 changes: 36 additions & 9 deletions src/js/controllers/apis.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
angular.module('app').controller("ApisController", ["initialData", "$scope", "Kong", "$route", function (initialData, $scope, Kong, $route) {
$scope.apis = initialData.data;
$scope.total = initialData.total;
$scope.next = initialData.next;
$scope.size = $route.current.params.size;
$scope.offset = initialData.next ? /offset=([^&]+)/.exec(initialData.next)[1] : null;

angular.module('app').controller("ApisController", ["$scope", "Kong", function ($scope, Kong) {
$scope.apis = [];
$scope.total = null;
$scope.offset = null;

var loaded_pages = [];
$scope.loadMore = function() {
var page = '/apis?';
if ($scope.offset) {
page += 'offset=' + $scope.offset + '&';
}
if (loaded_pages.indexOf(page) !== -1) {
return;
}
loaded_pages.push(page);

Kong.get(page).then(function(collection) {
if ($scope.total === null) {
$scope.total = 0;
}
$scope.apis.push.apply($scope.apis, collection.data);
$scope.total += collection.total;
$scope.offset = collection.offset ? collection.offset : null;
});
};
$scope.loadMore();

$scope.showDeleteModal = function (name, id) {
$scope.current = {name: name, id: id};
$('#deleteAPI').openModal();
};

$scope.abortDelete = function () {
$('#deleteAPI').closeModal();
};

$scope.performDelete = function () {
$('#deleteAPI').closeModal();
Kong.delete('/apis/' + $scope.current.id).then(function (response) {
$route.reload();
Kong.delete('/apis/' + $scope.current.id).then(function () {
$scope.total -= 1;
$scope.apis.forEach(function(element, index) {
if (element.id === $scope.current.id) {
$scope.apis.splice(index, 1);
}
});
});
}
}]);
Expand Down
Loading