From a24aee0fdfcbbc2200ad05ee5b789aec5988f1ad Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 24 Jun 2013 16:43:42 +0200 Subject: First step to provide an attended transfer. --- app/controllers/api/v1/calls_controller.rb | 17 +++++++++++++++++ app/views/switchboards/show.html.erb | 1 + 2 files changed, 18 insertions(+) (limited to 'app') diff --git a/app/controllers/api/v1/calls_controller.rb b/app/controllers/api/v1/calls_controller.rb index e6fbed4..329bd94 100644 --- a/app/controllers/api/v1/calls_controller.rb +++ b/app/controllers/api/v1/calls_controller.rb @@ -14,6 +14,23 @@ module Api if params[:transfer_blind] @call.transfer_blind(params[:transfer_blind]) + else + if params[:transfer_attended] && @call.b_sip_account.phones.first.phone_model.manufacturer.name == 'SNOM Technology AG' + phone = @call.b_sip_account.phones.first + ip_address = phone.ip_address + http_user = phone.http_user + http_password = phone.http_password + + # Hold + open("http://#{ip_address}/command.htm?key=F_HOLD", :http_basic_authentication=>[http_user, http_password]) + + # Call the other party + (0..(params[:transfer_attended].length - 1)).each do |i| + digit = params[:transfer_attended][i] + open("http://#{ip_address}/command.htm?key=#{digit}", :http_basic_authentication=>[http_user, http_password]) + end + open("http://#{ip_address}/command.htm?key=ENTER", :http_basic_authentication=>[http_user, http_password]) + end end respond_with @call diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index 1a8e5a0..f3304cf 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -50,6 +50,7 @@

{{#each activeCall in activeCalls}} + {{/each}}

{{/if}} -- cgit v1.2.3 From 17f94f46374d60e58a00071303c9081469e7997c Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 25 Jun 2013 12:53:13 +0200 Subject: Optimized the active_calls method. Much faster now. Added a dispatchable_incoming_calls method. --- app/models/switchboard.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 095f878..73219e8 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -25,8 +25,13 @@ class Switchboard < ActiveRecord::Base } belongs_to :user, :touch => true + has_many :switchboard_entries, :dependent => :destroy + has_many :switchable_switchboard_entries, :class_name => "SwitchboardEntry", :conditions => {:switchable => true} + has_many :sip_accounts, :through => :switchboard_entries + has_many :switchable_sip_accounts, :source => :sip_account, :through => :switchable_switchboard_entries, :uniq => true + has_many :phone_numbers, :through => :sip_accounts before_validation :convert_0_to_nil @@ -36,7 +41,11 @@ class Switchboard < ActiveRecord::Base end def active_calls - self.switchboard_entries.where(:switchable => true).map{|se| se.sip_account}.uniq.map{|sip_account| sip_account.calls}.flatten + Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids) + end + + def dispatchable_incoming_calls + Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids) end private -- cgit v1.2.3 From 14da4be11fe13d4fcd55143c39b73c0d086b901b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 25 Jun 2013 13:09:07 +0200 Subject: Show transfer buttons only for switchable incoming calls. --- app/models/switchboard.rb | 6 +++--- app/serializers/switchboard_serializer.rb | 1 + app/views/switchboards/show.html.erb | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 73219e8..d62657f 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -25,7 +25,7 @@ class Switchboard < ActiveRecord::Base } belongs_to :user, :touch => true - + has_many :switchboard_entries, :dependent => :destroy has_many :switchable_switchboard_entries, :class_name => "SwitchboardEntry", :conditions => {:switchable => true} @@ -41,11 +41,11 @@ class Switchboard < ActiveRecord::Base end def active_calls - Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids) + Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids).order(:start_stamp) end def dispatchable_incoming_calls - Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids) + Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids).order(:start_stamp) end private diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb index 6d39667..7c21f82 100644 --- a/app/serializers/switchboard_serializer.rb +++ b/app/serializers/switchboard_serializer.rb @@ -6,4 +6,5 @@ class SwitchboardSerializer < ActiveModel::Serializer has_many :sip_accounts, :through => :switchboard_entries has_many :phone_numbers has_many :active_calls + has_many :dispatchable_incoming_calls end diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index f3304cf..69b0ed6 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -46,11 +46,11 @@ {{phoneNumber.number}} - {{#if activeCalls.length}} + {{#if dispatchableIncomingCalls.length}}

- {{#each activeCall in activeCalls}} - - + {{#each dispatchableIncomingCall in dispatchableIncomingCalls}} + + {{/each}}

{{/if}} -- cgit v1.2.3 From 1c6646bc732def369e54ef4ac576d748c6ba9c92 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 25 Jun 2013 13:19:26 +0200 Subject: GUI improvements. --- app/serializers/switchboard_entry_serializer.rb | 2 +- app/views/switchboards/show.html.erb | 40 +++++++++++++++---------- 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'app') diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb index 1b6c761..5d76e16 100644 --- a/app/serializers/switchboard_entry_serializer.rb +++ b/app/serializers/switchboard_entry_serializer.rb @@ -1,5 +1,5 @@ class SwitchboardEntrySerializer < ActiveModel::Serializer - attributes :id, :name, :path_to_user, :avatar_src, :callstate + attributes :id, :name, :path_to_user, :avatar_src, :callstate, :switchable has_one :sip_account, embed: :ids has_one :switchboard, embed: :ids diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index 69b0ed6..b390ce5 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -40,22 +40,32 @@

{{/if}} -

- {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumberShortList}} - - {{phoneNumber.number}} - + {{#if switchboardEntry.switchable}} +

+ {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumberShortList}} + + {{phoneNumber.number}} + + {{/each}} +

+ {{else}} +

+ {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumberShortList}} + + {{phoneNumber.number}} + - {{#if dispatchableIncomingCalls.length}} -

- {{#each dispatchableIncomingCall in dispatchableIncomingCalls}} - - - {{/each}} -

- {{/if}} - {{/each}} -

+ {{#if dispatchableIncomingCalls.length}} +

+ {{#each dispatchableIncomingCall in dispatchableIncomingCalls}} + + + {{/each}} +

+ {{/if}} + {{/each}} +

+ {{/if}} {{#if switchboardEntry.sipAccount.calls.length}}

-- cgit v1.2.3