{% extends "base.html" %}

{% macro feed_table(feed_names, feeds, tag) -%}
<table class='table' id='feeds'>
		<tr>
			<th>Feed name</th>
			<th>Enabled</th>
			<th>Running</th>
			<th>Run every</th>
			<th>Last run</th>
			<th>Next run</th>
			<th>Fresh</th>
			<th>Status</th>
			{% if  not g.config['PUBLIC'] %}
			<th>Refresh</th>
			{% endif %}
		</tr>
		{% for name in feed_names %}
		{% if tag in feeds[name].tags %}
		<tr class='{{ "disabled" if not feeds[name].enabled }} {{ "error" if feeds[name].status != "OK" else "success" }}'>
			<td>{{ feeds[name].name }}&nbsp;&nbsp;<a href='{{feeds[name].source }}'><span class='glyphicon glyphicon-new-window'></span></a></td>
			<td>{{ "Yes" if feeds[name].enabled else "No" }}</td>
			<td>{{ "Yes" if feeds[name].running else "No" }}</td>
			<td>{{ feeds[name].run_every }}</td>
			<td>{{ feeds[name].last_run.strftime("%Y-%m-%d %H:%M:%S") if feeds[name].last_run else "N/A"}}</td>
			<td>{{ feeds[name].next_run.strftime("%Y-%m-%d %H:%M:%S") if feeds[name].next_run else "N/A"}}</td>
			<td>{{ feeds[name].elements_fetched }}</td>
			<td class='error-cause'>{{ feeds[name].status }}</td>
			<td>
			{% if feeds[name].enabled and not g.config['PUBLIC']%}
				<a href='{{ url_for("run_feed", feed_name=name)}}'><span class='glyphicon glyphicon-refresh'></span></a>
			{% endif %}
			</td>
		</tr>
		{%endif%}
		{% endfor %}
	</table>
{%- endmacro %}


{% block main %}
<div class='col-md-12'>
	<h3>Public feeds</h3>

	{{ feed_table(feed_names, feeds, 'public') }}

	<h3>Private feeds</h3>
	
	{{ feed_table(feed_names, feeds, 'private') }}

	<h3>Internal feeds</h3>

	{{ feed_table(feed_names, feeds, 'internal') }}

</div>



{% endblock %}