Sha256: d010825c10b7159b98b8f93a4758eb2e69b3cf2f22161ab4d84dee2c1063246d

Contents?: true

Size: 1.37 KB

Versions: 24

Compression:

Stored size: 1.37 KB

Contents

require "fileutils"

module Renalware
  module Admin
    module Feeds
      class FilesController < BaseController
        include Renalware::Concerns::Pageable

        def index
          authorize files
          render locals: {
            files: files,
            uploaded_file: Renalware::Feeds::Files::FileUploadForm.new
          }
        end

        def create
          authorize Renalware::Feeds::File, :create?
          form = Renalware::Feeds::Files::FileUploadForm.new(file_upload_params)

          if form.valid?
            file = Renalware::Feeds::Files::CreateFeedFile.call(
              uploaded_file: Pathname.new(form.file.path),
              file_type: Renalware::Feeds::FileType.find(form.file_type_id),
              user: current_user
            )
            Renalware::Feeds::Files::EnqueueFileForBackgroundProcessing.call(file)
            redirect_to(
              admin_feeds_files_path,
              notice: "File #{form.file.original_filename} queued for processing"
            )
          else
            render :index, locals: { files: files, uploaded_file: form }
          end
        end

        private

        def files
          @files ||= Renalware::Feeds::File.ordered.page(page).per(per_page)
        end

        def file_upload_params
          params.require(:file_upload).permit(:file, :file_type_id)
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.15 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.14 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.13 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.12 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.11 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.9 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.8 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.7 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.5 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.4 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.3 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.2 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.1 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.0 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/admin/feeds/files_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/admin/feeds/files_controller.rb