Merge pull request #181 from cloud-inovasi/feat95-responsehandler-generic-handler
feat(container): add a deletion generic handler used for container/ne…pull/184/head
commit
d93a69df95
|
@ -121,11 +121,21 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
|
||||||
$scope.remove = function () {
|
$scope.remove = function () {
|
||||||
$('#loadingViewSpinner').show();
|
$('#loadingViewSpinner').show();
|
||||||
Container.remove({id: $stateParams.id}, function (d) {
|
Container.remove({id: $stateParams.id}, function (d) {
|
||||||
$state.go('containers', {}, {reload: true});
|
if (d.message) {
|
||||||
Messages.send("Container removed", $stateParams.id);
|
$('#loadingViewSpinner').hide();
|
||||||
|
Messages.send("Error", d.message);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$state.go('containers', {}, {reload: true});
|
||||||
|
Messages.send("Container removed", $stateParams.id);
|
||||||
|
}
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
|
if (e.data.message) {
|
||||||
|
Messages.error("Failure", e.data.message);
|
||||||
|
} else {
|
||||||
|
Messages.error("Failure", 'Unable to remove container');
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
Messages.error("Failure", "Container failed to remove." + e.data);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,16 +71,19 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config,
|
||||||
}
|
}
|
||||||
else if (action === Container.remove) {
|
else if (action === Container.remove) {
|
||||||
action({id: c.Id}, function (d) {
|
action({id: c.Id}, function (d) {
|
||||||
var error = errorMsgFilter(d);
|
if (d.message) {
|
||||||
if (error) {
|
Messages.send("Error", d.message);
|
||||||
Messages.send("Error", "Unable to remove running container");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Messages.send("Container " + msg, c.Id);
|
Messages.send("Container " + msg, c.Id);
|
||||||
}
|
}
|
||||||
complete();
|
complete();
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
Messages.error("Failure", e.data);
|
if (e.data.message) {
|
||||||
|
Messages.error("Failure", e.data.message);
|
||||||
|
} else {
|
||||||
|
Messages.error("Failure", 'Unable to remove container');
|
||||||
|
}
|
||||||
complete();
|
complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,29 @@ function jsonObjectsToArrayHandler(data) {
|
||||||
return angular.fromJson(str);
|
return angular.fromJson(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The Docker API often returns an empty string on success (Docker 1.9 -> Docker 1.12).
|
||||||
|
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||||
|
// container the error (Docker = 1.12).
|
||||||
|
// This handler returns an empty object on success or a newly created JSON object with
|
||||||
|
// the field message containing the error message on failure.
|
||||||
|
// Used by the API in: container deletion, network deletion.
|
||||||
|
function deleteGenericHandler(data) {
|
||||||
|
var response = {};
|
||||||
|
// No data is returned when deletion is successful (Docker 1.9 -> 1.12)
|
||||||
|
if (!data) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
// A string is returned on failure (Docker < 1.12)
|
||||||
|
else if (!isJSON(data)) {
|
||||||
|
response.message = data;
|
||||||
|
}
|
||||||
|
// Docker 1.12 returns a valid JSON object when an error occurs
|
||||||
|
else {
|
||||||
|
response = angular.fromJson(data);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
// Image delete API returns an array on success (Docker 1.9 -> Docker 1.12).
|
// Image delete API returns an array on success (Docker 1.9 -> Docker 1.12).
|
||||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||||
// container the error (Docker = 1.12).
|
// container the error (Docker = 1.12).
|
||||||
|
@ -43,26 +66,3 @@ function deleteImageHandler(data) {
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network delete API returns an empty string on success (Docker 1.9 -> Docker 1.12).
|
|
||||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
|
||||||
// container the error (Docker = 1.12).
|
|
||||||
// This handler returns an empty object on success or a newly created JSON object with
|
|
||||||
// the field message containing the error message on failure.
|
|
||||||
function deleteNetworkHandler(data) {
|
|
||||||
var response = {};
|
|
||||||
// No data is returned when deletion is successful (Docker 1.9 -> 1.12)
|
|
||||||
if (!data) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
// A string is returned when an error occurs (Docker < 1.12)
|
|
||||||
else if (data && !isJSON(data)) {
|
|
||||||
response.message = data;
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
// Docker 1.12 returns a valid JSON object when an error occurs
|
|
||||||
else {
|
|
||||||
response = angular.fromJson(data);
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,7 +16,10 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize'])
|
||||||
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
|
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
|
||||||
changes: {method: 'GET', params: {action: 'changes'}, isArray: true},
|
changes: {method: 'GET', params: {action: 'changes'}, isArray: true},
|
||||||
create: {method: 'POST', params: {action: 'create'}},
|
create: {method: 'POST', params: {action: 'create'}},
|
||||||
remove: {method: 'DELETE', params: {id: '@id', v: 0}},
|
remove: {
|
||||||
|
method: 'DELETE', params: {id: '@id', v: 0},
|
||||||
|
transformResponse: deleteGenericHandler
|
||||||
|
},
|
||||||
rename: {method: 'POST', params: {id: '@id', action: 'rename', name: '@name'}},
|
rename: {method: 'POST', params: {id: '@id', action: 'rename', name: '@name'}},
|
||||||
stats: {method: 'GET', params: {id: '@id', stream: false, action: 'stats'}, timeout: 5000},
|
stats: {method: 'GET', params: {id: '@id', stream: false, action: 'stats'}, timeout: 5000},
|
||||||
exec: {method: 'POST', params: {id: '@id', action: 'exec'}}
|
exec: {method: 'POST', params: {id: '@id', action: 'exec'}}
|
||||||
|
@ -135,7 +138,7 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize'])
|
||||||
query: {method: 'GET', isArray: true},
|
query: {method: 'GET', isArray: true},
|
||||||
get: {method: 'GET'},
|
get: {method: 'GET'},
|
||||||
create: {method: 'POST', params: {action: 'create'}},
|
create: {method: 'POST', params: {action: 'create'}},
|
||||||
remove: { method: 'DELETE', transformResponse: deleteNetworkHandler },
|
remove: { method: 'DELETE', transformResponse: deleteGenericHandler },
|
||||||
connect: {method: 'POST', params: {action: 'connect'}},
|
connect: {method: 'POST', params: {action: 'connect'}},
|
||||||
disconnect: {method: 'POST', params: {action: 'disconnect'}}
|
disconnect: {method: 'POST', params: {action: 'disconnect'}}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue