<div class="box-me">
    <div class="row">
        <div class="col-xs-12 text-center">
            <h1>Level</h1>
        </div>
    </div>
    <div class="row">
        <div class="make-gauge col-xs-4"
            data-deviceName="plcpond"
            data-channelName="pond1height"
            data-displayName="Pond 1 Height"
            data-units="Ft"
            data-min="0"
            data-max="50"
            data-decimalPlaces="2"
            data-channelId="<%= channels['plcpond.pond1height'].channelId %>"
            data-timestamp="<%= channels['plcpond.pond1height'].timestamp %>"
        ></div>
        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 2) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pond2height"
                data-displayName="Pond 2 Height"
                data-units="Ft"
                data-min="0"
                data-max="50"
                data-decimalPlaces="2"
                data-channelId="<%= channels['plcpond.pond2height'].channelId %>"
                data-timestamp="<%= channels['plcpond.pond2height'].timestamp %>"
            ></div>
        <% }%>

        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 3) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pond3height"
                data-displayName="Pond 3 Height"
                data-units="Ft"
                data-min="0"
                data-max="50"
                data-decimalPlaces="2"
                data-channelId="<%= channels['plcpond.pond3height'].channelId %>"
                data-timestamp="<%= channels['plcpond.pond3height'].timestamp %>"
            ></div>
        <% }%>

        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 4) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pond4height"
                data-displayName="Pond 4 Height"
                data-units="Ft"
                data-min="0"
                data-max="50"
                data-decimalPlaces="2"
                data-channelId="<%= channels['plcpond.pond4height'].channelId %>"
                data-timestamp="<%= channels['plcpond.pond4height'].timestamp %>"
            ></div>
        <% }%>
    </div>
</div>


<div class="box-me">
    <div class="row">
        <div class="col-xs-12 text-center">
            <h1>Volume</h1>
        </div>
    </div>
    <div class="row">
        <div class="make-gauge col-xs-4"
            data-deviceName="plcpond"
            data-channelName="pond1volume"
            data-displayName="Pond 1 Volume"
            data-units="BBL"
            data-min="0"
            data-max="1000000"
            data-decimalPlaces="0"
            data-channelId="<%= channels['plcpond.pond1volume'].channelId %>"
            data-timestamp="<%= channels['plcpond.pond1volume'].timestamp %>"
        ></div>
        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 2) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pond2volume"
                data-displayName="Pond 2 Volume"
                data-units="BBL"
                data-min="0"
                data-max="1000000"
                data-decimalPlaces="0"
                data-channelId="<%= channels['plcpond.pond2volume'].channelId %>"
                data-timestamp="<%= channels['plcpond.pond2volume'].timestamp %>"
            ></div>
        <% }%>

        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 3) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pond3volume"
                data-displayName="Pond 3 Volume"
                data-units="BBL"
                data-min="0"
                data-max="1000000"
                data-decimalPlaces="0"
                data-channelId="<%= channels['plcpond.pond3volume'].channelId %>"
                data-timestamp="<%= channels['plcpond.pond3volume'].timestamp %>"
            ></div>
        <% }%>

        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 4) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pond4volume"
                data-displayName="Pond 4 Volume"
                data-units="BBL"
                data-min="0"
                data-max="1000000"
                data-decimalPlaces="0"
                data-channelId="<%= channels['plcpond.pond4volume'].channelId %>"
                data-timestamp="<%= channels['plcpond.pond4volume'].timestamp %>"
            ></div>
        <% }%>

        <% if (parseInt(channels['plcpond.cfgnumberofponds'].value) >= 2) { %>
            <div class="make-gauge col-xs-4"
                data-deviceName="plcpond"
                data-channelName="pondvolumetotal"
                data-displayName="Pond Volume Total"
                data-units="BBL"
                data-min="0"
                data-max="1000000"
                data-decimalPlaces="0"
                data-channelId="<%= channels['plcpond.pondvolumetotal'].channelId %>"
                data-timestamp="<%= channels['plcpond.pondvolumetotal'].timestamp %>"
            ></div>
        <% }%>
    </div>
</div>


<style>

.box-me {
    position: relative;
    padding: 0.5em;
    padding-bottom: 1.5em;
    border: 1px solid #eee;
    /*margin: 1em 0;*/
}

.box-me .gauge-box {
    margin-top: -0.25em;
}

h2 {
    text-transform: uppercase;
    font-size: 14px;
    color: #666;
    font-weight: 400;
    letter-spacing: 1px;
    z-index: 100;
}

.dynamic-chart-form {
    background-color: whiteSmoke;
    padding: 1em 0.5em;
    margin-top: 1em;
}

.row-flex {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    flex-wrap: wrap;
}

.row-flex > [class*='col-'] {
    display: flex;
    flex-direction: column;
}

#systemStatusTimelineContainer h2 {
    text-transform: uppercase;
    font-size: 14px;
    color: #666;
    font-weight: 400;
    letter-spacing: 1px;
    z-index: 100;
}

.slice.node-detail hr {
    border-color: #ccc;
}
.slice.node-detail #alarms li {
    margin-bottom: 1em;
    padding: 0.5em;
}
.slice.node-detail #alarms li:nth-child(even){
    background-color: whiteSmoke;
}
.slice.node-detail #alarms li span {
    margin-left: 1em;
    color: #aaa;
}
</style>

<script>

$('.val_box').each(function(topLevel){
    $(this).change(function(){
        var id = "#" + $(this).closest(".entry-top-level").attr('id');
        if (id !== "#undefined"){
            var val = $(id).find('.val_box').val();
            var tag = $(id).find('.setstatic').attr('data-staticsend', val);
            console.log($(id).find('.setstatic').attr('data-staticsend'));
        }
    });
});

$('.make-gauge').each(function(gaugeDiv) {
    const deviceName = $(this).attr("data-deviceName");
    const channelName = $(this).attr("data-channelName");
    const displayName = $(this).attr("data-displayName");
    const units = $(this).attr("data-units");
    const min = $(this).attr("data-min");
    const max = $(this).attr("data-max");
    const decimalPlaces = $(this).attr("data-decimalPlaces");
    const channelId = $(this).attr("data-channelId");
    const timestamp = $(this).attr("data-timestamp");
    const gaugeHTML = makeGauge(deviceName, channelName, displayName, units, min, max, decimalPlaces, channelId, timestamp);
    $(this).html(gaugeHTML);

});

function makeGauge(deviceName, channelName, displayName, units, min, max, decimalPlaces, channelId, timestamp) {

    return (
        '<div class="text-center"> \
            <h2>' + displayName + '</h2> \
            <div class="gauge-box"> \
                <div data-labelheight="10" \
                    style="height: 170px; background: transparent; margin: 0 auto;" \
                    id="gauge-' + channelName + '" \
                    data-chart="solidgauge" \
                    data-nodename="' + deviceName + '.' + channelName + '" \
                    data-units="'+ units + '" \
                    data-min="' + min + '" \
                    data-max="' + max + '" \
                    data-decimalplaces="' + decimalPlaces + '" \
                    data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B" \
                    data-valuefontsize="18px"> \
                </div> \
                <div class- "timestamp-box"> \
                    <a href="#" data-channelId="' + channelId + '" class="data-table" title="Download Channel History"> \
                        <i class="fa fa-download"></i> \
                    </a> \
                </div> \
                <span data-timeupdate="' + channelName + '">'+ timestamp + '</span> \
            </div> \
        </div>'
    );
}

</script>
