diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/v1/phone_numbers_controller.rb | 23 | ||||
-rw-r--r-- | app/controllers/api/v1/sip_accounts_controller.rb | 23 | ||||
-rw-r--r-- | app/controllers/api/v1/switchboard_entries_controller.rb | 23 | ||||
-rw-r--r-- | app/controllers/api/v1/switchboards_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/switchboard_entries_controller.rb | 26 | ||||
-rw-r--r-- | app/controllers/switchboards_controller.rb | 16 | ||||
-rw-r--r-- | app/models/switchboard.rb | 3 | ||||
-rw-r--r-- | app/models/switchboard_entry.rb | 33 | ||||
-rw-r--r-- | app/serializers/phone_number_serializer.rb | 3 | ||||
-rw-r--r-- | app/serializers/sip_account_serializer.rb | 6 | ||||
-rw-r--r-- | app/serializers/switchboard_entry_serializer.rb | 13 | ||||
-rw-r--r-- | app/serializers/switchboard_serializer.rb | 9 | ||||
-rw-r--r-- | app/views/switchboards/show.html.erb | 20 |
13 files changed, 163 insertions, 56 deletions
diff --git a/app/controllers/api/v1/phone_numbers_controller.rb b/app/controllers/api/v1/phone_numbers_controller.rb new file mode 100644 index 0000000..ff58fd3 --- /dev/null +++ b/app/controllers/api/v1/phone_numbers_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class PhoneNumbersController < ApplicationController + respond_to :json + + def index + if params[:ids] + @phone_numbers = PhoneNumber.where(:id => params[:ids]) + else + @phone_numbers = PhoneNumber.all + end + + respond_with @phone_numbers + end + + def show + @phone_number = PhoneNumber.find(params[:id]) + + respond_with @phone_number + end + end + end +end diff --git a/app/controllers/api/v1/sip_accounts_controller.rb b/app/controllers/api/v1/sip_accounts_controller.rb new file mode 100644 index 0000000..6f305a4 --- /dev/null +++ b/app/controllers/api/v1/sip_accounts_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class SipAccountsController < ApplicationController + respond_to :json + + def index + if params[:ids] + @sip_accounts = SipAccount.where(:id => params[:ids]) + else + @sip_accounts = SipAccount.all + end + + respond_with @sip_accounts + end + + def show + @sip_account = SipAccount.find(params[:id]) + + respond_with @sip_account + end + end + end +end diff --git a/app/controllers/api/v1/switchboard_entries_controller.rb b/app/controllers/api/v1/switchboard_entries_controller.rb new file mode 100644 index 0000000..688f108 --- /dev/null +++ b/app/controllers/api/v1/switchboard_entries_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class SwitchboardEntriesController < ApplicationController + respond_to :json + + def index + if params[:ids] + @switchboard_entries = SwitchboardEntry.where(:id => params[:ids]) + else + @switchboard_entries = SwitchboardEntry.all + end + + respond_with @switchboard_entries + end + + def show + @switchboard_entry = SwitchboardEntry.find(params[:id]) + + respond_with @switchboard_entry + end + end + end +end
\ No newline at end of file diff --git a/app/controllers/api/v1/switchboards_controller.rb b/app/controllers/api/v1/switchboards_controller.rb new file mode 100644 index 0000000..e6996ca --- /dev/null +++ b/app/controllers/api/v1/switchboards_controller.rb @@ -0,0 +1,21 @@ +module Api + module V1 + class SwitchboardsController < ApplicationController + respond_to :json + + def index + @user = current_user + @switchboards = @user.switchboards + + respond_with @switchboards + end + + def show + @user = current_user + @switchboard = @user.switchboards.find(params[:id]) + + respond_with @switchboard + end + end + end +end diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb index 3f82976..ef6c72e 100644 --- a/app/controllers/switchboard_entries_controller.rb +++ b/app/controllers/switchboard_entries_controller.rb @@ -3,31 +3,13 @@ class SwitchboardEntriesController < ApplicationController authorize_resource :switchboard_entry, :through => :switchboard, :except => [:sort] def index - if @switchboard - @switchboard_entries = @switchboard.switchboard_entries - spread_breadcrumbs - else - @switchboard_entries = SwitchboardEntry.where(:id => params[:ids]) - end - - respond_to do |format| - format.html - format.json { render json: @switchboard_entries } - end + @switchboard_entries = @switchboard.switchboard_entries + spread_breadcrumbs end def show - if @switchboard - @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) - spread_breadcrumbs - else - @switchboard_entry = SwitchboardEntry.find(params[:id]) - end - - respond_to do |format| - format.html - format.json { render json: @switchboard_entry } - end + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + spread_breadcrumbs end def new diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb index d3424ad..f48e7fb 100644 --- a/app/controllers/switchboards_controller.rb +++ b/app/controllers/switchboards_controller.rb @@ -3,30 +3,14 @@ class SwitchboardsController < ApplicationController authorize_resource :switchboard, :through => :user def index - if @user.nil? - @user = current_user - end @switchboards = @user.switchboards spread_breadcrumbs - - respond_to do |format| - format.html - format.json { render json: @switchboards } - end end def show - if @user.nil? - @user = current_user - end @switchboard = @user.switchboards.find(params[:id]) @switchboard_entries = @switchboard.switchboard_entries spread_breadcrumbs - - respond_to do |format| - format.html - format.json { render json: @switchboard } - end end def new diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 360de70..53f69a4 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -8,7 +8,7 @@ class Switchboard < ActiveRecord::Base validates :reload_interval, :numericality => { :only_integer => true, - :greater_than => 250, + :greater_than => 249, :allow_nil => true } @@ -21,6 +21,7 @@ class Switchboard < ActiveRecord::Base belongs_to :user, :touch => true has_many :switchboard_entries, :dependent => :destroy has_many :sip_accounts, :through => :switchboard_entries + has_many :phone_numbers, :through => :sip_accounts before_validation :convert_0_to_nil diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index faeba8c..44de7fd 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -30,4 +30,37 @@ class SwitchboardEntry < ActiveRecord::Base self.name.to_s end end + + def avatar_src + if self.sip_account.sip_accountable.class == User + if self.sip_account.sip_accountable.image? + self.sip_account.sip_accountable.image_url(:profile) + else + if self.sip_account.sip_accountable.male? + '/assets/icons/user-male-16x.png' + else + '/assets/icons/user-female-16x.png' + end + end + else + nil + end + end + + def callstate + if self.sip_account.call_legs.where(callstate: 'ACTIVE').any? || self.sip_account.b_call_legs.where(b_callstate: 'ACTIVE').any? + 'ACTIVE' + else + if self.sip_account.call_legs.where(callstate: 'EARLY').any? + 'EARLY' + else + if self.sip_account.call_legs.where(callstate: 'RINGING').any? + 'RINGING' + else + nil + end + end + end + end + end diff --git a/app/serializers/phone_number_serializer.rb b/app/serializers/phone_number_serializer.rb new file mode 100644 index 0000000..865534b --- /dev/null +++ b/app/serializers/phone_number_serializer.rb @@ -0,0 +1,3 @@ +class PhoneNumberSerializer < ActiveModel::Serializer + attributes :id, :name, :number +end diff --git a/app/serializers/sip_account_serializer.rb b/app/serializers/sip_account_serializer.rb new file mode 100644 index 0000000..c85c8a0 --- /dev/null +++ b/app/serializers/sip_account_serializer.rb @@ -0,0 +1,6 @@ +class SipAccountSerializer < ActiveModel::Serializer + embed :ids, :include => true + + attributes :id, :auth_name, :caller_name, :sip_accountable_id + has_many :phone_numbers +end diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb index 0b5f4c1..1b6c761 100644 --- a/app/serializers/switchboard_entry_serializer.rb +++ b/app/serializers/switchboard_entry_serializer.rb @@ -1,5 +1,14 @@ class SwitchboardEntrySerializer < ActiveModel::Serializer - attributes :id, :name + attributes :id, :name, :path_to_user, :avatar_src, :callstate - has_many :phone_numbers, embed: :ids + has_one :sip_account, embed: :ids + has_one :switchboard, embed: :ids + + def path_to_user + if object.sip_account && object.sip_account.sip_accountable_type == 'User' + "/tenants/#{object.sip_account.sip_accountable.current_tenant.id}/users/#{object.sip_account.sip_accountable.id}" + else + nil + end + end end diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb index 2912a56..600c79a 100644 --- a/app/serializers/switchboard_serializer.rb +++ b/app/serializers/switchboard_serializer.rb @@ -1,7 +1,8 @@ class SwitchboardSerializer < ActiveModel::Serializer - attributes :id, :name - - embed :ids + embed :ids, :include => true - has_many :switchboard_entries, :key => :switchboard_entrys + attributes :id, :name + has_many :switchboard_entries + has_many :sip_accounts, :through => :switchboard_entries + has_many :phone_numbers end diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index 87bb551..1fd9d9a 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -22,20 +22,18 @@ {{#each switchboardEntry in switchboardEntrys}} <li class="span2"> <div class="thumbnail"> - <a class="thumbnail" href="/tenants/2/users/2"> - <img alt="User-male-16x" class="img-rounded" src="/assets/icons/user-male-16x.png" style="width: 100px;"> - </a> + {{avatar_img switchboardEntry.avatar_src}} <p> <small> - {{switchboardEntry.name}} - <br> - <span class="label"> - 33 - </span> + {{switchboardEntry.name}}<br> + + {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumbers}} + <span class="label"> + {{phoneNumber.number}} + </span> + {{/each}} <br> - <span class="label label-inverse"> - <i class="icon-ban-circle icon-white"></i> - </span> + {{show_callstate switchboardEntry.callstate}} </small> </p> </div> |