<!--
 Copyright 2019 Novartis Institutes for BioMedical Research Inc. Licensed
 under the Apache License, Version 2.0 (the "License"); you may not use
 this file except in compliance with the License. You may obtain a copy
 of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless
 required by applicable law or agreed to in writing, software distributed
 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 OR CONDITIONS OF ANY KIND, either express or implied. See the License for
 the specific language governing permissions and limitations under the License.
-->

<html>
<head>
     <title>Cellxgene Gateway - FILE CRAWLER</title>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
     <link rel="icon" type="image/png" href="{{ url_for('static', filename='nibr.ico') }}">
	{% for script in extra_scripts %}
	<script src="{{ script }}"></script>
	{% endfor %}
     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
     <header class="navbar navbar-expand navbar-dark flex-column flex-md-row bd-navbar">
       <h3>Cellxgene Gateway - Cache Status</h3>
     </header>
     <br>
     <table class="table">
          <thead>
          <tr>
               <th>PID</th>
               <th>dataset</th>
               <th>annotation_file</th>
               <th>port</th>
               <th>launchtime</th>
               <th>last access</th>
               <th>status</th>
               <th>message</th>
               <th>http_status</th>
               <th>actions</th>
          </tr>
     </thead>
     <tbody>
	{% for entry in entry_list %}
          <tr>
               <td>{{ entry.pid }}</td>
               <td><a href="{{ url_for('do_view', path=entry.key.pathpart) }}">{{ entry.key.dataset }}</a></td>
               <td>{{ entry.key.annotation_file }}</td>
               <td>{{ entry.port }}</td>
               <td class="timestamp">{{ entry.launchtime }}</td>
               <td class="timestamp">{{ entry.timestamp }}</td>
               <td>{{ entry.status }}</td>
               <td>{{ entry.message }}</td>
               <td>{{ entry.http_status }}</td>
               <td>
                 {% if entry.status == 'loaded' %}
                   <a href="{{ url_for('do_terminate', path=entry.key.pathpart) }}"> terminate </a>
                 {% endif %}
               </td>
          </tr>
     {% endfor %}
     </tbody>
     </table>
     <script>
          $(() => {
               $(".timestamp").each(function(){
                    const el = $(this);
                    const ts = el.text();
                    const dt = new Date(parseInt(ts * 1000));
                    el.html(`${dt.toISOString()}<br>(${ts})`);
               });
          })
     </script>
</body>
</html>
