Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where user launches the app for the first time with no data #3

Merged
merged 1 commit into from
Feb 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/css/_splash.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
color: white;
font-size: 60px;
}

.retry-section {
@include center-in-parent;
top: 80%;
}
}
48 changes: 33 additions & 15 deletions source/js/controllers/splash_controller.coffee
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
class Controller
constructor: ($scope, $rootScope, $location, $timeout, SPLASH_SCREEN_DELAY, syncService) ->
syncFinished = false
delayFinished = false

constructor: ($scope, $rootScope, $location, $timeout, SPLASH_SCREEN_DELAY, syncService, configurationService, i18nService) ->
$rootScope.$emit 'navigationConfig',
navigationAvailable: false
searchAvailable: false

syncFinished = false
delayFinished = false

$scope.retryAvailable = false
$scope.retryButtonMessage = i18nService.get 'syncRetryButtonMessage'
$scope.retrySync = () ->
syncRemoteContent()

transitionIfFinished = () ->
$location.path('/home') if syncFinished and delayFinished

syncSuccess = () ->
syncFinished = true
transitionIfFinished()
return

syncFailed = () ->
if configurationService.initialSyncComplete()
alert i18nService.get('syncFailureOfflineMessage')
syncFinished = true
transitionIfFinished()
else
alert i18nService.get('syncFailureRetryMessage')
$scope.retryAvailable = true

return

syncRemoteContent = () ->
syncService.refresh().then(syncSuccess, syncFailed)

Platform.isReady () ->
$timeout () ->
delayFinished = true
transitionIfFinished()
, SPLASH_SCREEN_DELAY

syncService.refresh().then () ->
syncFinished = true
transitionIfFinished()
return
, () ->
# TODO: This should display an error somehow
console.log('Error syncing')
syncFinished = true
transitionIfFinished()
return
if window.navigator.onLine
syncRemoteContent()
else
syncFailed()

angular.module('app').controller 'splashController', ['$scope', '$rootScope', '$location', '$timeout', 'SPLASH_SCREEN_DELAY', 'syncService', Controller]
angular.module('app').controller 'splashController', ['$scope', '$rootScope', '$location', '$timeout', 'SPLASH_SCREEN_DELAY', 'syncService', 'configurationService', 'i18nService', Controller]
8 changes: 8 additions & 0 deletions source/js/services/configuration_service.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Service
constructor: (@$q) ->
initialSyncComplete: () =>
if window.localStorage['initialSyncComplete'] then true else false
initialSyncCompleted: () =>
window.localStorage['initialSyncComplete'] = true

angular.module('app').service 'configurationService', ['$q', Service]
3 changes: 3 additions & 0 deletions source/js/services/i18n_service.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ EN =
sessionTitleFailure: 'Oh no!'
sessionMessageFailure: 'You\'ve run out of chances! Better luck next time!'
acknowledgeButton: 'Ok'
syncFailureOfflineMessage: 'Unable to update content'
syncFailureRetryMessage: 'Unable to update content. Check your network connection and retry'
syncRetryButtonMessage: 'Retry Sync'

class Service
constructor: () ->
Expand Down
5 changes: 3 additions & 2 deletions source/js/services/sync_service.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Service
constructor: (@$http, @$q, @BACKEND_URL, @categoryService, @entryService, @imageCreditService, @downloadService) ->
constructor: (@$http, @$q, @BACKEND_URL, @configurationService, @categoryService, @entryService, @imageCreditService, @downloadService) ->
refresh: () =>
deferred = @$q.defer()
@$http.get("#{@BACKEND_URL}/api/sync/all")
Expand All @@ -15,10 +15,11 @@ class Service
@entryService.save e
@downloadService.saveAssetsForEntry e
@imageCreditService.store res.data.image_credits
@configurationService.initialSyncCompleted()
deferred.resolve()
, (err) =>
deferred.reject()

return deferred.promise

angular.module('app').service 'syncService', ['$http', '$q', 'BACKEND_URL', 'categoryService', 'entryService', 'imageCreditService', 'downloadService', Service]
angular.module('app').service 'syncService', ['$http', '$q', 'BACKEND_URL', 'configurationService', 'categoryService', 'entryService', 'imageCreditService', 'downloadService', Service]
5 changes: 4 additions & 1 deletion source/partials/_splash.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.splash
.name JILA
.name JILA

%div.retry-section{ng: {if: 'retryAvailable'}}
%button{ng: {click: 'retrySync()'}} {{ retryButtonMessage }}