-
Notifications
You must be signed in to change notification settings - Fork 25
Syncs board after a period of inactivity #278
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f1cede4
Adds a route for fetching issues with optional parameters
discorick dc2bce4
Begins working on the client-side session service and tests
discorick 275b732
Implements events & handlers for browser focus blur as an injected "b…
discorick 40c2205
Tweaks the focus logic and tests
discorick 1952937
Adds logged_in endpoint, tweaks issues api endpoint
discorick 9b0f528
Implements basic board syncing service (sans success/fail handlers) a…
discorick 51aba7a
Fixes a bug related to misunderstanding the RSVP.all contract
discorick f072790
Uses correct method to flatten the array
discorick 04c9148
Fixes flash sync messages from display an x on sync progress
discorick 5829e45
Make sure messageData is always a new object instance, ensures only o…
discorick 224d420
Implements session checking logic in the application controller
discorick 251b281
Adds #/sync-issues route to manually sync the board
discorick cb862ac
Fixes problem where array proxy wasn't propagating changes to the mod…
discorick 5e9bbc1
Removes logged_in route, throttles the board sync @30 seconds
discorick 0edf225
Gives syncing message 1 second (to adjust for insta-syncs) shortens s…
discorick e43f3e1
Implements a failure message for board syncing
discorick 8b69116
styles the progress flash message more subtley
discorick 533e684
Use same-as-background shadow on progress message
dahlbyk 3ac1cad
Force refresh after 24hours of no focus
discorick 87ca4b1
Gracefully returns if no flash can be found
discorick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ $lighterGrey: #CCC; | |
| $lightGrey: #999; | ||
| $grey: #666; | ||
| $darkGrey: #444; | ||
| $navGrey: #F3F3F3; | ||
|
|
||
| $red: red; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import BrowserSession from 'app/services/browser-session'; | ||
|
|
||
| export function initialize(container, application){ | ||
| application.register('browser-session:main', BrowserSession); | ||
| application.inject('controller', 'browser-session', 'browser-session:main'); | ||
| application.inject('component', 'browser-session', 'browser-session:main'); | ||
| } | ||
|
|
||
| export default { | ||
| name: 'browser-session', | ||
| after: 'advanceReadiness', | ||
| initialize: initialize | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ Router.map(function() { | |
|
|
||
| }); | ||
|
|
||
| this.resource("sync-issues"); | ||
| this.route("unauthorized"); | ||
| }); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| var SyncIssuesRoute = Ember.Route.extend({ | ||
| boardSyncing: Ember.inject.service(), | ||
|
|
||
| model: function(){ | ||
| var repo = this.modelFor("application"); | ||
| return repo; | ||
| }, | ||
|
|
||
| afterModel: function (model){ | ||
| var since = new Date(new Date().getTime() - 3600000); | ||
| this.get('boardSyncing').syncIssues(model.get('board'), {since: since.toISOString()}); | ||
| this.transitionTo('application'); | ||
| } | ||
| }); | ||
|
|
||
| export default SyncIssuesRoute; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| var BoardSyncingService = Ember.Service.extend({ | ||
|
|
||
| //Sync Notifier | ||
| flashMessages: Ember.inject.service(), | ||
| syncFlashNotifier: function(){ | ||
| if(this.get('syncInProgress')){ | ||
| this.get('flashMessages').add(this.messageData()); | ||
| } else { | ||
| var flash = this.get('flashMessages.queue').find((flash)=>{ | ||
| return flash.identifier === 'sync-message'; | ||
| }); | ||
| if(!flash){ return; } | ||
| Ember.set(flash.progress, 'status', false); | ||
| } | ||
| }.observes('syncInProgress'), | ||
| messageData: function(){ | ||
| return { | ||
| message: 'syncing your board, please wait...', | ||
| sticky: true, | ||
| type: 'progress', | ||
| identifier: 'sync-message', | ||
| progress: { | ||
| status: true, | ||
| callback: function(){ | ||
| setTimeout(()=>{ | ||
| this.set('message', 'sync complete!'); | ||
| this.get('flash')._setTimer('timer', 'destroyMessage', 2000); | ||
| }, 1000); | ||
| } | ||
| } | ||
| }; | ||
| }, | ||
|
|
||
| //Issue Syncing | ||
| syncIssues: function(board, opts){ | ||
| if(this.get('syncInProgress')){ return; } | ||
| var _self = this; | ||
| _self.set('syncInProgress', true); | ||
|
|
||
| board.fetchIssues(opts).then((issues)=>{ | ||
| _self.issueSuccess(board, issues); | ||
| _self.set('syncInProgress', false); | ||
| }, (error)=>{ | ||
| _self.issueFail(); | ||
| _self.set('syncInProgress', false); | ||
| }); | ||
| }, | ||
| issueSuccess: function(board, issues){ | ||
| if(!issues.length){ return; } | ||
| Ember.run.once(()=>{ | ||
| board.get('issues').forEach((issue)=>{ | ||
| issues.forEach((i)=>{ | ||
| if(i.id === issue.get('id')){ | ||
| Ember.set(issue, 'data', i); | ||
| }; | ||
| }); | ||
| }); | ||
| }); | ||
| }, | ||
| issueFail: function(error){ | ||
| var flash = this.get('flashMessages.queue').find((flash)=>{ | ||
| return flash.identifier === 'sync-message'; | ||
| }); | ||
| if(!flash){ return; } | ||
| flash.progress.callback = function(){ | ||
| setTimeout(()=>{ | ||
| this.set('flash.type', 'warning'); | ||
| this.set('message', 'unable to sync your board, try refreshing'); | ||
| this.set('flash.sticky', true); | ||
| }, 1000); | ||
| }; | ||
| } | ||
| }); | ||
|
|
||
| export default BoardSyncingService; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| var BrowserSessionService = Ember.Service.extend(Ember.Evented, { | ||
| initEventObservers: function(){ | ||
| var _self = this; | ||
| Ember.$(window).on('focus blur', (e)=>{ | ||
| _self[`${e.type}Handlers`].forEach((h) => _self[h]()); | ||
| }); | ||
| }.on('init'), | ||
| setLastFocus: function(){ | ||
| var before = this.get('lastBlur'); | ||
| var now = new Date().getTime(); | ||
| this.set('lastFocus', (now - before)); | ||
| }.on('didFocusBrowser'), | ||
|
|
||
| //Focus Handlers | ||
| focusHandlers: ['sendFocusEvent'], | ||
| sendFocusEvent: function(){ | ||
| this.trigger('didFocusBrowser'); | ||
| }, | ||
|
|
||
| //Blur Handlers | ||
| blurHandlers: ['updateLastBlur'], | ||
| lastBlur: new Date().getTime(), | ||
| updateLastBlur: function(){ | ||
| var time = new Date().getTime(); | ||
| this.set('lastBlur', time); | ||
| } | ||
| }); | ||
|
|
||
| export default BrowserSessionService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| {{#if flash.sticky}} | ||
| <i class='ui-icon ui-icon-x-thin'></i> | ||
| {{#if progress}} | ||
| {{hb-spinner}} | ||
| {{/if}} | ||
|
|
||
| {{#unless progress}} | ||
| {{#if flash.sticky}} | ||
| <i class='ui-icon ui-icon-x-thin'></i> | ||
| {{/if}} | ||
| {{/unless}} | ||
|
|
||
| <div class='message-copy'>{{truncate message 50}}</div> | ||
|
|
||
| {{#if progress}} | ||
| {{hb-spinner}} | ||
| {{/if}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import Ember from 'ember'; | ||
| import { | ||
| moduleFor, | ||
| test | ||
| } from 'ember-qunit'; | ||
|
|
||
| var sut; | ||
| var fakeServer; | ||
| var fakeResponse; | ||
| moduleFor('service:board-syncing', { | ||
| setup: function(){ | ||
| sut = this.subject(); | ||
| } | ||
| }); | ||
|
|
||
| test('syncs the boards issues successfuly', (assert)=>{ | ||
| var issues = ['issue1', 'issue2']; | ||
| var success = $.ajax().then(()=>{return issues}); | ||
| var board = { fetchIssues: sinon.stub().returns(success) }; | ||
| sut.syncFlashNotifier = sinon.stub(); | ||
| sut.issueSuccess = sinon.stub(); | ||
|
|
||
| var done = assert.async(); | ||
| sut.syncIssues(board, {}); | ||
| setTimeout(()=>{ | ||
| assert.ok(board.fetchIssues.calledWith({})); | ||
| assert.ok(sut.issueSuccess.calledWith(board, issues)); | ||
| assert.ok(sut.get('syncInProgress') === false); | ||
| done(); | ||
| }, 10); | ||
| }); | ||
|
|
||
| test('fails gracefully on syncing the boards issues', (assert)=>{ | ||
| var fail = $.ajax('fail'); | ||
| var board = { fetchIssues: sinon.stub().returns(fail) }; | ||
| sut.syncFlashNotifier = sinon.stub(); | ||
| sut.issueFail = sinon.stub(); | ||
|
|
||
| var done = assert.async(); | ||
| sut.syncIssues(board, {}); | ||
| setTimeout(()=>{ | ||
| assert.ok(board.fetchIssues.calledWith({})); | ||
| assert.ok(sut.issueFail.called); | ||
| assert.ok(sut.get('syncInProgress') === false); | ||
| done(); | ||
| }, 10); | ||
| }); | ||
|
|
||
| test('sends a flash notifier on sync', (assert)=> { | ||
| var flash = { add: sinon.stub() }; | ||
| sut.messageData = sinon.stub(); | ||
| sut.set('flashMessages', flash); | ||
| sut.set('syncInProgress', true); | ||
|
|
||
| assert.ok(sut.get('flashMessages').add.calledWith(sut.messageData())); | ||
| }); | ||
|
|
||
| test('clears flash when sync is finished', (assert)=> { | ||
| var flash = { queue: [sut.messageData()] }; | ||
| sut.set('flashMessages', flash); | ||
| sut.set('syncInProgress', false); | ||
|
|
||
| assert.ok(flash.queue[0].progress.status === false); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any need to guard against
flashbeingnullhere?