Permalink
Browse files

Fixing ribbon2 for LDAP, improve live2

  • Loading branch information...
1 parent dfde1c0 commit 294f909106ad509fe906a23456704c83d4df0276 @bougyman bougyman committed Feb 16, 2012
View
@@ -59,23 +59,25 @@ initializeIsotope = (elt) ->
extension: (e) ->
e.find('.extension').text()
status: (e) ->
- s = e.find('.status').text()
+ ext = e.find('.extension').text()
+ status = e.find('.status').text()
+
order =
- switch s
+ switch status
when 'Available'
- 0.7
+ 5
when 'Available (On Demand)'
- 0.8
+ 6
when 'On Break'
- 0.9
+ 7
when 'Logged Out'
- 1.0
+ 8
+ else
+ 4
- extension = e.find('.extension').text()
- parseFloat("" + order + extension)
+ parseInt([order, ext].join(''), 10)
idle: (e) ->
- [min, sec] = e.find('.time-since-status-change').text().split(':')
- (((parseInt(min, 10) * 60) + parseInt(sec, 10)) * -1)
+ parseInt(e.find('.lastStatusChange').text(), 10) * -1
},
sortBy: 'status',
)
@@ -97,7 +99,6 @@ Serenade.Helpers.liStatus = (klass, name, status) ->
class AgentCallController
calltap: ->
- p this
socket.live 'uuid_calltap', uuid: @model.id, agent: @model.agent.id
Serenade.controller 'agentCall', AgentCallController
@@ -185,6 +186,8 @@ Serenade.controller 'queueList', QueueController
class Call extends Serenade.Model
@property 'display_cid'
@property 'created_epoch'
+ @property 'duration'
+ @property 'initializeRan'
@belongsTo 'agent', as: (-> Agent)
@property 'createdTime',
@@ -195,22 +198,32 @@ class Call extends Serenade.Model
get: (-> @created_epoch * 1000),
dependsOn: ['created_epoch']
- constructor: -> @initialize(arguments ...) unless super
+ constructor: (obj) ->
+ super(arguments ...)
+ @initialize(arguments ...) unless @initializeRan?
initialize: ->
- @timer = setInterval((=>
- @set('duration', formatInterval(@created))
- ) , 1000)
+ @timer = setInterval((=> @duration = formatInterval(@created)), 1000)
+ @bind('delete', (=> @onDelete(arguments ...)))
+ @initializeRan = true
+
+ onDelete: ->
+ p 'onDelete', this
+ clearInterval(@timer)
+ @agent?.lastStatusChange = Date.now()
Agents = new Serenade.Collection([])
+window.Agents = Agents
class Agent extends Serenade.Model
@property 'extension'
@property 'username'
@property 'state'
@property 'status'
@property 'timeSinceStatusChange'
+ @property 'lastStatusChange'
@property 'queue'
+ @property 'initializeRan'
@hasMany 'calls', as: (-> Call)
@@ -222,24 +235,62 @@ class Agent extends Serenade.Model
get: (-> queueToClass(@queue)),
dependsOn: ['queue']
- constructor: -> @initialize(arguments ...) unless super(arguments ...)
+ constructor: (obj) ->
+ super(arguments ...)
+ @initialize(arguments ...) unless @initializeRan?
initialize: ->
- p this unless @id
- jtag = $(Serenade.render('agent', this))
- jtag.addClass(@statusClass)
- $('#agents').isotope('insert', jtag)
- @bind 'change:queue', (value) =>
- jtag.addClass(value)
+ @setupTimer()
+ dom = @setupDOM()
+ @setupBinds(dom)
+ @initializeRan = true
+
+ setupTimer: ->
+ @lastStatusChange = Date.now()
+ @timer = setInterval((=>
+ @timeSinceStatusChange = formatInterval(@lastStatusChange)
+ ), 1000)
+
+ setupDOM: ->
+ tag = $(Serenade.render('agent', this))
+ tag.addClass(@statusClass)
+ $('#agents').isotope('insert', tag)
+ tag
+
+ setupBinds: (tag) ->
+ # @calls.bind 'change', (value) => p '@calls.change', value
+ # @calls.bind 'add', (value) => p '@calls.add', value
+ # @calls.bind 'update', (value) => p '@calls.update', value
+ # @calls.bind 'delete', => p('@calls.delete', arguments ...)
+
+ # @bind 'change:calls', (value) => p 'agent.change:calls', value
+
+ @bind 'change:status', (value) => @lastStatusChange = Date.now()
+ @bind 'change:state', (value) => @lastStatusChange = Date.now()
+ @calls.bind 'delete', (value) => @lastStatusChange = Date.now()
+ @bind 'change:queue', (value) => tag.addClass(value)
+ @bind 'change:lastStatusChange', (value) =>
+ p 'change:lastStatusChange', value
+ isotopeRoot.isotope('updateSortData', tag)
@bind 'change:statusClass', (value) =>
- for klass in jtag.attr('class').split(' ')
- jtag.removeClass(klass) if /^status-/.test(klass)
- jtag.addClass(value)
+ for klass in tag.attr('class').split(' ')
+ tag.removeClass(klass) if /^status-/.test(klass)
+ tag.addClass(value)
+
+ # new or existing calls come in here.
+ updateCall: (msg) ->
+ id = msg.id
+ @calls.forEach (call) ->
+ if call.id == id
+ return call.set(msg)
+ call = new Call(msg, false)
+ @calls.set(call.id, call)
class Queue extends Serenade.Model
@property 'name', serialize: true
$ ->
+ Serenade.useJQuery()
isotopeRoot = $('#agents')
initializeIsotope(isotopeRoot)
@@ -270,25 +321,29 @@ $ ->
new Agent(msg.body)
socket.tag 'live:Call:create', (msg) ->
- p 'live:Call:create', msg
- call = new Call(msg.body)
- call.agent.calls.push(call)
+ p 'live:Call:create', msg.body.agentId, msg.body.display_cid, msg.body.id, msg.body
+ agentId = msg.body.agentId
+ Agents.forEach (agent) ->
+ if agent.id == agentId
+ agent.updateCall(msg.body)
socket.tag 'live:Call:update', (msg) ->
- p 'live:Call:update', msg
- call = new Call(msg.body)
+ p 'live:Call:update', msg.body.agentId, msg.body.display_cid, msg.body.id, msg.body
+ agentId = msg.body.agentId
+ Agents.forEach (agent) ->
+ if agent.id == agentId
+ agent.updateCall(msg.body)
socket.tag 'live:Call:delete', (msg) ->
- p 'live:Call:delete', msg
- toDelete = new Call(msg.body)
- toDeleteId = toDelete.id
-
- return unless agent = toDelete.agent
- calls = agent.calls
-
- pendingDeletion = []
- calls.forEach (call, index) ->
- pendingDeletion.push(call) if toDeleteId == call.id
- for call in pendingDeletion
- calls.delete(call)
+ p 'live:Call:delete', msg.body.agentId, msg.body.display_cid, msg.body.id, msg.body
+ agents = Agents.select((agent) -> agent.id == msg.body.agentId)
+ ids = [msg.body.id, msg.body.uuid, msg.body.call_uuid]
+ for agent in agents
+ calls = agent.calls.select (call) ->
+ any = false
+ for id in ids
+ any = any || call.id == id
+ any
+ for call in calls
+ p 'deleting', agent.calls.delete(call)
socket.live 'subscribe',
name: $('#agent_name').text(),
@@ -299,4 +354,7 @@ $ ->
socket.live 'agents',
success: (msg) =>
for agentMsg in msg.agents
- new Agent(agentMsg)
+ if calls = agentMsg.calls
+ delete call.agentId for call in calls
+ agentMsg.calls = calls
+ Agents.set(agentMsg.id, new Agent(agentMsg))
View
@@ -10,19 +10,21 @@ ul#queues.dropdown-menu
""")
Serenade.view('agent', """
-div.agent.span2[event:change:status=change! event:dblclick=details!]
- span.extension @extension
- span.username @username
- span.state @state
- span.status @status
- span.time-since-status-change @timeSinceStatusChange
- span.queue @queue
- span[class=@queue]
- span.calls
- - collection @calls
- .name-and-number @display_cid
- .duration @duration
- span.more-calls @moreCalls
+.span2.agent[event:dblclick=details!]
+ .row-fluid
+ .span2.extension @extension
+ .span10.username @username
+ - collection @calls
+ .row-fluid.call
+ .span3.duration @duration
+ .span9.name-and-number @display_cid
+ .row-fluid
+ .span3.atime @timeSinceStatusChange
+ .span9.state @state
+ .status @status
+ .queue @queue
+ .lastStatusChange @lastStatusChange
+ div[class=@queue]
""")
Serenade.view('agentCall', """
View
@@ -17,6 +17,7 @@ class Socket
reconnect: () ->
return if @connected
+ p "Opening WebSocket to #{@options.server}"
@socket = new @webSocket(@options.server)
@socket.onmessage = (messageEvent) =>
View
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8"/>
- <title>Live CallCenter &middot; #{h @agent}</title>
+ <title>Effortless CallCenter &middot; #{h @agent}</title>
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="/css/live2.css" />
@@ -60,18 +60,18 @@
</div>
</div>
- <div class="container-fluid">
+ <section id="app" class="container-fluid">
<div class="row-fluid">
<div id="agents">
</div>
</div>
- </div>
- <footer>
- <span id="agent_name">#{h @agent}</span>
- <span id="server">#{h @server}</span>
- <span id="couch_uri">#{h @couch_uri}</span>
- <div id="copyright">Effortless CallCenter &copy; by The Rubyists LLC. 2010-2012</div>
- </footer>
+ <footer class="row-fluid">
+ <div class="span12" id="copyright">Effortless CallCenter &copy; by The Rubyists LLC. 2010-2012</div>
+ <span id="agent_name">#{h @agent}</span>
+ <span id="server">#{h @server}</span>
+ <span id="couch_uri">#{h @couch_uri}</span>
+ </footer>
+ </div>
</body>
</html>
View
@@ -2,7 +2,7 @@
<html>
<head>
<meta encoding="UTF-8">
- <title>Ribbon v2</title>
+ <title>Effortless Agent Ribbon &middot; #{h @title}</title>
<link rel="stylesheet" href="/css/ribbon.css">
</head>
<body>
@@ -19,7 +19,11 @@ def self.format_display_name_and_number(name, number)
number = nil unless number =~ /\S/
if name && number
- "#{name} (#{number})"
+ if name == number
+ name
+ else
+ "#{name} (#{number})"
+ end
elsif name
name
elsif number
@@ -50,7 +54,7 @@ def self.agent_status(extension, calls)
display_cid: format_display_name_and_number(found.cid_name, found.cid_num),
cid_name: found.cid_name,
cid_number: found.cid_num,
- uuid: found.uuid,
+ id: found.uuid,
created_epoch: found.created_epoch.to_i,
agentId: extension,
}
@@ -62,7 +66,7 @@ def self.agent_status(extension, calls)
display_cid: format_display_name_and_number(found.dest, found.dest),
cid_name: found.dest,
cid_number: found.dest,
- uuid: found.uuid,
+ id: found.uuid,
created_epoch: found.created_epoch.to_i,
agentId: extension,
}
@@ -75,14 +79,14 @@ def self.agent_status(extension, calls)
caller_cid_name: found.caller_cid_name,
caller_dest_num: found.caller_dest_num,
callee_cid_num: found.callee_cid_num,
- uuid: found.call_uuid,
+ id: found.call_uuid,
created_epoch: found.call_created_epoch.to_i,
agentId: extension,
}
end
}
FSR::Log.debug "Sending agent status: #{found_calls}"
- found_calls.uniq{|call| call[:uuid] }
+ found_calls.uniq{|call| call[:id] }
end
end
end
@@ -16,7 +16,7 @@ def watch_socket(tube_names)
tube_names.each{|tube_name| watch(tube_name) }
each_job do |job|
- log({job: job}, :debug)
+ # log({job: job}, :debug)
delete(job) if handle_job(job)
end
end
Oops, something went wrong.

0 comments on commit 294f909

Please sign in to comment.