Guest User

Untitled

a guest
Jul 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. module UploadAssistant
  2.  
  3. extend ActiveSupport::Concern
  4. #
  5. # Code to execute when something does a `include ControllerAssistant`.
  6. #
  7. included do
  8. #
  9. # Make the application's local storage module more easily
  10. # accessible, too.
  11. #
  12. unless (self.const_defined?('LocalStore'))
  13. self.const_set('LocalStore', ::PerceptSys::LocalStore)
  14. end
  15.  
  16. def set_title_uploading
  17. title.base = 'Uploading records'
  18. title.add(model_info.friendly)
  19. end # def set_base_title
  20.  
  21. #+
  22. # Supply these routes to the controllers so they needn't define
  23. # them.
  24. #
  25.  
  26. #
  27. # GET /<model>/upload(.:format)
  28. #
  29. def webupload
  30. end # def webupload
  31.  
  32. #
  33. # POST /<model>/upload(.:format)
  34. #
  35. def upload
  36. title.add('Results')
  37. @uploads = {
  38. :success => {},
  39. :failure => {},
  40. }
  41. errors = 0
  42. @upload_records.each do |record|
  43. #
  44. # Stuff happens here.
  45. #
  46. end
  47. successes = @uploads[:success].count
  48. failures = @uploads[:failure].count
  49. respond_to do |format|
  50. format.html {
  51. render(:upload,
  52. :status => :ok,
  53. :template => 'application/upload.html')
  54. }
  55. format.json {
  56. render(:json => @uploads)
  57. }
  58. end
  59. end
  60.  
  61. def upload_file_params
  62. if (params[:file])
  63. params.require(:file).require(:upload)
  64. colname = model_info.collection
  65. file_id = params[:file][:upload]
  66. #
  67. # Get the file contents.
  68. #
  69. end
  70. @upload_records = params.delete(model_info.collection.to_sym)
  71. end # def upload_file_params
  72.  
  73. def upload_params
  74. @upload_records = params.require(model_info.collection.to_sym)
  75. end # def upload_params
  76.  
  77. def set_file_upload
  78. file_id = params.require(:file).require(:upload)
  79. #
  80. # Read/decompress the file.
  81. #
  82. data = JSON.parse(data)
  83. params[model_info.collection] = data[model_info.collection]
  84. end # def set_file_upload
  85.  
  86. end # included do
  87.  
  88. #+
  89. # Insert here any class methods we want added to our including class
  90. # or module.
  91. #
  92. class_methods do
  93.  
  94. #
  95. # Stuff relating specifically to bulk uploading.
  96. #
  97. before_action(:set_title_uploading,
  98. :only => [
  99. :upload,
  100. :webupload,
  101. ])
  102. before_action(:set_file_upload,
  103. :only => [
  104. :upload,
  105. ])
  106. before_action(:upload_params,
  107. :only => [
  108. :upload,
  109. ])
  110.  
  111. end # class_methods do
  112.  
  113. end # module ControllerAssistant
  114.  
  115. # Local Variables:
  116. # mode: ruby
  117. # eval: (fci-mode t)
  118. # End:
Add Comment
Please, Sign In to add comment