diff options
43 files changed, 584 insertions, 239 deletions
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index 9d33c6cb8..07a732fc9 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -15,6 +15,14 @@ class CompaniesController < BreadcrumbController          if collection.out_of_bounds?            redirect_to params.merge(:page => 1)          end + +        @companies = ModelDecorator.decorate( +          @companies, +          with: CompanyDecorator, +          context: { +            referential: line_referential +          } +        )        }        build_breadcrumb :index      end diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index ea8410c5b..d1f83340e 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -12,7 +12,12 @@ class NetworksController < BreadcrumbController    def show      @map = NetworkMap.new(resource).with_helpers(self) +      show! do +      @network = @network.decorate(context: { +        line_referential: line_referential +      }) +        build_breadcrumb :show      end    end @@ -31,6 +36,14 @@ class NetworksController < BreadcrumbController          if collection.out_of_bounds?            redirect_to params.merge(:page => 1)          end + +        @networks = ModelDecorator.decorate( +          @networks, +          with: NetworkDecorator, +          context: { +            line_referential: line_referential +          } +        )        }        build_breadcrumb :index      end diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb index e8b104d14..53dde93bb 100644 --- a/app/controllers/referential_companies_controller.rb +++ b/app/controllers/referential_companies_controller.rb @@ -13,6 +13,14 @@ class ReferentialCompaniesController < ChouetteController          if collection.out_of_bounds?            redirect_to params.merge(:page => 1)          end + +        @companies = ModelDecorator.decorate( +          @companies, +          with: CompanyDecorator, +          context: { +            referential: referential +          } +        )        }        build_breadcrumb :index      end diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index 4b4a822b4..1da64991d 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -10,18 +10,6 @@ class ReferentialLinesController < ChouetteController    belongs_to :referential -  def index -    @hide_group_of_line = referential.group_of_lines.empty? -    index! do |format| -      format.html { -        if collection.out_of_bounds? -          redirect_to params.merge(:page => 1) -        end -        build_breadcrumb :index -      } -    end -  end -    def show      @routes = resource.routes @@ -49,6 +37,14 @@ class ReferentialLinesController < ChouetteController      )      show! do +      @line = ReferentialLineDecorator.decorate( +        @line, +        context: { +          referential: referential, +          current_organisation: current_organisation +        } +      ) +        build_breadcrumb :show      end    end diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb index 30c7dd244..e0ce71ce4 100644 --- a/app/controllers/referential_networks_controller.rb +++ b/app/controllers/referential_networks_controller.rb @@ -10,7 +10,15 @@ class ReferentialNetworksController < ChouetteController    def show      @map = NetworkMap.new(resource).with_helpers(self) +      show! do +      @network = ReferentialNetworkDecorator.decorate( +        @network, +        context: { +          referential: referential +        } +      ) +        build_breadcrumb :show      end    end @@ -21,6 +29,14 @@ class ReferentialNetworksController < ChouetteController          if collection.out_of_bounds?            redirect_to params.merge(:page => 1)          end + +        @networks = ModelDecorator.decorate( +          @networks, +          with: ReferentialNetworkDecorator, +          context: { +            referential: referential +          } +        )        }        build_breadcrumb :index      end diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb index 4d33ebb2e..7519418e7 100644 --- a/app/controllers/referential_stop_areas_controller.rb +++ b/app/controllers/referential_stop_areas_controller.rb @@ -72,13 +72,16 @@ class ReferentialStopAreasController  < ChouetteController    def show      map.editable = false      @access_points = @stop_area.access_points +      show! do |format|        unless stop_area.position or params[:default] or params[:routing]          format.kml {            render :nothing => true, :status => :not_found          } -        end + +      @stop_area = @stop_area.decorate +        build_breadcrumb :show      end    end diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 9505a47f3..838c46168 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -27,6 +27,14 @@ class ReferentialsController < BreadcrumbController      show! do |format|        @referential = @referential.decorate        @reflines = lines_collection.paginate(page: params[:page], per_page: 10) +      @reflines = ModelDecorator.decorate( +        @reflines, +        with: ReferentialLineDecorator, +        context: { +          referential: referential, +          current_organisation: current_organisation +        } +      )        format.json {          render :json => { :lines_count => resource.lines.count, diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 4781d0d16..7ba2c1a58 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -47,6 +47,11 @@ class RoutesController < ChouetteController          line: @line        }) +      @route_sp = ModelDecorator.decorate( +        @route_sp, +        with: StopPointDecorator +      ) +        build_breadcrumb :show      end    end diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index c526e6348..6c3cb8a29 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -10,12 +10,29 @@ class RoutingConstraintZonesController < ChouetteController      belongs_to :line, parent_class: Chouette::Line    end +  def index +    index! do |format| +      @routing_constraint_zones = ModelDecorator.decorate( +        @routing_constraint_zones, +        with: RoutingConstraintZoneDecorator, +        context: { +          referential: referential, +          line: parent +        } +      ) + +      build_breadcrumb :index +    end +  end +    def show      show! do |format|        @routing_constraint_zone = @routing_constraint_zone.decorate(context: { -        referential: current_referential, -        line: parent.id +        referential: referential, +        line: parent        }) + +      build_breadcrumb :show      end    end diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index ae3edbd3e..cdb7c59ab 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -53,11 +53,18 @@ class StopAreasController < BreadcrumbController    def index      request.format.kml? ? @per_page = nil : @per_page = 12      @zip_codes = stop_area_referential.stop_areas.where("zip_code is NOT null").distinct.pluck(:zip_code) +      index! do |format|        format.html {          if collection.out_of_bounds?            redirect_to params.merge(:page => 1)          end + +        @stop_areas = ModelDecorator.decorate( +          @stop_areas, +          with: StopAreaDecorator +        ) +          build_breadcrumb :index        }      end @@ -90,6 +97,9 @@ class StopAreasController < BreadcrumbController          }        end + +      @stop_area = @stop_area.decorate +        build_breadcrumb :show      end    end diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index 030952483..402bd3ab6 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -13,7 +13,7 @@ class CompanyDecorator < Draper::Decorator    # Requires:    #   context: { -  #     line_referential: +  #     referential:    #   }    def action_links      links = [] @@ -23,7 +23,7 @@ class CompanyDecorator < Draper::Decorator        binding.pry        links << Link.new(          content: h.t('companies.actions.new'), -        href: h.new_line_referential_company_path(context[:line_referential]) +        href: h.new_line_referential_company_path(context[:referential])        )      end @@ -31,7 +31,7 @@ class CompanyDecorator < Draper::Decorator        links << Link.new(          content: h.t('companies.actions.edit'),          href: h.edit_line_referential_company_path( -          context[:line_referential], +          context[:referential],            object          )        ) @@ -41,7 +41,7 @@ class CompanyDecorator < Draper::Decorator        links << Link.new(          content: t('companies.actions.destroy'),          href: h.line_referential_company_path( -          context[:line_referential], +          context[:referential],            object          ),          method: :delete, diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb new file mode 100644 index 000000000..1f62fe512 --- /dev/null +++ b/app/decorators/network_decorator.rb @@ -0,0 +1,44 @@ +class NetworkDecorator < Draper::Decorator +  decorates Chouette::Network + +  delegate_all + +  # Requires: +  #   context: { +  #     line_referential: , +  #   } +  def action_links +    links = [] + +    if h.policy(Chouette::Network).create? +      links << Link.new( +        content: h.t('networks.actions.new'), +        href: h.new_line_referential_network_path(context[:line_referential]) +      ) +    end + +    if h.policy(object).update? +      links << Link.new( +        content: h.t('networks.actions.edit'), +        href: h.edit_line_referential_network_path( +          context[:line_referential], +          object +        ) +      ) +    end + +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content('networks.actions.destroy'), +        href: h.line_referential_network_path( +          context[:line_referential], +          object +        ), +        method: :delete, +        data: { confirm: t('networks.actions.destroy_confirm') } +      ) +    end + +    links +  end +end diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb new file mode 100644 index 000000000..55acf7ed9 --- /dev/null +++ b/app/decorators/referential_line_decorator.rb @@ -0,0 +1,64 @@ +class ReferentialLineDecorator < Draper::Decorator +  decorates Chouette::Line + +  delegate_all + +  # Requires: +  #   context: { +  #     referential: , +  #     current_organisation: +  #   } +  def action_links +    links = [] + +    links << Link.new( +      content: Chouette::Line.human_attribute_name(:footnotes), +      href: h.referential_line_footnotes_path(context[:referential], object) +    ) + +    links << Link.new( +      content: h.t('routing_constraint_zones.index.title'), +      href: h.referential_line_routing_constraint_zones_path( +        context[:referential], +        object +      ) +    ) + +    if h.policy(Chouette::Line).create? && +        context[:referential].organisation == context[:current_organisation] +      links << Link.new( +        content: h.t('actions.new'), +        href: h.new_referential_line_path(context[:referential]) +      ) +    end + +    if h.policy(object).update? +      links << Link.new( +        content: h.t('actions.edit'), +        href: h.edit_referential_line_path(context[:referential], object) +      ) +    end + +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content('actions.destroy'), +        href: h.referential_line_path(context[:referential], object), +        method: :delete, +        data: { confirm: t('lines.actions.destroy_confirm') } +      ) +    end + +    if !object.hub_restricted? || +        (object.hub_restricted? && object.routes.size < 2) +      if h.policy(Chouette::Route).create? && +          context[:referential].organisation == context[:current_organisation] +        links << Link.new( +          content: h.t('routes.actions.new'), +          href: h.new_referential_line_route_path(context[:referential], object) +        ) +      end +    end + +    links +  end +end diff --git a/app/decorators/referential_network_decorator.rb b/app/decorators/referential_network_decorator.rb new file mode 100644 index 000000000..9eb94c8d2 --- /dev/null +++ b/app/decorators/referential_network_decorator.rb @@ -0,0 +1,38 @@ +class ReferentialNetworkDecorator < Draper::Decorator +  decorates Chouette::Network + +  delegate_all + +  # Requires: +  #   context: { +  #     referential: , +  #   } +  def action_links +    links = [] + +    if h.policy(Chouette::Network).create? +      links << Link.new( +        content: h.t('networks.actions.new'), +        href: h.new_referential_network_path(context[:referential]) +      ) +    end + +    if h.policy(object).update? +      links << Link.new( +        content: h.t('networks.actions.edit'), +        href: h.edit_referential_network_path(context[:referential], object) +      ) +    end + +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content('networks.actions.destroy'), +        href: h.referential_network_path(context[:referential], object), +        method: :delete, +        data: { confirm: t('networks.actions.destroy_confirm') } +      ) +    end + +    links +  end +end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb new file mode 100644 index 000000000..4e777292d --- /dev/null +++ b/app/decorators/stop_area_decorator.rb @@ -0,0 +1,43 @@ +class StopAreaDecorator < Draper::Decorator +  decorates Chouette::StopArea + +  delegate_all + +  def action_links(stop_area = nil) +    links = [] +    stop_area ||= object + +    if h.policy(Chouette::StopArea).new? +      links << Link.new( +        content: h.t('stop_areas.actions.new'), +        href: h.new_stop_area_referential_stop_area_path( +          stop_area.stop_area_referential +        ) +      ) +    end + +    if h.policy(stop_area).update? +      links << Link.new( +        content: h.t('stop_areas.actions.edit'), +        href: h.edit_stop_area_referential_stop_area_path( +          stop_area.stop_area_referential, +          stop_area +        ) +      ) +    end + +    if h.policy(stop_area).destroy? +      links << Link.new( +        content: h.destroy_link_content('stop_areas.actions.destroy'), +        href: h.stop_area_referential_stop_area_path( +          stop_area.stop_area_referential, +          stop_area +        ), +        method: :delete, +        data: { confirm: t('stop_areas.actions.destroy_confirm') } +      ) +    end + +    links +  end +end diff --git a/app/decorators/stop_point_decorator.rb b/app/decorators/stop_point_decorator.rb new file mode 100644 index 000000000..196d6d490 --- /dev/null +++ b/app/decorators/stop_point_decorator.rb @@ -0,0 +1,9 @@ +class StopPointDecorator < StopAreaDecorator +  decorates Chouette::StopPoint + +  delegate_all + +  def action_links +    super(object.stop_area) +  end +end diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index e1b8b406d..897e842a8 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -104,10 +104,6 @@ module TableBuilderHelper    end    def tbody(collection, columns, selectable, links) -    # Certain controllers don't define a `#current_referential`. In these -    # cases, avoid a `NoMethodError`. -    referential = current_referential if respond_to?(:current_referential) -      content_tag :tbody do        collection.map do |item| @@ -161,7 +157,7 @@ module TableBuilderHelper      menu = content_tag :ul, class: 'dropdown-menu' do        ( -        CustomLinks.new(item, pundit_user, links).links + +        CustomLinks.new(item, pundit_user, links, referential).links +          item.action_links.select { |link| link.is_a?(Link) }        ).map do |link|          gear_menu_link(link) @@ -238,4 +234,10 @@ module TableBuilderHelper        class: ('delete-action' if link.method == :delete)      )    end + +  def referential +    # Certain controllers don't define a `#current_referential`. In these +    # cases, avoid a `NoMethodError`. +    @__referential__ ||= try(:current_referential) +  end  end diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb index 4e385b266..b1bb11f10 100644 --- a/app/helpers/table_builder_helper/custom_links.rb +++ b/app/helpers/table_builder_helper/custom_links.rb @@ -8,12 +8,13 @@ module TableBuilderHelper        unarchive: :put      } -    attr_reader :actions, :object, :user_context +    attr_reader :actions, :object, :user_context, :referential -    def initialize(object, user_context, actions) +    def initialize(object, user_context, actions, referential = nil)        @object       = object        @user_context = user_context        @actions      = actions +      @referential  = referential      end      def links @@ -33,10 +34,7 @@ module TableBuilderHelper          polymorph_url << action        end -      polymorph_url += URL.polymorphic_url_parts( -        object, -        user_context.context[:referential] -      ) +      polymorph_url += URL.polymorphic_url_parts(object, referential)      end      def method_for_action(action) diff --git a/app/views/companies/index.html.slim b/app/views/companies/index.html.slim index 8605a213b..ceea385b3 100644 --- a/app/views/companies/index.html.slim +++ b/app/views/companies/index.html.slim @@ -22,11 +22,20 @@      - if @companies.any?        .row          .col-lg-12 -          = table_builder @companies, -            { 'Oid' => Proc.new { |n| n.try(:objectid).try(:local_id) }, :name => 'name' }, -            [:show, :edit, :delete], -            [], -            'table has-search' +          = table_builder_2 @companies, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'Oid', \ +                attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ +                sortable: false \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ) \ +            ], +            links: [:show, :edit], +            cls: 'table has-search'            = new_pagination @companies, 'pull-right' diff --git a/app/views/networks/index.html.slim b/app/views/networks/index.html.slim index 7381b62f4..4c1f9783c 100644 --- a/app/views/networks/index.html.slim +++ b/app/views/networks/index.html.slim @@ -22,12 +22,20 @@      - if @networks.any?        .row          .col-lg-12 -          = table_builder @networks, -            { 'Oid' => Proc.new { |n| n.try(:objectid).try(:local_id) }, -            :name => 'name' }, -            [:show, :edit, :delete], -            [], -            'table has-search' +          = table_builder_2 @networks, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'Oid', \ +                attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ +                sortable: false \ +              ), +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ), \ +            ], +            links: [:show], +            cls: 'table has-search'            = new_pagination @networks, 'pull-right' diff --git a/app/views/networks/show.html.slim b/app/views/networks/show.html.slim index 1f24fc5c1..09edbad2e 100644 --- a/app/views/networks/show.html.slim +++ b/app/views/networks/show.html.slim @@ -7,14 +7,12 @@    / Below is secundary actions & optional contents (filters, ...)    .row      .col-lg-12.text-right.mb-sm -      - if policy(Chouette::Network).create? -        = link_to t('networks.actions.new'), new_line_referential_network_path(@line_referential), class: 'btn btn-primary' -      - if policy(@network).update? -        = link_to t('networks.actions.edit'), edit_line_referential_network_path(@line_referential, @network), class: 'btn btn-primary' -      - if policy(@network).destroy? -        = link_to line_referential_network_path(@line_referential, @network), method: :delete, data: { confirm: t('networks.actions.destroy_confirm')}, class: 'btn btn-primary' do -          span.fa.fa-trash -          span = t('networks.actions.destroy') +      - @network.action_links.each do |link| +        = link_to link.href, +            method: link.method, +            data: link.data, +            class: 'btn btn-primary' do +              = link.content  / PageContent  .page_content diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim index 85d1d416d..23eea40ce 100644 --- a/app/views/referential_companies/index.html.slim +++ b/app/views/referential_companies/index.html.slim @@ -22,12 +22,32 @@      - if @companies.any?        .row          .col-lg-12 -          = table_builder @companies, -            { 'ID Codifligne' => Proc.new { |n| n.try(:objectid).try(:local_id) }, -            :name => 'name', :phone => 'phone', :email => 'email', :url => 'url' }, -            [:show, :edit, :delete], -            [], -            'table has-search' +          = table_builder_2 @companies, +            [ \ +              TableBuilderHelper::Column.new( \ +                  name: 'ID Codifligne', \ +                  attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ +                  sortable: false \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :phone, \ +                attribute: 'phone' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :email, \ +                attribute: 'email' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :url, \ +                attribute: 'url' \ +              ) \ +            ], +            links: [:show, :edit], +            cls: 'table has-search'            = new_pagination @companies, 'pull-right' diff --git a/app/views/referential_lines/_lines.html.slim b/app/views/referential_lines/_lines.html.slim deleted file mode 100644 index 54f22c978..000000000 --- a/app/views/referential_lines/_lines.html.slim +++ /dev/null @@ -1,13 +0,0 @@ -- if @lines.any? -  = table_builder @lines, -    { 'Oid' => Proc.new { |n| n.objectid.local_id }, :id => 'id', -    :number => 'number', :name => 'name', :network => Proc.new { |n| n.try(:network).try(:name) }, :company => Proc.new { |n| n.try(:company).try(:name) } }, -    [:show], -    [], -    'table table-bordered' - -  .text-center -    = will_paginate @lines, container: false, renderer: RemoteBootstrapPaginationLinkRenderer - -- else -  = replacement_msg t('referential_lines.search_no_results') diff --git a/app/views/referential_lines/index.html.slim b/app/views/referential_lines/index.html.slim deleted file mode 100644 index 6b4fd5f38..000000000 --- a/app/views/referential_lines/index.html.slim +++ /dev/null @@ -1,33 +0,0 @@ -= title_tag t('lines.index.title') - -= render partial: 'shared/lines_search_form', locals: { referential: @referential } - -#lines -  = render 'lines' - -- content_for :sidebar do -  ul.actions -    - if policy(Chouette::Line).create? && @referential.organisation == current_organisation -      li -        = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'add' - -  - if policy(Chouette::Line).destroy? -    #multiple_selection_menu -      h4 = t(".multi_selection") - -      .disabled -        a.enable href="#" -          = t(".multi_selection_enable") - -      .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") - -      a.select_all href="#" -        = t(".select_all") -      = " | " -      a.deselect_all href="#" -        = t(".deselect_all") diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index 14e300aa2..34c296932 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -7,21 +7,12 @@    / Below is secundary actions & optional contents    .row      .col-lg-12.text-right.mb-sm -      = link_to @line.human_attribute_name(:footnotes), referential_line_footnotes_path(@referential, @line), class: 'btn btn-primary' -      = link_to t('routing_constraint_zones.index.title'), referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-primary' - -      - if policy(Chouette::Line).create? && @referential.organisation == current_organisation -        = link_to t('actions.new'), new_referential_line_path(@referential), class: 'btn btn-primary' -      - if policy(@line).update? -        = link_to t('actions.edit'), edit_referential_line_path(@referential, @line), class: 'btn btn-primary' -      - if policy(@line).destroy? -        = link_to referential_line_path(@referential, @line), method: :delete, data: {confirm: t('lines.actions.destroy_confirm')}, class: 'btn btn-primary' do -          span.fa.fa-trash -          span = t('actions.destroy') - -      - if !@line.hub_restricted? || (@line.hub_restricted? && @line.routes.size < 2) -        - if policy(Chouette::Route).create? && @referential.organisation == current_organisation -          = link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), class: 'btn btn-primary' +      - @line.action_links.each do |link| +        = link_to link.href, +            method: link.method, +            data: link.data, +            class: 'btn btn-primary' do +              = link.content  / PageContent  .page_content diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim index d6c52d352..c58a91321 100644 --- a/app/views/referential_networks/index.html.slim +++ b/app/views/referential_networks/index.html.slim @@ -22,11 +22,20 @@      - if @networks.any?        .row          .col-lg-12 -          = table_builder @networks, -            { 'ID Codifligne' => Proc.new { |n| n.try(:objectid).try(:local_id) }, :name => 'name' }, -            [:show, :edit, :delete], -            [], -            'table has-search' +          = table_builder_2 @networks, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'ID Codifligne', \ +                attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ +                sortable: false \ +              ), +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ) \ +            ], +            links: [:show], +            cls: 'table has-search'            = new_pagination @networks, 'pull-right' diff --git a/app/views/referential_networks/show.html.slim b/app/views/referential_networks/show.html.slim index 59bdd0dee..b9d9d5d8b 100644 --- a/app/views/referential_networks/show.html.slim +++ b/app/views/referential_networks/show.html.slim @@ -7,14 +7,12 @@    / Below is secundary actions & optional contents (filters, ...)    .row      .col-lg-12.text-right.mb-sm -      - if policy(Chouette::Network).create? -        = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'btn btn-primary' -      - if policy(@network).update? -        = link_to t('networks.actions.edit'), edit_referential_network_path(@referential, @network), class: 'btn btn-primary' -      - if policy(@network).destroy? -        = link_to referential_network_path(@referential, @network), method: :delete, data: { confirm: t('networks.actions.destroy_confirm')}, class: 'btn btn-primary' do -          span.fa.fa-trash -          span = t('networks.actions.destroy') +      - @network.action_links.each do |link| +        = link_to link.href, +            method: link.method, +            data: link.data, +            class: 'btn btn-primary' do +              = link.content  / PageContent  .page_content diff --git a/app/views/referential_stop_areas/show.html.slim b/app/views/referential_stop_areas/show.html.slim index 7932b6c2e..d594665f7 100644 --- a/app/views/referential_stop_areas/show.html.slim +++ b/app/views/referential_stop_areas/show.html.slim @@ -5,14 +5,12 @@    .row      .col-lg-12.text-right.mb-sm -      - if policy(Chouette::StopArea).new? -        = link_to t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), class: 'btn btn-primary' -      - if policy(@stop_area).update? -        = link_to t('stop_areas.actions.edit'), edit_stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), class: 'btn btn-primary' -      - if policy(@stop_area).destroy? -        = link_to stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), method: :delete, data: {confirm: t('stop_areas.actions.destroy_confirm')}, class: 'btn btn-primary' do -          span.fa.fa-trash -          span = t('stop_areas.actions.destroy') +      - @stop_area.action_links.each do |link| +        = link_to link.href, +            method: link.method, +            data: link.data, +            class: 'btn btn-primary' do +              = link.content  / PageContent  .page_content diff --git a/app/views/referentials/_filters.html.slim b/app/views/referentials/_filters.html.slim index 4b09ce1a6..9302ccaa8 100644 --- a/app/views/referentials/_filters.html.slim +++ b/app/views/referentials/_filters.html.slim @@ -8,15 +8,15 @@    .ffg-row      .form-group.togglable -      = f.label @reflines.human_attribute_name(:transport_mode), required: false, class: 'control-label' +      = f.label Chouette::Line.human_attribute_name(:transport_mode), required: false, class: 'control-label'        = f.input :transport_mode_eq_any, collection: @referential.lines.pluck(:transport_mode).uniq.compact, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.line.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }      .form-group.togglable -      = f.label @reflines.human_attribute_name(:network), required: false, class: 'control-label' +      = f.label Chouette::Line.human_attribute_name(:network), required: false, class: 'control-label'        = f.input :network_id_eq_any, collection: LineReferential.first.networks.order('name').pluck(:id), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>#{LineReferential.first.networks.find(l).name}</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }      .form-group.togglable -      = f.label @reflines.human_attribute_name(:company), required: false, class: 'control-label' +      = f.label Chouette::Line.human_attribute_name(:company), required: false, class: 'control-label'        = f.input :company_id_eq_any, collection: LineReferential.first.companies.order('name').pluck(:id), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>#{LineReferential.first.companies.find(l).name}</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }    .actions diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index 17ba8ad88..d3687c3a7 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -38,17 +38,40 @@        .row          .col-lg-12            / ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes] -          = table_builder @reflines, -            { 'ID Codifligne' => Proc.new { |n| n.objectid.local_id }, -            :number => 'number', -            :name => 'name', -            :deactivated => Proc.new{ |n| n.deactivated? ? t('false') : t('true') }, -            :transport_mode => Proc.new{ |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, -            'networks.name' => Proc.new { |n| n.try(:network).try(:name) }, -            'companies.name' => Proc.new { |n| n.try(:company).try(:name) } }, -            [:show], -            [], -            'table has-filter has-search' +          = table_builder_2 @reflines, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'ID Codifligne', \ +                attribute: Proc.new { |n| n.objectid.local_id }, \ +                sortable: false \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :number, \ +                attribute: 'number' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :deactivated, \ +                attribute: Proc.new { |n| n.deactivated? ? t('false') : t('true') } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :transport_mode, \ +                attribute: Proc.new { |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: 'networks.name', \ +                attribute: Proc.new { |n| n.try(:network).try(:name) } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: 'companies.name', \ +                attribute: Proc.new { |n| n.try(:company).try(:name) } \ +              ) \ +            ], +            links: [:show], +            cls: 'table has-filter has-search'            = new_pagination @reflines, 'pull-right' diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index eee19d85a..f2f8f1a9d 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -33,18 +33,44 @@      .row        .col-lg-12          - if @route_sp.any? -          = table_builder @route_sp, -            { 'ID Reflex' => Proc.new {|s| s.try(:stop_area).try(:user_objectid)}, -              :name => Proc.new {|s| s.try(:stop_area).try(:name)}, -              :deleted_at => Proc.new{|s| s.try(:stop_area).deleted_at ? t('false') : t('true')}, -              :zip_code => Proc.new {|s| s.try(:stop_area).try(:zip_code)}, -              :city_name => Proc.new {|s| s.try(:stop_area).try(:city_name)}, -              :for_boarding => Proc.new {|s| t("stop_points.stop_point.for_boarding.#{s.for_boarding}")}, -              :for_alighting => Proc.new {|s| t("stop_points.stop_point.for_alighting.#{s.for_alighting}")}, -              :position => 'position' }, -            [:show], -            [], -            'table' +          = table_builder_2 @route_sp, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'ID Reflex', \ +                attribute: Proc.new { |s| s.try(:stop_area).try(:user_objectid) }, \ +                sortable: false \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: Proc.new {|s| s.try(:stop_area).try(:name)} \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :deleted_at, \ +                attribute: Proc.new { |s| s.try(:stop_area).deleted_at ? t('false') : t('true') } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :zip_code, \ +                attribute: Proc.new { |s| s.try(:stop_area).try(:zip_code) } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :city_name, \ +                attribute: Proc.new { |s| s.try(:stop_area).try(:city_name) } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :for_boarding, \ +                attribute: Proc.new { |s| t("stop_points.stop_point.for_boarding.#{s.for_boarding}") } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :for_alighting, \ +                attribute: Proc.new { |s| t("stop_points.stop_point.for_alighting.#{s.for_alighting}") } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :position, \ +                attribute: 'position' \ +              ), \ +            ], +            links: [:show], +            cls: 'table'          - else            = replacement_msg t('stop_areas.search_no_results') diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim index 596ea9e91..6b3e73096 100644 --- a/app/views/routing_constraint_zones/index.html.slim +++ b/app/views/routing_constraint_zones/index.html.slim @@ -16,13 +16,28 @@      - if @routing_constraint_zones.any?        .row          .col-lg-12 -          = table_builder @routing_constraint_zones, -            { 'ID' => Proc.new { |n| n.try(:objectid).try(:local_id) }, -              :name => 'name', :stop_points_count => 'stop_points_count', -              :route => 'route_name' }, -            [:show, :edit, :delete], -            [], -            'table has-filter has-search' +          = table_builder_2 @routing_constraint_zones, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'ID', \ +                attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ +                sortable: false \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :stop_points_count, \ +                attribute: 'stop_points_count' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :route, \ +                attribute: 'route_name' \ +              ), \ +            ], +            links: [:show], +            cls: 'table has-filter has-search'      - unless @routing_constraint_zones.any?        .row.mt-xs diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim index b7c57e842..3b99f377c 100644 --- a/app/views/stop_areas/_filters.html.slim +++ b/app/views/stop_areas/_filters.html.slim @@ -7,11 +7,11 @@            span.fa.fa-search    .ffg-row -    = f.input :zip_code_cont, placeholder: t('.zip_code'), label: @stop_areas.human_attribute_name(:zip_code), required: false -    = f.input :city_name_cont, placeholder: t('.city_name'), label: @stop_areas.human_attribute_name(:city_name), required: false +    = f.input :zip_code_cont, placeholder: t('.zip_code'), label: Chouette::StopArea.human_attribute_name(:zip_code), required: false +    = f.input :city_name_cont, placeholder: t('.city_name'), label: Chouette::StopArea.human_attribute_name(:city_name), required: false      .form-group.togglable -      = f.label @stop_areas.human_attribute_name(:area_type), required: false, class: 'control-label' +      = f.label Chouette::StopArea.human_attribute_name(:area_type), required: false, class: 'control-label'        = f.input :area_type_eq_any, collection: Chouette::StopArea.area_type.options.sort, as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + t("enumerize.stop_area.area_type.#{w[1]}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }    .actions diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index 338e7e878..adb023633 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -16,12 +16,40 @@      - if @stop_areas.any?        .row          .col-lg-12 -          = table_builder @stop_areas, -            { 'ID Reflex' => Proc.new { |n| n.try(:user_objectid) }, :name => 'name', :registration_number => 'registration_number', :deleted_at => Proc.new{|s| s.deleted_at ? t('false') : t('true')}, -            :zip_code => 'zip_code', :city_name => 'city_name', :area_type => Proc.new{|s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}"))} }, -            [:show, :edit, :delete], -            [], -            'table has-filter has-search' +          = table_builder_2 @stop_areas, +            [ \ +              TableBuilderHelper::Column.new( \ +                name: 'ID Reflex', \ +                attribute: Proc.new { |n| n.try(:user_objectid) }, \ +                sortable: false \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :name, \ +                attribute: 'name' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :registration_number, \ +                attribute: 'registration_number' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :deleted_at, \ +                attribute: Proc.new { |s| s.deleted_at ? t('false') : t('true') } \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :zip_code, \ +                attribute: 'zip_code' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :city_name, \ +                attribute: 'city_name' \ +              ), \ +              TableBuilderHelper::Column.new( \ +                key: :area_type, \ +                attribute: Proc.new { |s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}")) } \ +              ), \ +            ], +            links: [:show, :edit, :delete], +            cls: 'table has-filter has-search'            = new_pagination @stop_areas, 'pull-right' diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index 0427554ef..05f66a33a 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -5,14 +5,12 @@    .row      .col-lg-12.text-right.mb-sm -      - if policy(Chouette::StopArea).new? -        = link_to t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), class: 'btn btn-primary' -      - if policy(@stop_area).update? -        = link_to t('stop_areas.actions.edit'), edit_stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), class: 'btn btn-primary' -      - if policy(@stop_area).destroy? -        = link_to stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), method: :delete, data: {confirm: t('stop_areas.actions.destroy_confirm')}, class: 'btn btn-primary' do -          span.fa.fa-trash -          span = t('stop_areas.actions.destroy') +      - @stop_area.action_links.each do |link| +        = link_to link.href, +            method: link.method, +            data: link.data, +            class: 'btn btn-primary' do +              = link.content  / PageContent  .page_content diff --git a/config/routes.rb b/config/routes.rb index f75578106..aa6713857 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,7 +99,7 @@ ChouetteIhm::Application.routes.draw do      resources :networks, controller: "referential_networks"      match 'lines' => 'lines#destroy_all', :via => :delete -    resources :lines, controller: "referential_lines" do +    resources :lines, controller: "referential_lines", except: :index do        resource :footnotes, controller: "line_footnotes"        delete :index, on: :collection, action: :delete_all        collection do diff --git a/spec/features/referential_lines_spec.rb b/spec/features/referential_lines_spec.rb index fd003effb..95fc596fd 100644 --- a/spec/features/referential_lines_spec.rb +++ b/spec/features/referential_lines_spec.rb @@ -5,45 +5,6 @@ describe 'ReferentialLines', type: :feature do    login_user    let!(:referential_metadata) { create :referential_metadata, referential: referential } -  describe 'index' do -    before(:each) { visit referential_lines_path(referential) } - -    it 'displays referential lines' do -      expect(page).to have_content(referential.lines.first.name) -      expect(page).to have_content(referential.lines.last.name) -    end - -    it 'allows only R in CRUD' do -      expect(page).to have_content(I18n.t('actions.show')) -      expect(page).not_to have_content(I18n.t('actions.edit')) -      expect(page).not_to have_content(I18n.t('actions.destroy')) -      expect(page).not_to have_content(I18n.t('actions.add')) -    end - -    context 'filtering' do -      it 'supports filtering by name' do -        fill_in 'q[name_or_number_or_objectid_cont]', with: referential.lines.first.name -        click_button 'search-btn' -        expect(page).to have_content(referential.lines.first.name) -        expect(page).not_to have_content(referential.lines.last.name) -      end - -      it 'supports filtering by number' do -        fill_in 'q[name_or_number_or_objectid_cont]', with: referential.lines.first.number -        click_button 'search-btn' -        expect(page).to have_content(referential.lines.first.name) -        expect(page).not_to have_content(referential.lines.last.name) -      end - -      it 'supports filtering by objectid' do -        fill_in 'q[name_or_number_or_objectid_cont]', with: referential.lines.first.objectid -        click_button 'search-btn' -        expect(page).to have_content(referential.lines.first.name) -        expect(page).not_to have_content(referential.lines.last.name) -      end -    end -  end -    describe 'show' do      it 'displays referential line' do        visit referential_line_path(referential, referential.lines.first) diff --git a/spec/features/routes_spec.rb b/spec/features/routes_spec.rb index 561725ddd..3bd2071d2 100644 --- a/spec/features/routes_spec.rb +++ b/spec/features/routes_spec.rb @@ -11,13 +11,10 @@ describe "Routes", :type => :feature do    before { @user.update(organisation: referential.organisation) }    with_permissions "boiv:read" do -    context "from lines page to a line page" do -      it "display line's routes" do -        visit referential_lines_path(referential) -        first(:link, 'Consulter').click -        expect(page).to have_content(route.name) -        expect(page).to have_content(route2.name) -      end +    it "line page displays line's routes" do +      visit referential_line_path(referential, line) +      expect(page).to have_content(route.name) +      expect(page).to have_content(route2.name)      end      describe "from line's page to route's page" do diff --git a/spec/helpers/table_builder_helper/custom_links_spec.rb b/spec/helpers/table_builder_helper/custom_links_spec.rb index 4b07922a7..ac60c7da3 100644 --- a/spec/helpers/table_builder_helper/custom_links_spec.rb +++ b/spec/helpers/table_builder_helper/custom_links_spec.rb @@ -1,5 +1,21 @@  describe TableBuilderHelper::CustomLinks do -  describe "#actions_after_policy_check" do +  describe "#polymorphic_url" do +    it "returns the correct URL path for Companies#show" do +      company = build_stubbed(:company) +      user_context = UserContext.new(build_stubbed(:user)) + +      expect( +        TableBuilderHelper::CustomLinks.new( +          company, +          user_context, +          [:show], +          company.line_referential +        ).polymorphic_url(:show) +      ).to eq([company.line_referential, company]) +    end +  end + +  describe "#authorized_actions" do      it "includes :show" do        referential = build_stubbed(:referential)        user_context = UserContext.new( diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 4f7c1bd69..c536a4c62 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -302,7 +302,7 @@ describe TableBuilderHelper, type: :helper do        companies = ModelDecorator.decorate(          companies,          with: CompanyDecorator, -        context: {line_referential: line_referential} +        context: { referential: line_referential }        )        stub_policy_scope(company) diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index e613ea948..72605fb46 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -2,7 +2,12 @@ require 'spec_helper'  describe "/networks/show", :type => :view do -  let!(:network) { assign(:network, create(:network)) } +  let!(:network) do +    network = create(:network) +    assign(:network, network.decorate(context: { +      line_referential: network.line_referential +    })) +  end    let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) }    let!(:line_referential) { assign :line_referential, network.line_referential } diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 538563578..dae8c9ed3 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -3,7 +3,12 @@ RSpec.describe "/routes/show", type: :view do    assign_referential    let!(:line) { assign :line, create(:line) }    let!(:route) { assign :route, create(:route, :line => line).decorate(context: {referential: referential, line: line }) } -  let!(:route_sp) { assign :route_sp, route.stop_points } +  let!(:route_sp) do +    assign :route_sp, ModelDecorator.decorate( +      route.stop_points, +      with: StopPointDecorator +    ) +  end    before do      self.params.merge!({ @@ -12,6 +17,10 @@ RSpec.describe "/routes/show", type: :view do        referential_id: referential.id      })      allow(view).to receive(:current_referential).and_return(referential) +    allow(view).to receive(:pundit_user).and_return(UserContext.new( +      build_stubbed(:user), +      referential +    ))    end    it "should render h1 with the route name" do diff --git a/spec/views/stop_areas/show.html.erb_spec.rb b/spec/views/stop_areas/show.html.erb_spec.rb index a22379402..6fd416128 100644 --- a/spec/views/stop_areas/show.html.erb_spec.rb +++ b/spec/views/stop_areas/show.html.erb_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper'  describe "/stop_areas/show", :type => :view do    let!(:stop_area_referential) { assign :stop_area_referential, stop_area.stop_area_referential } -  let!(:stop_area) { assign :stop_area, create(:stop_area) } +  let!(:stop_area) { assign :stop_area, create(:stop_area).decorate }    let!(:access_points) { assign :access_points, [] }    let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) }  | 
