<div class="box-me">
    <div class="row row-flex">
        <% if (channels['multisensor.an0active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an0val"
                data-displayName="<%= channels['multisensor.an0name'].value %>"
                data-units="<%= channels['multisensor.an0units'].value %>"
                data-min="<%= channels['multisensor.an0min'].value %>"
                data-max="<%= channels['multisensor.an0max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an0decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an0val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an0val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an0ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond0volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an1active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an1val"
                data-displayName="<%= channels['multisensor.an1name'].value %>"
                data-units="<%= channels['multisensor.an1units'].value %>"
                data-min="<%= channels['multisensor.an1min'].value %>"
                data-max="<%= channels['multisensor.an1max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an1decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an1val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an1val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an1ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond1volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an2active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an2val"
                data-displayName="<%= channels['multisensor.an2name'].value %>"
                data-units="<%= channels['multisensor.an2units'].value %>"
                data-min="<%= channels['multisensor.an2min'].value %>"
                data-max="<%= channels['multisensor.an2max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an2decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an2val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an2val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an2ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond2volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an3active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an3val"
                data-displayName="<%= channels['multisensor.an3name'].value %>"
                data-units="<%= channels['multisensor.an3units'].value %>"
                data-min="<%= channels['multisensor.an3min'].value %>"
                data-max="<%= channels['multisensor.an3max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an3decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an3val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an3val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an3ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond3volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an4active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an4val"
                data-displayName="<%= channels['multisensor.an4name'].value %>"
                data-units="<%= channels['multisensor.an4units'].value %>"
                data-min="<%= channels['multisensor.an4min'].value %>"
                data-max="<%= channels['multisensor.an4max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an4decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an4val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an4val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an4ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond4volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an5active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an5val"
                data-displayName="<%= channels['multisensor.an5name'].value %>"
                data-units="<%= channels['multisensor.an5units'].value %>"
                data-min="<%= channels['multisensor.an5min'].value %>"
                data-max="<%= channels['multisensor.an5max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an5decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an5val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an5val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an5ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond5volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an6active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an6val"
                data-displayName="<%= channels['multisensor.an6name'].value %>"
                data-units="<%= channels['multisensor.an6units'].value %>"
                data-min="<%= channels['multisensor.an6min'].value %>"
                data-max="<%= channels['multisensor.an6max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an6decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an6val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an6val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an6ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond6volume'].value %>"
            ></div>
        <% } %>

        <% if (channels['multisensor.an7active'].value == "true"){ %>
            <div class="make-gauge col-xs-4"
                data-deviceName="multisensor"
                data-channelName="an7val"
                data-displayName="<%= channels['multisensor.an7name'].value %>"
                data-units="<%= channels['multisensor.an7units'].value %>"
                data-min="<%= channels['multisensor.an7min'].value %>"
                data-max="<%= channels['multisensor.an7max'].value %>"
                data-decimalPlaces="<%= Math.round(channels['multisensor.an7decimals'].value) %>"
                data-channelId="<%= channels['multisensor.an7val'].channelId %>"
                data-timestamp="<%= channels['multisensor.an7val'].timestamp %>"
                data-ispond="<%= channels['multisensor.an7ispond'].value %>"
                data-pondvolume="<%= channels['multisensor.pond7volume'].value %>"
            ></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 isPond = $(this).attr("data-ispond");
    const pondVolume = $(this).attr("data-pondvolume");
    const gaugeHTML = makeGauge(deviceName, channelName, displayName, units, min, max, decimalPlaces, channelId, timestamp, isPond, pondVolume);
    $(this).html(gaugeHTML);

});

function makeGauge(deviceName, channelName, displayName, units, min, max, decimalPlaces, channelId, timestamp, isPond, pondVolume) {
    if (isPond === "true"){
        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> \
                    <hr /> \
                    <h3>Pond Volume</h3>\
                    <h4>' + pondVolume + ' BBL</h4>\
                </div> \
            </div>'
        );
    }

    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>
