diff options
| author | Luc Donnet | 2015-03-03 18:00:35 +0100 |
|---|---|---|
| committer | Luc Donnet | 2015-03-03 18:00:35 +0100 |
| commit | 20a7080ea63d4887e578fea37751487d817b0695 (patch) | |
| tree | 33ba2ac865d037ecc77c1b5e87d6ecdfd48e60df /app | |
| parent | 1f5fe2715c6dd51fa04244085faa6027528a9fe5 (diff) | |
| download | chouette-core-20a7080ea63d4887e578fea37751487d817b0695.tar.bz2 | |
Initialize import show with iev api
Diffstat (limited to 'app')
| -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 |
11 files changed, 222 insertions, 25 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 |
