rails_data 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +165 -0
  3. data/README.md +41 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/rails_data_manifest.js +1 -0
  6. data/app/assets/javascripts/channels/done.js +10 -0
  7. data/app/assets/javascripts/controllers/the_data_admin/data_lists/edit.js +1 -0
  8. data/app/assets/javascripts/controllers/the_data_admin/data_lists/new.js +1 -0
  9. data/app/assets/javascripts/controllers/the_data_admin/table_lists/index.js +10 -0
  10. data/app/channels/done_channel.rb +7 -0
  11. data/app/channels/rails_data_connection.rb +29 -0
  12. data/app/controllers/rails_data_admin/base_controller.rb +3 -0
  13. data/app/controllers/rails_data_admin/data_lists_controller.rb +75 -0
  14. data/app/controllers/rails_data_admin/data_records_controller.rb +71 -0
  15. data/app/controllers/rails_data_admin/record_lists_controller.rb +105 -0
  16. data/app/controllers/rails_data_admin/table_lists_controller.rb +115 -0
  17. data/app/helpers/data_records_helper.rb +2 -0
  18. data/app/helpers/rails_data_helper.rb +21 -0
  19. data/app/jobs/table_job.rb +11 -0
  20. data/app/mailers/report_finish_mailer.rb +17 -0
  21. data/app/models/rails_data/concerns/data_cache_service.rb +26 -0
  22. data/app/models/rails_data/concerns/data_export_helper.rb +55 -0
  23. data/app/models/rails_data/concerns/data_import_helper.rb +40 -0
  24. data/app/models/rails_data/concerns/data_import_service.rb +35 -0
  25. data/app/models/rails_data/data_list.rb +47 -0
  26. data/app/models/rails_data/data_lists/data_export.rb +11 -0
  27. data/app/models/rails_data/data_lists/data_import.rb +11 -0
  28. data/app/models/rails_data/data_lists/data_record.rb +18 -0
  29. data/app/models/rails_data/export_services/csv_export_service.rb +24 -0
  30. data/app/models/rails_data/export_services/pdf_export_service.rb +74 -0
  31. data/app/models/rails_data/export_services/xlsx_export_service.rb +51 -0
  32. data/app/models/rails_data/record_list.rb +69 -0
  33. data/app/models/rails_data/table_item.rb +5 -0
  34. data/app/models/rails_data/table_list.rb +47 -0
  35. data/app/pdfs/concerns/pdf_page_helper.rb +37 -0
  36. data/app/pdfs/concerns/pdf_table_helper.rb +107 -0
  37. data/app/pdfs/concerns/pdf_text_helper.rb +18 -0
  38. data/app/pdfs/rails_data_pdf.rb +32 -0
  39. data/app/views/rails_data_admin/base/_nav.html.erb +9 -0
  40. data/app/views/rails_data_admin/data_lists/_item_form.html.erb +15 -0
  41. data/app/views/rails_data_admin/data_lists/add_item.js.erb +4 -0
  42. data/app/views/rails_data_admin/data_lists/edit.html.erb +33 -0
  43. data/app/views/rails_data_admin/data_lists/index.html.erb +43 -0
  44. data/app/views/rails_data_admin/data_lists/new.html.erb +17 -0
  45. data/app/views/rails_data_admin/data_lists/remove_item.js.erb +1 -0
  46. data/app/views/rails_data_admin/data_lists/reportable.html.erb +31 -0
  47. data/app/views/rails_data_admin/data_lists/show.html.erb +20 -0
  48. data/app/views/rails_data_admin/data_records/_item_form.html.erb +15 -0
  49. data/app/views/rails_data_admin/data_records/add_item.js.erb +4 -0
  50. data/app/views/rails_data_admin/data_records/edit.html.erb +33 -0
  51. data/app/views/rails_data_admin/data_records/index.html.erb +57 -0
  52. data/app/views/rails_data_admin/data_records/new.html.erb +16 -0
  53. data/app/views/rails_data_admin/data_records/remove_item.js.erb +1 -0
  54. data/app/views/rails_data_admin/data_records/reportable.html.erb +31 -0
  55. data/app/views/rails_data_admin/data_records/show.html.erb +20 -0
  56. data/app/views/rails_data_admin/record_lists/_edit_columns.html.erb +19 -0
  57. data/app/views/rails_data_admin/record_lists/_edit_table.erb +44 -0
  58. data/app/views/rails_data_admin/record_lists/_index.html.erb +22 -0
  59. data/app/views/rails_data_admin/record_lists/_search_form.html.erb +9 -0
  60. data/app/views/rails_data_admin/record_lists/_show.html.erb +16 -0
  61. data/app/views/rails_data_admin/record_lists/_table.html.erb +12 -0
  62. data/app/views/rails_data_admin/record_lists/edit.html.erb +19 -0
  63. data/app/views/rails_data_admin/record_lists/edit_columns.html.erb +30 -0
  64. data/app/views/rails_data_admin/record_lists/edit_columns.js.erb +9 -0
  65. data/app/views/rails_data_admin/record_lists/find.js.erb +8 -0
  66. data/app/views/rails_data_admin/record_lists/index.html.erb +52 -0
  67. data/app/views/rails_data_admin/record_lists/new.html.erb +19 -0
  68. data/app/views/rails_data_admin/record_lists/show.html.erb +19 -0
  69. data/app/views/rails_data_admin/record_lists/show.js.erb +8 -0
  70. data/app/views/rails_data_admin/record_lists/update_columns.js.erb +8 -0
  71. data/app/views/rails_data_admin/table_lists/_import.html.erb +17 -0
  72. data/app/views/rails_data_admin/table_lists/_index.html.erb +22 -0
  73. data/app/views/rails_data_admin/table_lists/_process.html.erb +5 -0
  74. data/app/views/rails_data_admin/table_lists/_show.html.erb +10 -0
  75. data/app/views/rails_data_admin/table_lists/_table.html.erb +38 -0
  76. data/app/views/rails_data_admin/table_lists/create_import.js.erb +8 -0
  77. data/app/views/rails_data_admin/table_lists/edit.html.erb +19 -0
  78. data/app/views/rails_data_admin/table_lists/find.js.erb +2 -0
  79. data/app/views/rails_data_admin/table_lists/index.html.erb +55 -0
  80. data/app/views/rails_data_admin/table_lists/new.html.erb +19 -0
  81. data/app/views/rails_data_admin/table_lists/new_import.js.erb +30 -0
  82. data/app/views/rails_data_admin/table_lists/run.js.erb +10 -0
  83. data/app/views/rails_data_admin/table_lists/show.html.erb +11 -0
  84. data/app/views/report_finish_mailer/finish_notify.text.erb +5 -0
  85. data/config/initializers/the_data.rb +4 -0
  86. data/config/locales/en.yml +10 -0
  87. data/config/locales/zh.yml +10 -0
  88. data/config/routes.rb +35 -0
  89. data/db/migrate/20150618053929_create_report_lists.rb +51 -0
  90. data/lib/rails_data/config.rb +23 -0
  91. data/lib/rails_data/engine.rb +18 -0
  92. data/lib/rails_data/export.rb +52 -0
  93. data/lib/rails_data/import.rb +42 -0
  94. data/lib/rails_data/record.rb +42 -0
  95. data/lib/rails_data/version.rb +3 -0
  96. data/lib/rails_data.rb +5 -0
  97. data/test/controllers/data_records_controller_test.rb +48 -0
  98. data/test/controllers/rails_data_admin/report_lists_controller_test.rb +49 -0
  99. data/test/controllers/rails_data_admin/table_lists_controller_test.rb +49 -0
  100. data/test/factories/combines.rb +7 -0
  101. data/test/factories/report_lists.rb +14 -0
  102. data/test/factories/table_items.rb +6 -0
  103. data/test/factories/table_lists.rb +6 -0
  104. data/test/integration/navigation_test.rb +10 -0
  105. data/test/models/data_list_test.rb +10 -0
  106. data/test/system/data_records_test.rb +41 -0
  107. data/test/test_helper.rb +21 -0
  108. data/test/the_data_test.rb +7 -0
  109. metadata +247 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1b15a982fa559da9af934d78c65d9de10f53aed1545e3c7a32d5ba4a5c202b71
