mirror of https://github.com/portainer/portainer
refactor(handlers): remove duplicated code (#127)
parent
fb67769928
commit
54fd9561f0
|
@ -1,20 +1,7 @@
|
||||||
// Events query API return a list of JSON object.
|
// The Docker API often returns a list of JSON object.
|
||||||
// This handler wrap the JSON objects in an array.
|
// This handler wrap the JSON objects in an array.
|
||||||
function queryEventsHandler(data) {
|
// Used by the API in: Image push, Image create, Events query.
|
||||||
var str = "[" + data.replace(/\n/g, " ").replace(/\}\s*\{/g, "}, {") + "]";
|
function jsonObjectsToArrayHandler(data) {
|
||||||
return angular.fromJson(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Image create API return a list of JSON object.
|
|
||||||
// This handler wrap the JSON objects in an array.
|
|
||||||
function createImageHandler(data) {
|
|
||||||
var str = "[" + data.replace(/\n/g, " ").replace(/\}\s*\{/g, "}, {") + "]";
|
|
||||||
return angular.fromJson(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Image push API return a list of JSON object.
|
|
||||||
// This handler wrap the JSON objects in an array.
|
|
||||||
function pushImageHandler(data) {
|
|
||||||
var str = "[" + data.replace(/\n/g, " ").replace(/\}\s*\{/g, "}, {") + "]";
|
var str = "[" + data.replace(/\n/g, " ").replace(/\}\s*\{/g, "}, {") + "]";
|
||||||
return angular.fromJson(str);
|
return angular.fromJson(str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,11 +97,11 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize'])
|
||||||
inspect: {method: 'GET', params: {id: '@id', action: 'json'}},
|
inspect: {method: 'GET', params: {id: '@id', action: 'json'}},
|
||||||
push: {
|
push: {
|
||||||
method: 'POST', params: {action: 'push', id: '@tag'},
|
method: 'POST', params: {action: 'push', id: '@tag'},
|
||||||
isArray: true, transformResponse: pushImageHandler
|
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
method: 'POST', params: {action: 'create', fromImage: '@fromImage', tag: '@tag'},
|
method: 'POST', params: {action: 'create', fromImage: '@fromImage', tag: '@tag'},
|
||||||
isArray: true, transformResponse: createImageHandler
|
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
||||||
},
|
},
|
||||||
remove: {
|
remove: {
|
||||||
method: 'DELETE', params: {id: '@id'},
|
method: 'DELETE', params: {id: '@id'},
|
||||||
|
@ -115,7 +115,7 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize'])
|
||||||
return $resource(Settings.url + '/events', {}, {
|
return $resource(Settings.url + '/events', {}, {
|
||||||
query: {
|
query: {
|
||||||
method: 'GET', params: {since: '@since', until: '@until'},
|
method: 'GET', params: {since: '@since', until: '@until'},
|
||||||
isArray: true, transformResponse: queryEventsHandler
|
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}])
|
}])
|
||||||
|
|
Loading…
Reference in New Issue