aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/imports_controller.rb
diff options
context:
space:
mode:
authorZog2018-03-07 11:35:25 +0100
committerZog2018-03-12 12:00:14 +0100
commit1245099459bd3d7dce71fdf0d7c95b2377a0034e (patch)
treec17f2c4bd68fc6ad4eedead96e1106954d7093e4 /app/controllers/imports_controller.rb
parent0b9269780989dbd69a9be9d63670aab12050cf60 (diff)
downloadchouette-core-1245099459bd3d7dce71fdf0d7c95b2377a0034e.tar.bz2
Refs #6133; First Crud for exports
Diffstat (limited to 'app/controllers/imports_controller.rb')
-rw-r--r--app/controllers/imports_controller.rb56
1 files changed, 2 insertions, 54 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 3ebbeb665..f95b6acf1 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -1,31 +1,9 @@
class ImportsController < ChouetteController
include PolicyChecker
include RansackDateFilter
- before_action only: [:index] { set_date_time_params("started_at", DateTime) }
+ include IevInterfaces
skip_before_action :authenticate_user!, only: [:download]
defaults resource_class: Import::Base, collection_name: 'imports', instance_name: 'import'
- before_action :ransack_status_params, only: [:index]
- respond_to :html
- belongs_to :workbench
-
- def show
- show! do
- @import = @import.decorate(context: {
- workbench: @workbench
- })
- end
- end
-
- def index
- index! do |format|
- format.html {
- if collection.out_of_bounds?
- redirect_to params.merge(:page => 1)
- end
- @imports = decorate_imports(@imports)
- }
- end
- end
def download
if params[:token] == resource.token_download
@@ -35,31 +13,8 @@ class ImportsController < ChouetteController
end
end
- protected
- def collection
- scope = parent.imports.where(type: "Import::Workbench")
-
- scope = self.ransack_period_range(scope: scope, error_message: t('imports.filters.error_period_filter'), query: :where_started_at_in)
-
- @q = scope.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 ransack_status_params
- if params[:q]
- return params[:q].delete(:status_eq_any) if params[:q][:status_eq_any].empty? || ( (Import::Base.status.values & params[:q][:status_eq_any]).length >= 4 )
- params[:q][:status_eq_any].push("new", "running") if params[:q][:status_eq_any].include?("pending")
- params[:q][:status_eq_any].push("aborted", "canceled") if params[:q][:status_eq_any].include?("failed")
- end
- end
-
def build_resource
@import ||= Import::Workbench.new(*resource_params) do |import|
import.workbench = parent
@@ -76,14 +31,7 @@ class ImportsController < ChouetteController
)
end
- def sort_column
- parent.imports.column_names.include?(params[:sort]) ? params[:sort] : 'created_at'
- end
- def sort_direction
- %w[asc desc].include?(params[:direction]) ? params[:direction] : 'desc'
- end
-
- def decorate_imports(imports)
+ def decorate_collection(imports)
ImportDecorator.decorate(
imports,
context: {