4
+ data.tar.gz: a8efc9ec82b84a38ad3a89994ae7615c644719aed54b5d6c6cb4b45675b8a822
5
+ SHA512:
6
+ metadata.gz: b8d70bea26c1b6ec2d38dc424129de6e19d663ba81ba33080c0bdd36c0804fe7161c19cbfffce0bac2fa0ea27563c7435be06eb5f4f0f8abaed731c05f754e46
7
+ data.tar.gz: 1ed27490934b8b929b1974e218d84d7d5d5b74db5c423cdb5353c2905c6a0c54b31d30e323018b657475f80d02a060aa37aad581acf5fe8f4bd9d53698f8f7f0
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2018 Mingyuan Qin.
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # TheData
2
+ TheData is a MiddleMan for import data and export data, It can be used for generating complex report.
3
+ And It can transfer data to many format, Like: csv, pdf, html, xml and more.
4
+
5
+ ## Features
6
+ - Easy to use, Just config;
7
+ - Separate pdf style and data;
8
+ - Strong, even data processing break off, It can be restore easily;
9
+
10
+ ## Functions
11
+ - sidekiq job;
12
+ - report file store;
13
+ - send email notice user after finished sidekiq job;
14
+
15
+ ## Getting Started
16
+
17
+ #### step-1: Add one_report to you Gemfile:
18
+
19
+ ```ruby
20
+ gem 'the_data'
21
+ ```
22
+
23
+ #### step-2: Run migrations
24
+
25
+ ```bash
26
+ rake the_auth_engine:install:migrations
27
+ rake db:migrate
28
+ ```
29
+
30
+ ## How to use
31
+
32
+ #### step-1: Define table
33
+ The table defined the report's data format
34
+
35
+ [Define Report Table](docs/define-report-table.md)
36
+
37
+ #### step-3: (optional) Define report pdf's style
38
+ [Define report pdf style](docs/define-pdf-style)
39
+
40
+ # 依赖
41
+ [the_role](https://github.com/yigexiangfa/the_role)
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'TheData'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1 @@
1
+ //= link_tree ../javascripts/controllers .js
@@ -0,0 +1,10 @@
1
+ App.cable.subscriptions.create('DoneChannel', {
2
+ received: function(data) {
3
+ var c_id = '#done_' + data.done_id;
4
+ var collection = $(c_id);
5
+ collection.html(data.body);
6
+ },
7
+ connected: function() {
8
+ console.log('done channel connected success');
9
+ }
10
+ });
@@ -0,0 +1 @@
1
+ $('#data_list_type').dropdown();
@@ -0,0 +1,10 @@
1
+ //= require action_cable
2
+ //= require_self
3
+ //= require channels/done
4
+
5
+ (function() {
6
+ this.App || (this.App = {});
7
+
8
+ App.cable = ActionCable.createConsumer('/cable');
9
+
10
+ }).call(this);
@@ -0,0 +1,7 @@
1
+ class DoneChannel < ApplicationCable::Channel
2
+
3
+ def subscribed
4
+ stream_from "user:#{current_user_id}"
5
+ end
6
+
7
+ end
@@ -0,0 +1,29 @@
1
+ # prepend this module
2
+ module RailsDataConnection
3
+
4
+ def self.prepended(model)
5
+ model.identified_by :current_user
6
+ end
7
+
8
+ def connect
9
+ self.current_user = find_verified_user
10
+ super
11
+ end
12
+
13
+ protected
14
+ # todo why session got nil
15
+ def find_verified_user
16
+ if session && session['user_id']
17
+ User.find_by id: session['user_id']
18
+ else
19
+ logger.error 'An unauthorized connection attempt was rejected'
20
+ nil
21
+ end
22
+ end
23
+
24
+ def session
25
+ session_key = Rails.application.config.session_options[:key]
26
+ cookies.encrypted[session_key]
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ class RailsDataAdmin::BaseController < RailsData.config.admin_class.constantize
2
+
3
+ end
@@ -0,0 +1,75 @@
1
+ class RailsDataAdmin::DataListsController < RailsDataAdmin::BaseController
2
+ before_action :set_data_list, only: [:show, :edit, :update, :rebuild, :destroy]
3
+
4
+ def index
5
+ query = params.permit(:type).reverse_merge type: 'DataExport'
6
+ @data_lists = DataList.default_where(query)
7
+ end
8
+
9
+ def new
10
+ @data_list = DataList.new(type: params[:type])
11
+ end
12
+
13
+ def create
14
+ @data_list = DataList.new(data_list_params)
15
+ @data_list.save
16
+
17
+ redirect_to data_lists_url(type: @data_list.type)
18
+ end
19
+
20
+ def show
21
+ end
22
+
23
+ def edit
24
+ end
25
+
26
+ def update
27
+ @data_list.update(data_list_params)
28
+ redirect_to data_lists_url(type: @data_list.type)
29
+ end
30
+
31
+ def add_item
32
+ @data_list = DataList.new
33
+ end
34
+
35
+ def remove_item
36
+
37
+ end
38
+
39
+ def rebuild
40
+ @data_list.rebuild!
41
+
42
+ redirect_back fallback_location: data_lists_url
43
+ end
44
+
45
+ def just_run
46
+
47
+ end
48
+
49
+ def destroy
50
+ @data_list.destroy
51
+ redirect_to data_lists_url, notice: 'Export file was successfully destroyed.'
52
+ end
53
+
54
+ private
55
+ def set_data_list
56
+ @data_list = DataList.find params[:id]
57
+ end
58
+
59
+ def data_list_params
60
+ result = params[:data_list].permit(
61
+ :type,
62
+ :title,
63
+ :comment,
64
+ :data_table,
65
+ :export_excel,
66
+ :export_pdf,
67
+ parameters: [:key, :value]
68
+ )
69
+ _params = result['parameters']&.values&.map { |i| {i['key'] => i['value'] } }
70
+ _params = Array(_params).to_combined_hash
71
+ result['parameters'] = _params
72
+ result
73
+ end
74
+
75
+ end
@@ -0,0 +1,71 @@
1
+ class RailsDataAdmin::DataRecordsController < RailsDataAdmin::BaseController
2
+ before_action :set_data_record, only: [:show, :edit, :update, :rebuild, :destroy]
3
+
4
+ def index
5
+ @data_records = DataRecord.page(params[:page])
6
+ end
7
+
8
+ def new
9
+ @data_record = DataRecord.new(type: params[:type])
10
+ end
11
+
12
+ def create
13
+ @data_record = DataRecord.new(data_record_params)
14
+ @data_record.save
15
+
16
+ redirect_to data_records_url(type: @data_record.type)
17
+ end
18
+
19
+ def show
20
+ end
21
+
22
+ def edit
23
+ end
24
+
25
+ def update
26
+ @data_record.update(data_record_params)
27
+ redirect_to data_records_url(type: @data_record.type)
28
+ end
29
+
30
+ def add_item
31
+ @data_record = DataRecord.new
32
+ end
33
+
34
+ def remove_item
35
+
36
+ end
37
+
38
+ def rebuild
39
+ @data_record.columns = @data_record.config_columns
40
+ @data_record.save
41
+
42
+ redirect_back fallback_location: data_records_url
43
+ end
44
+
45
+ def destroy
46
+ @data_record.destroy
47
+ redirect_to data_records_url, notice: 'Export file was successfully destroyed.'
48
+ end
49
+
50
+ private
51
+ def set_data_record
52
+ @data_record = DataRecord.find params[:id]
53
+ end
54
+
55
+ def data_record_params
56
+ result = params[:data_record].permit(
57
+ :type,
58
+ :title,
59
+ :comment,
60
+ :data_table,
61
+ :export_excel,
62
+ :export_pdf,
63
+ parameters: [:key, :value]
64
+ )
65
+ _params = result['parameters']&.values&.map { |i| {i['key'] => i['value'] } }
66
+ _params = Array(_params).to_combined_hash
67
+ result['parameters'] = _params
68
+ result
69
+ end
70
+
71
+ end
@@ -0,0 +1,105 @@
1
+ class RailsDataAdmin::RecordListsController < RailsDataAdmin::BaseController
2
+ before_action :set_data_record
3
+ before_action :set_record_list, only: [:show, :edit, :row, :run, :update, :edit_columns, :update_columns, :destroy]
4
+ skip_before_action :require_role
5
+ before_action do |controller|
6
+ controller.require_role(params[:data_record_id])
7
+ end
8
+
9
+ def index
10
+ extra_params = params.fetch(:q, {}).permit(@data_record.parameters.keys)
11
+ extra_params.reject! { |_, value| value.blank? }
12
+ if extra_params.present?
13
+ query = { parameters: extra_params.to_unsafe_hash }
14
+ else
15
+ query = {}
16
+ end
17
+
18
+ @record_lists = @data_record.record_lists.where(query).page(params[:page])
19
+ end
20
+
21
+ def new
22
+ @record_list = @data_record.record_lists.build
23
+ end
24
+
25
+ def create
26
+ @record_list = @data_record.record_lists.build(record_list_params)
27
+ @record_list.save
28
+
29
+ redirect_to data_record_record_lists_url(@data_record)
30
+ end
31
+
32
+ def find
33
+ @record_list = @data_record.record_lists.find_or_create_by(parameters: params.permit(*@data_record.parameters.keys).to_h)
34
+ @record_list.run unless @record_list.done
35
+ end
36
+
37
+ def show
38
+ disposition = params[:disposition] || 'inline'
39
+ respond_to do |format|
40
+ format.html
41
+ format.js
42
+ format.csv { send_data @record_list.to_csv, filename: @record_list.csv_file_name, type: 'application/csv' }
43
+ format.pdf { send_data @record_list.to_pdf, filename: @record_list.pdf_file_name, disposition: disposition, type: 'application/pdf' }
44
+ format.xlsx { send_data @record_list.to_xlsx, filename: @record_list.file_name(self.formats[0]), type: 'application/xlsx' }
45
+ end
46
+ end
47
+
48
+ def edit
49
+ end
50
+
51
+ def update
52
+ @record_list.update(record_list_params)
53
+ redirect_to data_record_record_lists_url(@data_record)
54
+ end
55
+
56
+ def edit_columns
57
+ end
58
+
59
+ def update_columns
60
+ @record_list.update(columns: columns_params)
61
+ end
62
+
63
+ def row
64
+ send_data @record_list.to_row_pdf.render,
65
+ filename: @record_list.pdf_file_name,
66
+ type: 'application/pdf'
67
+ end
68
+
69
+ def run
70
+ @record_list.run
71
+ redirect_back fallback_location: data_record_record_lists_url(@data_record)
72
+ end
73
+
74
+ def destroy
75
+ @record_list.destroy
76
+ redirect_to data_record_record_lists_url(@data_record), notice: 'Export file was successfully destroyed.'
77
+ end
78
+
79
+ private
80
+ def set_record_list
81
+ @record_list = @data_record.record_lists.find(params[:id])
82
+ end
83
+
84
+ def set_data_record
85
+ if /\d/.match? params[:data_record_id]
86
+ @data_record = DataRecord.find params[:data_record_id]
87
+ else
88
+ @data_record = DataRecord.find_by data_table: params[:data_record_id]
89
+ end
90
+ end
91
+
92
+ def record_list_params
93
+ params.fetch(:record_list, {}).permit(parameters: @data_record.parameters.keys, columns: @data_record.columns.keys)
94
+ end
95
+
96
+ def columns_params
97
+ params.fetch(:columns, {}).permit!.to_h
98
+ end
99
+
100
+ def file_params
101
+ params.fetch(:record_list, {}).fetch(:file)
102
+ end
103
+
104
+
105
+ end
@@ -0,0 +1,115 @@
1
+ class RailsDataAdmin::TableListsController < RailsDataAdmin::BaseController
2
+ before_action :set_data_list
3
+ before_action :set_table_list, only: [:show, :xlsx, :edit, :row, :run, :migrate, :update, :destroy]
4
+ skip_before_action :require_role
5
+ before_action do |controller|
6
+ controller.require_role(params[:data_list_id])
7
+ end
8
+
9
+ def index
10
+ @table_lists = @data_list.table_lists.page(params[:page])
11
+ end
12
+
13
+ def new
14
+ @table_list = @data_list.table_lists.build
15
+ end
16
+
17
+ def create
18
+ @table_list = @data_list.table_lists.build(table_list_params)
19
+ @table_list.save
20
+
21
+ redirect_to data_list_table_lists_url(@data_list)
22
+ end
23
+
24
+ def find
25
+ @table_list = @data_list.table_lists.find_or_create_by(parameters: params.permit(*@data_list.parameters.keys).to_h)
26
+ @table_list.cached_run(params[:timestamp])
27
+ @table_items = @table_list.table_items.page(params[:page]).per(100)
28
+ end
29
+
30
+ def direct
31
+ @table_list = @data_list.table_lists.build(parameters: params.permit(*@data_list.parameters.keys).to_h)
32
+ respond_to do |format|
33
+ format.xlsx { send_data @table_list.direct_xlsx, filename: @table_list.file_name(formats[0]), type: 'application/xlsx' }
34
+ end
35
+ end
36
+
37
+ def new_import
38
+ @table_list = @data_list.table_lists.build
39
+ end
40
+
41
+ def create_import
42
+ @table_list = @data_list.table_lists.build
43
+ @table_list.import_to_table_list(file_params.tempfile)
44
+
45
+ @table_items = @table_list.table_items.page(params[:page]).per(100)
46
+ end
47
+
48
+ def migrate
49
+ @table_list.migrate
50
+ redirect_back fallback_location: data_list_table_lists_url(@data_list)
51
+ end
52
+
53
+ def show
54
+ @table_items = @table_list.table_items.page(params[:page]).per(100)
55
+
56
+ respond_to do |format|
57
+ format.html
58
+ format.csv { send_data @table_list.to_csv, filename: @table_list.csv_file_name, type: 'application/csv' }
59
+ format.pdf { send_data @table_list.to_pdf.render, filename: @table_list.pdf_file_name, type: 'application/pdf' }
60
+ format.xlsx { send_data @table_list.cached_xlsx, filename: @table_list.file_name(self.formats[0]), type: 'application/xlsx' }
61
+ end
62
+ end
63
+
64
+ def edit
65
+ end
66
+
67
+ def update
68
+ @table_list.update(table_list_params)
69
+ redirect_to data_list_table_lists_url(@data_list)
70
+ end
71
+
72
+ def row
73
+ send_data @table_list.to_row_pdf.render,
74
+ filename: @table_list.pdf_file_name,
75
+ type: 'application/pdf'
76
+ end
77
+
78
+ def xlsx
79
+ respond_to do |format|
80
+ format.xlsx { send_data @table_list.direct_xlsx, filename: @table_list.file_name(formats[0]), type: 'application/xlsx' }
81
+ end
82
+ end
83
+
84
+ def run
85
+ TableJob.perform_later(@table_list.id, current_user&.id)
86
+ end
87
+
88
+ def destroy
89
+ @table_list.destroy
90
+ redirect_to data_list_table_lists_url(@data_list), notice: 'Export file was successfully destroyed.'
91
+ end
92
+
93
+ private
94
+ def set_table_list
95
+ @table_list = @data_list.table_lists.find(params[:id])
96
+ end
97
+
98
+ def set_data_list
99
+ if /\d/.match? params[:data_list_id]
100
+ @data_list = DataList.find params[:data_list_id]
101
+ else
102
+ @data_list = DataList.find_by data_table: params[:data_list_id]
103
+ end
104
+ end
105
+
106
+ def table_list_params
107
+ params.fetch(:table_list, {}).permit(parameters: @data_list.parameters.keys)
108
+ end
109
+
110
+ def file_params
111
+ params.fetch(:table_list, {}).fetch(:file)
112
+ end
113
+
114
+
115
+ end