Skip to content

Commit de2f10f

Browse files
committed
Implements basic board syncing service (sans success/fail handlers) and model methods for fetching issues
1 parent f30b515 commit de2f10f

4 files changed

Lines changed: 128 additions & 2 deletions

File tree

ember-app/app/models/new/board.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ var Board = Model.extend({
112112
return issue.data.assignee && issue.data.assignee.login === assignee.login;
113113
});
114114
});
115-
}).property("assignees.[]", "issues.@each.assignee")
115+
}).property("assignees.[]", "issues.@each.assignee"),
116+
fetchIssues: function(options){
117+
var promises = this.get('repos').map((repo)=>{
118+
return repo.fetchIssues(options);
119+
});
120+
121+
return Ember.RSVP.all(promises).then((issues)=>{
122+
return issues;
123+
});
124+
}
116125
});
117126

118127
Board.reopenClass({

ember-app/app/models/new/repo.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ var Repo = Model.extend({
222222
},
223223
assigneesLength: function(){
224224
return this.get("assignees.length");
225-
}.property("assignees.[]")
225+
}.property("assignees.[]"),
226+
fetchIssues: function(options){
227+
var url = `/api/${this.get('data.repo.full_name')}/issues`
228+
return Ember.$.getJSON(url,{ options: options });
229+
}
226230
});
227231

228232
export default Repo;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Ember from 'ember';
2+
3+
var BoardSyncingService = Ember.Service.extend({
4+
5+
//Sync Notifier
6+
flashMessages: Ember.inject.service(),
7+
syncFlashNotifier: function(){
8+
if(this.get('syncInProgress')){
9+
this.get('flashMessages').add(this.messageData);
10+
} else {
11+
var message = this.messageData.message;
12+
var flash = this.get('flashMessages.queue').find((flash)=>{
13+
return flash.message === message;
14+
});
15+
Ember.set(flash.progress, 'status', false);
16+
}
17+
}.observes('syncInProgress'),
18+
messageData: {
19+
message: 'syncing your board, please wait...',
20+
sticky: true,
21+
type: 'info',
22+
progress: {
23+
status: true,
24+
callback: function(){
25+
this.set('message', 'sync complete!');
26+
this.get('flash')._setTimer('timer', 'destroyMessage', 3000);
27+
}
28+
}
29+
},
30+
31+
//Issue Syncing
32+
syncIssues: function(board){
33+
var _self = this;
34+
_self.set('syncInProgress', true);
35+
36+
board.fetchIssues(board).done((issues)=>{
37+
_self.issueSuccess(issues);
38+
}).fail((error)=>{
39+
_self.issueFail();
40+
}).always(()=> { _self.set('syncInProgress', false)});
41+
},
42+
issueSuccess: function(issues){
43+
44+
},
45+
issueFail: function(error){
46+
47+
}
48+
});
49+
50+
export default BoardSyncingService;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Ember from 'ember';
2+
import {
3+
moduleFor,
4+
test
5+
} from 'ember-qunit';
6+
7+
var sut;
8+
var fakeServer;
9+
var fakeResponse;
10+
moduleFor('service:board-syncing', {
11+
setup: function(){
12+
sut = this.subject();
13+
}
14+
});
15+
16+
test('syncs the boards issues successfuly', (assert)=>{
17+
var issues = ['issue1', 'issue2'];
18+
var success = $.ajax().then(()=>{return issues});
19+
var board = { fetchIssues: sinon.stub().returns(success) };
20+
sut.syncFlashNotifier = sinon.stub();
21+
sut.issueSuccess = sinon.stub();
22+
23+
var done = assert.async();
24+
sut.syncIssues(board);
25+
setTimeout(()=>{
26+
assert.ok(board.fetchIssues.called);
27+
assert.ok(sut.issueSuccess.calledWith(issues));
28+
assert.ok(sut.get('syncInProgress') === false);
29+
done();
30+
}, 10);
31+
});
32+
33+
test('fails gracefully on syncing the boards issues', (assert)=>{
34+
var fail = $.ajax('fail');
35+
var board = { fetchIssues: sinon.stub().returns(fail) };
36+
sut.syncFlashNotifier = sinon.stub();
37+
sut.issueFail = sinon.stub();
38+
39+
var done = assert.async();
40+
sut.syncIssues(board);
41+
setTimeout(()=>{
42+
assert.ok(board.fetchIssues.called);
43+
assert.ok(sut.issueFail.called);
44+
assert.ok(sut.get('syncInProgress') === false);
45+
done();
46+
}, 10);
47+
});
48+
49+
test('sends a flash notifier on sync', (assert)=> {
50+
var flash = { add: sinon.stub() };
51+
sut.set('flashMessages', flash);
52+
sut.set('syncInProgress', true);
53+
54+
assert.ok(sut.get('flashMessages').add.calledWith(sut.messageData));
55+
});
56+
57+
test('clears flash when sync is finished', (assert)=> {
58+
var flash = { queue: [sut.messageData] };
59+
sut.set('flashMessages', flash);
60+
sut.set('syncInProgress', false);
61+
62+
assert.ok(flash.queue[0].progress.status === false);
63+
});

0 commit comments

Comments
 (0)