From db9dbf03d88cfbd68ce99a242730b9e870339539 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Mar 2013 13:15:35 +0100 Subject: Added Switchboard scaffold. --- app/controllers/switchboards_controller.rb | 65 ++++++++++++++++++++++++ app/helpers/switchboards_helper.rb | 2 + app/models/call_route.rb | 2 +- app/models/switchboard.rb | 14 +++++ app/models/user.rb | 2 + app/views/switchboards/_form.html.haml | 7 +++ app/views/switchboards/_form_core.html.haml | 2 + app/views/switchboards/_index_core.html.haml | 10 ++++ app/views/switchboards/edit.html.haml | 3 ++ app/views/switchboards/index.html.haml | 8 +++ app/views/switchboards/new.html.haml | 3 ++ app/views/switchboards/show.html.haml | 12 +++++ config/locales/views/switchboards/de.yml | 45 ++++++++++++++++ config/locales/views/switchboards/en.yml | 45 ++++++++++++++++ config/routes.rb | 2 + db/migrate/20130307104654_create_switchboards.rb | 13 +++++ test/functional/switchboards_controller_test.rb | 49 ++++++++++++++++++ test/unit/switchboard_test.rb | 7 +++ 18 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 app/controllers/switchboards_controller.rb create mode 100644 app/helpers/switchboards_helper.rb create mode 100644 app/models/switchboard.rb create mode 100644 app/views/switchboards/_form.html.haml create mode 100644 app/views/switchboards/_form_core.html.haml create mode 100644 app/views/switchboards/_index_core.html.haml create mode 100644 app/views/switchboards/edit.html.haml create mode 100644 app/views/switchboards/index.html.haml create mode 100644 app/views/switchboards/new.html.haml create mode 100644 app/views/switchboards/show.html.haml create mode 100644 config/locales/views/switchboards/de.yml create mode 100644 config/locales/views/switchboards/en.yml create mode 100644 db/migrate/20130307104654_create_switchboards.rb create mode 100644 test/functional/switchboards_controller_test.rb create mode 100644 test/unit/switchboard_test.rb diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb new file mode 100644 index 0000000..8f21d5e --- /dev/null +++ b/app/controllers/switchboards_controller.rb @@ -0,0 +1,65 @@ +class SwitchboardsController < ApplicationController + load_and_authorize_resource :user + authorize_resource :switchboard, :through => :user + + def index + @switchboards = @user.switchboards + spread_breadcrumbs + end + + def show + @switchboard = @user.switchboards.find(params[:id]) + spread_breadcrumbs + end + + def new + @switchboard = @user.switchboards.build + spread_breadcrumbs + end + + def create + @switchboard = @user.switchboards.build(switchboard_params) + spread_breadcrumbs + if @switchboard.save + redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_created') + else + render :new + end + end + + def edit + @switchboard = @user.switchboards.find(params[:id]) + spread_breadcrumbs + end + + def update + @switchboard = @user.switchboards.find(params[:id]) + spread_breadcrumbs + if @switchboard.update_attributes(switchboard_params) + redirect_to [@user, @switchboard], :notice => t('switchboards.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @switchboard = @user.switchboards.find(params[:id]) + @switchboard.destroy + spread_breadcrumbs + redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_destroyed') + end + + private + def switchboard_params + params.require(:switchboard).permit(:name) + end + + def spread_breadcrumbs + add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant) + add_breadcrumb @user, tenant_user_path(@user.current_tenant, @user) + add_breadcrumb t("switchboards.index.page_title"), user_switchboards_path(@user) + if @switchboard && !@switchboard.new_record? + add_breadcrumb @switchboard, user_switchboard_path(@user, @switchboard) + end + end +end diff --git a/app/helpers/switchboards_helper.rb b/app/helpers/switchboards_helper.rb new file mode 100644 index 0000000..6fbea8a --- /dev/null +++ b/app/helpers/switchboards_helper.rb @@ -0,0 +1,2 @@ +module SwitchboardsHelper +end diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 8bc811a..6c54549 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -7,7 +7,7 @@ class CallRoute < ActiveRecord::Base has_many :route_elements, :dependent => :destroy, :order => :position validates :name, - :presence => true + :presence => true validates :routing_table, :presence => true, diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb new file mode 100644 index 0000000..cb0c70f --- /dev/null +++ b/app/models/switchboard.rb @@ -0,0 +1,14 @@ +class Switchboard < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + validates :name, + :presence => true, + :uniqueness => {:scope => :user_id} + + belongs_to :user, :touch => true + + def to_s + self.name.to_s + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 913d75f..6091e32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,8 @@ class User < ActiveRecord::Base has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true has_many :groups, :through => :group_memberships + has_many :switchboards, :dependent => :destroy + # Avatar like photo mount_uploader :image, ImageUploader diff --git a/app/views/switchboards/_form.html.haml b/app/views/switchboards/_form.html.haml new file mode 100644 index 0000000..bb09713 --- /dev/null +++ b/app/views/switchboards/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for([@user, @switchboard]) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('switchboards.form.submit') diff --git a/app/views/switchboards/_form_core.html.haml b/app/views/switchboards/_form_core.html.haml new file mode 100644 index 0000000..61b5934 --- /dev/null +++ b/app/views/switchboards/_form_core.html.haml @@ -0,0 +1,2 @@ +.inputs + = f.input :name, :label => t('switchboards.form.name.label'), :hint => conditional_hint('switchboards.form.name.hint'), :autofocus => true diff --git a/app/views/switchboards/_index_core.html.haml b/app/views/switchboards/_index_core.html.haml new file mode 100644 index 0000000..858f624 --- /dev/null +++ b/app/views/switchboards/_index_core.html.haml @@ -0,0 +1,10 @@ +%table.table.table-striped + %tr + %th= t('switchboards.index.name') + %th + + + - for switchboard in switchboards + %tr + %td= switchboard.name + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => user, :child => switchboard} \ No newline at end of file diff --git a/app/views/switchboards/edit.html.haml b/app/views/switchboards/edit.html.haml new file mode 100644 index 0000000..1ab0efe --- /dev/null +++ b/app/views/switchboards/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("switchboards.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/switchboards/index.html.haml b/app/views/switchboards/index.html.haml new file mode 100644 index 0000000..4f29d7d --- /dev/null +++ b/app/views/switchboards/index.html.haml @@ -0,0 +1,8 @@ +- content_for :title, t("switchboards.index.page_title") + +.row + .span6 + - if @switchboards && @switchboards.count > 0 + = render :partial => "index_core", :locals => {:switchboards => @switchboards, :user => @user} + + = render :partial => 'shared/create_link', :locals => {:parent => @user, :child_class => Switchboard} \ No newline at end of file diff --git a/app/views/switchboards/new.html.haml b/app/views/switchboards/new.html.haml new file mode 100644 index 0000000..9f5918f --- /dev/null +++ b/app/views/switchboards/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("switchboards.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/switchboards/show.html.haml b/app/views/switchboards/show.html.haml new file mode 100644 index 0000000..746e180 --- /dev/null +++ b/app/views/switchboards/show.html.haml @@ -0,0 +1,12 @@ +- content_for :title, t("switchboards.show.page_title") + +.row + .span6 + %table.table.table-striped + %tr + %td + %strong= t('switchboards.show.name') + ":" + %td + = @switchboard.name + += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @user, :child => @switchboard } \ No newline at end of file diff --git a/config/locales/views/switchboards/de.yml b/config/locales/views/switchboards/de.yml new file mode 100644 index 0000000..0bec502 --- /dev/null +++ b/config/locales/views/switchboards/de.yml @@ -0,0 +1,45 @@ +de: + switchboards: + name: 'Switchboard' + controller: + successfuly_created: 'Switchboard wurde angelegt.' + successfuly_updated: 'Switchboard wurde aktualisiert.' + successfuly_destroyed: 'Switchboard wurde gelöscht.' + index: + page_title: 'Liste aller Switchboards' + name: 'Name' + user_id: 'User' + actions: + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Switchboard' + destroy: 'Löschen' + edit: 'Bearbeiten' + show: 'Anzeigen' + create: 'Neu anlegen' + create_for: 'Switchboard neu anlegen für %{resource}' + show: + page_title: 'Switchboard bearbeiten' + name: 'Name' + user_id: 'User' + actions: + confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' + destroy: 'Löschen' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + new: + page_title: 'Switchboard neu anlegen' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: + page_title: 'Switchboard bearbeiten' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + form: + name: + label: 'Name' + hint: '' + user_id: + label: 'User' + hint: '' + submit: 'Absenden' \ No newline at end of file diff --git a/config/locales/views/switchboards/en.yml b/config/locales/views/switchboards/en.yml new file mode 100644 index 0000000..250d5de --- /dev/null +++ b/config/locales/views/switchboards/en.yml @@ -0,0 +1,45 @@ +en: + switchboards: + name: 'Switchboard' + controller: + successfuly_created: 'Successfully created Switchboard.' + successfuly_updated: 'Successfully updated Switchboard.' + successfuly_destroyed: 'Successfully destroyed Switchboard.' + index: + page_title: 'Listing Switchboard' + name: 'Name' + user_id: 'User' + actions: + confirm_destroy: 'Are you sure you want to delete this Switchboard?' + destroy: 'Delete' + edit: 'Edit' + show: 'View' + create: 'New' + create_for: 'New Switchboard for %{resource}' + show: + page_title: 'Show Switchboard' + name: 'Name' + user_id: 'User' + actions: + confirm_destroy: 'Are you sure you want to delete this element?' + destroy: 'Delete' + edit: 'Edit' + view_all: 'View All' + new: + page_title: 'New Switchboard' + actions: + back_to_list: 'Back to Index' + edit: + page_title: 'Editing Switchboard' + actions: + back_to_list: 'Back to Index' + edit: 'Edit' + view_all: 'View All' + form: + name: + label: 'Name' + hint: '' + user_id: + label: 'User' + hint: '' + submit: 'Submit' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 83ac5c4..821cf73 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Gemeinschaft42c::Application.routes.draw do + resources :switchboards resources :restore_jobs @@ -209,6 +210,7 @@ Gemeinschaft42c::Application.routes.draw do resources :fax_accounts resources :system_messages, :except => [ :edit, :update, :destroy ] resources :parking_stalls + resources :switchboards end resources :user_groups do diff --git a/db/migrate/20130307104654_create_switchboards.rb b/db/migrate/20130307104654_create_switchboards.rb new file mode 100644 index 0000000..222b168 --- /dev/null +++ b/db/migrate/20130307104654_create_switchboards.rb @@ -0,0 +1,13 @@ +class CreateSwitchboards < ActiveRecord::Migration + def self.up + create_table :switchboards do |t| + t.string :name + t.integer :user_id + t.timestamps + end + end + + def self.down + drop_table :switchboards + end +end diff --git a/test/functional/switchboards_controller_test.rb b/test/functional/switchboards_controller_test.rb new file mode 100644 index 0000000..6831fc2 --- /dev/null +++ b/test/functional/switchboards_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class SwitchboardsControllerTest < ActionController::TestCase + setup do + @switchboard = switchboards(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:switchboards) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create switchboard" do + assert_difference('Switchboard.count') do + post :create, switchboard: @switchboard.attributes + end + + assert_redirected_to switchboard_path(assigns(:switchboard)) + end + + test "should show switchboard" do + get :show, id: @switchboard.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @switchboard.to_param + assert_response :success + end + + test "should update switchboard" do + put :update, id: @switchboard.to_param, switchboard: @switchboard.attributes + assert_redirected_to switchboard_path(assigns(:switchboard)) + end + + test "should destroy switchboard" do + assert_difference('Switchboard.count', -1) do + delete :destroy, id: @switchboard.to_param + end + + assert_redirected_to switchboards_path + end +end diff --git a/test/unit/switchboard_test.rb b/test/unit/switchboard_test.rb new file mode 100644 index 0000000..97534fc --- /dev/null +++ b/test/unit/switchboard_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SwitchboardTest < ActiveSupport::TestCase + def test_should_be_valid + assert Switchboard.new.valid? + end +end -- cgit v1.2.3 From 6374c0b3e38dfc74eb1b4a5a1fcc5229eacdcaf2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 8 Mar 2013 12:09:17 +0100 Subject: Added SwitchboardEntry scaffold. switchboard has_many switchboard_entries --- app/assets/javascripts/switchboard_entry.js.coffee | 6 ++ app/assets/stylesheets/application.css | 1 + .../stylesheets/switchboard_entries.css.scss | 5 ++ app/controllers/switchboard_entries_controller.rb | 74 ++++++++++++++++++++++ app/helpers/switchboard_entries_helper.rb | 2 + app/models/sip_account.rb | 2 + app/models/switchboard.rb | 2 + app/models/switchboard_entry.rb | 30 +++++++++ app/views/switchboard_entries/_form.html.haml | 7 ++ app/views/switchboard_entries/_form_core.html.haml | 3 + .../switchboard_entries/_index_core.html.haml | 16 +++++ app/views/switchboard_entries/edit.html.haml | 3 + app/views/switchboard_entries/index.html.haml | 6 ++ app/views/switchboard_entries/new.html.haml | 3 + app/views/switchboard_entries/show.html.haml | 22 +++++++ config/locales/views/switchboard_entries/de.yml | 55 ++++++++++++++++ config/locales/views/switchboard_entries/en.yml | 55 ++++++++++++++++ config/routes.rb | 7 +- .../20130307122344_create_switchboard_entries.rb | 15 +++++ .../switchboard_entries_controller_test.rb | 49 ++++++++++++++ test/unit/switchboard_entry_test.rb | 7 ++ 21 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/switchboard_entry.js.coffee create mode 100644 app/assets/stylesheets/switchboard_entries.css.scss create mode 100644 app/controllers/switchboard_entries_controller.rb create mode 100644 app/helpers/switchboard_entries_helper.rb create mode 100644 app/models/switchboard_entry.rb create mode 100644 app/views/switchboard_entries/_form.html.haml create mode 100644 app/views/switchboard_entries/_form_core.html.haml create mode 100644 app/views/switchboard_entries/_index_core.html.haml create mode 100644 app/views/switchboard_entries/edit.html.haml create mode 100644 app/views/switchboard_entries/index.html.haml create mode 100644 app/views/switchboard_entries/new.html.haml create mode 100644 app/views/switchboard_entries/show.html.haml create mode 100644 config/locales/views/switchboard_entries/de.yml create mode 100644 config/locales/views/switchboard_entries/en.yml create mode 100644 db/migrate/20130307122344_create_switchboard_entries.rb create mode 100644 test/functional/switchboard_entries_controller_test.rb create mode 100644 test/unit/switchboard_entry_test.rb diff --git a/app/assets/javascripts/switchboard_entry.js.coffee b/app/assets/javascripts/switchboard_entry.js.coffee new file mode 100644 index 0000000..d14825e --- /dev/null +++ b/app/assets/javascripts/switchboard_entry.js.coffee @@ -0,0 +1,6 @@ +jQuery -> + $('#switchboard_entries').sortable + axis: 'y' + handle: '.handle' + update: -> + $.post($(this).data('update-url'), $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 44868e4..557bbda 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -16,4 +16,5 @@ *= require softkeys *= require phone_numbers *= require route_elements + *= require switchboard_entries */ diff --git a/app/assets/stylesheets/switchboard_entries.css.scss b/app/assets/stylesheets/switchboard_entries.css.scss new file mode 100644 index 0000000..12b67ee --- /dev/null +++ b/app/assets/stylesheets/switchboard_entries.css.scss @@ -0,0 +1,5 @@ +#switchboard_entries .handle { + font-size: 12px; + color: #777; + cursor: move; +} \ No newline at end of file diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb new file mode 100644 index 0000000..ef6c72e --- /dev/null +++ b/app/controllers/switchboard_entries_controller.rb @@ -0,0 +1,74 @@ +class SwitchboardEntriesController < ApplicationController + load_and_authorize_resource :switchboard + authorize_resource :switchboard_entry, :through => :switchboard, :except => [:sort] + + def index + @switchboard_entries = @switchboard.switchboard_entries + spread_breadcrumbs + end + + def show + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + spread_breadcrumbs + end + + def new + @switchboard_entry = @switchboard.switchboard_entries.build + @sip_accounts = SipAccount.all - @switchboard.sip_accounts + spread_breadcrumbs + end + + def create + @switchboard_entry = @switchboard.switchboard_entries.build(switchboard_entry_params) + spread_breadcrumbs + if @switchboard_entry.save + redirect_to switchboard_switchboard_entries_path(@switchboard), :notice => t('switchboard_entries.controller.successfuly_created') + else + render :new + end + end + + def edit + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + @sip_accounts = SipAccount.all - @switchboard.sip_accounts + [@switchboard_entry.sip_account] + spread_breadcrumbs + end + + def update + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + if @switchboard_entry.update_attributes(switchboard_entry_params) + redirect_to [@switchboard, @switchboard_entry], :notice => t('switchboard_entries.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + @switchboard_entry.destroy + redirect_to switchboard_switchboard_entries_path(@switchboard), :notice => t('switchboard_entries.controller.successfuly_destroyed') + end + + def sort + params[:switchboard_entry].reverse.each do |id| + @switchboard.switchboard_entries.find(id).move_to_top + end + render nothing: true + end + + private + def switchboard_entry_params + params.require(:switchboard_entry).permit(:name, :sip_account_id) + end + + def spread_breadcrumbs + add_breadcrumb t("users.index.page_title"), tenant_users_path(@switchboard.user.current_tenant) + add_breadcrumb @switchboard.user, tenant_user_path(@switchboard.user.current_tenant, @switchboard.user) + add_breadcrumb t("switchboards.index.page_title"), user_switchboards_path(@switchboard.user) + add_breadcrumb @switchboard, user_switchboard_path(@switchboard.user, @switchboard) + add_breadcrumb t("switchboard_entries.index.page_title"), switchboard_switchboard_entries_path(@switchboard) + if @switchboard_entry && !@switchboard_entry.new_record? + add_breadcrumb @switchboard_entry, switchboard_switchboard_entries_path(@switchboard, @switchboard_entry) + end + end +end diff --git a/app/helpers/switchboard_entries_helper.rb b/app/helpers/switchboard_entries_helper.rb new file mode 100644 index 0000000..ca9b1f9 --- /dev/null +++ b/app/helpers/switchboard_entries_helper.rb @@ -0,0 +1,2 @@ +module SwitchboardEntriesHelper +end diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index cdb609d..74a2562 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -41,6 +41,8 @@ class SipAccount < ActiveRecord::Base has_many :call_legs, :class_name => 'Call' has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' + has_many :switchboard_entries, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index cb0c70f..74e2767 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -7,6 +7,8 @@ class Switchboard < ActiveRecord::Base :uniqueness => {:scope => :user_id} belongs_to :user, :touch => true + has_many :switchboard_entries, :dependent => :destroy + has_many :sip_accounts, :through => :switchboard_entries def to_s self.name.to_s diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb new file mode 100644 index 0000000..d1e9a0c --- /dev/null +++ b/app/models/switchboard_entry.rb @@ -0,0 +1,30 @@ +class SwitchboardEntry < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + belongs_to :switchboard, :touch => true + belongs_to :sip_account, :touch => true + + validates :switchboard, + :presence => true + + validates :sip_account, + :presence => true + + validates :name, + :uniqueness => {:scope => :switchboard_id}, + :allow_blank => true, + :allow_nil => true + + acts_as_list :scope => [ :switchboard_id ] + + default_scope order(:position) + + def to_s + if self.name.blank? && !self.sip_account.to_s.blank? + self.sip_account.to_s + else + self.name.to_s + end + end +end diff --git a/app/views/switchboard_entries/_form.html.haml b/app/views/switchboard_entries/_form.html.haml new file mode 100644 index 0000000..b3d56ec --- /dev/null +++ b/app/views/switchboard_entries/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for([@switchboard, @switchboard_entry]) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('switchboard_entries.form.submit') diff --git a/app/views/switchboard_entries/_form_core.html.haml b/app/views/switchboard_entries/_form_core.html.haml new file mode 100644 index 0000000..6f340c2 --- /dev/null +++ b/app/views/switchboard_entries/_form_core.html.haml @@ -0,0 +1,3 @@ +.inputs + = f.association :sip_account, :collection => @sip_accounts, :label => t('switchboard_entries.form.sip_account_id.label'), :hint => conditional_hint('switchboard_entries.form.sip_account_id.hint'), :autofocus => true, :include_blank => false + = f.input :name, :label => t('switchboard_entries.form.name.label'), :hint => conditional_hint('switchboard_entries.form.name.hint') diff --git a/app/views/switchboard_entries/_index_core.html.haml b/app/views/switchboard_entries/_index_core.html.haml new file mode 100644 index 0000000..406db71 --- /dev/null +++ b/app/views/switchboard_entries/_index_core.html.haml @@ -0,0 +1,16 @@ +%table.table.table-striped + %tr + %th + %th= t('switchboard_entries.index.sip_account_id') + %th= t('switchboard_entries.index.name') + %th + + %tbody{ :id => "switchboard_entries", :'data-update-url' => sort_switchboard_switchboard_entries_path(switchboard_entries.first.switchboard) } + - for switchboard_entry in switchboard_entries + = content_tag_for :tr, switchboard_entry do + %td + %span.handle + %i.icon-resize-vertical + %td= switchboard_entry.sip_account + %td= switchboard_entry.name + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => switchboard_entry.switchboard, :child => switchboard_entry} \ No newline at end of file diff --git a/app/views/switchboard_entries/edit.html.haml b/app/views/switchboard_entries/edit.html.haml new file mode 100644 index 0000000..8885e25 --- /dev/null +++ b/app/views/switchboard_entries/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("switchboard_entries.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/switchboard_entries/index.html.haml b/app/views/switchboard_entries/index.html.haml new file mode 100644 index 0000000..302b778 --- /dev/null +++ b/app/views/switchboard_entries/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("switchboard_entries.index.page_title") + +- if @switchboard_entries && @switchboard_entries.count > 0 + = render "index_core", :switchboard_entries => @switchboard_entries + += render :partial => 'shared/create_link', :locals => {:parent => @switchboard, :child_class => SwitchboardEntry} \ No newline at end of file diff --git a/app/views/switchboard_entries/new.html.haml b/app/views/switchboard_entries/new.html.haml new file mode 100644 index 0000000..0801a65 --- /dev/null +++ b/app/views/switchboard_entries/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("switchboard_entries.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/switchboard_entries/show.html.haml b/app/views/switchboard_entries/show.html.haml new file mode 100644 index 0000000..b519781 --- /dev/null +++ b/app/views/switchboard_entries/show.html.haml @@ -0,0 +1,22 @@ +- content_for :title, t("switchboard_entries.show.page_title") + +.row + .span6 + %table.table.table-striped + %tr + %td + %strong= t('switchboard_entries.show.sip_account_id') + ":" + %td + = @switchboard_entry.sip_account + %tr + %td + %strong= t('switchboard_entries.show.name') + ":" + %td + = @switchboard_entry.name + %tr + %td + %strong= t('switchboard_entries.show.position') + ":" + %td + = @switchboard_entry.position + + = render :partial => 'shared/show_edit_destroy_part', :locals => {:parent => @switchboard, :child => @switchboard_entry } \ No newline at end of file diff --git a/config/locales/views/switchboard_entries/de.yml b/config/locales/views/switchboard_entries/de.yml new file mode 100644 index 0000000..41804b5 --- /dev/null +++ b/config/locales/views/switchboard_entries/de.yml @@ -0,0 +1,55 @@ +de: + switchboard_entries: + name: 'Switchboard-Eintrag' + controller: + successfuly_created: 'Switchboard-Eintrag wurde angelegt.' + successfuly_updated: 'Switchboard-Eintrag wurde aktualisiert.' + successfuly_destroyed: 'Switchboard-Eintrag wurde gelöscht.' + index: + page_title: 'Liste aller Switchboard-Einträge' + switchboard_id: 'Switchboard' + sip_account_id: 'SIP-Account' + name: 'Name' + position: 'Position' + actions: + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Switchboard-Eintrag' + destroy: 'Löschen' + edit: 'Bearbeiten' + show: 'Anzeigen' + create: 'Neu anlegen' + create_for: 'Switchboard-Eintrag neu anlegen für %{resource}' + show: + page_title: 'Switchboard-Eintrag bearbeiten' + switchboard_id: 'Switchboard' + sip_account_id: 'SIP-Account' + name: 'Name' + position: 'Position' + actions: + confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' + destroy: 'Löschen' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + new: + page_title: 'Switchboard-Eintrag neu anlegen' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: + page_title: 'Switchboard-Eintrag bearbeiten' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + form: + switchboard_id: + label: 'Switchboard' + hint: '' + sip_account_id: + label: 'SIP-Account' + hint: '' + name: + label: 'Name' + hint: '' + position: + label: 'Position' + hint: '' + submit: 'Absenden' \ No newline at end of file diff --git a/config/locales/views/switchboard_entries/en.yml b/config/locales/views/switchboard_entries/en.yml new file mode 100644 index 0000000..71f2fe4 --- /dev/null +++ b/config/locales/views/switchboard_entries/en.yml @@ -0,0 +1,55 @@ +en: + switchboard_entries: + name: 'Switchboardentry' + controller: + successfuly_created: 'Successfully created Switchboardentry.' + successfuly_updated: 'Successfully updated Switchboardentry.' + successfuly_destroyed: 'Successfully destroyed Switchboardentry.' + index: + page_title: 'Listing Switchboardentry' + switchboard_id: 'Switchboard' + sip_account_id: 'Sip account' + name: 'Name' + position: 'Position' + actions: + confirm_destroy: 'Are you sure you want to delete this Switchboardentry?' + destroy: 'Delete' + edit: 'Edit' + show: 'View' + create: 'New' + create_for: 'New Switchboardentry for %{resource}' + show: + page_title: 'Show Switchboardentry' + switchboard_id: 'Switchboard' + sip_account_id: 'Sip account' + name: 'Name' + position: 'Position' + actions: + confirm_destroy: 'Are you sure you want to delete this element?' + destroy: 'Delete' + edit: 'Edit' + view_all: 'View All' + new: + page_title: 'New Switchboardentry' + actions: + back_to_list: 'Back to Index' + edit: + page_title: 'Editing Switchboardentry' + actions: + back_to_list: 'Back to Index' + edit: 'Edit' + view_all: 'View All' + form: + switchboard_id: + label: 'Switchboard' + hint: '' + sip_account_id: + label: 'Sip account' + hint: '' + name: + label: 'Name' + hint: '' + position: + label: 'Position' + hint: '' + submit: 'Submit' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 821cf73..369ec92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,10 @@ Gemeinschaft42c::Application.routes.draw do - resources :switchboards + + resources :switchboards do + resources :switchboard_entries do + collection { post :sort } + end + end resources :restore_jobs diff --git a/db/migrate/20130307122344_create_switchboard_entries.rb b/db/migrate/20130307122344_create_switchboard_entries.rb new file mode 100644 index 0000000..1c7521e --- /dev/null +++ b/db/migrate/20130307122344_create_switchboard_entries.rb @@ -0,0 +1,15 @@ +class CreateSwitchboardEntries < ActiveRecord::Migration + def self.up + create_table :switchboard_entries do |t| + t.integer :switchboard_id + t.integer :sip_account_id + t.string :name + t.integer :position + t.timestamps + end + end + + def self.down + drop_table :switchboard_entries + end +end diff --git a/test/functional/switchboard_entries_controller_test.rb b/test/functional/switchboard_entries_controller_test.rb new file mode 100644 index 0000000..a20f39e --- /dev/null +++ b/test/functional/switchboard_entries_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class SwitchboardEntriesControllerTest < ActionController::TestCase + setup do + @switchboard_entry = switchboard_entries(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:switchboard_entries) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create switchboard_entry" do + assert_difference('SwitchboardEntry.count') do + post :create, switchboard_entry: @switchboard_entry.attributes + end + + assert_redirected_to switchboard_entry_path(assigns(:switchboard_entry)) + end + + test "should show switchboard_entry" do + get :show, id: @switchboard_entry.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @switchboard_entry.to_param + assert_response :success + end + + test "should update switchboard_entry" do + put :update, id: @switchboard_entry.to_param, switchboard_entry: @switchboard_entry.attributes + assert_redirected_to switchboard_entry_path(assigns(:switchboard_entry)) + end + + test "should destroy switchboard_entry" do + assert_difference('SwitchboardEntry.count', -1) do + delete :destroy, id: @switchboard_entry.to_param + end + + assert_redirected_to switchboard_entries_path + end +end diff --git a/test/unit/switchboard_entry_test.rb b/test/unit/switchboard_entry_test.rb new file mode 100644 index 0000000..a86c39a --- /dev/null +++ b/test/unit/switchboard_entry_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SwitchboardEntryTest < ActiveSupport::TestCase + def test_should_be_valid + assert SwitchboardEntry.new.valid? + end +end -- cgit v1.2.3 From 21d0843117c0962bd962fc50fccaf276a5b3067f Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 08:43:23 +0100 Subject: Misc --- app/models/switchboard_entry.rb | 1 + app/views/switchboards/show.html.haml | 53 ++++++++++++++++++++++++++++------- config/routes.rb | 4 ++- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index d1e9a0c..76d002f 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -12,6 +12,7 @@ class SwitchboardEntry < ActiveRecord::Base :presence => true validates :name, + :length => { :maximum => 10 }, :uniqueness => {:scope => :switchboard_id}, :allow_blank => true, :allow_nil => true diff --git a/app/views/switchboards/show.html.haml b/app/views/switchboards/show.html.haml index 746e180..b81980c 100644 --- a/app/views/switchboards/show.html.haml +++ b/app/views/switchboards/show.html.haml @@ -1,12 +1,45 @@ -- content_for :title, t("switchboards.show.page_title") +- content_for :title, @switchboard.name + .row - .span6 - %table.table.table-striped - %tr - %td - %strong= t('switchboards.show.name') + ":" - %td - = @switchboard.name - -= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @user, :child => @switchboard } \ No newline at end of file + .span12 + .well.pull-right + %p + =current_user + + %ul.thumbnails + - @switchboard.switchboard_entries.each do |switchboard_entry| + %li.span1 + %div.thumbnail + %a.thumbnail{:href => tenant_user_path(switchboard_entry.sip_account.sip_accountable.current_tenant, switchboard_entry.sip_account.sip_accountable)} + - if switchboard_entry.sip_account.sip_accountable.image? + = image_tag(switchboard_entry.sip_account.sip_accountable.image_url(:mini).to_s, :class => 'img-rounded') + - else + - if switchboard_entry.sip_account.sip_accountable.male? + = image_tag 'icons/user-male-16x.png', :class => 'img-rounded' + - else + = image_tag 'icons/user-female-16x.png', :class => 'img-rounded' + %p + %small + = truncate(switchboard_entry.to_s, :length => 10) + %span{:class => "label #{(switchboard_entry.sip_account.registration ? '' : 'label-inverse')}"} + - if !switchboard_entry.sip_account.registration + %i.icon-ban-circle.icon-white + - if switchboard_entry.sip_account.phone_numbers.count > 1 + - phone_numbers = [] + - switchboard_entry.sip_account.phone_numbers.order(:position).each do |phone_number| + - if phone_number.number.length < 6 + - phone_numbers << phone_number + - if phone_numbers.size == 0 + - phone_numbers = switchboard_entry.sip_account.phone_numbers.order(:position) + - else + - phone_numbers = switchboard_entry.sip_account.phone_numbers + = render 'phone_numbers/listing', :phone_numbers => phone_numbers + +- if can? :edit, @switchboard + .row + .span12 + %a.btn.btn-small.btn-warning{:href => switchboard_switchboard_entries_path(@switchboard) } + %i.icon-edit.icon-white + %span.hidden-phone + =t("switchboard_entries.index.page_title") diff --git a/config/routes.rb b/config/routes.rb index 369ec92..cfee51b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -215,7 +215,9 @@ Gemeinschaft42c::Application.routes.draw do resources :fax_accounts resources :system_messages, :except => [ :edit, :update, :destroy ] resources :parking_stalls - resources :switchboards + resources :switchboards do + get :display + end end resources :user_groups do -- cgit v1.2.3 From 4ce55596e3637b212de54aaeb24f8af114deb350 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 08:49:37 +0100 Subject: bundle update and some gem housekeeping. --- Gemfile | 5 +++-- Gemfile.lock | 59 ++++++++++++++++++++++++++++------------------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Gemfile b/Gemfile index e4e839f..f975133 100644 --- a/Gemfile +++ b/Gemfile @@ -54,8 +54,7 @@ group :test do end gem 'haml' -# gem 'simple_form', '~> 2.0.1' -gem 'simple_form', github: 'plataformatec/simple_form', branch: 'v2.1' +gem 'simple_form', '~> 2.1.0' # Image Upload gem 'carrierwave' @@ -80,6 +79,8 @@ gem 'uuid' # Application server gem 'unicorn' +# Thin is needed for the Private Pub stuff. +# http://railscasts.com/episodes/316-private-pub gem 'thin' # Backup https://github.com/meskyanichi/backup diff --git a/Gemfile.lock b/Gemfile.lock index d8531cd..2ca007c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,3 @@ -GIT - remote: git://github.com/plataformatec/simple_form.git - revision: e3da7301dcf6feb9a1db275ff5cb3f85afce0e80 - branch: v2.1 - specs: - simple_form (2.1.0.dev) - actionpack (~> 3.0) - activemodel (~> 3.0) - GEM remote: http://rubygems.org/ specs: @@ -37,16 +28,18 @@ GEM activesupport (3.2.12) i18n (~> 0.6) multi_json (~> 1.0) - acts_as_list (0.1.9) + acts_as_list (0.2.0) + activerecord (>= 3.0) arel (3.0.2) - backup (3.0.27) + backup (3.1.2) open4 (~> 1.3.0) thor (>= 0.15.4, < 2) bcrypt-ruby (3.0.1) - better_errors (0.5.0) + better_errors (0.7.2) coderay (>= 1.0.0) erubis (>= 2.6.6) - binding_of_caller (0.6.8) + binding_of_caller (0.7.1) + debug_inspector (>= 0.0.1) breadcrumbs_on_rails (2.3.0) builder (3.0.4) cache_digests (0.2.0) @@ -55,16 +48,16 @@ GEM carrierwave (0.8.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) - chronic (0.9.0) + chronic (0.9.1) chunky_png (1.2.7) - coderay (1.0.8) + coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) coffee-script (2.2.0) coffee-script-source execjs - coffee-script-source (1.4.0) + coffee-script-source (1.6.1) compass (0.12.2) chunky_png (~> 1.2) fssm (>= 0.2.7) @@ -73,13 +66,14 @@ GEM compass (>= 0.12.2, < 0.14) daemons (1.1.9) dalli (2.6.2) + debug_inspector (0.0.2) delayed_job (3.0.5) activesupport (~> 3.0) - delayed_job_active_record (0.4.1) + delayed_job_active_record (0.4.3) activerecord (>= 2.1.0, < 4) delayed_job (~> 3.0) erubis (2.7.0) - eventmachine (1.0.0) + eventmachine (1.0.3) execjs (1.4.0) multi_json (~> 1.0) factory_girl (4.2.0) @@ -93,7 +87,7 @@ GEM hike (1.2.1) hirb (0.7.1) http_accept_language (1.0.2) - i18n (0.6.1) + i18n (0.6.4) inifile (2.0.2) journey (1.0.4) jquery-rails (2.2.1) @@ -108,15 +102,15 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.21) - mini_magick (3.4) + mini_magick (3.5.0) subexec (~> 0.2.1) - multi_json (1.6.0) + multi_json (1.6.1) mysql2 (0.3.11) nokogiri (1.5.6) open4 (1.3.0) polyglot (0.3.3) - quiet_assets (1.0.1) - railties (~> 3.1) + quiet_assets (1.0.2) + railties (>= 3.1, < 5.0) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) @@ -141,9 +135,9 @@ GEM thor (>= 0.14.6, < 2.0) raindrops (0.10.0) rake (10.0.3) - rdoc (3.12.1) + rdoc (3.12.2) json (~> 1.4) - sass (3.2.5) + sass (3.2.7) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) @@ -151,6 +145,9 @@ GEM sextant (0.2.3) activesupport (>= 3.2) rails (>= 3.2) + simple_form (2.1.0) + actionpack (~> 3.0) + activemodel (~> 3.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -158,7 +155,7 @@ GEM tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.7) state_machine (1.1.2) - strong_parameters (0.1.6) + strong_parameters (0.2.0) actionpack (~> 3.0) activemodel (~> 3.0) railties (~> 3.0) @@ -169,19 +166,19 @@ GEM eventmachine (>= 0.12.6) rack (>= 1.0.0) thor (0.17.0) - tilt (1.3.3) + tilt (1.3.5) treetop (1.4.12) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.35) + tzinfo (0.3.36) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) - unicorn (4.6.0) + unicorn (4.6.2) kgio (~> 2.6) rack raindrops (~> 0.7) - uuid (2.3.6) + uuid (2.3.7) macaddr (~> 1.0) whenever (0.8.2) activesupport (>= 2.3.4) @@ -221,7 +218,7 @@ DEPENDENCIES rails (= 3.2.12) sass-rails sextant - simple_form! + simple_form (~> 2.1.0) sqlite3 state_machine strong_parameters -- cgit v1.2.3 From fc9b8e69e74a76d6727d5ddceebb018782027b16 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 08:57:50 +0100 Subject: Added Private Pub stuff. https://github.com/ryanb/private_pub --- Gemfile | 2 +- Gemfile.lock | 24 ++++++++++++++++++++++++ app/assets/javascripts/application.js | 1 + config/private_pub.yml | 2 +- private_pub.ru | 10 ++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 private_pub.ru diff --git a/Gemfile b/Gemfile index f975133..be5ab7c 100644 --- a/Gemfile +++ b/Gemfile @@ -79,9 +79,9 @@ gem 'uuid' # Application server gem 'unicorn' -# Thin is needed for the Private Pub stuff. # http://railscasts.com/episodes/316-private-pub gem 'thin' +gem 'private_pub' # Backup https://github.com/meskyanichi/backup gem 'backup' diff --git a/Gemfile.lock b/Gemfile.lock index 2ca007c..1ceaef2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,6 +30,7 @@ GEM multi_json (~> 1.0) acts_as_list (0.2.0) activerecord (>= 3.0) + addressable (2.3.3) arel (3.0.2) backup (3.1.2) open4 (~> 1.3.0) @@ -64,6 +65,7 @@ GEM sass (~> 3.1) compass-rails (1.0.3) compass (>= 0.12.2, < 0.14) + cookiejar (0.3.0) daemons (1.1.9) dalli (2.6.2) debug_inspector (0.0.2) @@ -72,6 +74,14 @@ GEM delayed_job_active_record (0.4.3) activerecord (>= 2.1.0, < 4) delayed_job (~> 3.0) + em-http-request (1.0.3) + addressable (>= 2.2.3) + cookiejar + em-socksify + eventmachine (>= 1.0.0.beta.4) + http_parser.rb (>= 0.5.3) + em-socksify (0.2.1) + eventmachine (>= 1.0.0.beta.4) erubis (2.7.0) eventmachine (1.0.3) execjs (1.4.0) @@ -81,12 +91,22 @@ GEM factory_girl_rails (4.2.1) factory_girl (~> 4.2.0) railties (>= 3.0.0) + faye (0.8.9) + cookiejar (>= 0.3.0) + em-http-request (>= 0.3.0) + eventmachine (>= 0.12.0) + faye-websocket (>= 0.4.0) + rack (>= 1.0.0) + yajl-ruby (>= 1.0.0) + faye-websocket (0.4.7) + eventmachine (>= 0.12.0) fssm (0.2.10) haml (4.0.0) tilt hike (1.2.1) hirb (0.7.1) http_accept_language (1.0.2) + http_parser.rb (0.5.3) i18n (0.6.4) inifile (2.0.2) journey (1.0.4) @@ -109,6 +129,8 @@ GEM nokogiri (1.5.6) open4 (1.3.0) polyglot (0.3.3) + private_pub (1.0.3) + faye quiet_assets (1.0.2) railties (>= 3.1, < 5.0) rack (1.4.5) @@ -184,6 +206,7 @@ GEM activesupport (>= 2.3.4) chronic (>= 0.6.3) will_paginate (3.0.4) + yajl-ruby (1.1.0) PLATFORMS ruby @@ -214,6 +237,7 @@ DEPENDENCIES mini_magick mysql2 nokogiri + private_pub quiet_assets rails (= 3.2.12) sass-rails diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index c6f4107..68a6e22 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,5 @@ //= require jquery //= require jquery-ui //= require jquery_ujs +//= require private_pub //= require_tree . diff --git a/config/private_pub.yml b/config/private_pub.yml index 19a7e9e..840b2c1 100644 --- a/config/private_pub.yml +++ b/config/private_pub.yml @@ -6,5 +6,5 @@ test: secret_token: "secret" production: server: "http://example.com/faye" - secret_token: "ade2c51226bf26e7fbbce1e0d8848082b750d23516b46dc5bc12e910e0e64558" + secret_token: "4a6049c5f60cd74690c094757dd7afc431a64ac83f1c54f7cf4b3f28215b3bec" signature_expiration: 3600 # one hour diff --git a/private_pub.ru b/private_pub.ru new file mode 100644 index 0000000..4892af4 --- /dev/null +++ b/private_pub.ru @@ -0,0 +1,10 @@ +# Run with: rackup private_pub.ru -s thin -E production +require "bundler/setup" +require "yaml" +require "faye" +require "private_pub" + +Faye::WebSocket.load_adapter('thin') + +PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development") +run PrivatePub.faye_app -- cgit v1.2.3 From 04730ba7acf55ed5310352eabf3876bf5b8d1f87 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 09:52:08 +0100 Subject: Set the Ability for Switchboard and SwitchboardEntry. --- app/models/ability.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/ability.rb b/app/models/ability.rb index fe67547..2dd96b8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -183,6 +183,11 @@ class Ability # can :manage, VoicemailMessage can :manage, VoicemailSetting + + # Switchboard + # + can :read, Switchboard, :id => user.switchboard_ids + can :read, SwitchboardEntry, :switchboard_id => user.switchboard_ids end end else -- cgit v1.2.3 From 13e16223977966f9751e7b8e3fb587e2df0a0801 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 09:52:31 +0100 Subject: Add a second configuration option. --- app/views/switchboards/edit.html.haml | 11 ++++++++++- app/views/users/_switchboards.html.haml | 7 +++++++ app/views/users/show.html.haml | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/views/users/_switchboards.html.haml diff --git a/app/views/switchboards/edit.html.haml b/app/views/switchboards/edit.html.haml index 1ab0efe..f2e69f4 100644 --- a/app/views/switchboards/edit.html.haml +++ b/app/views/switchboards/edit.html.haml @@ -1,3 +1,12 @@ - content_for :title, t("switchboards.edit.page_title") -= render "form" \ No newline at end of file +.row + .span12 + = render "form" + +.row + .span12 + - if @switchboard.switchboard_entries && @switchboard.switchboard_entries.count > 0 + = render "switchboard_entries/index_core", :switchboard_entries => @switchboard.switchboard_entries + + = render :partial => 'shared/create_link', :locals => {:parent => @switchboard, :child_class => SwitchboardEntry} \ No newline at end of file diff --git a/app/views/users/_switchboards.html.haml b/app/views/users/_switchboards.html.haml new file mode 100644 index 0000000..f79d6b8 --- /dev/null +++ b/app/views/users/_switchboards.html.haml @@ -0,0 +1,7 @@ +-# Switchboards +-# +- if (can?( :index, Switchboard ) && user.switchboards.any? ) || can?( :create, Switchboard ) + %h2= t('switchboards.index.page_title') + - if can?( :index, Switchboard ) && user.switchboards.count > 0 + = render :partial => "switchboards/index_core", :locals => {:switchboards => user.switchboards, :user => user} + = render :partial => 'shared/create_link', :locals => {:parent => user, :child_class => Conference} \ No newline at end of file diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index ea90ab4..98f7cc6 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -87,3 +87,6 @@ - cache(['user_show_conferences_overview', I18n.locale, @user, @user.conferences]) do = render :partial => 'conferences', :locals => {:user => @user} + + - cache(['user_switchboards_overview', I18n.locale, @user, @user.switchboards]) do + = render :partial => 'switchboards', :locals => {:user => @user} \ No newline at end of file -- cgit v1.2.3 From c563859fa60defd2b40f17a0b7cf1c4912f72792 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 12:06:06 +0100 Subject: added non_e164_phone_numbers method --- app/models/sip_account.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 930069d..cea5f0e 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -213,6 +213,11 @@ class SipAccount < ActiveRecord::Base return states end + def non_e164_phone_numbers + array_of_phone_numbers_as_strings = self.phone_numbers.map{ |phone_number| phone_number.number.to_s }.sort + self.phone_numbers.where(:number => array_of_phone_numbers_as_strings.select { |phone_number| phone_number[0] != '+' }) + end + private def save_value_of_to_s -- cgit v1.2.3 From f0932e38b890b08397020a5994ddde7110d7b8db Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 10:50:49 +0100 Subject: refactoring --- app/controllers/switchboards_controller.rb | 1 + .../_switchboard_entry.html.haml | 26 +++++++++++++++++++ app/views/switchboards/show.html.haml | 29 +--------------------- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 app/views/switchboard_entries/_switchboard_entry.html.haml diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb index 8f21d5e..98008c1 100644 --- a/app/controllers/switchboards_controller.rb +++ b/app/controllers/switchboards_controller.rb @@ -9,6 +9,7 @@ class SwitchboardsController < ApplicationController def show @switchboard = @user.switchboards.find(params[:id]) + @switchboard_entries = @switchboard.switchboard_entries spread_breadcrumbs end diff --git a/app/views/switchboard_entries/_switchboard_entry.html.haml b/app/views/switchboard_entries/_switchboard_entry.html.haml new file mode 100644 index 0000000..2902a83 --- /dev/null +++ b/app/views/switchboard_entries/_switchboard_entry.html.haml @@ -0,0 +1,26 @@ +%li.span1{:id => "switchboard_entry_id_#{switchboard_entry.id}"} + %div.thumbnail + %a.thumbnail{:href => tenant_user_path(switchboard_entry.sip_account.sip_accountable.current_tenant, switchboard_entry.sip_account.sip_accountable)} + - if switchboard_entry.sip_account.sip_accountable.image? + = image_tag(switchboard_entry.sip_account.sip_accountable.image_url(:mini).to_s, :class => 'img-rounded') + - else + - if switchboard_entry.sip_account.sip_accountable.male? + = image_tag 'icons/user-male-16x.png', :class => 'img-rounded' + - else + = image_tag 'icons/user-female-16x.png', :class => 'img-rounded' + %p + %small + = truncate(switchboard_entry.to_s, :length => 10) + %span{:class => "label #{(switchboard_entry.sip_account.registration ? '' : 'label-inverse')}"} + - if !switchboard_entry.sip_account.registration + %i.icon-ban-circle.icon-white + - if switchboard_entry.sip_account.phone_numbers.count > 1 + - phone_numbers = [] + - switchboard_entry.sip_account.phone_numbers.order(:position).each do |phone_number| + - if phone_number.number.length < 6 + - phone_numbers << phone_number + - if phone_numbers.size == 0 + - phone_numbers = switchboard_entry.sip_account.phone_numbers.order(:position) + - else + - phone_numbers = switchboard_entry.sip_account.phone_numbers + = render 'phone_numbers/listing', :phone_numbers => phone_numbers diff --git a/app/views/switchboards/show.html.haml b/app/views/switchboards/show.html.haml index b81980c..18671c2 100644 --- a/app/views/switchboards/show.html.haml +++ b/app/views/switchboards/show.html.haml @@ -1,6 +1,5 @@ - content_for :title, @switchboard.name - .row .span12 .well.pull-right @@ -8,33 +7,7 @@ =current_user %ul.thumbnails - - @switchboard.switchboard_entries.each do |switchboard_entry| - %li.span1 - %div.thumbnail - %a.thumbnail{:href => tenant_user_path(switchboard_entry.sip_account.sip_accountable.current_tenant, switchboard_entry.sip_account.sip_accountable)} - - if switchboard_entry.sip_account.sip_accountable.image? - = image_tag(switchboard_entry.sip_account.sip_accountable.image_url(:mini).to_s, :class => 'img-rounded') - - else - - if switchboard_entry.sip_account.sip_accountable.male? - = image_tag 'icons/user-male-16x.png', :class => 'img-rounded' - - else - = image_tag 'icons/user-female-16x.png', :class => 'img-rounded' - %p - %small - = truncate(switchboard_entry.to_s, :length => 10) - %span{:class => "label #{(switchboard_entry.sip_account.registration ? '' : 'label-inverse')}"} - - if !switchboard_entry.sip_account.registration - %i.icon-ban-circle.icon-white - - if switchboard_entry.sip_account.phone_numbers.count > 1 - - phone_numbers = [] - - switchboard_entry.sip_account.phone_numbers.order(:position).each do |phone_number| - - if phone_number.number.length < 6 - - phone_numbers << phone_number - - if phone_numbers.size == 0 - - phone_numbers = switchboard_entry.sip_account.phone_numbers.order(:position) - - else - - phone_numbers = switchboard_entry.sip_account.phone_numbers - = render 'phone_numbers/listing', :phone_numbers => phone_numbers + = render :partial => "switchboard_entries/switchboard_entry", :collection => @switchboard_entries - if can? :edit, @switchboard .row -- cgit v1.2.3 From 63339834ec520efae48f16f4d16b90d74e7bcdfd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 12:36:25 +0100 Subject: Added labels with the current status. --- .../_switchboard_entry.html.haml | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/views/switchboard_entries/_switchboard_entry.html.haml b/app/views/switchboard_entries/_switchboard_entry.html.haml index 2902a83..5608757 100644 --- a/app/views/switchboard_entries/_switchboard_entry.html.haml +++ b/app/views/switchboard_entries/_switchboard_entry.html.haml @@ -11,16 +11,22 @@ %p %small = truncate(switchboard_entry.to_s, :length => 10) - %span{:class => "label #{(switchboard_entry.sip_account.registration ? '' : 'label-inverse')}"} - - if !switchboard_entry.sip_account.registration + %br + - if !switchboard_entry.sip_account.registration + %span.label.label-inverse %i.icon-ban-circle.icon-white - - if switchboard_entry.sip_account.phone_numbers.count > 1 - - phone_numbers = [] - - switchboard_entry.sip_account.phone_numbers.order(:position).each do |phone_number| - - if phone_number.number.length < 6 - - phone_numbers << phone_number - - if phone_numbers.size == 0 - - phone_numbers = switchboard_entry.sip_account.phone_numbers.order(:position) - - else - - phone_numbers = switchboard_entry.sip_account.phone_numbers - = render 'phone_numbers/listing', :phone_numbers => phone_numbers + - else + - if switchboard_entry.sip_account.call_legs(:where => ["HELD", "ACTIVE"]).size != 0 + %span.label.label-success + %i.icon-user.icon-white + - if switchboard_entry.sip_account.call_legs(:where => ["RINGING"]).size != 0 + %span.label.label-info + %i.icon-bell.icon-white + - if switchboard_entry.sip_account.non_e164_phone_numbers.size == 0 + - phone_numbers = switchboard_entry.sip_account.phone_numbers + - else + - phone_numbers = switchboard_entry.sip_account.non_e164_phone_numbers + + - phone_numbers.each do |phone_number| + %span.label + = phone_number.number -- cgit v1.2.3 From b29f5e637816aeca6f5cc7c9acb3f380469d1630 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Sun, 10 Mar 2013 14:33:40 +0100 Subject: fix link --- app/views/users/_switchboards.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_switchboards.html.haml b/app/views/users/_switchboards.html.haml index f79d6b8..8dca15f 100644 --- a/app/views/users/_switchboards.html.haml +++ b/app/views/users/_switchboards.html.haml @@ -4,4 +4,4 @@ %h2= t('switchboards.index.page_title') - if can?( :index, Switchboard ) && user.switchboards.count > 0 = render :partial => "switchboards/index_core", :locals => {:switchboards => user.switchboards, :user => user} - = render :partial => 'shared/create_link', :locals => {:parent => user, :child_class => Conference} \ No newline at end of file + = render :partial => 'shared/create_link', :locals => {:parent => user, :child_class => Switchboard} \ No newline at end of file -- cgit v1.2.3 From 3004ad318aecab81d8d3fb451901efc4d485e9ab Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 18:21:38 +0100 Subject: Fixed a migration. #231 --- db/migrate/20130309055700_change_perimeter_gs_parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20130309055700_change_perimeter_gs_parameters.rb b/db/migrate/20130309055700_change_perimeter_gs_parameters.rb index 6e29bd0..7973ee0 100644 --- a/db/migrate/20130309055700_change_perimeter_gs_parameters.rb +++ b/db/migrate/20130309055700_change_perimeter_gs_parameters.rb @@ -1,6 +1,6 @@ class ChangePerimeterGsParameters < ActiveRecord::Migration def up - GsParameter.where(:entity => 'perimeter', :section => 'bad_headers_register', :name => 'from_user').first.update_attributes(:value => '^%d+$', :class_type => 'String') + GsParameter.find_or_create_by_entity_and_section_and_name('perimeter', 'bad_headers_register', 'from_user').update_attributes(:value => '^%d+$', :class_type => 'String') GsParameter.where(:entity => 'perimeter', :section => 'bad_headers_register', :name => 'to_user').first.update_attributes(:value => '^%d+$', :class_type => 'String') GsParameter.where(:entity => 'perimeter', :section => 'checks_call', :name => 'check_bad_headers').first.update_attributes(:value => '20', :class_type => 'Integer') -- cgit v1.2.3 From b9aeac77779f7a9ae0e51b8d95adc7d542e09ece Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 18:32:13 +0100 Subject: Small fixes. --- app/views/switchboard_entries/_index_core.html.haml | 19 ++++++++++--------- .../switchboard_entries/_switchboard_entry.html.haml | 11 +++-------- app/views/users/_switchboards.html.haml | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/views/switchboard_entries/_index_core.html.haml b/app/views/switchboard_entries/_index_core.html.haml index 406db71..d647626 100644 --- a/app/views/switchboard_entries/_index_core.html.haml +++ b/app/views/switchboard_entries/_index_core.html.haml @@ -5,12 +5,13 @@ %th= t('switchboard_entries.index.name') %th - %tbody{ :id => "switchboard_entries", :'data-update-url' => sort_switchboard_switchboard_entries_path(switchboard_entries.first.switchboard) } - - for switchboard_entry in switchboard_entries - = content_tag_for :tr, switchboard_entry do - %td - %span.handle - %i.icon-resize-vertical - %td= switchboard_entry.sip_account - %td= switchboard_entry.name - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => switchboard_entry.switchboard, :child => switchboard_entry} \ No newline at end of file + - if switchboard_entries.any? + %tbody{ :id => "switchboard_entries", :'data-update-url' => sort_switchboard_switchboard_entries_path(switchboard_entries.first.switchboard) } + - for switchboard_entry in switchboard_entries + = content_tag_for :tr, switchboard_entry do + %td + %span.handle + %i.icon-resize-vertical + %td= switchboard_entry.sip_account + %td= switchboard_entry.name + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => switchboard_entry.switchboard, :child => switchboard_entry} \ No newline at end of file diff --git a/app/views/switchboard_entries/_switchboard_entry.html.haml b/app/views/switchboard_entries/_switchboard_entry.html.haml index 5608757..8d8e747 100644 --- a/app/views/switchboard_entries/_switchboard_entry.html.haml +++ b/app/views/switchboard_entries/_switchboard_entry.html.haml @@ -21,12 +21,7 @@ %i.icon-user.icon-white - if switchboard_entry.sip_account.call_legs(:where => ["RINGING"]).size != 0 %span.label.label-info - %i.icon-bell.icon-white - - if switchboard_entry.sip_account.non_e164_phone_numbers.size == 0 - - phone_numbers = switchboard_entry.sip_account.phone_numbers - - else - - phone_numbers = switchboard_entry.sip_account.non_e164_phone_numbers - - - phone_numbers.each do |phone_number| + %i.icon-bell.icon-white + - if switchboard_entry.sip_account.phone_numbers.any? %span.label - = phone_number.number + = switchboard_entry.sip_account.phone_numbers.first.number diff --git a/app/views/users/_switchboards.html.haml b/app/views/users/_switchboards.html.haml index 8dca15f..183b6ae 100644 --- a/app/views/users/_switchboards.html.haml +++ b/app/views/users/_switchboards.html.haml @@ -1,6 +1,6 @@ -# Switchboards -# -- if (can?( :index, Switchboard ) && user.switchboards.any? ) || can?( :create, Switchboard ) +- if SipAccount.any? && (can?( :index, Switchboard ) && user.switchboards.any? ) || can?( :create, Switchboard ) %h2= t('switchboards.index.page_title') - if can?( :index, Switchboard ) && user.switchboards.count > 0 = render :partial => "switchboards/index_core", :locals => {:switchboards => user.switchboards, :user => user} -- cgit v1.2.3 From beb9e66a5b4e2744435f2c1f301828b68a58c96a Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 19:11:13 +0100 Subject: Indicate a new voicemail in the navigation bar. --- app/controllers/trigger_controller.rb | 4 ++++ app/views/layouts/_navbar.html.haml | 4 ++++ app/views/layouts/application.html.haml | 1 + app/views/trigger/voicemail.html.erb | 4 ---- 4 files changed, 9 insertions(+), 4 deletions(-) delete mode 100644 app/views/trigger/voicemail.html.erb diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 5e836c4..1a5bfca 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -42,6 +42,10 @@ class TriggerController < ApplicationController end end + # Indicate a new voicemail in the navigation bar. + # + PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_indicator').hide.delay(250).show('slow').hide.delay(250).show('slow');") + render( :status => 200, :layout => false, diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 8004c0e..fe5f48f 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -22,7 +22,11 @@ =t("call_histories.index.page_title") %li %a{:href => sip_account_voicemail_messages_path(current_user.sip_accounts.first)} + %i.icon-star.icon-white{:id => 'new_voicemail_indicator'} =t("voicemail_messages.index.page_title") + :javascript + $("#new_voicemail_indicator").hide() + = subscribe_to "/users/#{current_user.id}/messages/new" - if current_user %ul.nav.pull-right diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index eab6096..027f837 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -36,4 +36,5 @@ .span12 %hr/ = render 'layouts/footer' + / /container diff --git a/app/views/trigger/voicemail.html.erb b/app/views/trigger/voicemail.html.erb deleted file mode 100644 index 9bafe17..0000000 --- a/app/views/trigger/voicemail.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -

Trigger#voicemail

-

Find me in app/views/trigger/voicemail.html.erb

- -<%= debug(params) %> -- cgit v1.2.3