{% load static %} 
{% include "header.html" %}
{% include "navigation.html" with main_path='/main/' %}

<br/>
<br/>

<div class="container">
  <div class="dashboard">
    <div class="span8 offset2">
      <h1>New Task</h1> 
      <hr>

      {% if data.step == 'one' %}

          <h3>Step 1: name, container and computing.</h3> 
          
          <br/>
          
          <form action="/create_task/" method="POST">
          {% csrf_token %}
          <input type="hidden" name="step" value="one" />


          <table class="dashboard" style="max-width:700px">
          <tr><td></td></tr>

           <tr>
            <td><b>Task name </b></td>
            <td>
             <input type="text" name="task_name" value="" placeholder="" size="23" required />
            </td>
           </tr>

          <tr>
            <td><b>Task container</b></td><td>
              <select name="task_container_uuid" >
              <!-- <option value="metadesktop" selected>Meta Desktop</option>
              <option value="astroccok">Astrocook</option>
              <option value="gadgetviewer">Gadget Viewer</option> -->
              {% for container in data.containers %}
              <option value="{{container.uuid}}">{{container.name}} ({{container.type}})</option>
              {% endfor %}              
              
              </select>
              &nbsp; | <a href="/add_container">Add new...</a>          
            </td>
           </tr>
           
           <tr>
            <td><b>Computing resource</b></td><td>
              <select name="task_computing" >
              {% for computing in data.computings %}}
              <option value="{{ computing.uuid }}">{{ computing.name}} ({% if computing.user %}{{ computing.user }}{% else %}platform{% endif %})</option>
              {% endfor %}
              </select>
              &nbsp; | <a href="/add_computing">Add new...</a>
            </td>
           </tr>

           <tr>
           <td colspan=2 align=center style="padding:20px">
           <input type="submit" value="Next">
           </td>
           </tr>
          </table>
          </form>

      {% elif data.step == 'two' %}

          <h3>Step 2: authentication and computing details</h3> 

          <br/>
          
          {% if data.task.container.type == 'singularity' and not data.task.container.supports_dynamic_ports %}
          <div> <p style="font-size:15px; max-width:700px; margin-bottom:20px">
          <i class="fa fa-exclamation-triangle" style="color:orange"></i> This container does not support dynamic ports and you are running it with Singularity, without network insulation. This means that if the container port is already occupied, it will not be able to start.
          </p></div>
          {% endif %}
          
          {% if data.task.container.ports and not data.task.container.supports_pass_auth %}
          <div> <p style="font-size:15px; max-width:700px; margin-bottom:20px">
          <i class="fa fa-exclamation-triangle" style="color:orange"></i> This container does not support any authentication. This means that anyone running on the same network will be able to access it services.
          </p></div>
          {% endif %}
        
          <form action="/create_task/" method="POST">
          {% csrf_token %}
          <input type="hidden" name="step" value="two" />
          <input type="hidden" name="task_uuid" value="{{ data.task.uuid }}" />

          <table class="dashboard" style="max-width:700px">
          <tr><td></td></tr>
           {% if data.task.container.supports_user_auth %}
           <tr>
            <td><b>Task user</b></td>
            <td>
             <input type="text" name="auth_user" value="" placeholder="" size="23" />
            </td>
           </tr>
           {% endif %}

           {% if data.task.container.supports_pass_auth %}
           <tr>
            <td valign="top"><b>Set task password</b></td>
            <td>
             <input type="password" name="auth_password" value="" placeholder="" size="23" /><br>
             <font size=-1>Use a non-sensitive password as it will be stored in plain text. 6 chars min.</font>
            </td>
           </tr>
           {% endif %}

           <tr>
            <td><b>Access method</b></td><td>
              <select name="access_method" >
              <option value="https_proxy" disabled>HTTPS proxy</option>
              <option value="direct_tunnel" selected>Direct tunnel</option>
              <option value="None">None</option>
              </select>
            </td>
           </tr>

           <!-- <tr>
            <td><b>Run using</b></td><td>
              <select name="run_using" >
              <option value="docker" selected>Docker</option>
              <option value="singularity">Singularity</option>
              </select>
            </td>
           </tr>  -->
           
           {% if data.task.computing.type == 'slurm' %}
           <tr>
            <td><b>Computing options</b></td>
            <td>
            <table>
             <tr><td>Partition</td><td><input type="text" name="computing_partition" value="" placeholder="" size="20" /></td></tr>
             <tr><td>Cpus</td><td><input type="text" name="computing_cpus" value="" placeholder="" size="5" /></td></tr>
             <tr><td>Memory</td><td><input type="text" name="computing_memory" value="" placeholder="" size="5" /></td></tr>
             </table>
            </td>
           </tr>
           {% endif %}
             
           <tr><td colspan=2>
           <table><tr><td  style="border: 1px solid lightgray;" >
           I understand that files saved or modified in this container, if not explicitly saved to a persistent storage, will be LOST when the task ends.
           </td><td  style="border: 1px solid lightgray;" >
           <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
           </td></table>
           </td></tr>
           <tr>
           <td colspan=2 align=center style="padding:20px">
           <input type="submit" value="Create">
           </td>
           </tr>
          </table>
          </form>


      {% else %}
        Ok, task created. Go back to your <a href="/tasks">task list</a>.
        

      {% endif %} 
  
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      
    </div>
  </div>
</div>

{% include "footer.html" %}






