add interceptor to handle version errors
parent
a8caf6dae0
commit
7a6f689004
|
@ -161,7 +161,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
||||||
$tgEventsProvider.setSessionId(taiga.sessionId)
|
$tgEventsProvider.setSessionId(taiga.sessionId)
|
||||||
|
|
||||||
# Add next param when user try to access to a secction need auth permissions.
|
# Add next param when user try to access to a secction need auth permissions.
|
||||||
authHttpIntercept = ($q, $location, $confirm, $navUrls, $lightboxService) ->
|
authHttpIntercept = ($q, $location, $navUrls, $lightboxService) ->
|
||||||
httpResponseError = (response) ->
|
httpResponseError = (response) ->
|
||||||
if response.status == 0
|
if response.status == 0
|
||||||
$lightboxService.closeAll()
|
$lightboxService.closeAll()
|
||||||
|
@ -170,17 +170,37 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
||||||
else if response.status == 401
|
else if response.status == 401
|
||||||
nextPath = $location.path()
|
nextPath = $location.path()
|
||||||
$location.url($navUrls.resolve("login")).search("next=#{nextPath}")
|
$location.url($navUrls.resolve("login")).search("next=#{nextPath}")
|
||||||
|
|
||||||
return $q.reject(response)
|
return $q.reject(response)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
responseError: httpResponseError
|
responseError: httpResponseError
|
||||||
}
|
}
|
||||||
|
|
||||||
$provide.factory("authHttpIntercept", ["$q", "$location", "$tgConfirm", "$tgNavUrls",
|
$provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService", authHttpIntercept])
|
||||||
"lightboxService", authHttpIntercept])
|
|
||||||
|
|
||||||
$httpProvider.interceptors.push('authHttpIntercept');
|
$httpProvider.interceptors.push('authHttpIntercept');
|
||||||
|
|
||||||
|
# If there is an error in the version throw a notify error
|
||||||
|
versionCheckHttpIntercept = ($q, $confirm) ->
|
||||||
|
versionErrorMsg = "Someone inside Taiga has changed this before and our Oompa Loompas cannot apply your changes. Please reload and apply your changes again (they will be lost)." #TODO: i18n
|
||||||
|
|
||||||
|
httpResponseError = (response) ->
|
||||||
|
if response.status == 400 && response.data.version
|
||||||
|
$confirm.notify("error", versionErrorMsg, null, 10000)
|
||||||
|
|
||||||
|
return $q.reject(response)
|
||||||
|
|
||||||
|
return $q.reject(response)
|
||||||
|
|
||||||
|
return {
|
||||||
|
responseError: httpResponseError
|
||||||
|
}
|
||||||
|
|
||||||
|
$provide.factory("versionCheckHttpIntercept", ["$q", "$tgConfirm", versionCheckHttpIntercept])
|
||||||
|
|
||||||
|
$httpProvider.interceptors.push('versionCheckHttpIntercept');
|
||||||
|
|
||||||
window.checksley.updateValidators({
|
window.checksley.updateValidators({
|
||||||
linewidth: (val, width) ->
|
linewidth: (val, width) ->
|
||||||
lines = taiga.nl2br(val).split("<br />")
|
lines = taiga.nl2br(val).split("<br />")
|
||||||
|
|
|
@ -170,7 +170,7 @@ class ConfirmService extends taiga.Service
|
||||||
|
|
||||||
return defered.promise
|
return defered.promise
|
||||||
|
|
||||||
notify: (type, message, title) ->
|
notify: (type, message, title, time) ->
|
||||||
# NOTE: Typesi are: error, success, light-error
|
# NOTE: Typesi are: error, success, light-error
|
||||||
# See partials/components/notification-message.jade)
|
# See partials/components/notification-message.jade)
|
||||||
# Add default texts to NOTIFICATION_MSG for new notification types
|
# Add default texts to NOTIFICATION_MSG for new notification types
|
||||||
|
@ -178,6 +178,8 @@ class ConfirmService extends taiga.Service
|
||||||
selector = ".notification-message-#{type}"
|
selector = ".notification-message-#{type}"
|
||||||
el = angular.element(selector)
|
el = angular.element(selector)
|
||||||
|
|
||||||
|
return if el.hasClass("active")
|
||||||
|
|
||||||
if title
|
if title
|
||||||
el.find("h4").html(title)
|
el.find("h4").html(title)
|
||||||
else
|
else
|
||||||
|
@ -200,7 +202,8 @@ class ConfirmService extends taiga.Service
|
||||||
if @.tsem
|
if @.tsem
|
||||||
cancelTimeout(@.tsem)
|
cancelTimeout(@.tsem)
|
||||||
|
|
||||||
time = if type == 'error' or type == 'light-error' then 3500 else 1500
|
if !time
|
||||||
|
time = if type == 'error' or type == 'light-error' then 3500 else 1500
|
||||||
|
|
||||||
@.tsem = timeout time, =>
|
@.tsem = timeout time, =>
|
||||||
body.find(selector)
|
body.find(selector)
|
||||||
|
|
Loading…
Reference in New Issue