Shashank
Shashank

Reputation: 339

Unable to insert table inside a tab with Jade

I am fairly new to the Jade framework. I am trying to insert a table inside a tab div, with jade but I am unable to. This is how far I have got: enter image description here

As you can see the place for the content to say is empty (white line) followed by the contents of tab 2 followed by the contents of tab 1. Here is my jade code :

       .tabs
      ul.tab-links
        li.active
          a(href='#tab1') Tab #1
        li
          a(href='#tab2') Tab #2


  .tab-content
      #tab1.tab.active
    div.row(ng-cloak, style="padding-top: 10px")
      table.table.table-striped
        thead
          tr.text-info
            th.th-nodecheck
              i.icon-check-o(data-toggle="tooltip", data-placement="top", title="Pin nodes to display first", ng-click="orderTable(['-stats.block.number', 'stats.block.propagation'], false)")
            th.th-nodename
              i.icon-node(data-toggle="tooltip", data-placement="top", title="Node name", ng-click="orderTable(['info.name'], false)")
            th.th-nodetype
              i.icon-laptop(data-toggle="tooltip", data-placement="top", title="Node type", ng-click="orderTable(['info.node'], false)")
            th.th-latency
              i.icon-clock(data-toggle="tooltip", data-placement="top", title="Node latency", ng-click="orderTable(['stats.latency'], false)")
            th
              i.icon-mining(data-toggle="tooltip", data-placement="top", title="Is mining", ng-click="orderTable(['-stats.hashrate'], false)")
            th
              i.icon-group(data-toggle="tooltip", data-placement="top", title="Peers", ng-click="orderTable(['-stats.peers'], false)")
            th
              i.icon-network(data-toggle="tooltip", data-placement="top", title="Pending transactions", ng-click="orderTable(['-stats.pending'], false)")
            th
              i.icon-block(data-toggle="tooltip", data-placement="top", title="Last block", ng-click="orderTable(['-stats.block.number', 'stats.block.propagation'], false)")
            th.th-blockhash  
            th.th-blockhash
              i.icon-difficulty(data-toggle="tooltip", data-placement="top", title="Total difficulty", ng-click="orderTable(['-stats.block.totalDifficulty'], false)")
            th
              i.icon-check-o(data-toggle="tooltip", data-placement="top", title="Block transactions", ng-click="orderTable(['-stats.block.transactions.length'], false)")
            th
              i.icon-uncle(data-toggle="tooltip", data-placement="top", title="Uncles", ng-click="orderTable(['-stats.block.uncles.length'], false)")
            th.th-blocktime
              i.icon-time(data-toggle="tooltip", data-placement="top", title="Last block time", ng-click="orderTable(['-stats.block.received'], false)")
            th.th-peerPropagationTime
              i.icon-gas(data-toggle="tooltip", data-placement="top", title="Propagation time", ng-click="orderTable(['-stats.block.number', 'stats.block.propagation'], false)")
            th.th-peerPropagationChart
            th.th-peerPropagationAvg
              i.icon-gas(data-toggle="tooltip", data-placement="top", title="Average propagation time", ng-click="orderTable(['stats.propagationAvg'], false)")
            th
              i.icon-bulb(data-toggle="tooltip", data-placement="top", title="Up-time", ng-click="orderTable(['-stats.uptime'], false)")
        tbody(ng-cloak)
          tr(ng-repeat='node in nodes | orderBy:predicate track by node.id', class="{{ node.stats | mainClass : bestBlock }}", id="node_{{node.id}}")
            td.td-nodecheck
              i(ng-click="pinNode(node.id)", class="{{ node.pinned | nodePinClass }}", data-toggle="tooltip", data-placement="right", data-original-title="Click to {{ node.pinned ? 'un' : '' }}pin")
            td.nodeInfo(rel="{{node.id}}")
              span.small(data-toggle="tooltip", data-placement="top", data-html="true", data-original-title="{{node | geoTooltip}}") {{node.info.name}}
              //- span.small  ({{node.info.ip}})
              a.small(href="https://github.com/ethereum/wiki/wiki/Network-Status#updating", target="_blank", data-toggle="tooltip", data-placement="top", data-html="true", data-original-title="Netstats client needs update.<br>Click this icon for instructions.", class="{{ node.info | nodeClientClass : currentApiVersion }}")
                i.icon-warning-o
            td
              div.small(ng-bind-html="node.info.node | nodeVersion")
            td(class="{{ node.readable.latencyClass }}")
              span.small {{ node.readable.latency }}
            td(class="{{ node.stats.mining | hashrateClass : node.stats.active }}", ng-bind-html="node.stats.hashrate | hashrateFilter : node.stats.mining")
            td(class="{{ node.stats.peers | peerClass : node.stats.active }}", style="padding-left: 11px;") {{node.stats.peers}}
            td(style="padding-left: 15px;") {{node.stats.pending}}
            td(class="{{ node.stats | blockClass : bestBlock }}")
              span(class="{{ node.readable.forkMessage ? node.readable.forkClass : '' }}") {{'#'}}{{ node.stats.block.number | number }}
              //- a.small(data-toggle="tooltip", data-placement="top", data-html="true", data-original-title="{{ node.readable.forkMessage }}", class="{{ node.readable.forkClass }}")
                i.icon-warning-o
            td(class="{{ node.stats | blockClass : bestBlock }}")
              span.small {{node.stats.block.hash | hashFilter}}
            td(class="{{ node.stats | blockClass : bestBlock }}")
              span.small {{node.stats.block.totalDifficulty | number}}
            td(style="padding-left: 14px;") {{node.stats.block.transactions.length || 0}}
            td(style="padding-left: 14px;") {{node.stats.block.uncles.length || 0}}
            td(class="{{ node.stats.block.received | timeClass : node.stats.active }}") {{node.stats.block.received | blockTimeFilter }}
            td(class="{{ node.stats | propagationTimeClass : bestBlock }}")
              div.propagationBox
              span {{node.stats.block.propagation | blockPropagationFilter}}
            td.peerPropagationChart(class="{{node.id}}")
              nodepropagchart(data="{{node.history.join(',')}}")
            td(class="{{ node.stats | propagationNodeAvgTimeClass : bestBlock }}") {{ node.stats | blockPropagationAvgFilter : bestBlock }}
            td(class="{{ node.stats.uptime | upTimeClass : node.stats.active }}") {{ node.stats.uptime | upTimeFilter }}


        #tab2.tab
        p Tab #2 content goes here!

