[% IF global_config.global.restrict_access_auth_only.upper == 'YES' && !user_info.auth %]
<h1>You are not authorised to view Rig [% rig_info.name %]</h1>
[% RETURN %]
[% END %]

<div style="overflow-x:auto; padding:20px;">

<script>
is_logged_in = true;
</script>
<h2>Rig [% rig_info.name %] test [% rig_info.current_test %] [% IF data.start_by %]started by [% data.start_by %] and [% END %] running for [% data.runtime.replace('\.\d+','') %] h since [% data.start.replace('\d+\:\d+\:\d+','') %]</h2>
[% IF data.warning_message %]<h3 style="color:red;margin-top:10px;">[% data.warning_message %]</h3>[% END -%]
<br>
<div style="display:flex;justify-content:center;gap:50px;align-items:flex-start;">
[% INCLUDE toolbox.tt %]
[% IF config.userinterface.default_layout && !nav.legacy %]
[% file = "rigs/$config.userinterface.default_layout" %]
[% INCLUDE $file %]
[% ELSE %]
[% INCLUDE legacy.tt %]
[% END %]
<div style="width:150px;"></div>
</div>

[% INCLUDE devices/common.tt %]

<br>
<div class="logarea">
<div class="content-container">
<div class=child>
<div><h3 class=logheader> New entry </h3></div>
<div><textarea id=new_log style="width:400px;height:30px;"  autocomplete=off></textarea></div>
<div><button onclick="add_log(document.getElementById('new_log').value)" class="tool-btn">Add</button>
</div>
</div>
<div class=child>
<div><h3 class=logheader> Logbook </h3></div>
<div class=log_single id=userlog title="To see full logbook go to current test and userlog"></div>
</div>
<div class=child>
<div><h3 class=logheader> Errorlog </h3></div>
<div class=log_single id=errorlog title="To see full eror log go to current test and errorlog"></div>
</div>
</div>
<div class="content-container">
<div class=child style="align-items:flex-start;">
<div><h3 class=logheader> Proglog </h3></div>
<div class=log id=proglog title="To see full program log go to current test and program log"></div>
</div>
</div>
</div>


</div>


<script>



function add_log(val)
{
    var arr = new Object();
    arr['log'] = val;
    var json_str = encodeURI(JSON.stringify(arr));
    run_ajax('json_rig_ui.cgi','&action=userlog&json_data='+json_str,set_logs);
    document.getElementById('new_log').value = '';
[% IF config.main.equipmentid && global_config.global.remote_equipment_database -%]        
    remote_log('[% global_config.global.remote_equipment_database %]',[% config.main.equipmentid %],val,do_nothing);
[% END -%]
}

function get_logs()
{
    if (!is_logged_in)
    {
        return false;
    }
    run_ajax('json_rig_ui.cgi','&action=get_logs',set_logs);
}

function set_logs(res)
{
    var data = JSON.parse(res);
    if (data.status != 'OK')
    {
	is_logged_in = false;
	return;
    }
    var e = document.getElementById('proglog');
    e.innerHTML = data.proglog.join('<br>');
    e.scrollTop = e.scrollHeight;
    var e = document.getElementById('userlog');
    e.innerHTML = data.userlog.join('<br>');
    e.scrollTop = e.scrollHeight;
    var e2 = document.getElementById('errorlog');
    e2.innerHTML = data.errorlog.join('<br>');
    e2.scrollTop = e2.scrollHeight;
}

</script>
