From 7a6f68900473b2adfc984c9ab35a0807d3932e34 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Wed, 3 Dec 2014 14:46:30 +0100 Subject: [PATCH] add interceptor to handle version errors --- app/coffee/app.coffee | 26 +++++++++++++++++++++--- app/coffee/modules/common/confirm.coffee | 7 +++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 51dd695d..223d11d9 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -161,7 +161,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven $tgEventsProvider.setSessionId(taiga.sessionId) # 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) -> if response.status == 0 $lightboxService.closeAll() @@ -170,17 +170,37 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven else if response.status == 401 nextPath = $location.path() $location.url($navUrls.resolve("login")).search("next=#{nextPath}") + return $q.reject(response) return { responseError: httpResponseError } - $provide.factory("authHttpIntercept", ["$q", "$location", "$tgConfirm", "$tgNavUrls", - "lightboxService", authHttpIntercept]) + $provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService", 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({ linewidth: (val, width) -> lines = taiga.nl2br(val).split("
") diff --git a/app/coffee/modules/common/confirm.coffee b/app/coffee/modules/common/confirm.coffee index ce93c707..48d484a4 100644 --- a/app/coffee/modules/common/confirm.coffee +++ b/app/coffee/modules/common/confirm.coffee @@ -170,7 +170,7 @@ class ConfirmService extends taiga.Service return defered.promise - notify: (type, message, title) -> + notify: (type, message, title, time) -> # NOTE: Typesi are: error, success, light-error # See partials/components/notification-message.jade) # Add default texts to NOTIFICATION_MSG for new notification types @@ -178,6 +178,8 @@ class ConfirmService extends taiga.Service selector = ".notification-message-#{type}" el = angular.element(selector) + return if el.hasClass("active") + if title el.find("h4").html(title) else @@ -200,7 +202,8 @@ class ConfirmService extends taiga.Service if @.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, => body.find(selector)