summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-16 16:32:59 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-16 16:32:59 +0100
commit0ee17f52f8ad337c1240b4c55dbd8f6c6c74dc90 (patch)
tree1016d6e8f1d35629d82ef462fed20827d17c4e3d
parent225a812d5f2da7dc205c021a571ff3c6d5307f20 (diff)
Fixed routes and breadcrumbs. #106
-rw-r--r--app/controllers/call_routes_controller.rb19
-rw-r--r--app/controllers/route_elements_controller.rb36
-rw-r--r--app/models/call_route.rb7
-rw-r--r--app/models/route_element.rb5
-rw-r--r--app/views/route_elements/_form.html.haml2
-rw-r--r--app/views/route_elements/_form_core.html.haml1
-rw-r--r--app/views/route_elements/_index_core.html.haml4
-rw-r--r--app/views/route_elements/index.html.haml2
-rw-r--r--app/views/route_elements/show.html.haml5
-rw-r--r--config/routes.rb6
-rw-r--r--db/schema.rb25
11 files changed, 82 insertions, 30 deletions
diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb
index 631339b..41abe6d 100644
--- a/app/controllers/call_routes_controller.rb
+++ b/app/controllers/call_routes_controller.rb
@@ -1,14 +1,15 @@
class CallRoutesController < ApplicationController
+ load_and_authorize_resource :call_route
+
+ before_filter :spread_breadcrumbs
+
def index
- @call_routes = CallRoute.all
end
def show
- @call_route = CallRoute.find(params[:id])
end
def new
- @call_route = CallRoute.new
end
def create
@@ -21,11 +22,9 @@ class CallRoutesController < ApplicationController
end
def edit
- @call_route = CallRoute.find(params[:id])
end
def update
- @call_route = CallRoute.find(params[:id])
if @call_route.update_attributes(params[:call_route])
redirect_to @call_route, :notice => t('call_routes.controller.successfuly_updated')
else
@@ -34,8 +33,16 @@ class CallRoutesController < ApplicationController
end
def destroy
- @call_route = CallRoute.find(params[:id])
@call_route.destroy
redirect_to call_routes_url, :notice => t('call_routes.controller.successfuly_destroyed')
end
+
+ private
+ def spread_breadcrumbs
+ add_breadcrumb t("call_routes.index.page_title"), call_routes_path
+ if @call_route && !@call_route.new_record?
+ add_breadcrumb @call_route, call_route_path(@call_route)
+ end
+ end
+
end
diff --git a/app/controllers/route_elements_controller.rb b/app/controllers/route_elements_controller.rb
index 595a20d..699fcc6 100644
--- a/app/controllers/route_elements_controller.rb
+++ b/app/controllers/route_elements_controller.rb
@@ -1,41 +1,57 @@
class RouteElementsController < ApplicationController
+ load_and_authorize_resource :call_route
+ load_and_authorize_resource :route_element, :through => [:call_route]
+
+ before_filter :spread_breadcrumbs
+
def index
- @route_elements = RouteElement.all
+ @route_elements = @call_route.route_elements
end
def show
- @route_element = RouteElement.find(params[:id])
+ @route_element = @call_route.route_elements.find(params[:id])
end
def new
- @route_element = RouteElement.new
+ @route_element = @call_route.route_elements.build
end
def create
- @route_element = RouteElement.new(params[:route_element])
+ @route_element = @call_route.route_elements.build(params[:route_element])
if @route_element.save
- redirect_to @route_element, :notice => t('route_elements.controller.successfuly_created')
+ redirect_to [@call_route, @route_element], :notice => t('route_elements.controller.successfuly_created')
else
render :new
end
end
def edit
- @route_element = RouteElement.find(params[:id])
+ @route_element = @call_route.route_elements.find(params[:id])
end
def update
- @route_element = RouteElement.find(params[:id])
+ @route_element = @call_route.route_elements.find(params[:id])
if @route_element.update_attributes(params[:route_element])
- redirect_to @route_element, :notice => t('route_elements.controller.successfuly_updated')
+ redirect_to [@call_route, @route_element], :notice => t('route_elements.controller.successfuly_updated')
else
render :edit
end
end
def destroy
- @route_element = RouteElement.find(params[:id])
+ @route_element = @call_route.route_elements.find(params[:id])
@route_element.destroy
- redirect_to route_elements_url, :notice => t('route_elements.controller.successfuly_destroyed')
+ redirect_to call_route_route_elements_path(@call_route), :notice => t('route_elements.controller.successfuly_destroyed')
end
+
+ private
+ def spread_breadcrumbs
+ add_breadcrumb t("call_routes.index.page_title"), call_routes_path
+ add_breadcrumb @call_route, call_route_path(@call_route)
+ add_breadcrumb t("route_elements.index.page_title"), call_route_route_elements_path(@call_route)
+ if @route_element && !@route_element.new_record?
+ add_breadcrumb @route_element, call_route_route_element_path(@call_route, @route_element)
+ end
+ end
+
end
diff --git a/app/models/call_route.rb b/app/models/call_route.rb
index eba247c..de0f68a 100644
--- a/app/models/call_route.rb
+++ b/app/models/call_route.rb
@@ -2,4 +2,11 @@ class CallRoute < ActiveRecord::Base
attr_accessible :table, :name, :endpoint_type, :endpoint_id, :position
has_many :route_elements, :dependent => :destroy
+
+ validates :name,
+ :presence => true
+
+ def to_s
+ name.to_s
+ end
end
diff --git a/app/models/route_element.rb b/app/models/route_element.rb
index e845f24..11bb54a 100644
--- a/app/models/route_element.rb
+++ b/app/models/route_element.rb
@@ -2,4 +2,9 @@ class RouteElement < ActiveRecord::Base
attr_accessible :call_route_id, :var_in, :var_out, :pattern, :replacement, :action, :mandatory, :position
belongs_to :call_route
+
+ def to_s
+ "#{var_in} #{var_out}"
+ end
+
end
diff --git a/app/views/route_elements/_form.html.haml b/app/views/route_elements/_form.html.haml
index cfa4c6b..8feacaa 100644
--- a/app/views/route_elements/_form.html.haml
+++ b/app/views/route_elements/_form.html.haml
@@ -1,4 +1,4 @@
-= simple_form_for(@route_element) do |f|
+= simple_form_for([@call_route, @route_element]) do |f|
= f.error_notification
= render "form_core", :f => f
diff --git a/app/views/route_elements/_form_core.html.haml b/app/views/route_elements/_form_core.html.haml
index 7697cb0..133d1df 100644
--- a/app/views/route_elements/_form_core.html.haml
+++ b/app/views/route_elements/_form_core.html.haml
@@ -1,5 +1,4 @@
.inputs
- = f.input :call_route_id, :label => t('route_elements.form.call_route_id.label'), :hint => conditional_hint('route_elements.form.call_route_id.hint')
= f.input :var_in, :label => t('route_elements.form.var_in.label'), :hint => conditional_hint('route_elements.form.var_in.hint')
= f.input :var_out, :label => t('route_elements.form.var_out.label'), :hint => conditional_hint('route_elements.form.var_out.hint')
= f.input :pattern, :label => t('route_elements.form.pattern.label'), :hint => conditional_hint('route_elements.form.pattern.hint')
diff --git a/app/views/route_elements/_index_core.html.haml b/app/views/route_elements/_index_core.html.haml
index 63665fd..c1df665 100644
--- a/app/views/route_elements/_index_core.html.haml
+++ b/app/views/route_elements/_index_core.html.haml
@@ -1,6 +1,5 @@
%table
%tr
- %th= t('route_elements.index.call_route_id')
%th= t('route_elements.index.var_in')
%th= t('route_elements.index.var_out')
%th= t('route_elements.index.pattern')
@@ -12,7 +11,6 @@
- reset_cycle
- for route_element in route_elements
%tr{:class => cycle('odd', 'even')}
- %td= route_element.call_route_id
%td= route_element.var_in
%td= route_element.var_out
%td= route_element.pattern
@@ -20,4 +18,4 @@
%td= route_element.action
%td= route_element.mandatory
%td= route_element.position
- =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => route_element} \ No newline at end of file
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => @call_route, :child => route_element} \ No newline at end of file
diff --git a/app/views/route_elements/index.html.haml b/app/views/route_elements/index.html.haml
index b05236b..8a6f7bc 100644
--- a/app/views/route_elements/index.html.haml
+++ b/app/views/route_elements/index.html.haml
@@ -3,4 +3,4 @@
- if @route_elements && @route_elements.count > 0
= render "index_core", :route_elements => @route_elements
-= render :partial => 'shared/create_link', :locals => {:child_class => RouteElement} \ No newline at end of file
+= render :partial => 'shared/create_link', :locals => {:parent => @call_route, :child_class => RouteElement} \ No newline at end of file
diff --git a/app/views/route_elements/show.html.haml b/app/views/route_elements/show.html.haml
index a439353..8e41f80 100644
--- a/app/views/route_elements/show.html.haml
+++ b/app/views/route_elements/show.html.haml
@@ -1,9 +1,6 @@
- title t("route_elements.show.page_title")
%p
- %strong= t('route_elements.show.call_route_id') + ":"
- = @route_element.call_route_id
-%p
%strong= t('route_elements.show.var_in') + ":"
= @route_element.var_in
%p
@@ -25,4 +22,4 @@
%strong= t('route_elements.show.position') + ":"
= @route_element.position
-= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @route_element } \ No newline at end of file
+= render :partial => 'shared/show_edit_destroy_part', :locals => {:parent => @call_route, :child => @route_element } \ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 3874170..249c947 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,8 @@
Gemeinschaft42c::Application.routes.draw do
- resources :route_elements
-
- resources :call_routes
+ resources :call_routes do
+ resources :route_elements
+ end
resources :gateways do
resources :gateway_settings
diff --git a/db/schema.rb b/db/schema.rb
index bc51504..898faac 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130113090705) do
+ActiveRecord::Schema.define(:version => 20130116133433) do
create_table "access_authorizations", :force => true do |t|
t.string "access_authorizationable_type"
@@ -176,6 +176,16 @@ ActiveRecord::Schema.define(:version => 20130113090705) do
t.datetime "updated_at", :null => false
end
+ create_table "call_routes", :force => true do |t|
+ t.string "table"
+ t.string "name"
+ t.string "endpoint_type"
+ t.integer "endpoint_id"
+ t.integer "position"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "calls", :id => false, :force => true do |t|
t.string "call_uuid"
t.string "call_created", :limit => 128
@@ -806,6 +816,19 @@ ActiveRecord::Schema.define(:version => 20130113090705) do
t.datetime "updated_at", :null => false
end
+ create_table "route_elements", :force => true do |t|
+ t.integer "call_route_id"
+ t.string "var_in"
+ t.string "var_out"
+ t.string "pattern"
+ t.string "replacement"
+ t.string "action"
+ t.boolean "mandatory"
+ t.integer "position"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"