From 0d27e8cffccc5d404fecadbe8bc43c9287605534 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Sun, 22 Mar 2020 20:17:00 -0400 Subject: [PATCH] - tools item for /block-analysis (with a "/search"-like jump-off page) --- app/config.js | 5 +-- routes/baseActionsRouter.js | 55 ++++++++++++++++++-------------- views/block-analysis-search.pug | 30 +++++++++++++++++ views/includes/block-content.pug | 2 +- views/includes/tools-card.pug | 4 +-- views/search.pug | 8 ++--- 6 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 views/block-analysis-search.pug diff --git a/app/config.js b/app/config.js index 5d1f522..63848bf 100644 --- a/app/config.js +++ b/app/config.js @@ -165,8 +165,8 @@ module.exports = { } ] }, - subHeaderToolsList:[0, 10, 9, 4, 1, 6, 7], // indexes in "siteTools" below that are shown in the site "sub menu" (visible on all pages except homepage) - toolsDropdownIndexList: [0, 1, 4, 10, 9, 3, 2, 5, 6, 7, 8], + subHeaderToolsList:[0, 10, 9, 4, 11, 6, 7], // indexes in "siteTools" below that are shown in the site "sub menu" (visible on all pages except homepage) + toolsDropdownIndexList: [0, 1, 4, 10, 9, 3, 11, 2, 5, 6, 7, 8], }, credentials: credentials, @@ -188,6 +188,7 @@ module.exports = { /* 9 */ {name:"Mining Summary", url:"/mining-summary", desc:"Summary of recent data about miners.", fontawesome:"fas fa-chart-pie"}, /* 10 */ {name:"Block Stats", url:"/block-stats", desc:"Summary data for blocks in configurable range.", fontawesome:"fas fa-layer-group"}, + /* 11 */ {name:"Block Analysis", url:"/block-analysis", desc:"Summary analysis for all transactions in a block.", fontawesome:"fas fa-angle-double-down"}, ], donations:{ diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index 5a65e63..95b972b 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -483,14 +483,9 @@ router.get("/block-stats", function(req, res, next) { }); router.get("/search", function(req, res, next) { - if (!req.body.query) { - req.session.userMessage = "Enter a block height, block hash, or transaction id."; - req.session.userMessageType = "primary"; + res.render("search"); - res.render("search"); - - next(); - } + next(); }); router.post("/search", function(req, res, next) { @@ -737,37 +732,49 @@ router.get("/block/:blockHash", function(req, res, next) { }); }); -router.get("/block-analysis/:blockHash", function(req, res, next) { - var blockHash = req.params.blockHash; +router.get("/block-analysis/:blockHashOrHeight", function(req, res, next) { + var blockHashOrHeight = req.params.blockHashOrHeight; - res.locals.blockHash = blockHash; + var goWithBlockHash = function(blockHash) { + var blockHash = blockHash; - res.locals.result = {}; + res.locals.blockHash = blockHash; - var txResults = []; + res.locals.result = {}; - var promises = []; + var txResults = []; - res.locals.result = {}; + var promises = []; - coreApi.getBlockByHash(blockHash).then(function(block) { - res.locals.result.getblock = block; + res.locals.result = {}; - res.render("block-analysis"); + coreApi.getBlockByHash(blockHash).then(function(block) { + res.locals.result.getblock = block; - next(); + res.render("block-analysis"); - }).catch(function(err) { - res.locals.pageErrors.push(utils.logError("943h84ehedr", err)); + next(); + + }).catch(function(err) { + res.locals.pageErrors.push(utils.logError("943h84ehedr", err)); - res.render("block-analysis"); + res.render("block-analysis"); - next(); - }); + next(); + }); + }; + + if (!isNaN(blockHashOrHeight)) { + coreApi.getBlockByHeight(parseInt(blockHashOrHeight)).then(function(blockByHeight) { + goWithBlockHash(blockByHeight.hash); + }); + } else { + goWithBlockHash(blockHashOrHeight); + } }); router.get("/block-analysis", function(req, res, next) { - res.render("block-analysis"); + res.render("block-analysis-search"); next(); }); diff --git a/views/block-analysis-search.pug b/views/block-analysis-search.pug new file mode 100644 index 0000000..133bc83 --- /dev/null +++ b/views/block-analysis-search.pug @@ -0,0 +1,30 @@ +extends layout + +block headContent + title Block Analysis + +block content + h1.h3 Block Analysis + hr + + p Search for a block by height or hash to see a summary analysis of the transactions within that block. + + div.mb-huge + form.form.form-inline(method="get", action="/block-analysis") + input(type="hidden", name="_csrf", value=csrfToken) + + div.input-group + input.form-control(id="input-value", type="text", name="query", placeholder="block height/hash", value=(query), style="width: 400px;") + + div.input-group-append + button.btn.btn-primary(type="submit") Go + +block endOfBody + script. + $(document).ready(function() { + $("form").submit(function() { + window.location.href = `/block-analysis/${$("#input-value").val()}`; + + return false; + }); + }); \ No newline at end of file diff --git a/views/includes/block-content.pug b/views/includes/block-content.pug index 477927f..c30cdfe 100644 --- a/views/includes/block-content.pug +++ b/views/includes/block-content.pug @@ -364,7 +364,7 @@ div.tab-content else span Transactions - a.ml-2(href=`/block-analysis/${result.getblock.hash}`) See Transaction Analysis » + a.ml-2.border-dotted(href=`/block-analysis/${result.getblock.hash}`, title="See a summary analysis of all transactions in this block.", data-toggle="tooltip") See Block Analysis » if (false || (!config.demoSite && !crawlerBot && txCount > 20)) div.col-md-8.text-right diff --git a/views/includes/tools-card.pug b/views/includes/tools-card.pug index 81d7c00..439ad14 100644 --- a/views/includes/tools-card.pug +++ b/views/includes/tools-card.pug @@ -52,8 +52,8 @@ if (true) // md: 3 columns (requires separate layout implementation...see below) // lg, xl: 4 columns // xm: 2 columns - - var indexLists = [[0, 10, 4], [5, 9, 3], [2, 1, 6], [7, 8]]; - - var indexListsMediumWidth = [[0, 10, 4, 5], [9, 3, 2, 1], [6, 7, 8]]; + - var indexLists = [[0, 10, 4], [5, 9, 3], [2, 11, 1], [6, 7, 8]]; + - var indexListsMediumWidth = [[0, 10, 4, 5], [9, 3, 2, 11], [1, 6, 7, 8]]; // special case for medium-width layout div.col.d-none.d-md-block.d-lg-none diff --git a/views/search.pug b/views/search.pug index 60aa690..5b14663 100644 --- a/views/search.pug +++ b/views/search.pug @@ -7,12 +7,12 @@ block content h1.h3 Search hr - div.mb-5 - form.form(method="post", action="/search") + div.mb-huge + form.form.form-inline(method="post", action="/search") input(type="hidden", name="_csrf", value=csrfToken) - div.input-group.input-group-lg - input.form-control.form-control-sm(type="text", name="query", placeholder="block height/hash, txid, address", value=(query), style="width: 300px;") + div.input-group + input.form-control(type="text", name="query", placeholder="block height/hash, txid, address", value=(query), style="width: 400px;") div.input-group-append button.btn.btn-primary(type="submit") Search \ No newline at end of file