Skip to content

Commit 419f0c0

Browse files
committed
Upgraded to ABP v0.10.0.
1 parent f5cc3ae commit 419f0c0

File tree

5 files changed

+147
-58
lines changed

5 files changed

+147
-58
lines changed

Abp/Framework/scripts/abp.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,24 @@
651651
};
652652
})();
653653

654+
abp.timing.unspecifiedClockProvider = (function () {
655+
656+
var now = function () {
657+
return new Date();
658+
}
659+
660+
var normalize = function (date) {
661+
return date;
662+
}
663+
664+
// Public interface ///////////////////////////////////////////////////
665+
666+
return {
667+
now: now,
668+
normalize: normalize
669+
};
670+
})();
671+
654672
abp.timing.convertToUserTimezone = function (date) {
655673
var localTime = date.getTime();
656674
var utcTime = localTime + (date.getTimezoneOffset() * 60000);
@@ -677,6 +695,6 @@
677695
return date;
678696
}
679697

680-
abp.clock.provider = abp.timing.localClockProvider;
698+
abp.clock.provider = abp.timing.unspecifiedClockProvider;
681699

682700
})(jQuery);

Abp/Framework/scripts/libs/abp.jquery.js

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@
1818

1919
return $.Deferred(function ($dfd) {
2020
$.ajax(options)
21-
.done(function (data) {
22-
abp.ajax.handleResponse(data, userOptions, $dfd);
23-
}).fail(function () {
24-
$dfd.reject.apply(this, arguments);
21+
.done(function (data, textStatus, jqXHR) {
22+
if (data.__abp) {
23+
abp.ajax.handleResponse(data, userOptions, $dfd, jqXHR);
24+
} else {
25+
$dfd.resolve(data);
26+
userOptions.success && userOptions.success(data);
27+
}
28+
}).fail(function (jqXHR) {
29+
if (jqXHR.responseJSON && jqXHR.responseJSON.__abp) {
30+
abp.ajax.handleResponse(jqXHR.responseJSON, userOptions, $dfd, jqXHR);
31+
} else {
32+
abp.ajax.handleNonAbpErrorResponse(jqXHR, userOptions, $dfd);
33+
}
2534
});
2635
});
2736
};
@@ -34,10 +43,20 @@
3443
},
3544

3645
defaultError: {
37-
message: 'Ajax request did not succeed!',
46+
message: 'An error has occurred!',
3847
details: 'Error detail not sent by server.'
3948
},
4049

50+
defaultError401: {
51+
message: 'You are not authenticated!',
52+
details: 'You should be authenticated (sign in) in order to perform this operation.'
53+
},
54+
55+
defaultError403: {
56+
message: 'You are not authorized!',
57+
details: 'You are not allowed to perform this operation.'
58+
},
59+
4160
logError: function (error) {
4261
abp.log.error(error);
4362
},
@@ -52,12 +71,32 @@
5271

5372
handleTargetUrl: function (targetUrl) {
5473
if (!targetUrl) {
55-
location.reload();
74+
location.href = abp.appPath;
5675
} else {
5776
location.href = targetUrl;
5877
}
5978
},
6079

