Show proper error message for missing job template form

when visiting the job template page for a job template that has been deleted or doesn't exist, we want to show the 404 error message, not an error message about tags or labels.
This commit is contained in:
Jared Tabor 2016-07-13 15:38:38 -07:00
parent c60b8986de
commit f9de8db89a
3 changed files with 79 additions and 64 deletions

View File

@ -448,31 +448,40 @@ export default
}
});
};
if($state.params.id !== "null"){
Rest.setUrl(defaultUrl + $state.params.id +
"/labels");
Rest.get()
.success(function(data) {
if (data.next) {
getNext(data, data.results, seeMoreResolve);
} else {
seeMoreResolve.resolve(data.results);
}
Rest.setUrl(defaultUrl + $state.params.id +
"/labels");
Rest.get()
.success(function(data) {
if (data.next) {
getNext(data, data.results, seeMoreResolve);
} else {
seeMoreResolve.resolve(data.results);
}
seeMoreResolve.promise.then(function (labels) {
$scope.$emit("choicesReady");
var opts = labels
.map(i => ({id: i.id + "",
test: i.name}));
CreateSelect2({
element:'#job_templates_labels',
multiple: true,
addNew: true,
opts: opts
seeMoreResolve.promise.then(function (labels) {
$scope.$emit("choicesReady");
var opts = labels
.map(i => ({id: i.id + "",
test: i.name}));
CreateSelect2({
element:'#job_templates_labels',
multiple: true,
addNew: true,
opts: opts
});
Wait("stop");
});
Wait("stop");
}).error(function(){
// job template id is null in this case
$scope.$emit("choicesReady");
});
});
}
else {
// job template doesn't exist
$scope.$emit("choicesReady");
}
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, {

View File

@ -1,17 +1,19 @@
export default ['$scope', 'Refresh', 'tagSearchService',
function($scope, Refresh, tagSearchService) {
export default ['$scope', 'Refresh', 'tagSearchService', '$stateParams',
function($scope, Refresh, tagSearchService, $stateParams) {
// JSONify passed field elements that can be searched
$scope.list = angular.fromJson($scope.list);
// Access config lines from list spec
$scope.listConfig = $scope.$parent.list;
// Grab options for the left-dropdown of the searchbar
tagSearchService.getSearchTypes($scope.list, $scope.endpoint)
.then(function(searchTypes) {
$scope.searchTypes = searchTypes;
if($stateParams.id !== "null"){
tagSearchService.getSearchTypes($scope.list, $scope.endpoint)
.then(function(searchTypes) {
$scope.searchTypes = searchTypes;
// currently selected option of the left-dropdown
$scope.currentSearchType = $scope.searchTypes[0];
});
// currently selected option of the left-dropdown
$scope.currentSearchType = $scope.searchTypes[0];
});
}
// shows/hide the search type dropdown
$scope.toggleTypeDropdown = function() {

View File

@ -84,41 +84,45 @@ export default ['Rest', '$q', 'GetBasePath', 'Wait', 'ProcessErrors', '$log', fu
if (needsRequest.length) {
// make the options request to reutrn the typeOptions
Rest.setUrl(needsRequest[0].basePath ? GetBasePath(needsRequest[0].basePath) : basePath);
Rest.options()
.success(function (data) {
try {
var options = data.actions.GET;
needsRequest = needsRequest
.map(function (option) {
option.typeOptions = options[option
.value]
.choices
.map(function(i) {
return {
value: i[0],
label: i[1]
};
});
return option;
});
}
catch(err){
if (!basePath){
$log.error('Cannot retrieve OPTIONS because the basePath parameter is not set on the list with the following fieldset: \n', list);
var url = needsRequest[0].basePath ? GetBasePath(needsRequest[0].basePath) : basePath;
if(url.indexOf('null') === 0 ){
Rest.setUrl(url);
Rest.options()
.success(function (data) {
try {
var options = data.actions.GET;
needsRequest = needsRequest
.map(function (option) {
option.typeOptions = options[option
.value]
.choices
.map(function(i) {
return {
value: i[0],
label: i[1]
};
});
return option;
});
}
else { $log.error(err); }
}
Wait("stop");
defer.resolve(joinOptions());
})
.error(function (data, status) {
Wait("stop");
defer.reject("options request failed");
ProcessErrors(null, data, status, null, {
hdr: 'Error!',
msg: 'Getting type options failed'});
});
catch(err){
if (!basePath){
$log.error('Cannot retrieve OPTIONS because the basePath parameter is not set on the list with the following fieldset: \n', list);
}
else { $log.error(err); }
}
Wait("stop");
defer.resolve(joinOptions());
})
.error(function (data, status) {
Wait("stop");
defer.reject("options request failed");
ProcessErrors(null, data, status, null, {
hdr: 'Error!',
msg: 'Getting type options failed'});
});
}
} else {
Wait("stop");
defer.resolve(joinOptions());