diff options
| author | Luc Donnet | 2018-04-03 08:56:39 +0200 | 
|---|---|---|
| committer | Luc Donnet | 2018-04-03 08:56:39 +0200 | 
| commit | cc902baf4c2ba52c1e49f7c38027804ff73357eb (patch) | |
| tree | 6f136a49510c82b87c579bf4c25570682faeba78 | |
| parent | 2159a5e7b967ddc1e7964c143facdfb26d1fb9b9 (diff) | |
| download | chouette-core-6384-display_referential_ready_false.tar.bz2 | |
Draft version to add more referential statuses @86384-display_referential_ready_false
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/decorators/referential_decorator.rb | 6 | ||||
| -rw-r--r-- | app/helpers/referentials_helper.rb | 20 | ||||
| -rw-r--r-- | app/models/referential.rb | 2 | ||||
| -rw-r--r-- | app/models/workbench.rb | 1 | ||||
| -rw-r--r-- | app/policies/referential_policy.rb | 14 | ||||
| -rw-r--r-- | app/views/referentials/_show_not_ready.html.slim | 1 | ||||
| -rw-r--r-- | app/views/referentials/_show_ready.html.slim | 79 | ||||
| -rw-r--r-- | app/views/referentials/index.html.slim | 18 | ||||
| -rw-r--r-- | app/views/referentials/show.html.slim | 85 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 2 | ||||
| -rw-r--r-- | config/locales/referentials.en.yml | 4 | ||||
| -rw-r--r-- | config/locales/referentials.fr.yml | 4 | ||||
| -rw-r--r-- | config/routes.rb | 2 | 
14 files changed, 128 insertions, 112 deletions
| diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index fe661651e..f75326b6a 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -3,7 +3,7 @@ class ReferentialsController < ChouetteController    before_action :load_workbench    include PolicyChecker -  respond_to :html +  respond_to :html, :except => :index    respond_to :json, :only => :show    respond_to :js, :only => :show diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb index cce14d160..57d0d33b5 100644 --- a/app/decorators/referential_decorator.rb +++ b/app/decorators/referential_decorator.rb @@ -5,17 +5,17 @@ class ReferentialDecorator < AF83::Decorator      instance_decorator.show_action_link      instance_decorator.edit_action_link -    instance_decorator.action_link feature: :referential_vehicle_journeys, secondary: :show, on: :show do |l| +    instance_decorator.action_link policy: :vehicle_journeys, feature: :referential_vehicle_journeys, secondary: :show, on: :show do |l|        l.content t('referential_vehicle_journeys.index.title')        l.href { h.referential_vehicle_journeys_path(object) }      end -    instance_decorator.action_link feature: :purchase_windows, secondary: :show, on: :show do |l| +    instance_decorator.action_link policy: :purchase_windows, feature: :purchase_windows, secondary: :show, on: :show do |l|        l.content t('purchase_windows.index.title')        l.href { h.referential_purchase_windows_path(object) }      end -    instance_decorator.action_link secondary: :show do |l| +    instance_decorator.action_link policy: :time_tables, secondary: :show do |l|        l.content t('time_tables.index.title')        l.href { h.referential_time_tables_path(object) }      end diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb index 9c3852322..c72ef2922 100644 --- a/app/helpers/referentials_helper.rb +++ b/app/helpers/referentials_helper.rb @@ -16,6 +16,26 @@ module ReferentialsHelper      render partial: "referentials/overview", locals: {referential: referential, overview: service}    end +  def referential_status referential +    if !referential.ready +      if Import::Base.failed_statuses.include?(referential_creation_status(referential)&.status) +        "<div class='td-block'><span class='fa fa-times'></span><span>#{t('activerecord.attributes.referential.creation_failed')}</span></div>".html_safe +      else +        "<div class='td-block'><span class='fa fa-spinner fa-spin'></span><span>#{t('activerecord.attributes.referential.in_creation')}</span></div>".html_safe +      end +    elsif referential.referential_read_only? +      "<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>".html_safe +    else +      "<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>".html_safe +    end +  end + +  def referential_creation_status referential +    import = Import::Base.find_by_referential_id referential.id +    clone = ReferentialCloning.find_by_target_referential_id  referential.id +    operation = import || clone +  end +    def mutual_workbench workbench      current_user.organisation.workbenches.where(workgroup_id: workbench.workgroup_id).last    end diff --git a/app/models/referential.rb b/app/models/referential.rb index 0e48be43f..e7a32e4e9 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -300,7 +300,7 @@ class Referential < ActiveRecord::Base    before_destroy :destroy_jobs    def referential_read_only? -    in_referential_suite? || archived? +    in_referential_suite? || archived? || !ready    end    def in_referential_suite? diff --git a/app/models/workbench.rb b/app/models/workbench.rb index b5f4673bb..ed2790e79 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -38,7 +38,6 @@ class Workbench < ActiveRecord::Base          .referentials          .joins(:metadatas)          .where(['referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids]) -        .ready          .not_in_referential_suite      end    end diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb index f5c2d7c08..398e25bf2 100644 --- a/app/policies/referential_policy.rb +++ b/app/policies/referential_policy.rb @@ -18,7 +18,7 @@ class ReferentialPolicy < ApplicationPolicy    end    def clone? -    !record.in_referential_suite? && create? +    !record.in_referential_suite? && record.ready && create?    end    def validate? @@ -33,9 +33,15 @@ class ReferentialPolicy < ApplicationPolicy      record.archived? && !record.merged? && organisation_match? && user.has_permission?('referentials.update')    end -  def common_lines? -    # TODO: Replace with correct BL ASA available, c.f. https://projects.af83.io/issues/2692 -    true +  def vehicle_journeys? +    record.ready    end +  def time_tables? +    record.ready +  end + +  def purchase_windows? +    record.ready +  end  end diff --git a/app/views/referentials/_show_not_ready.html.slim b/app/views/referentials/_show_not_ready.html.slim new file mode 100644 index 000000000..e548bfca3 --- /dev/null +++ b/app/views/referentials/_show_not_ready.html.slim @@ -0,0 +1 @@ += "Opération en cours" diff --git a/app/views/referentials/_show_ready.html.slim b/app/views/referentials/_show_ready.html.slim new file mode 100644 index 000000000..08603b28a --- /dev/null +++ b/app/views/referentials/_show_ready.html.slim @@ -0,0 +1,79 @@ +- if params[:q].present? or reflines.any? +  .row +    .col-lg-12 +      = render 'filters' + +- if reflines.any? +  .row +    .col-lg-12 +      / ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes] +      = table_builder_2 reflines, +        [ \ +          TableBuilderHelper::Column.new( \ +            name: t('id_codif'), \ +            attribute: Proc.new { |n| n.get_objectid.short_id }, \ +            sortable: false \ +          ), \ +          TableBuilderHelper::Column.new( \ +            key: :number, \ +            attribute: 'number' \ +          ), \ +          TableBuilderHelper::Column.new( \ +            key: :name, \ +            attribute: 'name', \ +            link_to: lambda do |line| \ +              referential_line_path(referential, line) \ +            end \ +          ), \ +          TableBuilderHelper::Column.new( \ +            key: :state, \ +            attribute: Proc.new { |n| line_status(n.deactivated?) } \ +          ), \ +          TableBuilderHelper::Column.new( \ +            key: :transport_mode, \ +            attribute: Proc.new { |n| n.transport_mode ? t("enumerize.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&.company&.name || "-" } \ +          ) \ +        ], +        cls: 'table has-filter has-search', +        action: :index + +      = new_pagination reflines, 'pull-right' + +- unless reflines.any? +  .row.mt-xs +    .col-lg-12 +      = replacement_msg t('referential_lines.search_no_results') + + += referential_overview resource + +/ Modal(s) += modalbox 'purgeModal' do +  = simple_form_for [referential, CleanUp.new] do |clean_up_form| +    .modal-header +      h4.modal-title #{t('simple_form.labels.clean_up.title')} +    .modal-body +      .container-fluid +        .row +          .col-lg-8.col-ld-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2.col-xs-12 +            = clean_up_form.input :date_type, as: :radio_buttons, label: false + +          .col-lg-8.col-ld-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2.col-xs-12 +            label.control-label.begin_date = t('titles.clean_up.begin_date') +            label.control-label.end_date.hidden = t('titles.clean_up.end_date') +            = clean_up_form.input :begin_date, as: :date, label: false, wrapper_html: { class: 'date smart_date' } + +            = clean_up_form.input :end_date, as: :date, label: t('titles.clean_up.end_date'), wrapper_html: { class: 'date cleanup_end_date_wrapper smart_date', id: "end_date" } + +    .modal-footer +      button.btn.btn-link type='button' data-dismiss='modal' #{t('cancel')} +      - unless policy(referential).referential_read_only? +        = clean_up_form.button :submit, t('actions.clean_up') , class: 'btn btn-primary' diff --git a/app/views/referentials/index.html.slim b/app/views/referentials/index.html.slim deleted file mode 100644 index 8bb66da21..000000000 --- a/app/views/referentials/index.html.slim +++ /dev/null @@ -1,18 +0,0 @@ -/ FIXME #827 -- current_organisation.workbenches.each do |workbench| -  h2 = link_to workbench.name, workbench -  p = t('workbenches.referential_count', count: workbench.referentials.count) - -/ FIXME #823 -- if false -  = title_tag Referential.model_name.human(count: 2) -  .referentials.paginated_content -    = paginated_content @referentials - -- content_for :sidebar do -  ul.actions -    li = link_to t('reflex_data'), stop_area_referential_path(1) -    li = link_to t('codif_data'), line_referential_path(1) -    li = link_to t('calendars.standard_calendars'), calendars_path -    - if false -      li = link_to t('referentials.actions.new'), new_referential_path, class: 'add' diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index b2a079ab4..3bf5747ed 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -6,88 +6,13 @@      .row        .col-lg-6.col-md-6.col-sm-12.col-xs-12          - attributes = {} -        - attributes[@referential.human_attribute_name(:status)] = @referential.referential_read_only? ? "<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>".html_safe : "<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>".html_safe unless @referential.in_referential_suite? +        - attributes[@referential.human_attribute_name(:status)] = referential_status(@referential)          - attributes[@referential.human_attribute_name(:validity_period)] = (@referential.validity_period.present? ? t('validity_range', debut: l(@referential.try(:validity_period).try(:begin), format: :short), end: l(@referential.try(:validity_period).try(:end), format: :short)) : '-')          - attributes[@referential.human_attribute_name(:organisation)] = @referential.organisation.name          - attributes[@referential.human_attribute_name(:merged_at)] = @referential.merged_at ? l(@referential.merged_at, format: :short) : '-' unless @referential.in_referential_suite?          = definition_list t('metadatas'), attributes -    - if params[:q].present? or @reflines.any? -      .row -        .col-lg-12 -          = render 'filters' - -    - if @reflines.any? -      .row -        .col-lg-12 -          / ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes] -          = table_builder_2 @reflines, -            [ \ -              TableBuilderHelper::Column.new( \ -                name: t('id_codif'), \ -                attribute: Proc.new { |n| n.get_objectid.short_id }, \ -                sortable: false \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :number, \ -                attribute: 'number' \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :name, \ -                attribute: 'name', \ -                link_to: lambda do |line| \ -                  referential_line_path(@referential, line) \ -                end \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :state, \ -                attribute: Proc.new { |n| line_status(n.deactivated?) } \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :transport_mode, \ -                attribute: Proc.new { |n| n.transport_mode ? t("enumerize.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&.company&.name || "-" } \ -              ) \ -            ], -            cls: 'table has-filter has-search', -            action: :index - -          = new_pagination @reflines, 'pull-right' - -    - unless @reflines.any? -      .row.mt-xs -        .col-lg-12 -          = replacement_msg t('referential_lines.search_no_results') - - -    = referential_overview resource - -/ Modal(s) -= modalbox 'purgeModal' do -  = simple_form_for [@referential, CleanUp.new] do |f| -    .modal-header -      h4.modal-title #{t('simple_form.labels.clean_up.title')} -    .modal-body -      .container-fluid -        .row -          .col-lg-8.col-ld-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2.col-xs-12 -            = f.input :date_type, as: :radio_buttons, label: false - -          .col-lg-8.col-ld-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2.col-xs-12 -            label.control-label.begin_date = t('titles.clean_up.begin_date') -            label.control-label.end_date.hidden = t('titles.clean_up.end_date') -            = f.input :begin_date, as: :date, label: false, wrapper_html: { class: 'date smart_date' } - -            = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), wrapper_html: { class: 'date cleanup_end_date_wrapper smart_date', id: "end_date" } - -    .modal-footer -      button.btn.btn-link type='button' data-dismiss='modal' #{t('cancel')} -      - unless policy(@referential).referential_read_only? -        = f.button :submit, t('actions.clean_up') , class: 'btn btn-primary' +    - if referential.ready +      = render partial: 'show_ready', locals: { referentials: @referential, reflines: @reflines } +    - else +      = render partial: 'show_not_ready' diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 8312338d0..d02ce3fa9 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -33,7 +33,7 @@                  ), \                  TableBuilderHelper::Column.new( \                    key: :status, \ -                  attribute: Proc.new {|w| w.referential_read_only? ? ("<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>").html_safe : ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>").html_safe} \ +                  attribute: Proc.new {|w| referential_status w } \                  ), \                  TableBuilderHelper::Column.new( \                    key: :organisation, \ diff --git a/config/locales/referentials.en.yml b/config/locales/referentials.en.yml index 1381d5ddd..165b1322b 100644 --- a/config/locales/referentials.en.yml +++ b/config/locales/referentials.en.yml @@ -101,7 +101,9 @@ en:          updated_at: "Updated"          merged_at: "Finalized"          archived_at: "Archived" -        archived_at_null: "Unarchived" +        archived_at_null: "In edition" +        in_creation: "In creation" +        creation_failed: "Creation failed"          created_from: 'Created from'          updated_at: "Updated"          created_at: "Created" diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index ec6c7c643..1bf7e82f7 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -102,7 +102,9 @@ fr:          created_at: "Créé le"          merged_at: "Finalisé le"          archived_at: "Conservé" -        archived_at_null: "En préparation" +        archived_at_null: "En édition" +        in_creation: "En création" +        creation_failed: "Echec de la création"          created_from: 'Créé à partir de'          organisation: 'Organisation'          number_of_lines: 'Nb lignes' diff --git a/config/routes.rb b/config/routes.rb index 41b345aa5..aca321880 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,7 +36,7 @@ ChouetteIhm::Application.routes.draw do      end    end -  resources :referentials, except: %w(new create) do +  resources :referentials, except: %w(new create index) do      member do        put :archive | 
