diff options
| author | Xinhui | 2016-11-07 16:03:49 +0100 |
|---|---|---|
| committer | Xinhui | 2016-11-07 16:03:49 +0100 |
| commit | 360bf515230f76d836014df4a1b0623a64475915 (patch) | |
| tree | 820ce6ecdfc37593f76efb3457a80f4fe9dd8bf7 /app | |
| parent | e464f9be6857a0e51f12166d9cf8e1128b41f56c (diff) | |
| download | chouette-core-360bf515230f76d836014df4a1b0623a64475915.tar.bz2 | |
Workbench assocation + policy in views
Refs #1786
Diffstat (limited to 'app')
19 files changed, 126 insertions, 96 deletions
diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb index 104deba9f..a369488ba 100644 --- a/app/controllers/referential_companies_controller.rb +++ b/app/controllers/referential_companies_controller.rb @@ -27,7 +27,7 @@ class ReferentialCompaniesController < ChouetteController end def collection - @q = referential.companies.search(params[:q]) + @q = referential.workbench.companies.search(params[:q]) @companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) end diff --git a/app/controllers/referential_group_of_lines_controller.rb b/app/controllers/referential_group_of_lines_controller.rb index d40fd6090..4decef558 100644 --- a/app/controllers/referential_group_of_lines_controller.rb +++ b/app/controllers/referential_group_of_lines_controller.rb @@ -55,7 +55,7 @@ class ReferentialGroupOfLinesController < ChouetteController end def collection - @q = referential.group_of_lines.search(params[:q]) + @q = referential.workbench.group_of_lines.search(params[:q]) @group_of_lines ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) end diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index a566f440e..29d8fa664 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -82,7 +82,7 @@ class ReferentialLinesController < ChouetteController params[:q]["group_of_lines_id_blank"] = "1" end - @q = referential.lines.search(params[:q]) + @q = referential.workbench.lines.search(params[:q]) @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) end diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb index 2d3f4ad6b..00c680c65 100644 --- a/app/controllers/referential_networks_controller.rb +++ b/app/controllers/referential_networks_controller.rb @@ -35,7 +35,7 @@ class ReferentialNetworksController < ChouetteController end def collection - @q = referential.networks.search(params[:q]) + @q = referential.workbench.networks.search(params[:q]) @networks ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) end diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 8f6a1565a..1f55b1de8 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -26,6 +26,7 @@ class StopAreasController < BreadcrumbController end def add_children + authorize stop_area @stop_area = stop_area @children = stop_area.children build_breadcrumb :edit diff --git a/app/models/workbench.rb b/app/models/workbench.rb index 3525fe55e..adc0041dd 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -3,6 +3,12 @@ class Workbench < ActiveRecord::Base belongs_to :line_referential belongs_to :stop_area_referential + has_many :lines, through: :line_referential + has_many :networks, through: :line_referential + has_many :companies, through: :line_referential + has_many :group_of_lines, through: :line_referential + has_many :stop_areas, through: :stop_area_referential + validates :name, presence: true validates :organisation, presence: true diff --git a/app/views/referential_companies/_company.html.slim b/app/views/referential_companies/_company.html.slim index 06e13764e..e6090540d 100644 --- a/app/views/referential_companies/_company.html.slim +++ b/app/views/referential_companies/_company.html.slim @@ -2,10 +2,12 @@ .panel-heading .panel-title.clearfix span.pull-right - = link_to edit_referential_company_path(@referential, company), class: 'btn btn-default btn-sm' do - span.fa.fa-pencil - = link_to referential_company_path(@referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do - span.fa.fa-trash-o + - if policy(company).update? + = link_to edit_referential_company_path(@referential, company), class: 'btn btn-default btn-sm' do + span.fa.fa-pencil + - if policy(company).destroy? + = link_to referential_company_path(@referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do + span.fa.fa-trash-o h5 = link_to [@referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do span.name @@ -13,4 +15,4 @@ .panel-body p = company.human_attribute_name('code') - = company.code
\ No newline at end of file + = company.code diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim index b32f206ca..6af6d7fc8 100644 --- a/app/views/referential_companies/index.html.slim +++ b/app/views/referential_companies/index.html.slim @@ -19,6 +19,7 @@ - content_for :sidebar do ul.actions - li - = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' - br
\ No newline at end of file + - if policy(Chouette::Company).create? + li + = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + br diff --git a/app/views/referential_companies/show.html.slim b/app/views/referential_companies/show.html.slim index a445dad61..a1a767bbd 100644 --- a/app/views/referential_companies/show.html.slim +++ b/app/views/referential_companies/show.html.slim @@ -44,12 +44,15 @@ - content_for :sidebar do ul.actions - li - = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' - li - = link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), class: 'edit' - li - = link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' - br - - = creation_tag(@company)
\ No newline at end of file + - if policy(Chouette::Company).create? + li + = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + - if policy(@company).update? + li + = link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), class: 'edit' + - if policy(@company).destroy? + li + = link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' + br + + = creation_tag(@company) diff --git a/app/views/referential_lines/_line.html.slim b/app/views/referential_lines/_line.html.slim index 0dffb50aa..1c8b8eaa8 100644 --- a/app/views/referential_lines/_line.html.slim +++ b/app/views/referential_lines/_line.html.slim @@ -3,7 +3,7 @@ ul.ce-LineBlock-header-list li = check_box_tag "ids[]", line.id, false, class: "multiple_selection", style: "display: none;" - + - if line.number && line.number.length <= 3 span.label.label-default.line_number style="#{number_style(line)}" = line.number @@ -13,11 +13,11 @@ h5.ce-LineBlock-header-title = truncate(line.name, length: 24) li - - if edit + - if edit && policy(Chouette::Line).update? = link_to edit_referential_line_path(@referential, line), class: 'btn btn-default btn-sm' do span.fa.fa-pencil - - if delete + - if delete && policy(Chouette::Line).destroy? = link_to referential_line_path(@referential, line), method: :delete, data: { confirm: t('lines.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do span.fa.fa-trash-o @@ -46,4 +46,4 @@ = line.human_attribute_name('group_of_line') = link_to_if( line.group_of_lines.first, line.group_of_lines.first.name, referential_group_of_line_path(@referential, line.group_of_lines.first), :title => "#{line.human_attribute_name('group_of_line')} #{line.group_of_lines.first.name}") - else - = t('lines.form.several_group_of_lines', :count => line.group_of_lines.count)
\ No newline at end of file + = t('lines.form.several_group_of_lines', :count => line.group_of_lines.count) diff --git a/app/views/referential_lines/index.html.slim b/app/views/referential_lines/index.html.slim index 4922cde85..5647bde0c 100644 --- a/app/views/referential_lines/index.html.slim +++ b/app/views/referential_lines/index.html.slim @@ -24,25 +24,27 @@ - content_for :sidebar do ul.actions - li - = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'add' + - if policy(Chouette::Line).create? + li + = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'add' - #multiple_selection_menu - h4> = t(".multi_selection") + - if policy(Chouette::Line).destroy? + #multiple_selection_menu + h4> = t(".multi_selection") - .disabled - a.enable href="#" - = t(".multi_selection_enable") + .disabled + a.enable href="#" + = t(".multi_selection_enable") - .enabled style="display: none;" - a.disable href="#" - = t(".multi_selection_disable") + .enabled style="display: none;" + a.disable href="#" + = t(".multi_selection_disable") - ul.actions - = link_to t(".delete_selected"), referential_lines_path(@referential), "data-multiple-method" => "delete", :class => "remove", "confirmation-text" => t("lines.actions.destroy_selection_confirm") + ul.actions + = link_to t(".delete_selected"), referential_lines_path(@referential), "data-multiple-method" => "delete", :class => "remove", "confirmation-text" => t("lines.actions.destroy_selection_confirm") a.select_all href="#" = t(".select_all") = " | " a.deselect_all href="#" - = t(".deselect_all")
\ No newline at end of file + = t(".deselect_all") diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index ae8314a14..495f0bda7 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -121,15 +121,19 @@ h3.routes = t('.itineraries') - content_for :sidebar do ul.actions - li - = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'add' - li - = link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), class: 'edit' - li - = link_to t('lines.actions.destroy'), referential_line_path(@referential, @line), method: :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, class: 'remove' + - if policy(Chouette::Line).create? + li + = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'add' + - if policy(@line).update? + li + = link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), class: 'edit' + - if policy(@line).destroy? + li + = link_to t('lines.actions.destroy'), referential_line_path(@referential, @line), method: :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, class: 'remove' - if !@line.hub_restricted? || (@line.hub_restricted? && @line.routes.size < 2) - li - = link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), class: 'add' + / FIXME #825 + li + / = link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), class: 'add' - = creation_tag(@line)
\ No newline at end of file + = creation_tag(@line) diff --git a/app/views/referential_networks/_network.html.slim b/app/views/referential_networks/_network.html.slim index dc1aa6b5c..f7c7b66eb 100644 --- a/app/views/referential_networks/_network.html.slim +++ b/app/views/referential_networks/_network.html.slim @@ -2,13 +2,14 @@ .panel-heading .panel-title.clearfix span.pull-right - = link_to edit_referential_network_path(@referential, network), class: 'btn btn-default btn-sm' do - span.fa.fa-pencil - - = link_to referential_network_path(@referential, network), method: :delete, :data => { :confirm => t('networks.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do - span.fa.fa-trash-o + - if policy(network).update? + = link_to edit_referential_network_path(@referential, network), class: 'btn btn-default btn-sm' do + span.fa.fa-pencil + - if policy(network).destroy? + = link_to referential_network_path(@referential, network), method: :delete, :data => { :confirm => t('networks.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do + span.fa.fa-trash-o h5 = link_to [@referential, network], class: 'preview', title: "#{Chouette::Network.model_name.human.capitalize} #{network.name}" do span.name - = truncate(network.name, :length => 20)
\ No newline at end of file + = truncate(network.name, :length => 20) diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim index f3ead931e..e3e9f2a07 100644 --- a/app/views/referential_networks/index.html.slim +++ b/app/views/referential_networks/index.html.slim @@ -19,5 +19,6 @@ - content_for :sidebar do ul.actions li + - if policy(Chouette::Network).create? = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' - br
\ No newline at end of file + br diff --git a/app/views/referential_networks/show.html.slim b/app/views/referential_networks/show.html.slim index 936f6a4a8..d579d311b 100644 --- a/app/views/referential_networks/show.html.slim +++ b/app/views/referential_networks/show.html.slim @@ -36,12 +36,15 @@ - content_for :sidebar do ul.actions - li - = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' - li - = link_to t('networks.actions.edit'), edit_referential_network_path(@referential, @network), class: 'edit' - li - = link_to t('networks.actions.destroy'), referential_network_path(@referential, @network), method: :delete, data: { :confirm => t('networks.actions.destroy_confirm')}, class: 'remove' - br - - = creation_tag(@network)
\ No newline at end of file + - if policy(Chouette::Network).create? + li + = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' + - if policy(@network).update? + li + = link_to t('networks.actions.edit'), edit_referential_network_path(@referential, @network), class: 'edit' + - if policy(@network).destroy? + li + = link_to t('networks.actions.destroy'), referential_network_path(@referential, @network), method: :delete, data: { :confirm => t('networks.actions.destroy_confirm')}, class: 'remove' + br + + = creation_tag(@network) diff --git a/app/views/referential_stop_areas/_genealogical.html.slim b/app/views/referential_stop_areas/_genealogical.html.slim index a44884c92..162c24d9b 100644 --- a/app/views/referential_stop_areas/_genealogical.html.slim +++ b/app/views/referential_stop_areas/_genealogical.html.slim @@ -5,7 +5,7 @@ h3 = genealogical_title = link_to([@referential, @stop_area.parent], :title => t("area_types.label.#{@stop_area.parent.stop_area_type}") + "#{@stop_area.parent.name}") do = image_tag "map/" + @stop_area.parent.stop_area_type + ".png" = @stop_area.parent.name - + .link = image_tag "icons/link.png" @@ -18,7 +18,7 @@ h3 = genealogical_title .link = image_tag "icons/link.png" - else - .no_parent = + .no_parent .target = image_tag "map/" + @stop_area.stop_area_type + ".png" @@ -51,4 +51,4 @@ h3 = genealogical_title span = route.line.number = link_to([@referential, route.line , route]) do - span = route.name
\ No newline at end of file + span = route.name diff --git a/app/views/referential_stop_areas/_stop_area.html.slim b/app/views/referential_stop_areas/_stop_area.html.slim index f94bd319e..bb9ed7ce3 100644 --- a/app/views/referential_stop_areas/_stop_area.html.slim +++ b/app/views/referential_stop_areas/_stop_area.html.slim @@ -2,11 +2,13 @@ .panel-heading .panel-title.clearfix span.pull-right - = link_to edit_referential_stop_area_path(@referential, stop_area), class: 'btn btn-default btn-sm' do - span.fa.fa-pencil + - if policy(stop_area).update? + = link_to edit_referential_stop_area_path(@referential, stop_area), class: 'btn btn-default btn-sm' do + span.fa.fa-pencil - = link_to referential_stop_area_path(@referential, stop_area), method: :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do - span.fa.fa-trash-o + - if policy(stop_area).destroy? + = link_to referential_stop_area_path(@referential, stop_area), method: :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do + span.fa.fa-trash-o h5 = link_to([@referential, stop_area], class: "preview", :title => t("area_types.label.#{stop_area.stop_area_type}") + " #{stop_area.name}") do @@ -34,11 +36,11 @@ - else - stop_area.routing_lines.each do |line| span.label.label-default.line = line.number - + - else = "#{t('.lines')} : " - if stop_area.lines.blank? = t(".no_object") - else - stop_area.lines.each do |line| - span.label.label-default.line = line.number || truncate( line.name, length: 4 )
\ No newline at end of file + span.label.label-default.line = line.number || truncate( line.name, length: 4 ) diff --git a/app/views/referential_stop_areas/index.html.slim b/app/views/referential_stop_areas/index.html.slim index 85bd15d20..1b634b09c 100644 --- a/app/views/referential_stop_areas/index.html.slim +++ b/app/views/referential_stop_areas/index.html.slim @@ -26,7 +26,8 @@ - content_for :sidebar do ul.actions + - if policy(Chouette::StopArea).create? + li + = link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), class: 'add' li - = link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), class: 'add' - li - / = link_to t('stop_areas.actions.default_geometry'), default_geometry_referential_stop_areas_path(@referential), :method => :put, :class => "calculator"
\ No newline at end of file + / = link_to t('stop_areas.actions.default_geometry'), default_geometry_referential_stop_areas_path(@referential), :method => :put, :class => "calculator" diff --git a/app/views/referential_stop_areas/show.html.slim b/app/views/referential_stop_areas/show.html.slim index 76414edf0..2278c4812 100644 --- a/app/views/referential_stop_areas/show.html.slim +++ b/app/views/referential_stop_areas/show.html.slim @@ -109,7 +109,7 @@ p.after_map .genealogical.clearfix - = render "stop_areas/genealogical" + = render "referential_stop_areas/genealogical" - if manage_access_points div @@ -122,22 +122,25 @@ p.after_map tr td ul.actions - li - = link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), class: 'add' - li - = link_to t('stop_areas.actions.edit'), edit_referential_stop_area_path(@referential, @stop_area), class: 'edit' - li - = link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), method: :delete, data: { :confirm => t('stop_areas.actions.destroy_confirm') }, class: 'remove' + - if policy(Chouette::StopArea).new? + li + = link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), class: 'add' + - if policy(@stop_area).update? + li + = link_to t('stop_areas.actions.edit'), edit_referential_stop_area_path(@referential, @stop_area), class: 'edit' + - if policy(@stop_area).destroy? + li + = link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), method: :delete, data: { :confirm => t('stop_areas.actions.destroy_confirm') }, class: 'remove' - if manage_itl - tr - td - h4 = t('.itl_managment') - ul.actions - li - = link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), class: 'add_routing_lines' - li - = link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), class: 'add_routing_stops' + / tr + / td + / h4 = t('.itl_managment') + / ul.actions + / li + / = link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), class: 'add_routing_lines' + / li + / = link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), class: 'add_routing_stops' - else tr @@ -145,17 +148,17 @@ p.after_map h4 = t('.stop_managment') ul.actions li - = link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), class: 'parent' + / = link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), class: 'parent' - if @stop_area.parent == nil li - = link_to t('stop_areas.actions.clone_as_parent'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, hierarchy: 'parent'), class: 'clone' + / = link_to t('stop_areas.actions.clone_as_parent'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, hierarchy: 'parent'), class: 'clone' - if manage_children li - = link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), class: 'children' + / = link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), class: 'children' li - = link_to t('stop_areas.actions.clone_as_child'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, hierarchy: 'child'), class: 'clone' + / = link_to t('stop_areas.actions.clone_as_child'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, hierarchy: 'child'), class: 'clone' - if manage_access_points tr @@ -163,9 +166,9 @@ p.after_map h4 = t(".access_managment") ul.actions li - = link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), class: 'add' + / = link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), class: 'add' li - = link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), class: 'access_link' + / = link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), class: 'access_link' br |