80+
handleNonAbpErrorResponse: function (jqXHR, userOptions, $dfd) {
81+
switch (jqXHR.status) {
82+
case 401:
83+
abp.ajax.handleUnAuthorizedRequest(
84+
abp.ajax.showError(abp.ajax.defaultError401),
85+
abp.appPath
86+
);
87+
break;
88+
case 403:
89+
abp.ajax.showError(abp.ajax.defaultError403);
90+
break;
91+
default:
92+
abp.ajax.showError(abp.ajax.defaultError);
93+
break;
94+
}
95+
96+
$dfd.reject.apply(this, arguments);
97+
userOptions.error && userOptions.error.apply(this, arguments);
98+
},
99+
61100
handleUnAuthorizedRequest: function (messagePromise, targetUrl) {
62101
if (messagePromise) {
63102
messagePromise.done(function () {
@@ -68,11 +107,11 @@
68107
}
69108
},
70109

71-
handleResponse: function (data, userOptions, $dfd) {
110+
handleResponse: function (data, userOptions, $dfd, jqXHR) {
72111
if (data) {
73112
if (data.success === true) {
74-
$dfd && $dfd.resolve(data.result, data);
75-
userOptions.success && userOptions.success(data.result, data);
113+
$dfd && $dfd.resolve(data.result, data, jqXHR);
114+
userOptions.success && userOptions.success(data.result, data, jqXHR);
76115

77116
if (data.targetUrl) {
78117
abp.ajax.handleTargetUrl(data.targetUrl);
@@ -88,19 +127,19 @@
88127

89128
abp.ajax.logError(data.error);
90129

91-
$dfd && $dfd.reject(data.error);
92-
userOptions.error && userOptions.error(data.error);
130+
$dfd && $dfd.reject(data.error, jqXHR);
131+
userOptions.error && userOptions.error(data.error, jqXHR);
93132

94-
if (data.unAuthorizedRequest) {
133+
if (jqXHR.status == 401) {
95134
abp.ajax.handleUnAuthorizedRequest(messagePromise, data.targetUrl);
96135
}
97136
} else { //not wrapped result
98-
$dfd && $dfd.resolve(data);
99-
userOptions.success && userOptions.success(data);
137+
$dfd && $dfd.resolve(data, null, jqXHR);
138+
userOptions.success && userOptions.success(data, null, jqXHR);
100139
}
101140
} else { //no data sent to back
102-
$dfd && $dfd.resolve();
103-
userOptions.success && userOptions.success();
141+
$dfd && $dfd.resolve(jqXHR);
142+
userOptions.success && userOptions.success(jqXHR);
104143
}
105144
},
106145

@@ -163,4 +202,13 @@
163202
};
164203
}
165204

205+
abp.event.on('abp.dynamicScriptsInitialized', function () {
206+
abp.ajax.defaultError.message = abp.localization.abpWeb('DefaultError');
207+
abp.ajax.defaultError.details = abp.localization.abpWeb('DefaultErrorDetail');
208+
abp.ajax.defaultError401.message = abp.localization.abpWeb('DefaultError401');
209+
abp.ajax.defaultError401.details = abp.localization.abpWeb('DefaultErrorDetail401');
210+
abp.ajax.defaultError403.message = abp.localization.abpWeb('DefaultError403');
211+
abp.ajax.defaultError403.details = abp.localization.abpWeb('DefaultErrorDetail403');
212+
});
213+
166214
})(jQuery);

Abp/Framework/scripts/libs/angularjs/abp.ng.js

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@
88

99
abp.ng.http = {
1010
defaultError: {
11-
message: 'Ajax request did not succeed!',
11+
message: 'An error has occurred!',
1212
details: 'Error detail not sent by server.'
1313
},
1414

15+
defaultError401: {
16+
message: 'You are not authenticated!',
17+
details: 'You should be authenticated (sign in) in order to perform this operation.'
18+
},
19+
20+
defaultError403: {
21+
message: 'You are not authorized!',
22+
details: 'You are not allowed to perform this operation.'
23+
},
24+
1525
logError: function (error) {
1626
abp.log.error(error);
1727
},
@@ -25,24 +35,39 @@
2535
},
2636

2737
handleTargetUrl: function (targetUrl) {
28-
location.href = targetUrl;
38+
if (!targetUrl) {
39+
location.href = abp.appPath;
40+
} else {
41+
location.href = targetUrl;
42+
}
43+
},
44+
45+
handleNonAbpErrorResponse: function (response, defer) {
46+
switch (response.status) {
47+
case 401:
48+
abp.ng.http.handleUnAuthorizedRequest(
49+
abp.ng.http.showError(abp.ng.http.defaultError401),
50+
abp.appPath
51+
);
52+
break;
53+
case 403:
54+
abp.ng.http.showError(abp.ajax.defaultError403);
55+
break;
56+
default:
57+
abp.ng.http.showError(abp.ng.http.defaultError);
58+
break;
59+
}
60+
61+
defer.reject(response);
2962
},
3063

3164
handleUnAuthorizedRequest: function (messagePromise, targetUrl) {
3265
if (messagePromise) {
3366
messagePromise.done(function () {
34-
if (!targetUrl) {
35-
location.reload();
36-
} else {
37-
abp.ng.http.handleTargetUrl(targetUrl);
38-
}
67+
abp.ng.http.handleTargetUrl(targetUrl || abp.appPath);
3968
});
4069
} else {
41-
if (!targetUrl) {
42-
location.reload();
43-
} else {
44-
abp.ng.http.handleTargetUrl(targetUrl);
45-
}
70+
abp.ng.http.handleTargetUrl(targetUrl || abp.appPath);
4671
}
4772
},
4873

@@ -70,7 +95,7 @@
7095
response.data = originalData.error;
7196
defer.reject(response);
7297

73-
if (originalData.unAuthorizedRequest) {
98+
if (response.status == 401) {
7499
abp.ng.http.handleUnAuthorizedRequest(messagePromise, originalData.targetUrl);
75100
}
76101
} else { //not wrapped result
@@ -96,29 +121,26 @@
96121
},
97122

98123
'response': function (response) {
99-
if (!response.config || !response.config.abp || !response.data) {
124+
if (!response.data || !response.data.__abp) {
125+
//Non ABP related return value
100126
return response;
101127
}
102128

103129
var defer = $q.defer();
104-
105130
abp.ng.http.handleResponse(response, defer);
106-
107131
return defer.promise;
108132
},
109133

110134
'responseError': function (ngError) {
111-
var error = {
112-
message: ngError.data || abp.ng.http.defaultError.message,
113-
details: ngError.statusText || abp.ng.http.defaultError.details,
114-
responseError: true
115-
}
116-
117-
abp.ng.http.showError(error);
135+
var defer = $q.defer();
118136

119-
abp.ng.http.logError(error);
137+
if (!ngError.data || !ngError.data.__abp) {
138+
abp.ng.http.handleNonAbpErrorResponse(ngError, defer);
139+
} else {
140+
abp.ng.http.handleResponse(ngError, defer);
141+
}
120142

121-
return $q.reject(ngError);
143+
return defer.promise;
122144
}
123145

124146
};
@@ -134,4 +156,13 @@
134156
return str.indexOf(suffix, str.length - suffix.length) !== -1;
135157
}
136158

