mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 05:45:50 +00:00
LH :: Fix bug with mock-data loading due to timing
This commit is contained in:
parent
16bbf17d98
commit
202d4fdcef
2 changed files with 27 additions and 19 deletions
|
@ -2,7 +2,7 @@ var app = angular.module('spring-petclinic', ['ui.router','ui.router.stateHelper
|
||||||
|
|
||||||
|
|
||||||
/** Start of Configurable constants **/
|
/** Start of Configurable constants **/
|
||||||
app.constant('useMockData', true);
|
app.constant('useMockData', false);
|
||||||
app.constant('context', '/petclinic');
|
app.constant('context', '/petclinic');
|
||||||
/** End of Configurable constants **/
|
/** End of Configurable constants **/
|
||||||
|
|
||||||
|
|
|
@ -18,28 +18,36 @@ var Visit = ['$resource','context', function($resource, context) {
|
||||||
return $resource(context + '/api/pets/:petId/visits', {petId : '@id'});
|
return $resource(context + '/api/pets/:petId/visits', {petId : '@id'});
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var MockService = ['$httpBackend', '$http', 'context', function($httpBackend, $http, context) {
|
var MockService = ['$httpBackend', '$http', '$q', 'context', function($httpBackend, $http, $q, context) {
|
||||||
return {
|
return {
|
||||||
mock : function(useMockData) {
|
mock : function(useMockData) {
|
||||||
|
|
||||||
if(useMockData) {
|
var passThroughRegex = new RegExp('/static/mock-data/|components/');
|
||||||
$http.get(context + '/static/mock-data/pets.json').success(function(data) {
|
$httpBackend.whenGET(passThroughRegex).passThrough();
|
||||||
console.log("Mocking /api/pets");
|
|
||||||
$httpBackend.whenGET(context + '/api/pets').respond(data);
|
|
||||||
});
|
|
||||||
$http.get(context + '/static/mock-data/vets.json').success(function(data) {
|
|
||||||
console.log("Mocking /api/vets");
|
|
||||||
$httpBackend.whenGET(context + '/api/vets').respond(data);
|
|
||||||
});
|
|
||||||
$http.get(context + '/static/mock-data/owners.json').success(function(data) {
|
|
||||||
console.log("Mocking /api/owners");
|
|
||||||
$httpBackend.whenGET(context + '/api/owners').respond(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(useMockData) {
|
||||||
|
$q.defer();
|
||||||
|
$q.all([
|
||||||
|
$http.get(context + '/static/mock-data/pets.json'),
|
||||||
|
$http.get(context + '/static/mock-data/vets.json'),
|
||||||
|
$http.get(context + '/static/mock-data/owners.json')
|
||||||
|
]).then(function(data) {
|
||||||
|
console.log("Mocking /api/pets");
|
||||||
|
$httpBackend.whenGET(context + '/api/pets').respond(data[0].data);
|
||||||
|
console.log("Mocking /api/vets");
|
||||||
|
$httpBackend.whenGET(context + '/api/vets').respond(data[1].data);
|
||||||
|
console.log("Mocking /api/owners");
|
||||||
|
$httpBackend.whenGET(context + '/api/owners').respond(data[2].data);
|
||||||
|
|
||||||
|
console.log("Setting up passthrough for other urls");
|
||||||
|
var passThroughRegex = new RegExp('/');
|
||||||
|
$httpBackend.whenGET(passThroughRegex).passThrough();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
console.log("Setting up passthrough for other urls");
|
console.log("Setting up passthrough for other urls");
|
||||||
var passThroughRegex = new RegExp('/');
|
var passThroughRegex = new RegExp('/');
|
||||||
$httpBackend.whenGET(passThroughRegex).passThrough();
|
$httpBackend.whenGET(passThroughRegex).passThrough();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}];
|
}];
|
Loading…
Reference in a new issue