Skip to content

Commit

Permalink
clean, camel case variables and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kitone committed Sep 4, 2018
1 parent 16ec114 commit dd7b4a8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 57 deletions.
15 changes: 8 additions & 7 deletions templates/web/static/base.js
@@ -1,6 +1,7 @@
function human_filesize(bytes) {
var i = -1;
var byteUnits = [" kB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"];
/*jshint esversion: 6 */
function humanFileSize(bytes) {
let i = -1;
const byteUnits = [" kB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"];
do {
bytes = bytes / 1024;
i++;
Expand All @@ -9,13 +10,13 @@ function human_filesize(bytes) {
return Math.max(bytes, 0.1).toFixed(1) + byteUnits[i];
}

function human_date(datetime) {
function humanDate(datetime) {
return moment(datetime).format("YYYY/MM/DD HH:MM:SS");
}

function array_to_div(arr) {
var r = "";
$.each(arr, function(i, a) {
function arrayToDiv(arr) {
let r = "";
$.each(arr, (i, a) => {
r += `<div>${a}</div>`;
});
return r;
Expand Down
41 changes: 21 additions & 20 deletions templates/web/static/nodes.js
@@ -1,8 +1,9 @@
/*jshint esversion: 6 */
function convertData(data) {
// work with the childs "nodes"
nodes = data.nodes;
// adjust field and fix struct
nodes = $.map(nodes, function(c) {
nodes = $.map(nodes, c => {
// delete unused attributes
delete c.atime;
delete c.ctime;
Expand All @@ -22,11 +23,11 @@ function convertData(data) {
return nodes;
}

function path_from_root(node) {
function pathFromRoot(node) {
if (node.parent === null) {
return "";
}
return path_from_root(node.parent) + "/" + node.data.name;
return `${pathFromRoot(node.parent)}/${node.data.name}`;
}

function readyFn(jQuery) {
Expand All @@ -41,47 +42,47 @@ function readyFn(jQuery) {
checkbox: true,
selectMode: 3,
source: {
url: "/api/snapshots/" + $("#treeview").data("snapshot-id") + "/nodes/"
url: `/api/snapshots/${$("#treeview").data("snapshot-id")}/nodes/`
},
lazyLoad: function(event, data) {
var node = data.node;
var snapshot_id = node.tree.data["snapshot-id"];
var node_key = node.data.subtree;
lazyLoad(event, data) {
const node = data.node;
const snapshotID = node.tree.data["snapshot-id"];
const nodeKey = node.data.subtree;
data.result = {
url: "/api/snapshots/" + snapshot_id + "/nodes/" + node_key
url: `/api/snapshots/${snapshotID}/nodes/${nodeKey}`
};
},
// apply parent's state to new child nodes
loadChildren: function(event, data) {
loadChildren(event, data) {
data.node.fixSelection3AfterClick();
},
// This event is part of the table extension:
renderColumns: function(event, data) {
var n = data.node.data;
var path = path_from_root(data.node);
var td = $(data.node.tr).find(">td");
renderColumns(event, data) {
const n = data.node.data;
const path = pathFromRoot(data.node);
const td = $(data.node.tr).find(">td");

$(data.node.tr)[0].setAttribute("data-path", path);

td.eq(1).attr("title", path);
td.eq(2).text(n.user);
td.eq(3).text(n.group);
// mtime
td.eq(4).text(human_date(n.mtime));
td.eq(4).text(humanDate(n.mtime));
// size
if (n.hasOwnProperty("size")) {
td.eq(5).text(human_filesize(n.size));
td.eq(5).text(humanFileSize(n.size));
}
// actions
if (data.node.type !== "dir") {
var snapshot_id = data.tree.data["snapshotId"];
var link = document.createElement("a");
const snapshotID = data.tree.data["snapshotId"];
const link = document.createElement("a");
link.text = "Download";
link.href = `/web/snapshots/${snapshot_id}/download?path=${path}`;
link.href = `/web/snapshots/${snapshotID}/download?path=${path}`;
td.eq(6).append(link);
}
},
postProcess: function(event, data) {
postProcess(event, data) {
data.result = convertData(data.response);
}
});
Expand Down
45 changes: 23 additions & 22 deletions templates/web/static/nodes_restore.js
@@ -1,9 +1,10 @@
function files_to_restore() {
var files = [];
var tree = $("#treeview").fancytree("getTree");
tree.visit(function(node) {
/*jshint esversion: 6 */
function filesToRestore() {
const files = [];
const tree = $("#treeview").fancytree("getTree");
tree.visit(node => {
if (node.selected) {
var path = $(node.tr).data("path");
const path = $(node.tr).data("path");
files.push(path);
// if the node is a dir, we don't need to enable childs
if (node.type === "dir") {
Expand All @@ -14,40 +15,40 @@ function files_to_restore() {
return files;
}

$(document).ready(function() {
$(document).ready(() => {
$("#restore-form").submit(function(ev) {
// Stop the browser from submitting the form.
ev.preventDefault();
// Api url and values to send
var restore_api = $(this).attr("action");
var restore_data = JSON.stringify({
const restoreApi = $(this).attr("action");
const restoreData = JSON.stringify({
target: $("input[name=restore_target]").val(),
files: files_to_restore()
files: filesToRestore()
});
var submit_button = $("input[name=submit]");
submit_button.attr("disabled", true);
submit_button.val("In Progress...");
const submitButton = $("input[name=submit]");
submitButton.attr("disabled", true);
submitButton.val("In Progress...");
// Submit the form using AJAX.
$.ajax({
type: "POST",
url: restore_api,
data: restore_data
url: restoreApi,
data: restoreData
})
.done(function(response) {
var msg = $("#form-messages");
.done(response => {
const msg = $("#form-messages");
$(msg).removeClass("alert-danger");
$(msg).addClass("alert alert-success");
$(msg).text(response);
submit_button.attr("disabled", false);
submit_button.val("Restore");
submitButton.attr("disabled", false);
submitButton.val("Restore");
})
.fail(function(data) {
var msg = $("#form-messages");
.fail(data => {
const msg = $("#form-messages");
$(msg).removeClass("alert-success");
$(msg).addClass("alert alert-danger");
$(msg).text(data.responseText);
submit_button.attr("disabled", false);
submit_button.val("Restore");
submitButton.attr("disabled", false);
submitButton.val("Restore");
});
});
});
17 changes: 9 additions & 8 deletions templates/web/static/snapshots.js
@@ -1,22 +1,23 @@
/*jshint esversion: 6 */
function readyFn(jQuery) {
$.getJSON("/api/snapshots/", function(data) {
data = data.sort(function(a, b) {
var x = a.time;
var y = b.time;
$.getJSON("/api/snapshots/", data => {
data = data.sort((a, b) => {
const x = a.time;
const y = b.time;
return x < y ? -1 : x > y ? 1 : 0;
});
// console.log(data);
$.each(data, function(k, v) {
$.each(data, (k, v) => {
$("#table-snapshots tbody").append(
`<tr>
<td>
<a href="/web/snapshots/${v.short_id}/nodes/">${v.short_id}<a>
</td>
<td>${human_date(v.time)}</td>
<td>${humanDate(v.time)}</td>
<td>${v.username}</td>
<td>${v.hostname}</td>
<td>${array_to_div(v.paths)}</td>
<td>${array_to_div(v.tags)}</td>
<td>${arrayToDiv(v.paths)}</td>
<td>${arrayToDiv(v.tags)}</td>
</tr>`
);
});
Expand Down

0 comments on commit dd7b4a8

Please sign in to comment.