<!DOCTYPE html>
<html lang="pt-br">
<head>
  <script type="text/JavaScript" {{#main.NonceToken}}nonce="{{main.NonceToken}}"{{/main.NonceToken}}>
    <!--
    function AutoRefresh( t ) {
      setTimeout("location.reload(true);", t);
    }

    function Ping( pid ) {
      var xmlHttp = new XMLHttpRequest();
      xmlHttp.open( "GET", 'ping?PID='+pid, false ); // false for synchronous request
      xmlHttp.send( null );
      //alert(xmlHttp.responseText);

      let newWin = window.open('_blank', 'ResultadoPing'+Math.floor(Math.random() * 100), 'popup=yes');
      newWin.document.write(
        xmlHttp.responseText
      );
    }

    function Params( valor ) {
      let newWin = window.open('_blank', 'Params'+Math.floor(Math.random() * 100), 'popup=yes');
      newWin.document.write(
        valor
      );
    }
			
			
         //-->
  </script>
  <style>
    table {
      font-family: arial, sans-serif;
      border-collapse: collapse;
      width: 100%;
    }

    td, th {
      border: 1px solid #dddddd;
      text-align: left;
      padding: 8px;
    }

    tr:nth-child(even) {
      background-color: #dddddd;
    }
  </style>

  {{#Scope.Tempo}}
  <script {{#main.NonceToken}}nonce="{{main.NonceToken}}"{{/main.NonceToken}}>
    window.addEventListener('load', function() { AutoRefresh({{{Scope.Tempo}}}) });
  </script>
  {{/Scope.Tempo}}
  {{>GoogleTag}}
</head>
<body>
<h1>Processos</h1>
{{^Main.administradorcloud}}<a href="Inicio">Login</a>{{/Main.administradorcloud}}{{#Main.administradorcloud}}<a href="LogOut">Sair</a>{{/Main.administradorcloud}}<br><a href="Info">Informações do Servidor</a><br><a href="Estatisticas">Estatísticas</a><br><a href="Sessoes">Sessões</a><br>
<p> Tempo atualizacao da página em milisegundos: <input type="text" id="tempo" value="{{Scope.Tempo}}"></p>

{{#Scope.ServerInfo}}
<h2 style="color:{{MemoriaCor}}">Processador em Uso: {{ProcessadorEmUso}}%</h2>
<h2 style="color:{{MemoriaCor}}">Memória em Uso: {{MemoriaEmUso}}% Limite: {{MemoriaLimite}}%</h2>
{{/Scope.ServerInfo}}
<h2>Executáveis</h2>

Executáveis por base
<table>
<tr>
    <th>Base</th>
	<th>Total</th>	
	{{#Main.administradorcloud}}<th>Ações</th>{{/Main.administradorcloud}}
</tr>
{{#Scope.Processos.Totais}}
<tr>
  <td>{{Base}}</td>
  <td>{{Total}}</td> 
  {{#Main.administradorcloud}}<td><a href="FinalizarDatabaseExe?Database={{Base}}">Finalizar Executaveis</a></td>{{/Main.administradorcloud}}
</tr>
{{/Scope.Processos.Totais}}
</table>
<br>
Executáveis por módulo
<table>
<tr>
    <th>Módulo</th>
	<th>Total</th>	
	{{#Main.administradorcloud}}<th>Ações</th>{{/Main.administradorcloud}}
</tr>
{{#Scope.Processos.Modulos}}
<tr>
  <td>{{Modulo}}</td>
  <td>{{Total}}</td> 
  {{#Main.administradorcloud}}<td><a href="FinalizarModuloExe?Modulo={{Modulo}}">Finalizar Executaveis</a></td>{{/Main.administradorcloud}}
</tr>
{{/Scope.Processos.Modulos}}
</table>
<br>
<table>
<tr>
    <th>PID</th>
	<th>Inicio</th>
	<th>Nome</th>
	<th>Threads</th>
	<th>Request Ativa</th>
	<th>Ultima Request</th>	
	<th>Memória</th>
    {{#Main.administradorcloud}}<th>Ações</th>{{/Main.administradorcloud}}
</tr>
{{#Scope.Processos.Executaveis}}
<tr>
  <td>{{PID}}</td>
  <td>{{Inicio}}</td>
  <td>{{Nome}}</td>
  <td>{{Threads}}</td> 
  <th>{{Ativo}}</th>
  <th>{{#Ping}}<button data-ping="{{PID}}">Ping</button>{{/Ping}}{{#UltimoUso}}<button data-params="{{LastRequestParams}}">Params</button>{{UltimoUso}} - {{LastRequest}}{{/UltimoUso}}</th>
  <td>{{Memoria}}</td> 
  {{#Main.administradorcloud}}<td>{{#Acoes}}<a href="FinalizarExe?PID={{PID}}">Finalizar</a>{{/Acoes}}{{/Main.administradorcloud}}</td>
</tr>
{{/Scope.Processos.Executaveis}}
</table>

<script {{#main.NonceToken}}nonce="{{main.NonceToken}}"{{/main.NonceToken}}>
  const tempoEl = document.getElementById('tempo');

  if (tempoEl) {
    tempoEl.addEventListener('change', function() { 
      window.location.assign('Processos?tempo='+ document.getElementById('tempo').value) 
    });
  }
  
  document
    .querySelectorAll('button[data-ping]')
    .forEach(function (buttonEl) {
      buttonEl.addEventListener('click', function() {
        Ping(buttonEl.dataset.ping);
      });
    });

  document
    .querySelectorAll('button[data-params]')
    .forEach(function (buttonEl) {
      buttonEl.addEventListener('click', function () { 
        Params(buttonEl.dataset.params);
      });
    });
</script>
</body>
</html>
