dbviewer 0.9.4.pre.alpha.3 → 0.9.4
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/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 +2 -1
- data/app/views/dbviewer/tables/_record_form_fields.html.erb +7 -7
- data/app/views/dbviewer/tables/show.html.erb +8 -3
- data/lib/dbviewer/configuration.rb +4 -0
- data/lib/dbviewer/version.rb +1 -1
- 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: 60a92d1cfd091ad3a1688fcf9d2e532dc651ac69384cf4540b56bdb65b31416a
|
4
|
+
data.tar.gz: 1f467d83cfefb95aebc1701f18ddca6a7ad5710495b3bf711857ee29eb0c35b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95eaf3a6eb2e0f134c92dc4a90ea87a139febfd1fe3977afc58ec17a29243975d53564b021893ecc10cfe826610a6886dfc8d32fb2752f794a6b817168583c4b
|
7
|
+
data.tar.gz: 20fb72442a5f1cb113cbce9cb04792850da47aa1401747a307253d12dd8221f3d224b2485a86086cb9e8a56f77406fde5f7ebac5508afbcc811708f3e79b4798
|
@@ -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
|
@@ -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 %>
|
@@ -202,7 +206,7 @@
|
|
202
206
|
</button>
|
203
207
|
<% end %>
|
204
208
|
<% if Dbviewer.configuration.enable_record_deletion %>
|
205
|
-
<button type="button" class="btn btn-danger" id="recordDetailDeleteBtn" data-record-id="">
|
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
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
|
4
|
+
version: 0.9.4
|
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:
|