Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from huboard/discorick/messaging
Discorick/messaging
- Loading branch information
Showing
22 changed files
with
613 additions
and
206 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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'; | ||
import Issue from 'app/models/issue'; | ||
|
||
var BoardEventsMixin = Ember.Mixin.create({ | ||
hbevents: { | ||
channel: "{model.full_name}", | ||
"issues.*.issue_opened": "newIssue" | ||
}, | ||
_eventHandlers: { | ||
newIssue: function(message) { | ||
var issue = this.get("model.board.issues").findBy('number', message.issue.number); | ||
|
||
if(issue) { | ||
issue.set("state", "open"); | ||
} else { | ||
var model = Issue.create(message.issue); | ||
if(message.issue.current_state.name === "__nil__") { | ||
model.set("current_state", this.get("model.board.columns.firstObject")); | ||
}else { | ||
var column = this.get("model.board.columns").find(function(c) { | ||
return c.name === message.issue.current_state.name; | ||
}); | ||
model.set("current_state", column); | ||
} | ||
this.get("model.board.issues").pushObject(model); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export default BoardEventsMixin; |
This file contains 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,47 @@ | ||
import Ember from 'ember'; | ||
|
||
var CardEventMixin = Ember.Mixin.create({ | ||
hbevents: { | ||
channel: "{repositoryName}", | ||
"issues.{issue.number}.issue_status_changed": "statusChanged", | ||
"issues.{issue.number}.issue_archived": "archived", | ||
"issues.{issue.number}.issue_closed": "closed", | ||
"issues.{issue.number}.issue_reopened": "opened", | ||
"issues.{issue.number}.assigned": "assigned", | ||
"issues.{issue.number}.moved": "moved", | ||
"issues.{issue.number}.reordered": "reordered", | ||
"issues.{issue.number}.milestone_changed": "milestoneChanged", | ||
}, | ||
_eventHandlers: { | ||
statusChanged: function(message){ | ||
this.get("issue").set("_data", message.issue._data); | ||
}, | ||
archived: function(){ | ||
this.get('issue').set('isArchived', true); | ||
}, | ||
closed: function(message){ | ||
this.get("issue").set("state", message.issue.state); | ||
}, | ||
opened: function(message){ | ||
this.get("issue").set("state", message.issue.state); | ||
}, | ||
assigned: function(message){ | ||
this.get("issue").set("assignee", message.issue.assignee); | ||
}, | ||
moved: function (message) { | ||
this.get('issue').setProperties({ | ||
current_state : message.issue.current_state, | ||
_data: message.issue._data | ||
}); | ||
}, | ||
reordered: function (message) { | ||
this.get("issue").set("current_state", message.issue.current_state); | ||
this.get("issue").set("_data", message.issue._data); | ||
}, | ||
milestoneChanged: function(message) { | ||
this.get("issue").set("milestone", message.issue.milestone); | ||
}, | ||
} | ||
}); | ||
|
||
export default CardEventMixin; |
This file contains 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,19 @@ | ||
import Ember from 'ember'; | ||
|
||
var IssueEventMixin = Ember.Mixin.create({ | ||
hbevents: { | ||
channel: "{model.repo.full_name}", | ||
"issues.{model.number}.issue_closed": "closed", | ||
"issues.{model.number}.issue_reopened": "opened" | ||
}, | ||
_eventHandlers: { | ||
closed: function(){ | ||
//Not Yet Implemented | ||
}, | ||
opened: function(){ | ||
//Not Yet Implemented | ||
}, | ||
} | ||
}); | ||
|
||
export default IssueEventMixin; |
This file contains 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,20 @@ | ||
import Ember from 'ember'; | ||
|
||
var MilestoneEventMixin = Ember.Mixin.create({ | ||
hbevents: { | ||
channel: "{model.milestone.repo.full_name}", | ||
}, | ||
_eventHandlers: { | ||
milestone_reordered: function(message){ | ||
this.get('model.milestone').setProperties({ | ||
description: message.milestone.description, | ||
_data: message.milestone._data | ||
}); | ||
}, | ||
_socketDisabled: function(){ | ||
return !!this.get('model.noMilestone'); | ||
}.property('model.noMilestone') | ||
} | ||
}); | ||
|
||
export default MilestoneEventMixin; |
This file contains 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,83 @@ | ||
import Ember from "ember"; | ||
import eventParsing from "app/utilities/messaging/event-parsing"; | ||
|
||
var MessagingMixin = Ember.Mixin.create({ | ||
|
||
//// | ||
// event_data: { | ||
// channel: "thechannel", | ||
// indentifier: 1, | ||
// type: "sometype", | ||
// action: "theaction", | ||
// handler: "theHandler" | ||
// } | ||
//// | ||
|
||
//Subscribing | ||
subscribeToMessages: function(){ | ||
var _self = this; | ||
var socket = this.get("socket"); | ||
_.each(this.get("hbevents"), function(handler, event){ | ||
if(event === "channel"){ return; } | ||
var event_data = eventParsing.parse(event, handler, _self); | ||
var sub = socket.subscribe(event_data.channel, function(message){ | ||
if(socket.correlationId !== message.meta.correlationId){ | ||
_self._eventHandler(event_data, message); | ||
} | ||
}); | ||
_self._subscriptions[event] = [event_data.channel, sub]; | ||
}); | ||
}, | ||
_eventHandler: function(event_data, message){ | ||
var _self = this; | ||
if(event_data.action === message.meta.action){ | ||
this._handleEventInScope(event_data, message, function(){ | ||
_self._eventHandlers[event_data.handler].call(_self, message.payload); | ||
}); | ||
} | ||
}, | ||
_handleEventInScope: function(event_data, message, callback){ | ||
if(!message.meta.type || event_data.type === message.meta.type){ | ||
if(event_data.identifier === "*"){ callback(); } | ||
if(event_data.identifier === String(message.meta.identifier)){ | ||
callback(); | ||
} | ||
} | ||
}, | ||
|
||
unsubscribeFromMessages: function(){ | ||
var _self = this; | ||
_.each(this._subscriptions, function(sub, event){ | ||
if(event === "channel"){ return; } | ||
_self.get("socket").unsubscribe(sub[0], sub[1]); | ||
delete _self._subscriptions[event]; | ||
}); | ||
}, | ||
|
||
//Publishing | ||
publish: function(channel, topic, payload){ | ||
var meta = eventParsing.parse(`${channel} ${topic}`, null, this); | ||
this.get("socket").publish({ | ||
meta: meta, | ||
payload: payload | ||
}); | ||
}, | ||
|
||
//Lifecycle | ||
init: function(){ | ||
if(!this.get("socket")){ | ||
throw "Missing the Socket!"; | ||
} | ||
this._super(); | ||
this._subscriptions = {}; | ||
if(!this.get("subscribeDisabled")){ | ||
this.subscribeToMessages(); | ||
} | ||
}, | ||
willDestroy: function(){ | ||
this.unsubscribeFromMessages(); | ||
this._super(); | ||
} | ||
}); | ||
|
||
export default MessagingMixin; |
Oops, something went wrong.