fix project loader
parent
517d393bd7
commit
1ea5412265
|
@ -5,15 +5,16 @@ module = angular.module("taigaCommon")
|
||||||
|
|
||||||
LoaderDirective = (tgLoader) ->
|
LoaderDirective = (tgLoader) ->
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs) ->
|
||||||
tgLoader.end () ->
|
tgLoader.onStart () ->
|
||||||
|
$(document.body).addClass("loader-active")
|
||||||
|
$el.addClass("active")
|
||||||
|
|
||||||
|
tgLoader.onEnd () ->
|
||||||
$(document.body).removeClass("loader-active")
|
$(document.body).removeClass("loader-active")
|
||||||
$el.removeClass("active")
|
$el.removeClass("active")
|
||||||
|
|
||||||
$scope.$on "$routeChangeSuccess", () ->
|
$scope.$on "$routeChangeSuccess", () ->
|
||||||
tgLoader.start () ->
|
tgLoader.start()
|
||||||
$(document.body).addClass("loader-active")
|
|
||||||
$el.addClass("active")
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
|
@ -22,10 +23,6 @@ LoaderDirective = (tgLoader) ->
|
||||||
module.directive("tgLoader", ["tgLoader", LoaderDirective])
|
module.directive("tgLoader", ["tgLoader", LoaderDirective])
|
||||||
|
|
||||||
Loader = () ->
|
Loader = () ->
|
||||||
interval = null
|
|
||||||
onLoad = () ->
|
|
||||||
startLoadTime = 0
|
|
||||||
|
|
||||||
defaultLog = {
|
defaultLog = {
|
||||||
request: {
|
request: {
|
||||||
count: 0,
|
count: 0,
|
||||||
|
@ -38,7 +35,7 @@ Loader = () ->
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig = {
|
defaultConfig = {
|
||||||
enabled: false,
|
enabled: true,
|
||||||
minTime: 1000,
|
minTime: 1000,
|
||||||
auto: false
|
auto: false
|
||||||
}
|
}
|
||||||
|
@ -46,55 +43,52 @@ Loader = () ->
|
||||||
log = _.merge({}, defaultLog)
|
log = _.merge({}, defaultLog)
|
||||||
config = _.merge({}, defaultConfig)
|
config = _.merge({}, defaultConfig)
|
||||||
|
|
||||||
reset = () ->
|
|
||||||
log = _.merge({}, defaultLog)
|
|
||||||
config = _.merge({}, defaultConfig)
|
|
||||||
|
|
||||||
pageLoaded = () ->
|
|
||||||
reset()
|
|
||||||
|
|
||||||
endTime = new Date().getTime()
|
|
||||||
diff = endTime - startLoadTime
|
|
||||||
|
|
||||||
if diff < config.minTime
|
|
||||||
timeout = config.minTime - diff
|
|
||||||
else
|
|
||||||
timeout = 0
|
|
||||||
|
|
||||||
setTimeout ( ->
|
|
||||||
onLoad()
|
|
||||||
), timeout
|
|
||||||
|
|
||||||
autoCheckLoad = () ->
|
|
||||||
interval = setInterval ( ->
|
|
||||||
currentDate = new Date().getTime()
|
|
||||||
|
|
||||||
if log.request.count == log.response.count && currentDate - log.response.time > 200
|
|
||||||
clearInterval(interval)
|
|
||||||
pageLoaded()
|
|
||||||
|
|
||||||
), 100
|
|
||||||
|
|
||||||
@.add = (auto = false) ->
|
@.add = (auto = false) ->
|
||||||
return () ->
|
return () ->
|
||||||
config.enabled = true
|
|
||||||
config.auto = auto
|
config.auto = auto
|
||||||
|
|
||||||
@.$get = () ->
|
@.$get = ["$rootScope", ($rootscope) ->
|
||||||
|
interval = null
|
||||||
|
startLoadTime = 0
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: (callback) ->
|
pageLoaded: () ->
|
||||||
|
if config.enabled
|
||||||
|
log = _.merge({}, defaultLog)
|
||||||
|
config = _.merge({}, defaultConfig)
|
||||||
|
|
||||||
|
endTime = new Date().getTime()
|
||||||
|
diff = endTime - startLoadTime
|
||||||
|
|
||||||
|
if diff < config.minTime
|
||||||
|
timeout = config.minTime - diff
|
||||||
|
else
|
||||||
|
timeout = 0
|
||||||
|
|
||||||
|
setTimeout ( ->
|
||||||
|
$rootscope.$broadcast("loader:end");
|
||||||
|
), timeout
|
||||||
|
|
||||||
|
start: () ->
|
||||||
if config.enabled
|
if config.enabled
|
||||||
if config.auto
|
if config.auto
|
||||||
autoCheckLoad()
|
interval = setInterval ( ->
|
||||||
|
currentDate = new Date().getTime()
|
||||||
|
|
||||||
|
if log.request.count == log.response.count && currentDate - log.response.time > 200
|
||||||
|
clearInterval(interval)
|
||||||
|
pageLoaded()
|
||||||
|
|
||||||
|
), 100
|
||||||
|
|
||||||
startLoadTime = new Date().getTime()
|
startLoadTime = new Date().getTime()
|
||||||
callback()
|
$rootscope.$broadcast("loader:start");
|
||||||
|
|
||||||
end: (fn) ->
|
onStart: (fn) ->
|
||||||
onLoad = fn
|
$rootscope.$on("loader:start", fn);
|
||||||
|
|
||||||
pageLoaded: () ->
|
onEnd: (fn) ->
|
||||||
pageLoaded()
|
$rootscope.$on("loader:end", fn);
|
||||||
|
|
||||||
logRequest: () ->
|
logRequest: () ->
|
||||||
log.request.count++
|
log.request.count++
|
||||||
|
@ -103,11 +97,21 @@ Loader = () ->
|
||||||
logResponse: () ->
|
logResponse: () ->
|
||||||
log.response.count++
|
log.response.count++
|
||||||
log.response.time = new Date().getTime()
|
log.response.time = new Date().getTime()
|
||||||
|
|
||||||
|
isEneabled: () ->
|
||||||
|
config.enabled == true
|
||||||
|
|
||||||
|
disabled: () ->
|
||||||
|
config.enabled = false
|
||||||
|
|
||||||
|
enabled: () ->
|
||||||
|
config.enabled = true
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
module.provider("tgLoader", Loader)
|
module.provider("tgLoader", [Loader])
|
||||||
|
|
||||||
loaderInterceptor = (tgLoader) ->
|
loaderInterceptor = (tgLoader) ->
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ProjectsNavigationController extends taiga.Controller
|
||||||
module.controller("ProjectsNavigationController", ProjectsNavigationController)
|
module.controller("ProjectsNavigationController", ProjectsNavigationController)
|
||||||
|
|
||||||
|
|
||||||
ProjectsNavigationDirective = ($rootscope, animationFrame, $timeout) ->
|
ProjectsNavigationDirective = ($rootscope, animationFrame, $timeout, tgLoader) ->
|
||||||
baseTemplate = _.template("""
|
baseTemplate = _.template("""
|
||||||
<h1>Your projects</h1>
|
<h1>Your projects</h1>
|
||||||
<form>
|
<form>
|
||||||
|
@ -111,8 +111,8 @@ ProjectsNavigationDirective = ($rootscope, animationFrame, $timeout) ->
|
||||||
difftime = new Date().getTime() - loadingStart
|
difftime = new Date().getTime() - loadingStart
|
||||||
timeout = 0
|
timeout = 0
|
||||||
|
|
||||||
if (difftime < 3500)
|
if (difftime < 1000)
|
||||||
timeout = 3500 - timeout
|
timeout = 1000 - timeout
|
||||||
|
|
||||||
setTimeout ( ->
|
setTimeout ( ->
|
||||||
overlay.one 'transitionend', () ->
|
overlay.one 'transitionend', () ->
|
||||||
|
@ -120,6 +120,8 @@ ProjectsNavigationDirective = ($rootscope, animationFrame, $timeout) ->
|
||||||
|
|
||||||
$(document.body)
|
$(document.body)
|
||||||
.removeClass("loading-project open-projects-nav")
|
.removeClass("loading-project open-projects-nav")
|
||||||
|
|
||||||
|
tgLoader.enabled()
|
||||||
), timeout
|
), timeout
|
||||||
|
|
||||||
renderProjects = ($el, projects) ->
|
renderProjects = ($el, projects) ->
|
||||||
|
@ -151,6 +153,8 @@ ProjectsNavigationDirective = ($rootscope, animationFrame, $timeout) ->
|
||||||
$(document.body)
|
$(document.body)
|
||||||
.addClass('loading-project')
|
.addClass('loading-project')
|
||||||
|
|
||||||
|
tgLoader.disabled()
|
||||||
|
|
||||||
loadingStart = new Date().getTime()
|
loadingStart = new Date().getTime()
|
||||||
|
|
||||||
$el.on "click", ".create-project-button .button", (event) ->
|
$el.on "click", ".create-project-button .button", (event) ->
|
||||||
|
@ -246,7 +250,7 @@ ProjectsNavigationDirective = ($rootscope, animationFrame, $timeout) ->
|
||||||
link: link
|
link: link
|
||||||
}
|
}
|
||||||
|
|
||||||
module.directive("tgProjectsNav", ["$rootScope", "animationFrame", "$timeout", ProjectsNavigationDirective])
|
module.directive("tgProjectsNav", ["$rootScope", "animationFrame", "$timeout", "tgLoader", ProjectsNavigationDirective])
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
Loading…
Reference in New Issue