Skip to content

Commit

Permalink
Return to owner details (#195)
Browse files Browse the repository at this point in the history
* Use Github Actions for CI

* Return to the Owner details view
  • Loading branch information
arey authored Dec 18, 2021
1 parent 0ab2e95 commit 05007a6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<script src="/scripts/vet-list/vet-list.js"></script>
<script src="/scripts/vet-list/vet-list.controller.js"></script>
<script src="/scripts/vet-list/vet-list.component.js"></script>

<script src="/scripts/infrastructure/infrastructure.js"></script>
<script src="/scripts/infrastructure/httpErrorHandlingInterceptor.js"></script>
</head>

<body class="container">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';
/* App Module */
var petClinicApp = angular.module('petClinicApp', [
'ui.router', 'layoutNav', 'layoutFooter', 'layoutWelcome',
'ui.router', 'infrastructure', 'layoutNav', 'layoutFooter', 'layoutWelcome',
'ownerList', 'ownerDetails', 'ownerForm', 'petForm', 'visits', 'vetList']);

petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider', function(
$stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {

// safari turns to be lazy sending the Cache-Control header
$httpProvider.defaults.headers.common["Cache-Control"] = 'no-cache';
$httpProvider.interceptors.push('HttpErrorHandlingInterceptor');

$locationProvider.hashPrefix('!');

Expand All @@ -32,4 +33,4 @@ petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider'
angular.module(mod).component(mod, {
templateUrl: "scripts/fragments/" + c + ".html"
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

/**
* Global HTTP errors handler.
*/
angular.module('infrastructure')
.factory('HttpErrorHandlingInterceptor', function () {
return {
responseError: function (response) {
var error = response.data;
alert(error.error + "\r\n" + error.errors.map(function (e) {
return e.field + ": " + e.defaultMessage;
}).join("\r\n"));
return response;
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

angular.module('infrastructure', []);
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ angular.module('ownerForm')

self.submitOwnerForm = function () {
var id = self.owner.id;
var req;

if (id) {
req = $http.put("api/customer/owners/" + id, self.owner);
$http.put('api/customer/owners/' + id, self.owner).then(function () {
$state.go('ownerDetails', {ownerId: ownerId});
});
} else {
req = $http.post("api/customer/owners", self.owner);
$http.post('api/customer/owners', self.owner).then(function () {
$state.go('owners');
});
}

req.then(function () {
$state.go('owners');
}, function (response) {
var error = response.data;
alert(error.error + "\r\n" + error.errors.map(function (e) {
return e.field + ": " + e.defaultMessage;
}).join("\r\n"));
});
};
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ angular.module('petForm')
}

req.then(function () {
$state.go("owners", {ownerId: ownerId});
}, function (response) {
var error = response.data;
error.errors = error.errors || [];
alert(error.error + "\r\n" + error.errors.map(function (e) {
return e.field + ": " + e.defaultMessage;
}).join("\r\n"));
$state.go('ownerDetails', {ownerId: ownerId});
});
};
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ angular.module('visits')
};

$http.post(url, data).then(function () {
$state.go("owners", { ownerId: $stateParams.ownerId });
}, function (response) {
var error = response.data;
alert(error.error + "\r\n" + error.errors.map(function (e) {
return e.field + ": " + e.defaultMessage;
}).join("\r\n"));
$state.go('ownerDetails', { ownerId: $stateParams.ownerId });
});
};
}]);

0 comments on commit 05007a6

Please sign in to comment.