Skip to content

Commit 75141b0

Browse files
authored
Merge pull request #15 from flant/fix_get_snapshot_list
Вернул сортировку по времени, мелкие исправления
2 parents bc85fe7 + f79c0b8 commit 75141b0

File tree

3 files changed

+64
-35
lines changed

3 files changed

+64
-35
lines changed

front/index.html

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ <h1 class="my-4">Snapshots list
6767
<li class="nav-item">
6868
<a class="nav-link" href="#" id="get_repo_sort_name" data-otype="name" data-odir="asc">Sort by Name</a>
6969
</li>
70-
<!--li class="nav-item">
70+
<li class="nav-item">
7171
<a class="nav-link" href="#" id="get_repo_sort_time" data-otype="time" data-odir="asc">Sort by Time</a>
72-
</li-->
72+
</li>
7373
</ul>
7474

7575
<div class="d-flex align-items-center invisible" id="loading"><strong>Loading...</strong><div class="spinner-border ml-auto" role="status" aria-hidden="true"></div></div>
@@ -282,14 +282,14 @@ <h5 class="modal-title" id="exampleModalLabel">X-tract indices from snapshot</h5
282282

283283
$('#selectedsnap').html("from <strong>"+reponame+"</strong>");
284284

285-
//$("#get_repo_sort_time").attr("data-id", reponame);
285+
$("#get_repo_sort_time").attr("data-id", reponame);
286286
$("#get_repo_sort_name").attr("data-id", reponame);
287287

288288
var post = {
289289
"action": "get_snapshots",
290290
"values" : {
291291
"repo": reponame,
292-
"otype": "name",
292+
"otype": "time",
293293
"odir": "asc"
294294
}
295295
};
@@ -305,23 +305,27 @@ <h5 class="modal-title" id="exampleModalLabel">X-tract indices from snapshot</h5
305305

306306
dlicon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path fill-rule="evenodd" d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/></svg>';
307307

308+
ok_icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-success" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
309+
310+
fail_icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-danger" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
311+
308312
for(var k in data) {
309313
snapshot = data[k].snapshot;
310-
// uniqid = data[k].start_epoch;
314+
uniqid = data[k].uuid;
311315
status = data[k].state;
312-
// date = new Date(data[k].start_epoch * 1000);
313-
// hdate = date.toLocaleString("ru-RU", {timeZoneName: "short"});
316+
date = new Date(data[k].CreateEpoch * 1000);
317+
hdate = date.toLocaleString("ru-RU", {timeZoneName: "short"});
314318
restore_button = "";
315319

316320
if (status == "SUCCESS") {
317-
icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-success" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
318-
restore_button = "<a href='#' class='float-right btn' title='X-tract it' data-target='#update_instance' data-toggle='modal' data-repo='" + reponame + "' data-id='" + data[k].id + "'>"+dlicon+"</a>";
321+
restore_button = "<a href='#' class='float-right btn' title='X-tract it' data-target='#update_instance' data-toggle='modal' data-repo='" + reponame + "' data-id='" + snapshot + "'>"+dlicon+"</a>";
322+
icon = ok_icon;
319323
} else {
320-
icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-danger" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
321324
restore_button = "";
325+
icon = fail_icon;
322326
}
323327

324-
str += "<li><h5 class='font-weight-bold list-group-item list-group-item-action' title='"+status+"'>"+icon+" <strong>" + snapshot + "</strong> " + restore_button +"</h5></li>";
328+
str += "<li><h5 class='font-weight-bold list-group-item list-group-item-action' title='"+status+"'>"+icon+" <strong>" + snapshot + "</strong> created at " + hdate + restore_button +"</h5></li>";
325329
}
326330

327331
$("#loading").addClass('invisible');
@@ -331,7 +335,7 @@ <h5 class="modal-title" id="exampleModalLabel">X-tract indices from snapshot</h5
331335
});
332336

333337

