summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-07 13:15:35 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-07 13:15:35 +0100
commitdb9dbf03d88cfbd68ce99a242730b9e870339539 (patch)
tree72947eddcb03f8a6ae6efd79a035bd9e761b4963
parent3e19646f46c772e10ed3d7a45e8c974ab23f625b (diff)
Added Switchboard scaffold.
-rw-r--r--app/controllers/switchboards_controller.rb65
-rw-r--r--app/helpers/switchboards_helper.rb2
-rw-r--r--app/models/call_route.rb2
-rw-r--r--app/models/switchboard.rb14
-rw-r--r--app/models/user.rb2
-rw-r--r--app/views/switchboards/_form.html.haml7
-rw-r--r--app/views/switchboards/_form_core.html.haml2
-rw-r--r--app/views/switchboards/_index_core.html.haml10
-rw-r--r--app/views/switchboards/edit.html.haml3
-rw-r--r--app/views/switchboards/index.html.haml8
-rw-r--r--app/views/switchboards/new.html.haml3
-rw-r--r--app/views/switchboards/show.html.haml12
-rw-r--r--config/locales/views/switchboards/de.yml45
-rw-r--r--config/locales/views/switchboards/en.yml45
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20130307104654_create_switchboards.rb13
-rw-r--r--test/functional/switchboards_controller_test.rb49
-rw-r--r--test/unit/switchboard_test.rb7
18 files changed, 290 insertions, 1 deletions
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