Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module UploadAssistant
- extend ActiveSupport::Concern
- #
- # Code to execute when something does a `include ControllerAssistant`.
- #
- included do
- #
- # Make the application's local storage module more easily
- # accessible, too.
- #
- unless (self.const_defined?('LocalStore'))
- self.const_set('LocalStore', ::PerceptSys::LocalStore)
- end
- def set_title_uploading
- title.base = 'Uploading records'
- title.add(model_info.friendly)
- end # def set_base_title
- #+
- # Supply these routes to the controllers so they needn't define
- # them.
- #
- #
- # GET /<model>/upload(.:format)
- #
- def webupload
- end # def webupload
- #
- # POST /<model>/upload(.:format)
- #
- def upload
- title.add('Results')
- @uploads = {
- :success => {},
- :failure => {},
- }
- errors = 0
- @upload_records.each do |record|
- #
- # Stuff happens here.
- #
- end
- successes = @uploads[:success].count
- failures = @uploads[:failure].count
- respond_to do |format|
- format.html {
- render(:upload,
- :status => :ok,
- :template => 'application/upload.html')
- }
- format.json {
- render(:json => @uploads)
- }
- end
- end
- def upload_file_params
- if (params[:file])
- params.require(:file).require(:upload)
- colname = model_info.collection
- file_id = params[:file][:upload]
- #
- # Get the file contents.
- #
- end
- @upload_records = params.delete(model_info.collection.to_sym)
- end # def upload_file_params
- def upload_params
- @upload_records = params.require(model_info.collection.to_sym)
- end # def upload_params
- def set_file_upload
- file_id = params.require(:file).require(:upload)
- #
- # Read/decompress the file.
- #
- data = JSON.parse(data)
- params[model_info.collection] = data[model_info.collection]
- end # def set_file_upload
- end # included do
- #+
- # Insert here any class methods we want added to our including class
- # or module.
- #
- class_methods do
- #
- # Stuff relating specifically to bulk uploading.
- #
- before_action(:set_title_uploading,
- :only => [
- :upload,
- :webupload,
- ])
- before_action(:set_file_upload,
- :only => [
- :upload,
- ])
- before_action(:upload_params,
- :only => [
- :upload,
- ])
- end # class_methods do
- end # module ControllerAssistant
- # Local Variables:
- # mode: ruby
- # eval: (fci-mode t)
- # End:
Add Comment
Please, Sign In to add comment