addBackgroundProcess: ->
uid = _.uniqueId 'process'
- @queue[uid] = new Date()
- setTimeout (=> @showSpinner uid if @isBackgroundProcessAlive uid), @timeout
+ @renderSpinner uid
+ @queue[uid] = setTimeout (=> @showSpinner uid), @timeout
uid
finishBackgroundProcess: (uid) ->
- delete @queue[uid]
- @removeSpinner uid
+ if @isBackgroundProcessAlive uid
+ clearInterval @queue[uid]
+ delete @queue[uid]
+ @removeSpinner uid
- showSpinner: (uid) ->
+ failBackgroundProcess: (uid) ->
+ if @isBackgroundProcessAlive uid
+ clearInterval @queue[uid]
+ delete @queue[uid]
+ spinner = @getSpinner uid
+ spinner.addClass 'process-spinner-failed'
+ spinner.text t 'process.fail'
+ close = $('<button></button>').html('<i class="icon-close"></i>').addClass 'process-spinner-close'
+ close.appendTo spinner
+ close.on 'click', => @removeSpinner uid
+
+
+ renderSpinner: (uid) ->
id = "spinner-#{uid}"
spinner = $ '<div></div>'
spinner.addClass 'process-spinner'
spinner.prop 'id', id
- spinner.text t 'process.still_working'
+ text = t 'process.still_working'
+ text = 'Still Working...' if text == 'process.still_working'
+ spinner.text text
spinner.appendTo $('body')
+
+
+ showSpinner: (uid) ->
+ spinner = @getSpinner(uid)
setTimeout (-> spinner.addClass 'shown'), @fadeTimeout
removeSpinner: (uid) ->
+ @getSpinner(uid).remove()
+
+
+ getSpinner: (uid) ->
id = "spinner-#{uid}"
- $('#' + id).remove()
+ $('#' + id)
_.extend window, process: process
_.extend data, @options.app.state.get 'query'
fetchIssuesProcess = window.process.addBackgroundProcess()
- $.get "#{baseUrl}/api/issues/search", data, (r) =>
+ $.get "#{baseUrl}/api/issues/search", data
+ .done (r) =>
issues = @options.app.issues.parseIssues r
if firstPage
@options.app.issues.reset issues
else
@options.app.issues.add issues
-
FACET_DATA_FIELDS.forEach (field) => @options.app.facets[field] = r[field]
@options.app.facets.reset @_allFacets()
@options.app.facets.add r.facets, merge: true
@enableFacets @_enabledFacets()
-
@options.app.state.set
page: r.p
pageSize: r.ps
total: r.total
maxResultsReached: r.p * r.ps >= r.total
-
window.process.finishBackgroundProcess fetchIssuesProcess
+ .fail ->
+ window.process.failBackgroundProcess fetchIssuesProcess
fetchNextPage: ->
facet.set enabled: true
else
p = window.process.addBackgroundProcess()
- @requestFacet(id).done =>
+ @requestFacet(id)
+ .done =>
facet.set enabled: true
window.process.finishBackgroundProcess p
+ .fail ->
+ window.process.failBackgroundProcess p
disableFacet: (id) ->
top: 0; left: 50%;
width: 300px;
margin-left: -150px;
- padding: 3px 0;
+ line-height: 22px;
background-color: #f0e8ac;
border-radius: 0 0 3px 3px;
text-align: center;
&.shown { opacity: 1; }
}
+
+.process-spinner-failed {
+ background-color: @red;
+ color: @white;
+}
+
+.process-spinner-close {
+ float: right;
+ margin-right: 5px;
+ padding: 3px;
+ background: none !important;
+ border: none !important;
+ line-height: 1;
+}