diff options
| author | Zakaria BOUZIANE | 2015-03-10 12:04:25 +0100 |
|---|---|---|
| committer | Zakaria BOUZIANE | 2015-03-10 12:04:25 +0100 |
| commit | e3cd779d28af135dc32b25ba249be48ebf6658bf (patch) | |
| tree | 5f59356149e5eb58f7bf9459db5c2229a0d278ca /app | |
| parent | 8d9281dcc994ad76092b4878b26801507915f16a (diff) | |
| parent | dc6fc17f5ea46c871154e398037fab3bb741504e (diff) | |
| download | chouette-core-e3cd779d28af135dc32b25ba249be48ebf6658bf.tar.bz2 | |
Merged code
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/javascripts/application.js | 2 | ||||
| -rw-r--r-- | app/assets/stylesheets/application.css.scss.erb | 2 | ||||
| -rw-r--r-- | app/assets/stylesheets/main/compliance_check_tasks.css.scss | 19 | ||||
| -rw-r--r-- | app/assets/stylesheets/main/imports.css.scss (renamed from app/assets/stylesheets/main/import_tasks.css.scss) | 39 | ||||
| -rw-r--r-- | app/controllers/imports_controller.rb | 66 | ||||
| -rw-r--r-- | app/helpers/breadcrumb_helper.rb | 6 | ||||
| -rw-r--r-- | app/models/import.rb | 14 | ||||
| -rw-r--r-- | app/models/import_report.rb | 103 | ||||
| -rw-r--r-- | app/views/imports/_results_dashboard.html.erb | 61 | ||||
| -rw-r--r-- | app/views/imports/show.html.erb | 6 | ||||
| -rw-r--r-- | app/views/imports/show.js.coffee | 42 |
11 files changed, 266 insertions, 94 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 07fc8694c..d138ec187 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,7 +10,7 @@ //= require modernizr //= require cocoon //= require raphael -//= require morris +//= require morrisjs //= require bootstrap-sass-official //= require typeahead.js //= require jquery-tokeninput diff --git a/app/assets/stylesheets/application.css.scss.erb b/app/assets/stylesheets/application.css.scss.erb index af43d97a6..66217204a 100644 --- a/app/assets/stylesheets/application.css.scss.erb +++ b/app/assets/stylesheets/application.css.scss.erb @@ -24,7 +24,7 @@ $body-bg: #eee; @import "font-awesome-sprockets"; @import "font-awesome"; @import "jquery.ui.all"; -@import "morris"; +@import "morrisjs"; @import "formtastic"; @import 'eonasdan-bootstrap-datetimepicker'; diff --git a/app/assets/stylesheets/main/compliance_check_tasks.css.scss b/app/assets/stylesheets/main/compliance_check_tasks.css.scss index 13ab1e674..f64a01b34 100644 --- a/app/assets/stylesheets/main/compliance_check_tasks.css.scss +++ b/app/assets/stylesheets/main/compliance_check_tasks.css.scss @@ -1,19 +1,18 @@ - -.status { - margin-left: 10px; -} - -.status_failed { color: #a94442;} -.status_pending { color: #31708f;} -.status_processing { color: #31708f;} -.status_completed { color: #3c763d;} - #workspace.compliance_check_tasks.index { } #workspace.compliance_check_tasks.show { + .status { + margin-left: 10px; + } + + .status_failed { color: #a94442;} + .status_pending { color: #31708f;} + .status_processing { color: #31708f;} + .status_completed { color: #3c763d;} + .links{ margin: 0px 0 20px 0; diff --git a/app/assets/stylesheets/main/import_tasks.css.scss b/app/assets/stylesheets/main/imports.css.scss index 198f83129..93fb499f9 100644 --- a/app/assets/stylesheets/main/import_tasks.css.scss +++ b/app/assets/stylesheets/main/imports.css.scss @@ -1,9 +1,18 @@ -#workspace.import_tasks.index +#workspace.imports.index { } -#workspace.import_tasks.show { +#workspace.imports.show { + .status { + margin-left: 10px; + } + + .status_aborted,.status_canceled { color: #a94442;} + .status_created { color: #31708f;} + .status_scheduled { color: #31708f;} + .status_terminated { color: #3c763d;} + .links{ margin: 0 0 20px 0; img{ margin: 0 5px 0 15px; } @@ -18,19 +27,8 @@ visibility: hidden; } - .col1 { - float: left; - width: 45%; - } - - .col2 { - margin-left: 10px; - float: left; - width: 45%; - } - - #files_statistics { height: 200px; } - #objects_statistics { height: 200px; } + #files_statistics { height: 225px; } + #objects_statistics { height: 225px; } .caption { text-align :center; @@ -67,11 +65,18 @@ display: none; } - .lines{ display: none; } + .lines{ + display: none; + + td{ + text-align: center; + } + + } } } -#workspace.import_tasks.new #workspace.import_tasks.create form.import_task_new { +#workspace.imports.new #workspace.imports.create form.import_new { padding: 0.5em 0; margin-top: -0.5em; margin-bottom: 1em; diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 7bf4897ce..2af6a57d6 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,7 +1,9 @@ require 'will_paginate/array' class ImportsController < ChouetteController - respond_to :html, :xml, :json + defaults :resource_class => Import + + respond_to :html, :only => [:show, :index, :new, :create, :delete] respond_to :js, :only => [:show, :index] belongs_to :referential @@ -9,15 +11,65 @@ class ImportsController < ChouetteController # index curl http://localhost:8080/mobi.chouette.api/referentials/test/jobs # show curl http://localhost:8080/mobi.chouette.api/referentials/test/jobs + def index - index! do - build_breadcrumb :index + begin + index! do + build_breadcrumb :index + end + rescue IevApi::IevError => error + logger.error("Iev failure : #{error.message}") + flash[:error] = t('iev.failure') + redirect_to referential_path(@referential) end end def show - show! do - build_breadcrumb :show + begin + show! do + build_breadcrumb :show + end + rescue IevApi::IevError => error + logger.error("Iev failure : #{error.message}") + flash[:error] = t('iev.failure') + redirect_to referential_path(@referential) + end + end + + def new + begin + new! do + puts "OK" + end + rescue IevApi::IevError => error + logger.error("Iev failure : #{error.message}") + flash[:error] = t('iev.failure') + redirect_to referential_path(@referential) + end + end + + def create + begin + create! do + puts "OK" + end + rescue IevApi::IevError => error + logger.error("Iev failure : #{error.message}") + flash[:error] = t('iev.failure') + redirect_to referential_path(@referential) + end + end + + def delete + begin + delete! do + import_service.delete(@import.id) + redirect_to referential_imports_path(@referential) + end + rescue IevApi::IevError => error + logger.error("Iev failure : #{error.message}") + flash[:error] = t('iev.failure') + redirect_to referential_path(@referential) end end @@ -27,6 +79,10 @@ class ImportsController < ChouetteController ImportService.new(@referential) end + def build_resource(attributes = {}) + @import ||= ImportTask.new + end + def resource @import ||= import_service.find( params[:id] ) end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index b85dc3527..89cb92633 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -30,7 +30,7 @@ module BreadcrumbHelper time_table_breadcrumb action when "StopAreaCopy" stop_area_copy_breadcrumb action - when "ImportTask" + when "Import" import_breadcrumb action when "Export" export_breadcrumb action @@ -133,8 +133,8 @@ module BreadcrumbHelper end def import_breadcrumb (action) - referential_breadcrumb - add_breadcrumb Referential.human_attribute_name("import_tasks"), referential_import_tasks_path(@referential) unless action == :index + referential_breadcrumb + add_breadcrumb Referential.human_attribute_name("imports"), referential_imports_path(@referential) unless action == :index end def export_breadcrumb (action) diff --git a/app/models/import.rb b/app/models/import.rb index 7b2405db2..f1d6169f1 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -9,20 +9,28 @@ class Import attr_reader :datas, :report def initialize( options = Hashie::Mash.new ) - puts "options #{options.inspect}" @datas = options @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" }) ) + result = IevApi.job(referential_name, id,{ :action => "importer" }) + ImportReport.new( result ) end def id @datas.id end + def filename + @datas.filename + end + + def filename_extension + File.extname(filename) if filename + end + def percentage_progress if %w{created}.include? status 0 @@ -38,7 +46,7 @@ class Import end def referential_name - @datas.parameters.referential + @datas.referential end def name diff --git a/app/models/import_report.rb b/app/models/import_report.rb index 8ec112dc3..50857b4e7 100644 --- a/app/models/import_report.rb +++ b/app/models/import_report.rb @@ -1,7 +1,4 @@ class ImportReport - extend Enumerize - extend ActiveModel::Naming - include ActiveModel::Model attr_reader :datas @@ -9,4 +6,104 @@ class ImportReport @datas = options end + def zip_file + datas.zip_file + end + + def error_files + datas.files.select{ |file| file[:status] == "ERROR"} + end + + def ignored_files + datas.files.select{ |file| file[:status] == "IGNORED"} + end + + def ok_files + datas.files.select{ |file| file[:status] == "OK"} + end + + def files + datas.files + end + + def line_items + [].tap do |line_items| + datas.lines.each do |line| + line_items << LineItem.new(line) + end + end + end + + def lines + 1 #datas.stats.line_count if datas.stats_.line_count? + end + + def routes + datas.stats.route_count if datas.stats_.route_count? + end + + def connection_links + datas.stats.connection_link_count if datas.stats_.connection_link_count? + end + + def time_tables + datas.stats.time_table_count if datas.stats_.time_table_count? + end + + def stop_areas + datas.stats.stop_area_count if datas.stats_.stop_area_count? + end + + def access_points + datas.stats.access_point_count if datas.stats_.access_point_count? + end + + def vehicle_journeys + datas.stats.vehicle_journey_count if datas.stats_.vehicle_journey_count? + end + + def journey_patterns + datas.stats.journey_pattern_count if datas.stats_.journey_pattern_count? + end + + class LineItem + attr_reader :name, :status, :stats + + def initialize( options = Hashie::Mash.new ) + @name = options.name if options.name? + @status = options.status if options.status? + @stats = options.stats if options.stats? + end + + def routes + stats.route_count + end + + def connection_links + stats.connection_link_count + end + + def time_tables + stats.time_table_count + end + + def stop_areas + stats.stop_area_count + end + + def access_points + stats.access_point_count + end + + def vehicle_journeys + stats.vehicle_journey_count + end + + def journey_patterns + stats.journey_pattern_count + end + + end + end + diff --git a/app/views/imports/_results_dashboard.html.erb b/app/views/imports/_results_dashboard.html.erb index bde732f73..e873e8902 100644 --- a/app/views/imports/_results_dashboard.html.erb +++ b/app/views/imports/_results_dashboard.html.erb @@ -1,38 +1,40 @@ - <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="resume row"> + <div class="col-md-4"> + <% file_title = (@import.filename_extension=="zip") ? t( "imports.show.graph.files.title_zip") : t( "imports.show.graph.files.title_default", :extension => @import.filename_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 class="col-md-8"> + <div class="caption"><%= t "imports.show.graph.lines.title" %></div> <div id="objects_statistics"></div> </div> </div> - <div class="report"> + <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 %> + <% @import.report.error_files.each_with_index do |file, index| %> + <div class="col-md-6"> + <%= image_tag "icons/file_xml_md.png" %><span class="file_name" title='<%= file.name %>'><%= truncate(file.name, :length => 40) %></span> + </div> <% 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 %> + <% @import.report.ignored_files.each_with_index do |file, index| %> + <div class="col-md-6"> + <%= image_tag "icons/file_xml_md.png" %><span class="file_name" title='<%= file.name %>'><%= truncate(file.name, :length => 40) %></span> + </div> <% 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 %> + <% @import.report.ok_files.each_with_index do |file, index| %> + <div class="col-md-6"> + <%= image_tag "icons/file_xml_md.png" %><span class="file_name" title='<%= file.name %>'><%= truncate(file.name, :length => 40) %></span> + </div> <% end %> </div> <div class="lines"> - <table class="table table-hover"> + <table class="table table-hover table-striped"> <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> @@ -45,24 +47,23 @@ </tr> </thead> <tbody> - <% @lines_list.each_with_index do |line, index| %> - <% tr_class = (line["status"]=="saved") ? '' : 'class=\'danger\''%> + <% @import.report.line_items.each_with_index do |line_item, index| %> + <% tr_class = (line_item.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> + <td><%= line_item.name %></td> + <td><%= t("import_tasks.show.table.line." + line_item.status ) %></td> + <td><%= line_item.routes %></td> + <td><%= line_item.connection_links %></td> + <td><%= line_item.time_tables %></td> + <td><%= line_item.stop_areas %></td> + <td><%= line_item.access_points %></td> + <td><%= line_item.vehicle_journeys %></td> + <td><%= line_item.journey_patterns %></td> </tr> <% end %> </tbody> </table> </div> </div> - <%= javascript_include_tag referential_import_task_path(@import_task.referential, @import_task,:format => :js) %> + <%= javascript_include_tag referential_import_path(@referential, @import.id,:format => :js) %> diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb index 41b04d22b..e87292b85 100644 --- a/app/views/imports/show.html.erb +++ b/app/views/imports/show.html.erb @@ -1,8 +1,10 @@ +<div class="test"> <% 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>" %> +<%= title_tag "#{title} #{@import.name} <span class='status status_#{@import.status}'>#{ t('imports.statuses.'+ @import.status) }</span>" %> +</div> <div class="import_show"> - + <%= render( :partial => "results_dashboard", :locals => { :referential => @referential} ) %> </div> <% content_for :sidebar do %> diff --git a/app/views/imports/show.js.coffee b/app/views/imports/show.js.coffee index c856154fa..e2416e967 100644 --- a/app/views/imports/show.js.coffee +++ b/app/views/imports/show.js.coffee @@ -1,5 +1,5 @@ jQuery -> - + get_import_results = (html_container, html_element) -> html_container.children().each -> if( $( this ).is(html_element) ) @@ -10,32 +10,36 @@ jQuery -> 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"] %> } + {label: "<%= t 'imports.show.graph.files.error' %>", value: <%= @import.report.error_files.count %> }, + {label: "<%= t 'imports.show.graph.files.ignored' %>", value: <%= @import.report.ignored_files.count %> }, + {label: "<%= t 'imports.show.graph.files.ok' %>", value: <%= @import.report.ok_files.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") + 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"] %> }, + { object: "<%= t("imports.show.graph.lines.lines_stats").html_safe %>", value: <%= @import.report.lines %> }, + { object: "<%= t("imports.show.graph.lines.routes_stats").html_safe %>", value: <%= @import.report.routes %> }, + { object: "<%= t("imports.show.graph.lines.connection_links_stats").html_safe %>", value: <%= @import.report.connection_links %> }, + { object: "<%= t("imports.show.graph.lines.time_tables_stats").html_safe %>", value: <%= @import.report.time_tables %> }, + { object: "<%= t("imports.show.graph.lines.stop_areas_stats").html_safe %>", value: <%= @import.report.stop_areas %> }, + { object: "<%= t("imports.show.graph.lines.access_points_stats").html_safe %>", value: <%= @import.report.access_points %> }, + { object: "<%= t("imports.show.graph.lines.vehicle_journeys_stats").html_safe %>", value: <%= @import.report.vehicle_journeys %> }, + { object: "<%= t("imports.show.graph.lines.journey_patterns_stats").html_safe %>", value: <%= @import.report.journey_patterns %> }, ], xkey: 'object', ykeys: ['value'], - labels: ['<%= t "import_tasks.show.graph.lines.objects_label" %>'] + labels: ['<%= t "imports.show.graph.lines.objects_label" %>'] + xLabelAngle: 40, + xAxisLabelTopPadding: 7, + padding: 40, + hideHover: true }).on('click', update = (i, row) -> - get_import_results( $(".report"), $(".lines")) )
\ No newline at end of file + get_import_results( $(".report"), $(".lines")) )
\ No newline at end of file |
