summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/phone_numbers_controller.rb23
-rw-r--r--app/controllers/api/v1/sip_accounts_controller.rb23
-rw-r--r--app/controllers/api/v1/switchboard_entries_controller.rb23
-rw-r--r--app/controllers/api/v1/switchboards_controller.rb21
-rw-r--r--app/controllers/switchboards_controller.rb5
-rw-r--r--app/models/switchboard.rb22
-rw-r--r--app/models/switchboard_entry.rb35
-rw-r--r--app/serializers/phone_number_serializer.rb3
-rw-r--r--app/serializers/sip_account_serializer.rb6
-rw-r--r--app/serializers/switchboard_entry_serializer.rb14
-rw-r--r--app/serializers/switchboard_serializer.rb8
-rw-r--r--app/views/switchboards/_form_core.html.haml3
-rw-r--r--app/views/switchboards/show-old.html.haml (renamed from app/views/switchboards/show.html.haml)0
-rw-r--r--app/views/switchboards/show.html.erb52
14 files changed, 237 insertions, 1 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/switchboards_controller.rb b/app/controllers/switchboards_controller.rb
index 98008c1..f48e7fb 100644
--- a/app/controllers/switchboards_controller.rb
+++ b/app/controllers/switchboards_controller.rb
@@ -15,6 +15,9 @@ class SwitchboardsController < ApplicationController
def new
@switchboard = @user.switchboards.build
+ @switchboard.show_avatars = true
+ @switchboard.entry_width = 2
+ @switchboard.reload_interval = 2000
spread_breadcrumbs
end
@@ -52,7 +55,7 @@ class SwitchboardsController < ApplicationController
private
def switchboard_params
- params.require(:switchboard).permit(:name)
+ params.require(:switchboard).permit(:name, :reload_interval, :show_avatars, :entry_width)
end
def spread_breadcrumbs
diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb
index 74e2767..53f69a4 100644
--- a/app/models/switchboard.rb
+++ b/app/models/switchboard.rb
@@ -6,11 +6,33 @@ class Switchboard < ActiveRecord::Base
:presence => true,
:uniqueness => {:scope => :user_id}
+ validates :reload_interval,
+ :numericality => { :only_integer => true,
+ :greater_than => 249,
+ :allow_nil => true
+ }
+
+ validates :entry_width,
+ :numericality => { :only_integer => true,
+ :greater_than => 0,
+ :less_than => 5
+ }
+
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
def to_s
self.name.to_s
end
+
+ private
+ def convert_0_to_nil
+ if self.reload_interval == 0
+ self.reload_interval = nil
+ end
+ end
end
diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb
index 76d002f..44de7fd 100644
--- a/app/models/switchboard_entry.rb
+++ b/app/models/switchboard_entry.rb
@@ -5,6 +5,8 @@ class SwitchboardEntry < ActiveRecord::Base
belongs_to :switchboard, :touch => true
belongs_to :sip_account, :touch => true
+ has_many :phone_numbers, :through => :sip_account
+
validates :switchboard,
:presence => true
@@ -28,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
new file mode 100644
index 0000000..1b6c761
--- /dev/null
+++ b/app/serializers/switchboard_entry_serializer.rb
@@ -0,0 +1,14 @@
+class SwitchboardEntrySerializer < ActiveModel::Serializer
+ attributes :id, :name, :path_to_user, :avatar_src, :callstate
+
+ 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
new file mode 100644
index 0000000..600c79a
--- /dev/null
+++ b/app/serializers/switchboard_serializer.rb
@@ -0,0 +1,8 @@
+class SwitchboardSerializer < ActiveModel::Serializer
+ embed :ids, :include => true
+
+ 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/_form_core.html.haml b/app/views/switchboards/_form_core.html.haml
index 61b5934..59a2442 100644
--- a/app/views/switchboards/_form_core.html.haml
+++ b/app/views/switchboards/_form_core.html.haml
@@ -1,2 +1,5 @@
.inputs
= f.input :name, :label => t('switchboards.form.name.label'), :hint => conditional_hint('switchboards.form.name.hint'), :autofocus => true
+ = f.input :reload_interval, :label => t('switchboards.form.reload_interval.label'), :hint => conditional_hint('switchboards.form.reload_interval.hint')
+ = f.input :show_avatars, :label => t('switchboards.form.show_avatars.label'), :hint => conditional_hint('switchboards.form.show_avatars.hint')
+ = f.input :entry_width, :label => t('switchboards.form.entry_width.label'), :hint => conditional_hint('switchboards.form.entry_width.hint')
diff --git a/app/views/switchboards/show.html.haml b/app/views/switchboards/show-old.html.haml
index a825806..a825806 100644
--- a/app/views/switchboards/show.html.haml
+++ b/app/views/switchboards/show-old.html.haml
diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb
new file mode 100644
index 0000000..1fd9d9a
--- /dev/null
+++ b/app/views/switchboards/show.html.erb
@@ -0,0 +1,52 @@
+<% content_for :title, "Switchboard #{@switchboard.name}" %>
+
+<script>
+ var switchboard_id = <%= @switchboard.id %>;
+ var show_avatars = <%= @switchboard.show_avatars.to_s %>;
+ var reload_interval = <%= @switchboard.reload_interval.nil? ? 0 : @switchboard.reload_interval %>;
+</script>
+
+<div class='row'>
+ <div class='span12'>
+ <div id='emberjs-container'></div>
+
+ <script type="text/x-handlebars" data-template-name="application">
+ {{outlet}}
+ </script>
+
+ <script type="text/x-handlebars" data-template-name="switchboard">
+ <h2>{{name}}</h2>
+
+ {{#if switchboardEntrys.length}}
+ <ul class="thumbnails">
+ {{#each switchboardEntry in switchboardEntrys}}
+ <li class="span2">
+ <div class="thumbnail">
+ {{avatar_img switchboardEntry.avatar_src}}
+ <p>
+ <small>
+ {{switchboardEntry.name}}<br>
+
+ {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumbers}}
+ <span class="label">
+ {{phoneNumber.number}}
+ </span>
+ {{/each}}
+ <br>
+ {{show_callstate switchboardEntry.callstate}}
+ </small>
+ </p>
+ </div>
+ </li>
+ {{/each}}
+ </ul>
+ {{/if}}
+ </script>
+
+ </div>
+</div>
+
+<script src="/js/libs/handlebars.js"></script>
+<script src="/js/libs/ember.js"></script>
+<script src="/js/libs/ember-data.js"></script>
+<script src="/js/app.js"></script>