dbviewer 0.9.4.pre.alpha.3 → 0.9.5
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.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/app/assets/javascripts/dbviewer/record_creation.js +14 -0
- data/app/assets/javascripts/dbviewer/record_deletion.js +4 -6
- data/app/controllers/dbviewer/tables_controller.rb +39 -0
- data/app/helpers/dbviewer/datatable_ui_table_helper.rb +4 -3
- data/app/views/dbviewer/tables/_record_form_fields.html.erb +7 -7
- data/app/views/dbviewer/tables/show.html.erb +10 -5
- data/lib/dbviewer/configuration.rb +4 -0
- data/lib/dbviewer/version.rb +1 -1
- data/lib/generators/dbviewer/templates/initializer.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6832bfc909e5e4ff2afa835a92a93acbc1c940f70fe0cfb6c6e75a50205901e
|
4
|
+
data.tar.gz: e0f8d8a2de6d252a68e8b17367efcbef18184aaa483bc1b4b039a501673a2624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76f574e7f7df877df3468d17e1797bcb321c0bb59fab83297945abc85213a3230fe1527e5f9fae0f21fe6dc2f2ccb5d94ca1b582807c44bd350e30371fc699bb
|
7
|
+
data.tar.gz: 3270f55cf27eeb03b75c6f3a309ed82292218f4bfede415f483d7af568086598cd63285bfdc4170556ebf7b26cfef5be6d533ae17f40279667aba7246cc8cc6f
|
data/README.md
CHANGED
@@ -114,7 +114,7 @@ This will create a file at `config/initializers/dbviewer.rb` with the default co
|
|
114
114
|
```ruby
|
115
115
|
# config/initializers/dbviewer.rb
|
116
116
|
Dbviewer.configure do |config|
|
117
|
-
config.per_page_options = [10, 20, 50, 100, 250]
|
117
|
+
config.per_page_options = [10, 20, 50, 100, 250] # Default pagination options
|
118
118
|
config.default_per_page = 20 # Default records per page
|
119
119
|
config.max_query_length = 10000 # Maximum SQL query length
|
120
120
|
config.cache_expiry = 300 # Cache expiration in seconds
|
@@ -130,6 +130,11 @@ Dbviewer.configure do |config|
|
|
130
130
|
config.query_log_path = "log/dbviewer.log" # Path for query log file when in :file mode
|
131
131
|
config.max_memory_queries = 1000 # Maximum number of queries to store in memory
|
132
132
|
|
133
|
+
# Data Management options
|
134
|
+
config.enable_record_deletion = true # Whether to allow record deletion functionality
|
135
|
+
config.enable_record_editing = true # Whether to allow record editing functionality
|
136
|
+
config.enable_record_creation = true # Whether to allow record creation functionality
|
137
|
+
|
133
138
|
# Authentication options
|
134
139
|
# config.admin_credentials = { username: "admin", password: "your_secure_password" } # Basic HTTP auth credentials
|
135
140
|
|
@@ -143,7 +148,7 @@ Dbviewer.configure do |config|
|
|
143
148
|
# }
|
144
149
|
|
145
150
|
# Disable DBViewer completely
|
146
|
-
# config.disabled = Rails.env.production?
|
151
|
+
# config.disabled = Rails.env.production? # Disable in production
|
147
152
|
end
|
148
153
|
```
|
149
154
|
|
@@ -57,6 +57,20 @@ function initializeFormElements() {
|
|
57
57
|
width: "100%",
|
58
58
|
});
|
59
59
|
}
|
60
|
+
|
61
|
+
if (typeof flatpickr !== "undefined") {
|
62
|
+
flatpickr(".datetime-picker", {
|
63
|
+
enableTime: true,
|
64
|
+
dateFormat: "Y-m-d H:i:S",
|
65
|
+
time_24hr: true,
|
66
|
+
wrap: true,
|
67
|
+
});
|
68
|
+
|
69
|
+
flatpickr(".date-picker", {
|
70
|
+
dateFormat: "Y-m-d",
|
71
|
+
wrap: true,
|
72
|
+
});
|
73
|
+
}
|
60
74
|
}
|
61
75
|
|
62
76
|
async function handleNewRecordSubmit(event) {
|
@@ -87,9 +87,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
87
87
|
}
|
88
88
|
});
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
Object.keys(recordData)[0];
|
90
|
+
// Get primary key from button's data attribute or from hidden field
|
91
|
+
const pkName = detailDeleteBtn.getAttribute("data-primary-key") || "id";
|
93
92
|
const pkValue = recordData[pkName];
|
94
93
|
|
95
94
|
setupDeleteConfirmModal(recordData, pkName, pkValue);
|
@@ -105,9 +104,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
105
104
|
document.querySelectorAll(".delete-record-btn").forEach((button) => {
|
106
105
|
button.addEventListener("click", () => {
|
107
106
|
const recordData = JSON.parse(button.dataset.recordData || "{}");
|
108
|
-
|
109
|
-
|
110
|
-
Object.keys(recordData)[0];
|
107
|
+
// Get primary key from button's data attribute or from hidden field
|
108
|
+
const pkName = button.dataset.primaryKey || "id";
|
111
109
|
const pkValue = recordData[pkName];
|
112
110
|
setupDeleteConfirmModal(recordData, pkName, pkValue);
|
113
111
|
});
|
@@ -4,6 +4,9 @@ module Dbviewer
|
|
4
4
|
|
5
5
|
before_action :set_table_name, except: [ :index ]
|
6
6
|
before_action :validate_table, only: [ :show, :query, :export_csv, :new_record, :create_record, :destroy_record, :edit_record, :update_record ]
|
7
|
+
before_action :check_record_creation_enabled, only: [ :new_record, :create_record ]
|
8
|
+
before_action :check_record_editing_enabled, only: [ :edit_record, :update_record ]
|
9
|
+
before_action :check_record_deletion_enabled, only: [ :destroy_record ]
|
7
10
|
before_action :set_query_filters, only: [ :show, :export_csv ]
|
8
11
|
before_action :set_global_filters, only: [ :show, :export_csv ]
|
9
12
|
|
@@ -249,5 +252,41 @@ module Dbviewer
|
|
249
252
|
end
|
250
253
|
options
|
251
254
|
end
|
255
|
+
|
256
|
+
def check_record_creation_enabled
|
257
|
+
unless Dbviewer.configuration.enable_record_creation
|
258
|
+
respond_to do |format|
|
259
|
+
format.html {
|
260
|
+
flash[:alert] = "Record creation is disabled in the configuration"
|
261
|
+
redirect_to table_path(@table_name)
|
262
|
+
}
|
263
|
+
format.json { render json: { error: "Record creation is disabled" }, status: :forbidden }
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def check_record_editing_enabled
|
269
|
+
unless Dbviewer.configuration.enable_record_editing
|
270
|
+
respond_to do |format|
|
271
|
+
format.html {
|
272
|
+
flash[:alert] = "Record editing is disabled in the configuration"
|
273
|
+
redirect_to table_path(@table_name)
|
274
|
+
}
|
275
|
+
format.json { render json: { error: "Record editing is disabled" }, status: :forbidden }
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def check_record_deletion_enabled
|
281
|
+
unless Dbviewer.configuration.enable_record_deletion
|
282
|
+
respond_to do |format|
|
283
|
+
format.html {
|
284
|
+
flash[:alert] = "Record deletion is disabled in the configuration"
|
285
|
+
redirect_to table_path(@table_name)
|
286
|
+
}
|
287
|
+
format.json { render json: { error: "Record deletion is disabled" }, status: :forbidden }
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
252
291
|
end
|
253
292
|
end
|
@@ -138,7 +138,7 @@ module Dbviewer
|
|
138
138
|
end
|
139
139
|
|
140
140
|
# Edit Record button (only if enabled in configuration)
|
141
|
-
edit_button = if Dbviewer.configuration.enable_record_editing
|
141
|
+
edit_button = if Dbviewer.configuration.enable_record_editing && table_name != "schema_migrations"
|
142
142
|
button_tag(
|
143
143
|
type: "button",
|
144
144
|
class: "btn btn-sm btn-outline-primary edit-record-btn",
|
@@ -156,7 +156,7 @@ module Dbviewer
|
|
156
156
|
end
|
157
157
|
|
158
158
|
# Delete Record button (only if enabled in configuration)
|
159
|
-
delete_button = if Dbviewer.configuration.enable_record_deletion
|
159
|
+
delete_button = if Dbviewer.configuration.enable_record_deletion && table_name != "schema_migrations"
|
160
160
|
button_tag(
|
161
161
|
type: "button",
|
162
162
|
class: "btn btn-sm btn-outline-danger delete-record-btn",
|
@@ -165,7 +165,8 @@ module Dbviewer
|
|
165
165
|
bs_toggle: "modal",
|
166
166
|
bs_target: "#deleteConfirmModal",
|
167
167
|
record_data: data_attributes.to_json,
|
168
|
-
table_name: table_name
|
168
|
+
table_name: table_name,
|
169
|
+
primary_key: metadata && metadata[:primary_key] ? metadata[:primary_key] : "id"
|
169
170
|
}
|
170
171
|
) do
|
171
172
|
content_tag(:i, "", class: "bi bi-trash")
|
@@ -58,25 +58,25 @@
|
|
58
58
|
"true", "false" %>
|
59
59
|
</div>
|
60
60
|
|
61
|
-
<% elsif field_type == :
|
61
|
+
<% elsif field_type == :datetime_local_field %>
|
62
62
|
<!-- Date time picker -->
|
63
|
-
<div class="input-group
|
63
|
+
<div class="input-group datetime-picker">
|
64
64
|
<%= form.text_field "record[#{column_name}]",
|
65
65
|
value: current_value,
|
66
|
-
class: "form-control
|
66
|
+
class: "form-control",
|
67
67
|
id: field_id,
|
68
68
|
required: required,
|
69
69
|
data: { input: "" },
|
70
70
|
disabled: disabled %>
|
71
71
|
<button type="button" class="input-group-text" data-toggle><i class="bi bi-calendar-event"></i></button>
|
72
72
|
</div>
|
73
|
-
|
74
|
-
<% elsif field_type == :
|
73
|
+
|
74
|
+
<% elsif field_type == :date_field %>
|
75
75
|
<!-- Date picker -->
|
76
|
-
<div class="input-group
|
76
|
+
<div class="input-group date-picker">
|
77
77
|
<%= form.text_field "record[#{column_name}]",
|
78
78
|
value: current_value,
|
79
|
-
class: "form-control
|
79
|
+
class: "form-control",
|
80
80
|
id: field_id,
|
81
81
|
required: required,
|
82
82
|
data: { input: "" },
|
@@ -13,8 +13,12 @@
|
|
13
13
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
14
14
|
<%= stylesheet_link_tag "dbviewer/table", "data-turbo-track": "reload" %>
|
15
15
|
<%= javascript_include_tag "dbviewer/table", "data-turbo-track": "reload" %>
|
16
|
+
<% if Dbviewer.configuration.enable_record_creation %>
|
16
17
|
<%= javascript_include_tag "dbviewer/record_creation", "data-turbo-track": "reload" %>
|
18
|
+
<% end %>
|
19
|
+
<% if Dbviewer.configuration.enable_record_deletion %>
|
17
20
|
<%= javascript_include_tag "dbviewer/record_deletion", "data-turbo-track": "reload" %>
|
21
|
+
<% end %>
|
18
22
|
<% if Dbviewer.configuration.enable_record_editing %>
|
19
23
|
<%= javascript_include_tag "dbviewer/record_editing", "data-turbo-track": "reload" %>
|
20
24
|
<% end %>
|
@@ -196,13 +200,13 @@
|
|
196
200
|
</div>
|
197
201
|
<div class="modal-footer">
|
198
202
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
199
|
-
<% if Dbviewer.configuration.enable_record_editing %>
|
203
|
+
<% if Dbviewer.configuration.enable_record_editing && @table_name != 'schema_migrations' %>
|
200
204
|
<button type="button" class="btn btn-primary" id="recordDetailEditBtn" data-record-id="" data-primary-key="<%= @metadata[:primary_key] || 'id' %>">
|
201
205
|
<i class="bi bi-pencil me-1"></i>Edit Record
|
202
206
|
</button>
|
203
207
|
<% end %>
|
204
|
-
<% if Dbviewer.configuration.enable_record_deletion %>
|
205
|
-
<button type="button" class="btn btn-danger" id="recordDetailDeleteBtn" data-record-id="">
|
208
|
+
<% if Dbviewer.configuration.enable_record_deletion && @table_name != 'schema_migrations' %>
|
209
|
+
<button type="button" class="btn btn-danger" id="recordDetailDeleteBtn" data-record-id="" data-primary-key="<%= @metadata[:primary_key] || 'id' %>">
|
206
210
|
<i class="bi bi-trash me-1"></i>Delete Record
|
207
211
|
</button>
|
208
212
|
<% end %>
|
@@ -375,8 +379,7 @@
|
|
375
379
|
<% end %>
|
376
380
|
|
377
381
|
<!-- Floating Add Record Button -->
|
378
|
-
|
379
|
-
<% if @table_name != 'schema_migrations'%>
|
382
|
+
<% if Dbviewer.configuration.enable_record_creation && @table_name != 'schema_migrations' %>
|
380
383
|
<div class="floating-add-record d-none d-lg-block">
|
381
384
|
<button id="floatingAddRecordBtn"
|
382
385
|
class="btn btn-success btn-lg shadow-lg rounded-circle"
|
@@ -388,6 +391,7 @@
|
|
388
391
|
<% end %>
|
389
392
|
|
390
393
|
<!-- New Record Modal -->
|
394
|
+
<% if Dbviewer.configuration.enable_record_creation %>
|
391
395
|
<div id="newRecordModal" class="modal fade" tabindex="-1" aria-labelledby="newRecordModalLabel" aria-hidden="true">
|
392
396
|
<div class="modal-dialog modal-lg">
|
393
397
|
<div class="modal-content">
|
@@ -395,6 +399,7 @@
|
|
395
399
|
</div>
|
396
400
|
</div>
|
397
401
|
</div>
|
402
|
+
<% end %>
|
398
403
|
|
399
404
|
<% if Dbviewer.configuration.enable_record_deletion %>
|
400
405
|
<!-- Delete Confirmation Modal -->
|
@@ -123,6 +123,9 @@ module Dbviewer
|
|
123
123
|
# Enable or disable record editing functionality
|
124
124
|
attr_accessor :enable_record_editing
|
125
125
|
|
126
|
+
# Enable or disable record creation functionality
|
127
|
+
attr_accessor :enable_record_creation
|
128
|
+
|
126
129
|
def initialize
|
127
130
|
@per_page_options = [ 10, 20, 50, 100 ]
|
128
131
|
@default_per_page = 20
|
@@ -132,6 +135,7 @@ module Dbviewer
|
|
132
135
|
@enable_data_export = false
|
133
136
|
@enable_record_deletion = true
|
134
137
|
@enable_record_editing = true
|
138
|
+
@enable_record_creation = true
|
135
139
|
@query_timeout = 30
|
136
140
|
@query_logging_mode = :memory
|
137
141
|
@query_log_path = "log/dbviewer.log"
|
data/lib/dbviewer/version.rb
CHANGED
@@ -15,6 +15,8 @@ Dbviewer.configure do |config|
|
|
15
15
|
|
16
16
|
# Data Management options
|
17
17
|
config.enable_record_deletion = true # Whether to allow record deletion functionality
|
18
|
+
config.enable_record_editing = true # Whether to allow record editing functionality
|
19
|
+
config.enable_record_creation = true # Whether to allow record creation functionality
|
18
20
|
|
19
21
|
# Authentication options (Basic Auth)
|
20
22
|
# config.admin_credentials = {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbviewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wailan Tirajoh
|
@@ -198,9 +198,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
198
|
version: '0'
|
199
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
200
|
requirements:
|
201
|
-
- - "
|
201
|
+
- - ">="
|
202
202
|
- !ruby/object:Gem::Version
|
203
|
-
version:
|
203
|
+
version: '0'
|
204
204
|
requirements: []
|
205
205
|
rubygems_version: 3.4.10
|
206
206
|
signing_key:
|