{{ define "content" }}

<p>
    Information about this process.
</p>

<table>
    <thead>
    <tr>
        <th>Name</th>
        <th>Value</th>
    </tr>
    </thead>

    <tbody>
        <tr>
            <td># Threads</td>
            <td id="Threads">{{.Threads}}</td>
        </tr>

        <tr>
            <td># Goroutines</td>
            <td id="Goroutines">{{.Goroutines}}</td>
        </tr>

        <tr>
            <td>Effective Group Id</td>
            <td>{{.Egid}}</td>
        </tr>

        <tr>
            <td>Effective User Id</td>
            <td>{{.Euid}}</td>
        </tr>

        <tr>
            <td>Group Id</td>
            <td>{{.GID}}</td>
        </tr>

        <tr>
            <td>Groups</td>
            <td>{{.Groups}}</td>
        </tr>

        <tr>
            <td>Hostname</td>
            <td>{{.Hostname}}</td>
        </tr>

        <tr>
            <td>Parent Process Id</td>
            <td>{{.Ppid}}</td>
        </tr>

        <tr>
            <td>Process Id</td>
            <td>{{.Pid}}</td>
        </tr>

        <tr>
            <td>Temporary Directory</td>
            <td>{{.TempDir}}</td>
        </tr>

        <tr>
            <td>User Id</td>
            <td>{{.UID}}</td>
        </tr>

        <tr>
            <td>Working Directory</td>
            <td>{{.Wd}}</td>
        </tr>
    </tbody>
</table>

{{ template "last-refresh" .}}

<script>
    "use strict";

    function refreshProcStats() {
        let url = window.location.protocol + "//" + window.location.host + "/procj/";

        let ajax = new XMLHttpRequest();
        ajax.onload = onload;
        ajax.onerror = onerror;
        ajax.open("GET", url, true);
        ajax.send();

        function onload() {
            if (this.status === 200) { // request succeeded
                let pi = JSON.parse(this.responseText);
                document.getElementById("Threads").innerText = pi.threads;
                document.getElementById("Goroutines").innerText = pi.goroutines;

                updateRefreshTime();
            }
        }

        function onerror(e) {
            console.error(e);
        }
    }

    refreshProcStats();
    window.setInterval(refreshProcStats, 1000);

</script>

{{ end }}
