fix(registry-manager): add repositories pagination support (#2641)

* fix(registry-management): add support for repositories list with multiple requests

* refactor(registry-management): change regex usage to a reusable interceptor function

* refactor(registry-management): change interceptor to transformResponse function
pull/2659/head
baron_l 2019-01-24 01:38:36 +01:00 committed by Anthony Lapenna
parent 90a0998502
commit 801336336f
3 changed files with 40 additions and 8 deletions

View File

@ -1,11 +1,13 @@
angular.module('portainer.extensions.registrymanagement')
.factory('RegistryCatalog', ['$resource', 'API_ENDPOINT_REGISTRIES', function RegistryCatalogFactory($resource, API_ENDPOINT_REGISTRIES) {
.factory('RegistryCatalog', ['$resource', 'API_ENDPOINT_REGISTRIES',
function RegistryCatalogFactory($resource, API_ENDPOINT_REGISTRIES) {
'use strict';
return $resource(API_ENDPOINT_REGISTRIES + '/:id/v2/:action', {},
{
get: {
method: 'GET',
params: { id: '@id', action: '_catalog' }
params: { id: '@id', action: '_catalog' },
transformResponse: linkGetResponse
},
ping: {
method: 'GET',

View File

@ -0,0 +1,13 @@
function linkGetResponse(data, headers) {
var response = angular.fromJson(data);
var link = headers('link');
if (link) {
var queryString = link.substring(link.indexOf('?') + 1).split('>;')[0];
var queries = queryString.split('&');
for (var i = 0; i < queries.length; i++) {
var kv = queries[i].split('=');
response[kv[0]] = kv[1];
}
}
return response;
}

View File

@ -11,16 +11,33 @@ function RegistryV2ServiceFactory($q, RegistryCatalog, RegistryTags, RegistryMan
return RegistryCatalog.ping({ id: id }).$promise;
};
function getCatalog(id) {
var deferred = $q.defer();
var repositories = [];
_getCatalogPage({id: id}, deferred, repositories);
return deferred.promise;
}
function _getCatalogPage(params, deferred, repositories) {
RegistryCatalog.get(params).$promise.then(function(data) {
repositories = _.concat(repositories, data.repositories);
if (data.last && data.n) {
_getCatalogPage({id: params.id, n: data.n, last: data.last}, deferred, repositories);
} else {
deferred.resolve(repositories);
}
});
}
service.repositories = function (id) {
var deferred = $q.defer();
RegistryCatalog.get({
id: id
}).$promise
.then(function success(data) {
getCatalog(id).then(function success(data) {
var promises = [];
for (var i = 0; i < data.repositories.length; i++) {
var repository = data.repositories[i];
for (var i = 0; i < data.length; i++) {
var repository = data[i];
promises.push(RegistryTags.get({
id: id,
repository: repository