aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjpl2017-08-16 15:04:35 +0200
committerjpl2017-08-16 15:04:35 +0200
commitf4f9f04f41696dd59cc982d8ea7a8ed862536622 (patch)
tree404629e24cbabff2e401e5e6fec6a0ccb0bf5563
parent6b15887670d16978d81f3481ee402ba11ca37625 (diff)
downloadchouette-core-f4f9f04f41696dd59cc982d8ea7a8ed862536622.tar.bz2
Refs #4256: adding pagination and so for imports#index
-rw-r--r--app/controllers/imports_controller.rb45
-rw-r--r--app/decorators/import_decorator.rb24
-rw-r--r--app/views/imports/index.html.slim8
-rw-r--r--config/locales/imports.fr.yml2
4 files changed, 73 insertions, 6 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
diff --git a/config/locales/imports.fr.yml b/config/locales/imports.fr.yml
index 911dfc56a..cc41a4f81 100644
--- a/config/locales/imports.fr.yml
+++ b/config/locales/imports.fr.yml
@@ -53,7 +53,7 @@ fr:
created_at: "Créé le"
started_at: Démarrage
name: "Nom de l'import"
- status: "Statut"
+ status: "Etat"
no_save: "Pas de sauvegarde"
references_type: "Données à importer"
rule_parameter_set_id: "Jeu de paramètres pour validation"