bx_builder_chain 0.1.5 → 0.1.6
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 006f8200cd1577b6ad0687b1607cad5aabf833971d3a3e3fe2f7718988ec6fbb
|
4
|
+
data.tar.gz: 51be4ca4f480ab7ed47582fc2482b10e53e2a858eb798889ed65cbcf85f76e91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f2e15d46fa5c06974fa10df37d27204d30bf92e4615a0c77dfbed4a0e84091a0e304ae5b98e52b2434c8937d97616e4d4e3213f959226657c84075431663b9c
|
7
|
+
data.tar.gz: b4762d1c53c6ccc6fc434f53ed058f55273798af70da586e722981a53159d49fc93f197321a7ece9b95b90c80d2c731c5de76d0830782e488571caf7cee8c682
|
data/lib/generators/bx_builder_chain/templates/app/views/bx_builder_chain/test/form.html.erb
CHANGED
@@ -23,6 +23,10 @@
|
|
23
23
|
height: 340px;
|
24
24
|
}
|
25
25
|
|
26
|
+
div.fullwidth {
|
27
|
+
width: 100%;
|
28
|
+
}
|
29
|
+
|
26
30
|
form {
|
27
31
|
width: 100%;
|
28
32
|
}
|
@@ -73,6 +77,19 @@
|
|
73
77
|
.console_message {
|
74
78
|
white-space: pre-line; /* To respect new lines in the content */
|
75
79
|
}
|
80
|
+
|
81
|
+
div.fullwidth .form-group {
|
82
|
+
width: 80%;
|
83
|
+
float: left;
|
84
|
+
}
|
85
|
+
|
86
|
+
div.fullwidth .actions {
|
87
|
+
float: right;
|
88
|
+
margin-top: 17px;
|
89
|
+
}
|
90
|
+
#file_list button {
|
91
|
+
margin-left: 10px;
|
92
|
+
}
|
76
93
|
</style>
|
77
94
|
|
78
95
|
<div class="page_wrapper">
|
@@ -119,7 +136,24 @@
|
|
119
136
|
<% end %>
|
120
137
|
</div>
|
121
138
|
<div style="clear: both;"></div>
|
139
|
+
<div class="form_wrapper fullwidth">
|
140
|
+
<h2>Retrieve Files</h2>
|
122
141
|
|
142
|
+
<%= form_tag(bx_builder_chain_documents_list_path, method: :get, id: 'list_form') do %>
|
143
|
+
<div class="form-group">
|
144
|
+
<label for="current_user_groups">Enter User ID:</label>
|
145
|
+
<%= text_field_tag 'current_user_groups', 1, class: 'form-control' %>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<div class="actions">
|
149
|
+
<%= submit_tag "Retrieve Files", class: 'btn btn-primary' %>
|
150
|
+
</div>
|
151
|
+
<% end %>
|
152
|
+
|
153
|
+
<div style="clear: both;"></div>
|
154
|
+
<ul id="file_list"></ul>
|
155
|
+
</div>
|
156
|
+
<div style="clear: both;"></div>
|
123
157
|
<!-- Console box -->
|
124
158
|
<div class="console_wrapper">
|
125
159
|
<div class="console_message">
|
@@ -161,4 +195,83 @@
|
|
161
195
|
});
|
162
196
|
});
|
163
197
|
});
|
198
|
+
document.addEventListener('DOMContentLoaded', function () {
|
199
|
+
const listForm = document.querySelector('#list_form');
|
200
|
+
const fileList = document.querySelector('#file_list');
|
201
|
+
const consoleBox = document.querySelector('.console_message');
|
202
|
+
|
203
|
+
listForm.addEventListener('submit', async function (event) {
|
204
|
+
event.preventDefault();
|
205
|
+
|
206
|
+
consoleBox.textContent = "Retrieving files...";
|
207
|
+
const current_user_groups = event.target.current_user_groups.value;
|
208
|
+
const endpoint = `${
|
209
|
+
event.target.action
|
210
|
+
}?current_user_groups=${current_user_groups}`;
|
211
|
+
|
212
|
+
try {
|
213
|
+
let response = await fetch(endpoint, {
|
214
|
+
method: 'GET',
|
215
|
+
headers: {
|
216
|
+
'Content-Type': 'application/json'
|
217
|
+
}
|
218
|
+
});
|
219
|
+
|
220
|
+
if (response.ok) {
|
221
|
+
let files = await response.json();
|
222
|
+
|
223
|
+
fileList.innerHTML = ''; // Clear the file list
|
224
|
+
|
225
|
+
const current_user_groups = event.target.current_user_groups.value;
|
226
|
+
files.forEach(file => {
|
227
|
+
let listItem = document.createElement('li');
|
228
|
+
listItem.textContent = file.name; // Assuming the file object has a 'name' property
|
229
|
+
|
230
|
+
let deleteBtn = document.createElement('button');
|
231
|
+
deleteBtn.textContent = "Delete";
|
232
|
+
deleteBtn.addEventListener('click', async function () {
|
233
|
+
event.preventDefault();
|
234
|
+
await deleteFile(file.id, current_user_groups); // Assuming the file object has an 'id' property
|
235
|
+
});
|
236
|
+
|
237
|
+
listItem.appendChild(deleteBtn);
|
238
|
+
fileList.appendChild(listItem);
|
239
|
+
});
|
240
|
+
|
241
|
+
consoleBox.textContent = "Files retrieved successfully.";
|
242
|
+
} else {
|
243
|
+
let errorData = await response.json();
|
244
|
+
consoleBox.textContent = errorData.error || "An error occurred while retrieving files.";
|
245
|
+
}
|
246
|
+
} catch (error) {
|
247
|
+
consoleBox.textContent = "Failed to retrieve files. Please try again.";
|
248
|
+
}
|
249
|
+
});
|
250
|
+
|
251
|
+
async function deleteFile(fileId, current_user_groups) {
|
252
|
+
consoleBox.textContent = "Deleting file...";
|
253
|
+
|
254
|
+
try {
|
255
|
+
let response = await fetch('/bx_builder_chain/documents/delete', {
|
256
|
+
method: 'DELETE',
|
257
|
+
headers: {
|
258
|
+
'Content-Type': 'application/json'
|
259
|
+
},
|
260
|
+
body: JSON.stringify(
|
261
|
+
{ids: [fileId], current_user_groups: current_user_groups}
|
262
|
+
)
|
263
|
+
});
|
264
|
+
|
265
|
+
if (response.ok) {
|
266
|
+
consoleBox.textContent = "File deleted successfully.";
|
267
|
+
document.querySelector('#list_form .actions input').click()
|
268
|
+
} else {
|
269
|
+
let errorData = await response.json();
|
270
|
+
consoleBox.textContent = errorData.error || "An error occurred while deleting the file.";
|
271
|
+
}
|
272
|
+
} catch (error) {
|
273
|
+
consoleBox.textContent = "Failed to delete file. Please try again.";
|
274
|
+
}
|
275
|
+
}
|
276
|
+
});
|
164
277
|
</script>
|