<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>

<%@taglib prefix="p" uri="http://primefaces.prime.com.tr/ui"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<f:subview id="server_status">
    <html>
        <body>
            <a4j:keepAlive beanName="clients" ajaxOnly="true"/>
            <a4j:region>
                <h:form>
                    <a4j:poll id="pollData" interval="5000" enabled="true"
                              reRender="memory, cpu" />
                </h:form>
            </a4j:region>

            <h:form id="dashboard">
                <p:panel id="board" header="Aktuálny stav servera" style="height:100%; width:90%; vertical-align: top;">
                    <table border="0" style="width: 100%;" cellspacing="10">
                        <tr><td style="width: 40%; vertical-align: top;">
                                <p:panel id="memory" style="top:0px;">
                                    <f:facet name="header">
                                        <h:outputText value="Pamäť"/>
                                    </f:facet>
                                    <h:panelGrid columns="2">
                                        <h:outputText value="Celkom:"/>
                                        <h:outputText value="#{user.information.memoryInfo.ram/1024}">
                                            <f:convertNumber pattern="#.## GB" />
                                        </h:outputText>

                                        <h:outputText value="Využitých [%]:"/>
                                        <h:outputText value="#{user.information.memoryInfo.usedPercent}">
                                            <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                             pattern="#.##"/>
                                        </h:outputText>
                                    </h:panelGrid>
                                </p:panel>
                                <br/>
                                <p:panel id="cpu" header="CPU">
                                    <h:panelGrid columns="2">
                                        <h:outputText value="#{msg.cpuVendor}:" />
                                        <h:outputText value="#{user.information.cpuInfo.vendor}" />

                                        <h:outputText value="#{msg.cpuModel}:" />
                                        <h:outputText value="#{user.information.cpuInfo.model}" />

                                        <h:outputText value="#{msg.cpuCores}:" />
                                        <h:outputText value="#{user.information.cpuInfo.totalCores}" />

                                        <h:outputText value="#{msg.cpuMHZ}:" />
                                        <h:outputText value="#{user.information.cpuInfo.mhz} MHz" />

                                        <h:outputText value="#{msg.cpuUsage} [%]:" />
                                        <h:outputText value="#{user.information.cpuPerc.combined * 100}">
                                            <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                             pattern="#.##" groupingUsed="false" />
                                        </h:outputText>
                                    </h:panelGrid>
                                </p:panel>
                                <br/>
                                <p:panel id="state">
                                    <f:facet name="header">
                                        <h:outputText value="Stav"/>
                                    </f:facet>

                                    <h:outputText value="Stav"  />
                                </p:panel>
                            </td>
                            <td style="width: 60%; vertical-align: top;">
                                <p:panel id="network" header="Sieť">
                                    <p:dataTable id="networksList" var="interface" value="#{user.information.netInformation}"
                                                 style="width: 100%;" >

                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{msg.name}" />
                                            </f:facet>
                                            <h:outputText value="#{interface.config.description}" />
                                        </p:column>

                                        <p:column width="50">
                                            <f:facet name="header">
                                                <h:outputText value="#{msg.type}" />
                                            </f:facet>
                                            <center>
                                                <h:graphicImage value="images/ethernet.png" width="18" height="18"
                                                                rendered="#{interface.ethernet}"/>
                                                <h:graphicImage value="images/loop.png" width="18" height="18"
                                                                rendered="#{interface.loopback}"/>
                                                <h:outputText value="#{interface.config.type}" />
                                            </center>
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="#{msg.ipAddress}" />
                                            </f:facet>
                                            <center>
                                                <h:outputText value="#{interface.config.address}" />
                                            </center>
                                        </p:column>

                                        <p:column styleClass="rightAlign">
                                            <f:facet name="header">
                                                <h:outputText value="#{msg.recieved}" />
                                            </f:facet>                                          
                                            <h:outputText value="#{interface.stat.rxBytes/1048576}">
                                                <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                                 pattern="#.## MB" groupingUsed="false"/>
                                            </h:outputText>
                                        </p:column>

                                        <p:column styleClass="rightAlign">
                                            <f:facet name="header">
                                                <h:outputText value="#{msg.sended}" />
                                            </f:facet>
                                            <h:outputText value="#{interface.stat.txBytes/1048576}"
                                                          style="text-align: right;">
                                                <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                                 pattern="#.## MB" groupingUsed="false"/>
                                            </h:outputText>
                                        </p:column>
                                    </p:dataTable>
                                </p:panel>
                            </td></tr></table>
                        </p:panel>
                    </h:form>
        </body>
    </html>
</f:subview>