334-
$('#get_repo_sort_name').on('click', function(e) {
338+
$('#get_repo_sort_name,#get_repo_sort_time').on('click', function(e) {
335339

336340
var reponame = e.target.dataset.id;
337341
var otype = e.target.dataset.otype;
@@ -363,24 +367,26 @@ <h5 class="modal-title" id="exampleModalLabel">X-tract indices from snapshot</h5
363367
var str = "";
364368

365369
dlicon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path fill-rule="evenodd" d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/></svg>';
370+
ok_icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-success" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
371+
fail_icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-danger" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
366372

367373
for(var k in data) {
368374
snapshot = data[k].snapshot;
369375
uniqid = data[k].uuid;
370376
status = data[k].state;
371-
// date = new Date(data[k].start_epoch * 1000);
372-
// hdate = date.toLocaleString("ru-RU", {timeZoneName: "short"});
377+
date = new Date(data[k].CreateEpoch * 1000);
378+
hdate = date.toLocaleString("ru-RU", {timeZoneName: "short"});
373379
restore_button = "";
374380

375381
if (status == "SUCCESS") {
376-
icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-success" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
377-
restore_button = "<a href='#' class='float-right btn' title='X-tract it' data-target='#update_instance' data-toggle='modal' data-repo='" + reponame + "' data-id='" + data[k].id + "'>"+dlicon+"</a>";
382+
restore_button = "<a href='#' class='float-right btn' title='X-tract it' data-target='#update_instance' data-toggle='modal' data-repo='" + reponame + "' data-id='" + data[k].snapshot + "'>"+dlicon+"</a>";
383+
icon = ok_icon;
378384
} else {
379-
icon = '<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-server text-danger" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M1.333 2.667C1.333 1.194 4.318 0 8 0s6.667 1.194 6.667 2.667V4C14.665 5.474 11.68 6.667 8 6.667 4.318 6.667 1.333 5.473 1.333 4V2.667zm0 3.667v3C1.333 10.805 4.318 12 8 12c3.68 0 6.665-1.193 6.667-2.665V6.334c-.43.32-.931.58-1.458.79C11.81 7.684 9.967 8 8 8c-1.967 0-3.81-.317-5.21-.876a6.508 6.508 0 0 1-1.457-.79zm13.334 5.334c-.43.319-.931.578-1.458.789-1.4.56-3.242.876-5.209.876-1.967 0-3.81-.316-5.21-.876a6.51 6.51 0 0 1-1.457-.79v1.666C1.333 14.806 4.318 16 8 16s6.667-1.194 6.667-2.667v-1.665z"/></svg>';
380385
restore_button = "";
386+
icon = fail_icon;
381387
}
382388

383-
str += "<li><h5 class='font-weight-bold list-group-item list-group-item-action' title='"+status+"'>"+icon+" <strong>" + snapshot + "</strong> " + restore_button +"</h5></li>";
389+
str += "<li><h5 class='font-weight-bold list-group-item list-group-item-action' title='"+status+"'>"+icon+" <strong>" + snapshot + "</strong> created at " + hdate + restore_button +"</h5></li>";
384390
}
385391

386392
$("#loading").addClass('invisible');

modules/router/router.go

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ type snapResponse struct {
140140
Snapshots []snapItem `json:"snapshots"`
141141
}
142142
type snapItem struct {
143-
Snapshot string `json:"snapshot,omitempty"`
144-
Uuid string `json:"uuid,omitempty"`
145-
State string `json:"state,omitempty"`
143+
Snapshot string `json:"snapshot,omitempty"`
144+
Uuid string `json:"uuid,omitempty"`
145+
State string `json:"state,omitempty"`
146+
CreateEpoch int64
147+
CreateDate string
146148
}
147149

148150
type scrollResponse struct {
@@ -366,6 +368,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
366368
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
367369
return
368370
}
371+
re := regexp.MustCompile(`^(.*)-(\d{4}\.\d{2}\.\d{2})`)
369372

370373
if !rt.conf.Snapshot.Include {
371374
for _, n := range snap_resp.Snapshots {
@@ -374,25 +377,46 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
374377
log.Println("Regex error for ", n.Snapshot)
375378
}
376379
if !matched {
380+
match := re.FindStringSubmatch(n.Snapshot)
381+
n.CreateDate = match[2]
382+
d, err := time.Parse("2006.01.02", n.CreateDate)
383+
n.CreateEpoch = d.Unix()
384+
if err != nil {
385+
http.Error(w, err.Error(), http.StatusInternalServerError)
386+
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
387+
return
388+
}
377389
snap_items = append(snap_items, n)
378390
}
379-
391+
}
392+
} else {
393+
for _, n := range snap_resp.Snapshots {
394+
match := re.FindStringSubmatch(n.Snapshot)
395+
n.CreateDate = match[2]
396+
d, err := time.Parse("2006.01.02", n.CreateDate)
397+
n.CreateEpoch = d.Unix()
398+
if err != nil {
399+
http.Error(w, err.Error(), http.StatusInternalServerError)
400+
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", http.StatusInternalServerError, "\t", err.Error())
401+
return
402+
}
403+
snap_items = append(snap_items, n)
380404
}
381405
}
382-
/*if request.Values.OrderType == "time" {
406+
407+
if request.Values.OrderType == "time" {
383408

384409
if request.Values.OrderDir == "asc" {
385-
sort.Slice(snap_list[:], func(i, j int) bool {
386-
return snap_list[i].End_epoch < snap_list[j].End_epoch
410+
sort.Slice(snap_items[:], func(i, j int) bool {
411+
return snap_items[i].CreateEpoch < snap_items[j].CreateEpoch
387412
})
388413
} else {
389-
sort.Slice(snap_list[:], func(i, j int) bool {
390-
return snap_list[i].End_epoch > snap_list[j].End_epoch
414+
sort.Slice(snap_items[:], func(i, j int) bool {
415+
return snap_items[i].CreateEpoch > snap_items[j].CreateEpoch
391416
})
392417
}
393418

394-
} else */
395-
if request.Values.OrderType == "name" {
419+
} else if request.Values.OrderType == "name" {
396420

397421
if request.Values.OrderDir == "asc" {
398422
sort.Slice(snap_items[:], func(i, j int) bool {
@@ -414,20 +438,19 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
414438

415439
case "get_snapshots_sorted":
416440
{
417-
/*if request.Values.OrderType == "time" {
441+
if request.Values.OrderType == "time" {
418442

419443
if request.Values.OrderDir == "asc" {
420444
sort.Slice(rt.sl[:], func(i, j int) bool {
421-
return rt.sl[i].End_epoch < rt.sl[j].End_epoch
445+
return rt.sl[i].CreateEpoch < rt.sl[j].CreateEpoch
422446
})
423447
} else {
424448
sort.Slice(rt.sl[:], func(i, j int) bool {
425-
return rt.sl[i].End_epoch > rt.sl[j].End_epoch
449+
return rt.sl[i].CreateEpoch > rt.sl[j].CreateEpoch
426450
})
427451
}
428452

429-
} else */
430-
if request.Values.OrderType == "name" {
453+
} else if request.Values.OrderType == "name" {
431454

432455
if request.Values.OrderDir == "asc" {
433456
sort.Slice(rt.sl[:], func(i, j int) bool {

modules/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313

1414
package version
1515

16-
var Version = "extractor/v0.2.25"
16+
var Version = "extractor/v0.2.26"

0 commit comments

Comments
 (0)