diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/imports_controller.rb | 45 | ||||
| -rw-r--r-- | app/decorators/import_decorator.rb | 24 | ||||
| -rw-r--r-- | app/views/imports/index.html.slim | 8 |
3 files changed, 72 insertions, 5 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 70c5c1a0d..9ddbbb012 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -11,7 +11,15 @@ class ImportsController < BreadcrumbController end def index - index! do + index! do |format| + format.html { + if collection.out_of_bounds? + redirect_to params.merge(:page => 1) + end + + @imports = decorate_imports(@imports) + } + build_breadcrumb :index end end @@ -34,6 +42,17 @@ class ImportsController < BreadcrumbController end end + protected + def collection + @q = parent.imports.search(params[:q]) + + if sort_column && sort_direction + @imports ||= @q.result(distinct: true).order(sort_column + ' ' + sort_direction).paginate(page: params[:page], per_page: 10) + else + @imports ||= @q.result(distinct: true).order(:name).paginate(page: params[:page], per_page: 10) + end + end + private def build_resource @@ -44,6 +63,28 @@ class ImportsController < BreadcrumbController end def import_params - params.require(:import).permit(:name, :file, :type, :referential_id) + params.require(:import).permit( + :name, + :file, + :type, + :referential_id + ) + end + + def sort_column + parent.imports.column_names.include?(params[:sort]) ? params[:sort] : 'name' + end + def sort_direction + %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' + end + + def decorate_imports(imports) + ModelDecorator.decorate( + imports, + with: ImportDecorator, + context: { + workbench: @workbench + } + ) end end diff --git a/app/decorators/import_decorator.rb b/app/decorators/import_decorator.rb new file mode 100644 index 000000000..2cf1defc4 --- /dev/null +++ b/app/decorators/import_decorator.rb @@ -0,0 +1,24 @@ +class ImportDecorator < Draper::Decorator + decorates Import + + delegate_all + + def action_links + links = [] + + if h.policy(object).destroy? + links << Link.new( + content: t('actions.destroy'), + href: h.workbench_import_path( + context[:workbench], + object + ), + method: :delete, + data: { confirm: h.t('imports.actions.destroy_confirm') } + ) + end + + links + end + +end diff --git a/app/views/imports/index.html.slim b/app/views/imports/index.html.slim index a3e06840f..fa0109971 100644 --- a/app/views/imports/index.html.slim +++ b/app/views/imports/index.html.slim @@ -19,7 +19,7 @@ ), \ TableBuilderHelper::Column.new( \ key: :started_at, \ - attribute: 'started_at' \ + attribute: Proc.new { |imp| imp.started_at ? l(imp.started_at, format: :short) : '-' } \ ), \ TableBuilderHelper::Column.new( \ key: :name, \ @@ -30,10 +30,12 @@ # attribute: '' \ # ) \ ], - links: [], + links: [:show, :destroy], cls: 'table has-search' + + / links to include: show, rapports de controle, dl source, destroy - / = new_pagination @imports, 'pull-right' + = new_pagination @imports, 'pull-right' - unless @imports.any? .row |
