From 0b6c2b032a1a18172437e88af995aaf216317ee6 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 17 Aug 2016 12:29:13 +1200 Subject: [PATCH 1/2] feat(image): add the ability to push an image tag (#126) --- app/components/image/image.html | 11 +++++++++-- app/components/image/imageController.js | 15 +++++++++++++++ app/shared/responseHandlers.js | 7 +++++++ app/shared/services.js | 5 ++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/components/image/image.html b/app/components/image/image.html index dac34024b..2e81db682 100644 --- a/app/components/image/image.html +++ b/app/components/image/image.html @@ -13,14 +13,21 @@
- {{ tag }} + + + + + {{ tag }}
- Note: you can click on the trash icon to delete a tag + + Note: you can click on the upload icon to push an image + and on the trash icon to delete a tag +
diff --git a/app/components/image/imageController.js b/app/components/image/imageController.js index a249b9905..1502debad 100644 --- a/app/components/image/imageController.js +++ b/app/components/image/imageController.js @@ -15,6 +15,21 @@ function ($scope, $stateParams, $state, Image, Messages) { }); } + $scope.pushImage = function(tag) { + $('#loadingViewSpinner').show(); + Image.push({tag: tag}, function (d) { + if (d[d.length-1].error) { + Messages.error("Unable to push image", d[d.length-1].error); + } else { + Messages.send('Image successfully pushed'); + } + $('#loadingViewSpinner').hide(); + }, function (e) { + $('#loadingViewSpinner').hide(); + Messages.error("Unable to push image", e.data); + }); + }; + $scope.removeImage = function (id) { $('#loadingViewSpinner').show(); Image.remove({id: id}, function (d) { diff --git a/app/shared/responseHandlers.js b/app/shared/responseHandlers.js index a0e44306c..958f8661b 100644 --- a/app/shared/responseHandlers.js +++ b/app/shared/responseHandlers.js @@ -12,6 +12,13 @@ function createImageHandler(data) { 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, "}, {") + "]"; + return angular.fromJson(str); +} + // Image delete API returns an array on success and an object on error. // This handler creates an array from an object in case of error. function deleteImageHandler(data) { diff --git a/app/shared/services.js b/app/shared/services.js index 7a323ba9e..8d7ed6bd7 100644 --- a/app/shared/services.js +++ b/app/shared/services.js @@ -93,9 +93,12 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize']) search: {method: 'GET', params: {action: 'search'}}, history: {method: 'GET', params: {action: 'history'}, isArray: true}, insert: {method: 'POST', params: {id: '@id', action: 'insert'}}, - push: {method: 'POST', params: {id: '@id', action: 'push'}}, tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}}, inspect: {method: 'GET', params: {id: '@id', action: 'json'}}, + push: { + method: 'POST', params: {action: 'push', id: '@tag'}, + isArray: true, transformResponse: pushImageHandler + }, create: { method: 'POST', params: {action: 'create', fromImage: '@fromImage', tag: '@tag'}, isArray: true, transformResponse: createImageHandler From 54fd9561f0510c4d3569375ba7b77cd72051b8f4 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 17 Aug 2016 13:50:55 +1200 Subject: [PATCH 2/2] refactor(handlers): remove duplicated code (#127) --- app/shared/responseHandlers.js | 19 +++---------------- app/shared/services.js | 6 +++--- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/app/shared/responseHandlers.js b/app/shared/responseHandlers.js index 958f8661b..4625ba1fc 100644 --- a/app/shared/responseHandlers.js +++ b/app/shared/responseHandlers.js @@ -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. -function queryEventsHandler(data) { - var str = "[" + data.replace(/\n/g, " ").replace(/\}\s*\{/g, "}, {") + "]"; - 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) { +// Used by the API in: Image push, Image create, Events query. +function jsonObjectsToArrayHandler(data) { var str = "[" + data.replace(/\n/g, " ").replace(/\}\s*\{/g, "}, {") + "]"; return angular.fromJson(str); } diff --git a/app/shared/services.js b/app/shared/services.js index 8d7ed6bd7..7f7cd59f6 100644 --- a/app/shared/services.js +++ b/app/shared/services.js @@ -97,11 +97,11 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize']) inspect: {method: 'GET', params: {id: '@id', action: 'json'}}, push: { method: 'POST', params: {action: 'push', id: '@tag'}, - isArray: true, transformResponse: pushImageHandler + isArray: true, transformResponse: jsonObjectsToArrayHandler }, create: { method: 'POST', params: {action: 'create', fromImage: '@fromImage', tag: '@tag'}, - isArray: true, transformResponse: createImageHandler + isArray: true, transformResponse: jsonObjectsToArrayHandler }, remove: { method: 'DELETE', params: {id: '@id'}, @@ -115,7 +115,7 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize']) return $resource(Settings.url + '/events', {}, { query: { method: 'GET', params: {since: '@since', until: '@until'}, - isArray: true, transformResponse: queryEventsHandler + isArray: true, transformResponse: jsonObjectsToArrayHandler } }); }])