Here is the CSS :

 /*----- Tabs -----*/
.tabs {
    width:100%;
    display:inline-block;
}

    /*----- Tab Links -----*/
    /* Clearfix */
    .tab-links:after {
        display:block;
        clear:both;
        content:'';
    }

    .tab-links li {
        margin:0px 5px;
        float:left;
        list-style:none;
    }

        .tab-links a {
            padding:9px 15px;
            display:inline-block;
            border-radius:3px 3px 0px 0px;
            background:#7FB5DA;
            font-size:16px;
            font-weight:600;
            color:#4c4c4c;
            transition:all linear 0.15s;
        }

        .tab-links a:hover {
            background:#a7cce5;
            text-decoration:none;
        }

    li.active a, li.active a:hover {
        background:#fff;
        color:#4c4c4c;
    }

    /*----- Content of Tabs -----*/
    .tab-content {
        padding:15px;
        border-radius:3px;
        box-shadow:-1px 1px 1px rgba(0,0,0,0.15);
        background:#fff;
    }

        .tab {
            display:none;
        }

        .tab.active {
            display:block;
        }

Here is the javascript :

  jQuery(document).ready(function() {
  jQuery('.tabs .tab-links a').on('click', function(e)  {
  var currentAttrValue = jQuery(this).attr('href');
  // Show/Hide Tabs
  jQuery('.tabs ' + currentAttrValue).show().siblings().hide();
  // Change/remove current tab to active
  jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
  e.preventDefault();
  });
  });

And this is how I have referenced it in the layout.jade file which the index.jade file (code extract above) extends.

//- layout.jade
doctype html
html(ng-app="netStatsApp")
  head
    meta(name="viewport", content="width=device-width, initial-scale=1.0, maximum-scale=1.0")
    title Ethereum Network Status
    style(type="text/css") [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; }
    link(rel='stylesheet', href='//fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700')
    link(rel='stylesheet', href='/css/netstats.min.css')
  body
    block content

    script(src="/js/netstats.min.js")
    script(src="/js/tabs.js")

Help would be appreciated :)

Upvotes: 1

Views: 475

Answers (1)

Oli Beatson
Oli Beatson

Reputation: 841

Your Jade code seems to have a lot of indentation issues. As indentation is Jade's way of recognizing document element hierarchy, this will obviously affect the output HTML (elements will be siblings instead of parent-child, elements will be closed too early, etc).

For example, div.row(ng-cloak, style="padding-top: 10px") needs to be more indented than its parent element #tab1.tab.active, as do all the children of that element, to represent the desired HTML structure.

Setting up your text editor to automatically indent your code in a uniform way (e.g. using tabs) could help prevent issues like this. I use Sublime Text which not only displays code really nicely but makes manipulating code like this easy with lots of formatting tools.

Upvotes: 1

Related Questions