159+
abp.event.on('abp.dynamicScriptsInitialized', function () {
160+
abp.ng.http.defaultError.message = abp.localization.abpWeb('DefaultError');
161+
abp.ng.http.defaultError.details = abp.localization.abpWeb('DefaultErrorDetail');
162+
abp.ng.http.defaultError401.message = abp.localization.abpWeb('DefaultError401');
163+
abp.ng.http.defaultError401.details = abp.localization.abpWeb('DefaultErrorDetail401');
164+
abp.ng.http.defaultError403.message = abp.localization.abpWeb('DefaultError403');
165+
abp.ng.http.defaultError403.details = abp.localization.abpWeb('DefaultErrorDetail403');
166+
});
167+
137168
})((abp || (abp = {})), (angular || undefined));

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"authors": [
55
"Halil İbrahim Kalkan"
66
],
7-
"version": "v0.9.2",
7+
"version": "v0.10.0",
88
"description": "Script and style resources for ASP.NET Boilerplate based web projects.",
99
"main": "Abp/Framework/scripts/abp.js",
1010
"moduleType": [],

package.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "abp-resources",
3-
"version": "0.8.0.1",
4-
"description": "ASP.NET Boilerplate javascripts",
2+
"name": "abp-web-resources",
3+
"version": "0.10.0",
4+
"description": "ASP.NET Boilerplate web resources",
55
"main": "Abp/Framework/scripts/abp.js",
66
"dependencies": {},
77
"devDependencies": {
@@ -15,26 +15,18 @@
1515
},
1616
"repository": {
1717
"type": "git",
18-
"url": "git+https://github.com/stromsky/bower-abp-resources.git"
18+
"url": "git+https://github.com/aspnetboilerplate/bower-abp-resources.git"
1919
},
2020
"keywords": [
2121
"asp.net",
2222
"boilerplate",
23-
"mvc",
24-
"application",
2523
"web",
26-
"framework",
27-
"domain",
28-
"driven",
29-
"design",
30-
"dependency",
31-
"injection",
3224
"resources"
3325
],
3426
"author": "Halil İbrahim Kalkan",
35-
"license": "ISC",
27+
"license": "MIT",
3628
"bugs": {
37-
"url": "https://github.com/stromsky/bower-abp-resources/issues"
29+
"url": "https://github.com/aspnetboilerplate/bower-abp-resources/issues"
3830
},
39-
"homepage": "https://github.com/stromsky/bower-abp-resources#readme"
31+
"homepage": "http://www.aspnetboilerplate.com/"
4032
}

0 commit comments

Comments
 (0)