diff options
-rw-r--r-- | app/models/call.rb | 2 | ||||
-rw-r--r-- | app/models/sip_account.rb | 2 | ||||
-rw-r--r-- | app/views/calls/_form_core.html.haml | 2 | ||||
-rw-r--r-- | app/views/calls/_index_core.html.haml | 10 | ||||
-rw-r--r-- | db/migrate/20130307065200_create_calls_active.rb | 38 |
5 files changed, 46 insertions, 8 deletions
diff --git a/app/models/call.rb b/app/models/call.rb index db6d9d6..b0cd9b2 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -1,5 +1,5 @@ class Call < ActiveRecord::Base - self.table_name = 'detailed_calls' + self.table_name = 'calls_active' self.primary_key = 'uuid' attr_writer :sip_account_id diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 1499d62..81b9c1c 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -38,7 +38,7 @@ class SipAccount < ActiveRecord::Base has_many :ringtones, :as => :ringtoneable, :dependent => :destroy - has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT detailed_calls.* FROM detailed_calls WHERE presence_id LIKE '#{self.auth_name}@%' OR b_presence_id LIKE '#{self.auth_name}@%'" } + has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT calls_active.* FROM calls_active WHERE sip_account_id = #{self.id} OR b_sip_account_id = #{self.id}" } # Delegations: # diff --git a/app/views/calls/_form_core.html.haml b/app/views/calls/_form_core.html.haml index 4cdd55e..ec795f2 100644 --- a/app/views/calls/_form_core.html.haml +++ b/app/views/calls/_form_core.html.haml @@ -1,2 +1,2 @@ .inputs - = f.input :dest, :as => :string, :label => t('calls.form.destination.label'), :hint => conditional_hint('calls.form.destination.hint'), :autofocus => true + = f.input :destination, :as => :string, :label => t('calls.form.destination.label'), :hint => conditional_hint('calls.form.destination.hint'), :autofocus => true diff --git a/app/views/calls/_index_core.html.haml b/app/views/calls/_index_core.html.haml index e5b769e..5ed5538 100644 --- a/app/views/calls/_index_core.html.haml +++ b/app/views/calls/_index_core.html.haml @@ -19,17 +19,17 @@ - else %i.icon-arrow-right %td - = call.created + = l Time.at(call.start_stamp), :format => :short %td - = call.dest + = call.destination %td - = "#{call.cid_name} #{call.cid_num}" + = "#{call.caller_id_name} #{call.caller_id_number}" %td - = "#{call.callee_name} #{call.callee_num}" + = "#{call.callee_name} #{call.callee_number}" %td = call.callstate %td - = "#{call.read_codec}/#{call.write_codec}" + = "#{call.read_codec}/#{call.read_rate}:#{call.write_codec}/#{call.write_rate}" %td %p diff --git a/db/migrate/20130307065200_create_calls_active.rb b/db/migrate/20130307065200_create_calls_active.rb new file mode 100644 index 0000000..930bbc7 --- /dev/null +++ b/db/migrate/20130307065200_create_calls_active.rb @@ -0,0 +1,38 @@ +class CreateCallsActive < ActiveRecord::Migration + def self.up + execute %q{CREATE VIEW calls_active AS SELECT + a.uuid AS uuid, + a.direction AS direction, + a.created_epoch AS start_stamp, + a.cid_name AS caller_id_name, + a.cid_num AS caller_id_number, + a.dest AS destination, + d.id AS sip_account_id, + d.caller_name AS sip_caller_name, + a.callee_name as callee_name, + a.callee_num as callee_number, + a.callstate AS callstate, + a.read_codec AS read_codec, + a.read_rate AS read_rate, + a.read_bit_rate AS read_bit_rate, + a.write_codec AS write_codec, + a.write_rate AS write_rate, + a.write_bit_rate AS write_bit_rate, + a.secure AS secure, + b.uuid AS b_uuid, + b.cid_name AS b_caller_id_name, + b.cid_num AS b_caller_id_number, + e.id AS b_sip_account_id, + e.caller_name AS b_sip_caller_name + FROM channels a + LEFT JOIN calls c ON a.uuid = c.caller_uuid AND a.hostname = c.hostname + LEFT JOIN channels b ON b.uuid = c.callee_uuid AND b.hostname = c.hostname + LEFT JOIN sip_accounts d ON a.presence_id LIKE CONCAT(d.auth_name, "@%") + LEFT JOIN sip_accounts e ON b.presence_id LIKE CONCAT(e.auth_name, "@%") + WHERE a.uuid = c.caller_uuid OR a.uuid NOT IN (select callee_uuid from calls)} + end + + def self.down + execute "DROP VIEW calls_active" + end +end |