diff options
| -rw-r--r-- | app/controllers/imports_controller.rb | 28 | ||||
| -rw-r--r-- | app/helpers/history_helper.rb | 6 | ||||
| -rw-r--r-- | app/helpers/imports_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/pagination_helper.rb | 5 | ||||
| -rw-r--r-- | app/models/import.rb | 47 | ||||
| -rw-r--r-- | app/models/import_report.rb | 12 | ||||
| -rw-r--r-- | app/models/import_service.rb | 21 | ||||
| -rw-r--r-- | app/views/imports/_import.erb | 2 | ||||
| -rw-r--r-- | app/views/imports/_results_dashboard.html.erb | 68 | ||||
| -rw-r--r-- | app/views/imports/show.html.erb | 15 | ||||
| -rw-r--r-- | app/views/imports/show.js.coffee | 41 | ||||
| -rw-r--r-- | config/initializers/apartment.rb | 2 | ||||
| -rw-r--r-- | config/locales/import_tasks.yml | 18 | ||||
| -rw-r--r-- | lib/iev_api/client.rb | 14 | 
14 files changed, 243 insertions, 38 deletions
| diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 14e7a9b95..7bf4897ce 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -5,16 +5,34 @@ class ImportsController < ChouetteController    respond_to :js, :only => [:show, :index]    belongs_to :referential -  protected +  # create => curl -F "file=@Citura_050115_220215_ref.zip;filename=Citura_050115_220215_ref.zip" -F "file=@parameters.json;filename=parameters.json" http://localhost:8080/mobi.chouette.api/referentials/test/importer/neptune +  # index curl http://localhost:8080/mobi.chouette.api/referentials/test/jobs +  # show curl http://localhost:8080/mobi.chouette.api/referentials/test/jobs -  def test -    test = IevApi.jobs(@referential.slug, { :action => "importer" }).map do |import_hash| -      Import.new(import_hash) +  def index +    index! do +      build_breadcrumb :index      end    end +  def show +    show! do +      build_breadcrumb :show +    end +  end +   +  protected + +  def import_service +    ImportService.new(@referential) +  end + +  def resource +    @import ||= import_service.find( params[:id] ) +  end +    def collection -    @imports ||= test.paginate(:page => params[:page])     +    @imports ||= import_service.all.paginate(:page => params[:page])    end  end diff --git a/app/helpers/history_helper.rb b/app/helpers/history_helper.rb index ccc6374a1..bece2d212 100644 --- a/app/helpers/history_helper.rb +++ b/app/helpers/history_helper.rb @@ -33,17 +33,17 @@ module HistoryHelper      field_set_tag t("layouts.history_tag.title"), :class => "history_tag" do        content_tag :ul do          [(content_tag :li do -          if object.has_attribute?(:created_at)     +          if object.created_at?              t('layouts.history_tag.created_at') + ' : ' + l(object.created_at, :format => :short)            end          end),          (content_tag :li do -          if object.has_attribute?(:updated_at)     +          if object.updated_at?              t('layouts.history_tag.updated_at') + ' : ' + l(object.updated_at, :format => :short)            end          end),            (content_tag :li do -           if object.has_attribute?(:user_name) +           if object.user_name?               t('layouts.history_tag.user_name') + ' : ' + object.user_name if  object.user_name             end          end)].join.html_safe diff --git a/app/helpers/imports_helper.rb b/app/helpers/imports_helper.rb index 42db85b43..772533a8e 100644 --- a/app/helpers/imports_helper.rb +++ b/app/helpers/imports_helper.rb @@ -42,7 +42,7 @@ module ImportsHelper      content_tag :div, :class => "progress" do        content_tag :div, :class => div_class, role: "progressbar", :'aria-valuenow' => "#{import.percentage_progress}", :'aria-valuemin' => "0", :'aria-valuemax' => "100", :style => "width: #{import.percentage_progress}%;" do -        "#{import.percentage_progress}% " + I18n.t("import_tasks.statuses.#{import.import_status}") +        "#{import.percentage_progress}% " + I18n.t("import_tasks.statuses.#{import.status}")        end      end diff --git a/app/helpers/pagination_helper.rb b/app/helpers/pagination_helper.rb index 41f225aa9..68c3d462f 100644 --- a/app/helpers/pagination_helper.rb +++ b/app/helpers/pagination_helper.rb @@ -10,10 +10,7 @@ module PaginationHelper        html += '<div class="row">'        row_models.each do |model|          partial_name = default_partial_name || model.class.name.underscore.gsub("chouette/", "") -        puts "PARTIAL_NAME = #{partial_name}\nMODEL = #{model.inspect}\nOPTIONS = #{options}" -        #html += '<div  class="col-md-4">' + (render :partial => partial_name, :object => model, :locals => options).to_s + '</div>' -        #html += '<div  class="col-md-4">' + "<%= link_to referential_export_path(#{model.referential}, #{model}) %>" + '</div>' -        puts "HTML= #{html}" +        html += '<div  class="col-md-4">' + (render :partial => partial_name, :object => model, :locals => options).to_s + '</div>'        end        html += '</div>'      end diff --git a/app/models/import.rb b/app/models/import.rb index 6a6b78c9e..7b2405db2 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -3,21 +3,30 @@ class Import    extend ActiveModel::Naming    include ActiveModel::Model   -  enumerize :import_status, in: %w{created scheduled terminated canceled aborted}, default: "created", predicates: true -  enumerize :import_format, in: %w{neptune netex gtfs}, default: "neptune", predicates: true +  enumerize :status, in: %w{created scheduled terminated canceled aborted}, default: "created", predicates: true +  enumerize :format, in: %w{neptune netex gtfs}, default: "neptune", predicates: true -  attr_reader :datas +  attr_reader :datas, :report -  def initialize(options=Hashie::Mash.new) +  def initialize( options = Hashie::Mash.new ) +    puts "options #{options.inspect}"      @datas = options -    @import_status = @datas.status.downcase if @datas.status -    @import_format = @datas.type.downcase if @datas.type +    @status = @datas.status.downcase if @datas.status? +    @format = @datas.type.downcase if @datas.type? +  end + +  def report +    ImportReport.new( IevApi.job(referential_name, id,{ :action => "importer" }) ) +  end + +  def id +    @datas.id    end    def percentage_progress -    if %w{created}.include? import_status +    if %w{created}.include? status        0 -    elsif %w{ terminated canceled aborted }.include? import_status +    elsif %w{ terminated canceled aborted }.include? status        100      else        20 @@ -28,12 +37,20 @@ class Import      @datas.links    end +  def referential_name +    @datas.parameters.referential +  end +      def name      @datas.parameters.name    end +  def user_name? +    @datas.parameters? && @datas.parameters.user_name? +  end +      def user_name -    @datas.parameters.user_name +    @datas.parameters.user_name if user_name?    end    def no_save @@ -44,12 +61,20 @@ class Import      @datas.filename    end +  def created_at? +    @datas.created? +  end +      def created_at -    Time.at(@datas.created.to_i / 1000) +    Time.at(@datas.created.to_i / 1000) if created_at? +  end + +  def updated_at? +    @datas.updated?    end    def updated_at -    Time.at(@datas.updated.to_i / 1000) +    Time.at(@datas.updated.to_i / 1000) if updated_at?    end  end diff --git a/app/models/import_report.rb b/app/models/import_report.rb new file mode 100644 index 000000000..8ec112dc3 --- /dev/null +++ b/app/models/import_report.rb @@ -0,0 +1,12 @@ +class ImportReport +  extend Enumerize +  extend ActiveModel::Naming +  include ActiveModel::Model   + +  attr_reader :datas +   +  def initialize( options = Hashie::Mash.new ) +    @datas = options +  end + +end diff --git a/app/models/import_service.rb b/app/models/import_service.rb new file mode 100644 index 000000000..cbd39644c --- /dev/null +++ b/app/models/import_service.rb @@ -0,0 +1,21 @@ +class ImportService + +  attr_reader :referential +   +  def initialize( referential ) +    @referential = referential +  end + +  # Merge report import and datas from import +  def find(id) +    all.find {|v| "#{v.id}" == id } +  end + +  # Find all imports +  def all +    IevApi.jobs(referential.slug, { :action => "importer" }).map do |import_hash| +      Import.new( import_hash ) +    end +  end + +end diff --git a/app/views/imports/_import.erb b/app/views/imports/_import.erb index 8b6889aa4..8c3da0320 100644 --- a/app/views/imports/_import.erb +++ b/app/views/imports/_import.erb @@ -7,7 +7,7 @@          <% end %>        </span>        <h5> -        <%= link_to( "#{Rails.application.config.iev_url}#{import.datas.links[3].href}", :class => "preview", :title => "#{ImportTask.model_name.human.capitalize} #{import.name}") do %>         +        <%= link_to( referential_import_path(@referential, import.id), :class => "preview", :title => "#{ImportTask.model_name.human.capitalize} #{import.name}") do %>                  <span class="name">            <% if !import.no_save %><i class="fa fa-save"></i><% end %> <%= truncate(import.name, :length => 20) %>                    </span> diff --git a/app/views/imports/_results_dashboard.html.erb b/app/views/imports/_results_dashboard.html.erb new file mode 100644 index 000000000..bde732f73 --- /dev/null +++ b/app/views/imports/_results_dashboard.html.erb @@ -0,0 +1,68 @@ + <div class="resume"> +   <div class="col1"> +     <% file_title = (@import_task.file_path_extension=="zip") ? t( "import_tasks.show.graph.files.title_zip") : t( "import_tasks.show.graph.files.title_default", :extension => @import_task.file_path_extension)%> +     <div class="caption"><%= file_title %></div> +     <div id="files_statistics"></div> +   </div> +   <div class="col2"> +     <div class="caption"><%= t "import_tasks.show.graph.lines.title" %></div> +     <div id="objects_statistics"></div> +   </div> + </div> + <div class="report"> +   <div class="files files_error"> +     <% @files_list["error"].each_with_index do |error, index| %> +       <% index += 1 %> +       <%= image_tag "icons/file_xml_md.png" %><span class="file_name"><%= truncate(error["name"], :length => 20) %></span> <% if index%4 == 0 %><br><% end %> +     <% end %> +   </div> +   <div class="files files_ignored"> +     <% @files_list["ignored"].each_with_index do |ignored, index| %> +       <% index += 1 %> +       <%= image_tag "icons/file_xml_md.png" %><span class="file_name"><%= truncate(ignored["name"], :length => 20) %></span> <% if index%4 == 0 %><br><% end %> +     <% end %> +   </div> +   <div class="files files_ok"> +     <% @files_list["ok"].each_with_index do |ok, index| %> +       <% index += 1 %> +       <%= image_tag "icons/file_xml_md.png" %><span class="file_name"><%= truncate(ok["name"], :length => 20) %></span> <% if index%4 == 0 %><br><% end %> +     <% end %> +   </div> +   <div class="lines"> +     <table class="table table-hover"> +       <thead> +         <tr> +           <th>#</th> +           <th><%= t("import_tasks.show.table.line.name") %></th> +           <th><%= t("import_tasks.show.table.line.save") %></th> +           <th><%= t("import_tasks.show.table.line.routes") %></th> +           <th><%= t("import_tasks.show.table.line.connection_links") %></th> +           <th><%= t("import_tasks.show.table.line.time_tables") %></th> +           <th><%= t("import_tasks.show.table.line.stop_areas") %></th> +           <th><%= t("import_tasks.show.table.line.access_points") %></th> +           <th><%= t("import_tasks.show.table.line.vehicle_journeys") %></th> +           <th><%= t("import_tasks.show.table.line.journey_patterns") %></th> +         </tr> +       </thead> +       <tbody> +         <% @lines_list.each_with_index do |line, index| %> +           <% tr_class = (line["status"]=="saved") ? '' : 'class=\'danger\''%> +           <tr <%=  tr_class %>> +           <td><%= index + 1 %></td> +           <td><%= line["name"] %></td> +           <td><%= t("import_tasks.show.table.line." + line["status"] ) %></td> +           <td><%= line["stats"]["route_count"] %></td> +           <td><%= line["stats"]["connection_link_count"] %></td> +           <td><%= line["stats"]["time_table_count"] %></td> +           <td><%= line["stats"]["stop_area_count"] %></td> +           <td><%= line["stats"]["acces_point_count"] %></td> +           <td><%= line["stats"]["vehicle_journey_count"] %></td> +           <td><%= line["stats"]["journey_pattern_count"] %></td> +         </tr> +         <% end %> +       </tbody> +     </table> +   </div> + </div> + <%= javascript_include_tag referential_import_task_path(@import_task.referential, @import_task,:format => :js) %> + diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb new file mode 100644 index 000000000..41b04d22b --- /dev/null +++ b/app/views/imports/show.html.erb @@ -0,0 +1,15 @@ +<% title = @import.no_save ? "": "<i class='fa fa-save'></i>" %> +<%= title_tag "#{title} #{@import.name} <span class='status status_#{@import.status}'>#{ t('imports.show.'+ @import.status) }</span>" %> + +<div class="import_show"> + +</div> + +<% content_for :sidebar do %> +<ul class="actions"> +  <li><%= link_to  t('imports.actions.destroy'), referential_import_path(@referential, @import.id), :method => :delete,  :data => {:confirm =>  t('imports.actions.destroy_confirm')}, :class => "remove" %></li> +</ul> + +<%= history_tag(@import) %> + +<% end %> diff --git a/app/views/imports/show.js.coffee b/app/views/imports/show.js.coffee new file mode 100644 index 000000000..c856154fa --- /dev/null +++ b/app/views/imports/show.js.coffee @@ -0,0 +1,41 @@ +jQuery -> + +  get_import_results = (html_container, html_element) -> +    html_container.children().each -> +      if( $( this ).is(html_element) ) +        $( this ).show() +      else +        $( this ).hide() + +  Morris.Donut({ +    element: 'files_statistics', +    data: [ +      {label: "<%= t 'import_tasks.show.graph.files.error' %>", value: <%= @files_stats["error_count"] %> }, +      {label: "<%= t 'import_tasks.show.graph.files.ignored' %>", value: <%= @files_stats["ignored_count"] %> }, +      {label: "<%= t 'import_tasks.show.graph.files.ok' %>", value: <%= @files_stats["ok_count"] %> } +    ] +    colors: [ "#e22b1b", "#898e7f", "#8fc861" ] +  }).on('click', update = (i, row) -> +    switch i +      when 0 then get_import_results( $(".report"), $(".files_error")) +      when 1 then get_import_results( $(".report"), $(".files_ignored")) +      when 2 then get_import_results( $(".report"), $(".files_ok")) +      else console.log "Error no other value for donut chart") + +  Morris.Bar({ +    element: 'objects_statistics', +    data: [ +      { object: "<%= t("import_tasks.show.graph.lines.lines_stats") %>", value: <%= @lines_stats["line_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.routes_stats") %>", value: <%= @lines_stats["route_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.connection_links_stats") %>", value: <%= @lines_stats["connection_link_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.time_tables_stats") %>", value: <%= @lines_stats["time_table_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.stop_areas_stats") %>", value: <%= @lines_stats["stop_area_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.access_points_stats") %>", value: <%= @lines_stats["access_point_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.vehicle_journeys_stats") %>", value: <%= @lines_stats["vehicle_journey_count"] %> }, +      { object: "<%= t("import_tasks.show.graph.lines.journey_patterns_stats") %>", value: <%= @lines_stats["journey_pattern_count"] %> },  +    ], +    xkey: 'object', +    ykeys: ['value'], +    labels: ['<%= t "import_tasks.show.graph.lines.objects_label" %>'] +  }).on('click', update = (i, row) -> +    get_import_results( $(".report"), $(".lines")) )
\ No newline at end of file diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 03ae0ed0a..6d2eff31a 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -17,7 +17,7 @@ Apartment.configure do |config|    #    # config.excluded_models = %w{Tenant}    # -  config.excluded_models = ["Referential", "Organisation", "User", "ImportTask", "Export", "ExportLogMessage","ComplianceCheckTask", "ComplianceCheckResult", "Delayed::Backend::ActiveRecord::Job", "Api::V1::ApiKey", "RuleParameterSet"] +  config.excluded_models = ["Referential", "Organisation", "User", "ImportTask", "ComplianceCheckTask", "ComplianceCheckResult", "Delayed::Backend::ActiveRecord::Job", "Api::V1::ApiKey", "RuleParameterSet"]    # use postgres schemas?    config.use_schemas = true diff --git a/config/locales/import_tasks.yml b/config/locales/import_tasks.yml index df81a28d1..d016d9664 100644 --- a/config/locales/import_tasks.yml +++ b/config/locales/import_tasks.yml @@ -40,10 +40,11 @@ en:            vehicle_journeys_stats: "Vehicle Journeys"            journey_patterns_stats: "Journey Patterns"      statuses: -      pending: "Pending" -      processing: "Processing" -      completed: "Completed" -      failed: "Failed" +      created: "Pending ..." +      scheduled: "Processing ..." +      terminated: "Completed" +      canceled: "Canceled" +      aborted: "Failed"      compliance_check_task: "Validate Report"      severities:        info: "Information" @@ -150,10 +151,11 @@ fr:            saved: "Sauvé"            save_error: "Sauvegarde en erreur"      statuses: -      pending: "En attente ..." -      processing: "En cours ..." -      completed: "Achevé" -      failed: "Echoué" +      created: "En attente ..." +      scheduled: "En cours ..." +      terminated: "Achevé" +      canceled: "Annulé" +      aborted: "Echoué"      compliance_check_task: "Validation"      severities:        info: "Information" diff --git a/lib/iev_api/client.rb b/lib/iev_api/client.rb index 9fb9c94c3..f38d64624 100644 --- a/lib/iev_api/client.rb +++ b/lib/iev_api/client.rb @@ -2,7 +2,7 @@ module IevApi    class Client      PER_PAGE = 12 -    PARALLEL_WORKERS = 10 +    #PARALLEL_WORKERS = 10      ACTIONS = %w{ importer exporter validator }      IMPORT_FORMAT = %w{ neptune netex gtfs }      EXPORT_FORMAT = %w{ neptune netex gtfs hub kml } @@ -34,7 +34,13 @@ module IevApi      def job(referential_id, job_id, options = {})        results = request(:get, job_path(referential_id, job_id), options) -      results.respond_to?(:job) ? results.job : [] +      if results.respond_to?(:job) +        results.job +      elsif results.respond_to?(:report) +        results.report +      else +        [] +      end      end      def jobs_path(referential_id) @@ -51,7 +57,7 @@ module IevApi      end      def report_path(referential_id, report_id) -      "/referential/#{referential_id}/job/#{report_id}" +      "/referentials/#{referential_id}/reports/#{report_id}"      end      def account_path @@ -67,7 +73,7 @@ module IevApi        action_and_format = (params[:action].present? && params[:format].present?) ? "/#{params[:action]}/#{params[:format]}" : ""              build_path = connection.path_prefix + path + action_and_format -      puts build_path.inspect +        response = connection(options).run_request(method, nil, nil, nil) do |request|          case method          when :delete, :get | 
