Skip to content

Commit 702025a

Browse files
Дмитрий БережновДмитрий Бережнов
Дмитрий Бережнов
authored and
Дмитрий Бережнов
committed
feat(api): add JSON eXtract feature
1 parent c00b399 commit 702025a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

front/assets/js/app-search.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,15 @@ $("#search").click(function(){
400400
//event.preventDefault();
401401
});
402402

403-
$("#xtract_csv").click(function(){
403+
$( ".xtract_it" ).click(function(){
404404
$("#loading").removeClass('invisible');
405405
fname = (Math.random() + 1).toString(36).substring(4);
406406
fields = []
407407
tf = []
408408
xql = $('#xql').val()
409+
format = $(this).hasClass('csv') ? 'csv' : 'json'
410+
filePath = '/data/' + fname + "." + format
411+
action = 'prepare_' + format
409412
indexOfLargestValue = 0
410413
for (var k in fmapping) {
411414
if (fmapping[k] =="date") {
@@ -425,7 +428,7 @@ $("#xtract_csv").click(function(){
425428
fields = mapping;
426429
}
427430
var post = {
428-
"action": "prepare_csv",
431+
"action": action,
429432
"search" : {
430433
"index": $('#igs').val(),
431434
"fields": fields,
@@ -449,8 +452,8 @@ $("#xtract_csv").click(function(){
449452
contentType: 'application/json',
450453
success: function (data) {},
451454
error: function (data) {
452-
$("#download_link").html("<a href='/data/"+fname+".csv'>скачать</a>");
453-
document.location.href = "/data/"+fname+".csv";
455+
$("#download_link").html("<a href='" + filePath + "'>скачать</a>");
456+
document.location.href = filePath;
454457
}
455458
})
456459
$("#loading").addClass('invisible');

front/search.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@
6969
<button type="button" class="btn btn-primary btn-sm" id="search">Search</button>
7070
</div>
7171
<div class="col">
72-
<button type="button" class="btn btn-success btn-sm" id="xtract_csv" disabled>Xtract it</button>
72+
<div class="btn-group" role="group">
73+
<button id="xtract_it" type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
74+
Xtract it
75+
</button>
76+
<div class="dropdown-menu" aria-labelledby="xtract_it">
77+
<a class="dropdown-item xtract_it csv" href="#">CSV</a>
78+
<a class="dropdown-item xtract_it json" href="#">JSON</a>
79+
</div>
80+
</div>
81+
7382
<span id="download_link"></span>
7483
</div>
7584
</div>

0 commit comments

Comments
 (0)