2015-09-25 02:03:11 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
_str = require 'underscore.string'
|
|
|
|
classNames = require 'classnames'
|
|
|
|
React = require 'react'
|
|
|
|
{Actions, AccountStore, NylasSyncStatusStore} = require 'nylas-exports'
|
|
|
|
|
|
|
|
class InitialSyncActivity extends React.Component
|
|
|
|
@displayName: 'InitialSyncActivity'
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStores()
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@_usub = NylasSyncStatusStore.listen @_onDataChanged
|
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
@_usub?()
|
|
|
|
|
|
|
|
_onDataChanged: =>
|
|
|
|
@setState(@_getStateFromStores())
|
|
|
|
|
|
|
|
_getStateFromStores: =>
|
|
|
|
sync: NylasSyncStatusStore.state()
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
count = 0
|
|
|
|
fetched = 0
|
|
|
|
totalProgress = 0
|
|
|
|
incomplete = 0
|
|
|
|
|
|
|
|
for acctId, state of @state.sync
|
2016-04-12 04:51:31 +08:00
|
|
|
for modelName in NylasSyncStatusStore.ModelsForSync
|
2016-04-11 15:34:01 +08:00
|
|
|
modelState = state[modelName]
|
|
|
|
continue unless modelState
|
|
|
|
|
|
|
|
if not modelState.complete
|
|
|
|
incomplete += 1
|
2015-09-25 02:03:11 +08:00
|
|
|
if modelState.count
|
|
|
|
count += modelState.count / 1
|
|
|
|
fetched += modelState.fetched / 1
|
|
|
|
|
|
|
|
totalProgress = (fetched / count) * 100 if count > 0
|
|
|
|
|
|
|
|
classSet = classNames
|
|
|
|
'item': true
|
|
|
|
'expanded-sync': @state.expandedSync
|
|
|
|
|
|
|
|
if incomplete is 0
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
<div className={classSet} key="initial-sync" onClick={=> @setState expandedSync: !@state.expandedSync}>
|
|
|
|
{@_renderProgressBar(totalProgress)}
|
2015-10-03 06:01:26 +08:00
|
|
|
<div className="inner">Syncing your mailbox…</div>
|
2015-09-25 02:03:11 +08:00
|
|
|
{@_expandedSyncState()}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_expandedSyncState: ->
|
|
|
|
accounts = []
|
|
|
|
for acctId, state of @state.sync
|
2016-01-09 01:31:24 +08:00
|
|
|
account = _.findWhere(AccountStore.accounts(), id: acctId)
|
2015-09-25 02:03:11 +08:00
|
|
|
continue unless account
|
2015-09-30 15:35:45 +08:00
|
|
|
|
2015-09-25 02:03:11 +08:00
|
|
|
modelStates = _.map state, (modelState, model) =>
|
|
|
|
@_renderModelProgress(model, modelState, 100)
|
|
|
|
|
2015-09-30 15:35:45 +08:00
|
|
|
accounts.push(
|
|
|
|
<div className="account inner" key={acctId}>
|
|
|
|
<h2>{account.emailAddress}</h2>
|
|
|
|
{modelStates}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
2015-09-25 02:03:11 +08:00
|
|
|
<div className="account-detail-area">
|
|
|
|
{accounts}
|
2015-09-30 15:35:45 +08:00
|
|
|
<a className="close-expanded" onClick={@_hideExpandedState}>Hide</a>
|
2015-09-25 02:03:11 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
_hideExpandedState: (event) =>
|
|
|
|
event.stopPropagation() # So it doesn't reach the parent's onClick
|
|
|
|
event.preventDefault()
|
|
|
|
@setState expandedSync: false
|
|
|
|
return
|
|
|
|
|
|
|
|
_renderModelProgress: (model, modelState) ->
|
|
|
|
if modelState.error
|
|
|
|
status = "error"
|
|
|
|
else if modelState.complete
|
|
|
|
status = "complete"
|
|
|
|
else
|
|
|
|
status = "busy"
|
|
|
|
percent = (+modelState.fetched / +modelState.count) * 100
|
|
|
|
|
|
|
|
<div className="model-progress #{status}" key={model}>
|
|
|
|
<h3>{_str.titleize(model)}:</h3>
|
|
|
|
{@_renderProgressBar(percent)}
|
|
|
|
<div className="amount">{_str.numberFormat(modelState.fetched)} / {_str.numberFormat(modelState.count)}</div>
|
|
|
|
<div className="error-text">{modelState.error}</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderProgressBar: (percent) ->
|
|
|
|
<div className="progress-track">
|
|
|
|
<div className="progress" style={width: "#{percent}%"}></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_onTryAgain: =>
|
2016-04-05 08:11:09 +08:00
|
|
|
Actions.retrySync()
|
2015-09-25 02:03:11 +08:00
|
|
|
|
|
|
|
module.exports = InitialSyncActivity
|