Skip to content

Commit 7dd0489

Browse files
authored
Merge pull request #28 from ibering/issue-14
Issue #14 Disable cache for AngularJS/Ajax requests Resolve #14
2 parents 528fa1a + fad7f00 commit 7dd0489

File tree

1 file changed

+66
-59
lines changed

1 file changed

+66
-59
lines changed

public/js/scripts/ng.app.js

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
angular.module('Statusengine', ['ui.router', 'infinite-scroll', 'duScroll', 'ui.bootstrap'])
22

33

4-
.factory("httpInterceptor", function ($q, $rootScope, $timeout) {
4+
.factory("httpInterceptor", function($q, $rootScope, $timeout){
55
$rootScope.ajax_server_error = '';
66
$rootScope.ajax_server_error_message = '';
77
var hasAjaxServerError = false;
88

99
return {
10-
response: function (result) {
11-
$timeout(function () {
10+
response: function(result){
11+
$timeout(function(){
1212
//Let the weel spin for one seconds
1313
$rootScope.loading = false;
1414
}, 1000);
1515

16-
if ($rootScope.ajaxError === true) {
16+
if($rootScope.ajaxError === true){
1717
$rootScope.ajaxError = false;
1818
$('#ajax-modal-dialog').addClass('animated hinge');
19-
$('#ajax-modal').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
19+
$('#ajax-modal').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
2020
$('#ajax-modal').modal('hide');
2121
$('#ajax-modal-dialog').removeClass('animated hinge');
2222
});
2323
}
2424

25-
if (hasAjaxServerError === true) {
25+
if(hasAjaxServerError === true){
2626
hasAjaxServerError = false;
2727
$('#server-error-modal-dialog').addClass('animated hinge');
28-
$('#server-error-modal').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
28+
$('#server-error-modal').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
2929
$('#server-error-modal').modal('hide');
3030
$('#server-error-modal-dialog').removeClass('animated hinge');
3131
});
@@ -34,23 +34,23 @@ angular.module('Statusengine', ['ui.router', 'infinite-scroll', 'duScroll', 'ui.
3434

3535
return result || $.then(result)
3636
},
37-
request: function (response) {
37+
request: function(response){
3838
$rootScope.loading = true;
3939
return response || $q.when(response);
4040
},
41-
responseError: function (rejection) {
41+
responseError: function(rejection){
4242
console.log(rejection);
4343
$rootScope.loading = false;
44-
if (rejection.status === -1) {
44+
if(rejection.status === -1){
4545
$rootScope.ajaxError = true;
4646
$('#ajax-modal').modal('show');
4747
}
4848

49-
if (rejection.status == 401) {
49+
if(rejection.status == 401){
5050
window.location = '/login.html';
5151
}
5252

53-
if (rejection.status >= 500) {
53+
if(rejection.status >= 500){
5454
hasAjaxServerError = true;
5555
$('#server-error-modal').modal('show');
5656
$rootScope.ajax_server_error = '[' + rejection.status + '] ' + rejection.statusText;
@@ -62,160 +62,167 @@ angular.module('Statusengine', ['ui.router', 'infinite-scroll', 'duScroll', 'ui.
6262
};
6363
})
6464

65-
.filter('isNotEmpty', function () {
66-
return function (obj) {
67-
if (typeof obj == 'undefined') {
65+
.filter('isNotEmpty', function(){
66+
return function(obj){
67+
if(typeof obj == 'undefined'){
6868
return false;
6969
}
7070
return !angular.equals(obj, {}) && !angular.equals(obj, []);
7171
}
7272
})
7373

74-
.filter('configEnabled', function () {
75-
return function (value) {
76-
if (value === true) {
74+
.filter('configEnabled', function(){
75+
return function(value){
76+
if(value === true){
7777
return 'Enabled';
7878
}
7979
return 'Disabled';
8080
}
8181
})
8282

83-
.filter('stateType', function () {
84-
return function (stateType) {
85-
if (stateType == true) {
83+
.filter('stateType', function(){
84+
return function(stateType){
85+
if(stateType == true){
8686
return 'Hard';
8787
}
8888
return 'Soft';
8989
}
9090
})
9191

92-
.filter('serviceStatusNameByStatusCode', function () {
93-
return function (statuscode) {
94-
if (statuscode == 0) {
92+
.filter('serviceStatusNameByStatusCode', function(){
93+
return function(statuscode){
94+
if(statuscode == 0){
9595
return "Ok";
9696
}
9797

98-
if (statuscode == 1) {
98+
if(statuscode == 1){
9999
return "Warning"
100100
}
101101

102-
if (statuscode == 2) {
102+
if(statuscode == 2){
103103
return "Critical"
104104
}
105105

106106
return "Unknown";
107107
}
108108
})
109109

110-
.filter('bootstrapClassStatusCodeHost', function () {
111-
return function (statuscode) {
112-
if (statuscode == 0) {
110+
.filter('bootstrapClassStatusCodeHost', function(){
111+
return function(statuscode){
112+
if(statuscode == 0){
113113
return "success";
114114
}
115115

116-
if (statuscode == 1) {
116+
if(statuscode == 1){
117117
return "danger"
118118
}
119119

120120
return "primary";
121121
}
122122
})
123123

124-
.filter('bootstrapClassStatusCodeService', function () {
125-
return function (statuscode) {
126-
if (statuscode == 0) {
124+
.filter('bootstrapClassStatusCodeService', function(){
125+
return function(statuscode){
126+
if(statuscode == 0){
127127
return "success";
128128
}
129129

130-
if (statuscode == 1) {
130+
if(statuscode == 1){
131131
return "warning"
132132
}
133133

134-
if (statuscode == 2) {
134+
if(statuscode == 2){
135135
return "danger"
136136
}
137137

138138
return "primary";
139139
}
140140
})
141141

142-
.filter('statusNameByStatusCodeHost', function () {
143-
return function (statuscode) {
144-
if (statuscode == 0) {
142+
.filter('statusNameByStatusCodeHost', function(){
143+
return function(statuscode){
144+
if(statuscode == 0){
145145
return "Up";
146146
}
147147

148-
if (statuscode == 1) {
148+
if(statuscode == 1){
149149
return "Down"
150150
}
151151

152152
return "Unreachable";
153153
}
154154
})
155155

156-
.filter('statusBgByStatusCodeService', function () {
157-
return function (statuscode) {
158-
if (statuscode == 0) {
156+
.filter('statusBgByStatusCodeService', function(){
157+
return function(statuscode){
158+
if(statuscode == 0){
159159
return 'bg-green';
160160
}
161161

162-
if (statuscode == 1) {
162+
if(statuscode == 1){
163163
return 'bg-yellow';
164164
}
165165

166-
if (statuscode == 2) {
166+
if(statuscode == 2){
167167
return 'bg-red';
168168
}
169169

170170
return 'bg-primary';
171171
}
172172
})
173173

174-
.filter('yesOrNo', function () {
175-
return function (value) {
176-
if (value === true || value === 1 || value === 'true') {
174+
.filter('yesOrNo', function(){
175+
return function(value){
176+
if(value === true || value === 1 || value === 'true'){
177177
return 'Yes';
178178
}
179179
return 'No';
180180
}
181181
})
182182

183-
.filter('iconByStatusCodeService', function () {
184-
return function (statuscode) {
185-
if (statuscode == 0) {
183+
.filter('iconByStatusCodeService', function(){
184+
return function(statuscode){
185+
if(statuscode == 0){
186186
return 'fa-check-circle-o';
187187
}
188188

189-
if (statuscode == 1) {
189+
if(statuscode == 1){
190190
return 'fa-exclamation-triangle';
191191
}
192192

193-
if (statuscode == 2) {
193+
if(statuscode == 2){
194194
return 'fa-times';
195195
}
196196

197197
return 'fa-question-circle-o';
198198
}
199199
})
200200

201-
.filter('base64encode', function () {
202-
return function (str) {
201+
.filter('base64encode', function(){
202+
return function(str){
203203
return btoa(str);
204204
}
205205
})
206206

207-
.filter('encodeURI', function () {
208-
return function (str) {
207+
.filter('encodeURI', function(){
208+
return function(str){
209209
return encodeURI(str);
210210
}
211211
})
212212

213213

214-
.config(function ($httpProvider) {
214+
.config(function($httpProvider){
215215
$httpProvider.interceptors.push("httpInterceptor");
216-
})
216+
$httpProvider.defaults.cache = false;
217+
if(!$httpProvider.defaults.headers.get){
218+
$httpProvider.defaults.headers.get = {};
219+
}
220+
// disable IE ajax request caching
221+
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
217222

218-
.config(function ($urlRouterProvider, $stateProvider) {
223+
})
224+
225+
.config(function($urlRouterProvider, $stateProvider){
219226
$urlRouterProvider.otherwise("/dashboard");
220227

221228
$stateProvider

0 commit comments

Comments
 (0)