{% extends "pages/menu.html" %}

{% block css %}
{% load staticfiles %}
<link rel="stylesheet" href="{% static "lib/bootstrap/3.0.2/bootstrap.css" %}">

<script src="{% static "lib/jquery/1.11.1/jquery.min.js" %}" type="text/javascript"></script>

{% endblock %}



{% block content %}
<!--
<div class="container theme-showcase" role="main">
	<div class="jumbotron">
      <h2>Your file has been uploaded ! </h2>
      <h2>Gargantext need some time to eat it.</h2>
      <h2>Duration depends on the size of the dish.</h2>

    <a class="btn btn-primary btn-lg" href="/projects/{{ project.id }}" title="Click and test by yourself">Continue on Gargantext</a>
	</div> -->
	<div class="container theme-showcase" role="main">
	    <div class="jumbotron">
	        <div class="row">
	            <div class="col-md-6">
	                {% if project %}
	                <h1>
	                    <span class="glyphicon glyphicon-book" aria-hidden="true"></span>
	                    {{ project.name | truncatechars:25 }}</h1>
	                <!--<h3> {{number}} corpora </h3>-->
	                {% endif %}
	            </div>

	            <div class="col-md-4">
	                <p>
	                    {% if donut %}
	                    <div id="hero-donut" style="height: 200px;"></div>
	                    {% endif %}
	                    <center>

	                        <a data-toggle="modal" href="#addcorpus">
	                            <button
	                            type="button"
	                            class="btn btn-primary btn-lg"
	                            data-container="body"
	                            data-toggle="popover"
	                            data-placement="bottom"
	                            >
	                            <span class="glyphicon glyphicon-plus" aria-hidden="true" ></span>
	                            Add a corpus
	                            </button>
	                        </a>
	                    </center>
	                </p>
	            </div>
	    </div>

	</div>


	<!-- Add jumbotron container for each type of corpus (presse, science etc.) -->
	<div id="semLoader" style="position:absolute; top:50%; left:40%; width:80px; visibility: hidden;">
	    <img src="{% static "img/loading-bar.gif" %}"></img>
	</div>


	<div class="container">


	    {% if list_corpora  %}
	        {% for key, corpora in list_corpora.items %}
	            <h2>
	                <div class="row">
	                <div class="col-md-1 content"></div>
	                    <span class="glyphicon glyphicon-cd" aria-hidden="true"></span>
	                    {{ key }}
	            </h2>
	                    {% for corpus in corpora %}
	                        <div id="corpus_{{corpus.id}}">
	                            <div class="row">
	                                <h4>
	                                    <div class="col-md-1 content"></div>
	                                    <div class="col-md-5 content">
	                                        <a href="/projects/{{project.id}}/corpora/{{corpus.id}}">
	                                            <span class="glyphicon glyphicon-file" aria-hidden="true"></span>
	                                            {{corpus.name}}, {{ corpus.count }} documents {{ corpus.status_message }}
	                                        </a>
	                                    </div>
	                                    <div class="col-md-3 content">
	                                        <!--  -->
	                                        {% for state in corpus.hyperdata.statuses %}
	                                            {% ifequal state.action "Workflow" %}
	                                                {% if state.complete %}

	                                                    <a href="/projects/{{project.id}}/corpora/{{corpus.id}}" title="View the corpus">
	                                                        <button type="button" class="btn btn-default" aria-label="Left Align">
	                                                              <span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
	                                                        </button>
	                                                    </a>

	                                                    <button type="button" class="btn btn-default yopla" data-container="body" data-toggle="popover" data-placement="bottom"  data-trigger="focus"
	                                                        data-content="
	                                                        <ul>
	                                                            <li
	                                                            onclick=&quot;
	                                                                    garganrest.metrics.update({{corpus.id}}, function(){alert('The corpus ({{corpus.name|escapejs}}) was updated')});
	                                                                    &quot;>
	                                                                <a href='#'>Recalculate ngram metrics</a> <br/> (can take a little while)
	                                                            </li>
	                                                        </ul>
	                                                        ">
	                                                        <span class="glyphicon glyphicon-repeat" aria-hidden="true"
	                                                        title='Recalculate ngram scores and similarities'></span>
	                                                    </button>
	                                                {% endif %}

	                                                    <!-- TODO: delete non seulement si state.complete mais aussi si state.error -->
	                                                    <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
	                                                        data-content="
	                                                        <ul>
	                                                            <li
	                                                            onclick=&quot;
	                                                                    garganrest.nodes.delete({{corpus.id}}, function(){$('#corpus_'+{{corpus.id}}).remove()});
	                                                                    $(this).parent().parent().remove();
	                                                                &quot;>
	                                                                <a href='#'>Delete this</a>
	                                                            </li>
	                                                        </ul>
	                                                        ">
	                                                        <span class="glyphicon glyphicon-trash" aria-hidden="true"
	                                                        title='Delete this corpus'></span>
	                                                    </button>
	                                            {% endifequal %}
	                                        {% endfor %}
	                                    </div>
	                                    <div class="col-md-3 content">
	                                        {% for state in corpus.hyperdata.statuses %}
	                                                {% ifequal state.action "Workflow" %}
	                                                    {% if state.complete %}
	                                                        <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>

	                                                    {% else %}
	                                                        {% if state.error %}
	                                                            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
	                                                            {{ state.error }}
	                                                        {% else %}
	                                                            <div class="progress">
	                                                                <div class=" progress-bar progress-bar-striped
	                                                                                            progress-bar-success
	                                                                                     "
	                                                                                role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
	                                                                              <span>
	                                                                                  Upload
	                                                                              </span>
	                                                                </div>

	                                                                {% for state in corpus.hyperdata.statuses %}
	                                                                <!-- {% if state.action != "Workflow" %} --!>
	                                                                      <div class=" progress-bar progress-bar-striped
	                                                                                        {% if state.complete %}
	                                                                                            progress-bar-success
	                                                                                            {% else %}
	                                                                                            active
	                                                                                        {% endif %}
	                                                                                     "
	                                                                                role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
	                                                                              <span>
	                                                                                  {{ state.action }}
	                                                                                        {% if not state.complete %}
	                                                                                            Processing
	                                                                                        {% endif %}

	                                                                              </span>
	                                                                      </div>
	                                                                      <!-- {% endif %} --!>
	                                                                {% endfor %}
	                                                            </div>
	                                                        {% endif %}
	                                                    {% endif %}
	                                                {% endifequal %}
	                                        {% endfor %}
	                                    </div>
	                                    <div class="col-md-1 content"></div>
	                                </h4>
	                            </div>
	                        </div>
	                    {% endfor %}
	        {% endfor %}
	    {% endif %}


	<!-- Modal -->
	<div id="wait" class="modal fade">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
			<h2 class="modal-title"><h2><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>Building the corpus...</h2>
		</div>
		<div class="modal-body">
			<p>
			Gargantext is gathering your texts
			 and need some time to eat it.
			Duration depends on the size of the dish.
			</p>
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">Continue on Gargantext</button>
		</div>
	</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
	<script type="text/javascript" src="{% static "lib/jquery/1.11.2/jquery-ui.js" %}"></script>
	<script type="text/javascript">
	$(window).load(function() {
		var projectid = window.location.href.split("projects")[1].replace(/\//g, '')//replace all the slashes
		$('#wait').modal({ show: false})
		$("#wait").modal("show");
		$('#wait').on('hidden.bs.modal', function (e) {
		// reload page when dismiss the info box
			$(location).attr('href', window.location.origin+'/projects/'+projectid)
		})
	});
	</script>
{% endblock %}