Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/lib/Tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,13 +1746,15 @@ def get_nb_objs(self):
objs[obj_type] = nb
return objs

def get_objs(self):
def get_objs(self, page=1, per_page=15):
objs = []
for obj_type in get_objects_retro_hunted():
for obj in self.get_objs_by_type(obj_type):
subtype, obj_id = obj.split(':', 1)
objs.append((obj_type, subtype, obj_id))
return objs

paginated_objs = ail_core.paginate_iterator(objs, page=page, per_page=per_page)
return paginated_objs

def add(self, obj_type, subtype, obj_id):
# match by object type:
Expand Down
9 changes: 7 additions & 2 deletions var/www/blueprints/hunters.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ def retro_hunt_show_task():
task_uuid = request.args.get('uuid', None)
objs = request.args.get('objs', False)

page = request.args.get('page', 1, type=int)
per_page = 15
# date_from_item = request.args.get('date_from')
# date_to_item = request.args.get('date_to')
# if date_from_item:
Expand All @@ -582,13 +584,16 @@ def retro_hunt_show_task():
dict_task['filters'] = json.dumps(dict_task['filters'], indent=4)

if objs:
dict_task['objs'] = ail_objects.get_objects_meta(retro_hunt.get_objs(), options={'last_full_date'}, flask_context=True)

pagination = retro_hunt.get_objs(page=page, per_page=per_page)
dict_task['objs'] = ail_objects.get_objects_meta(pagination.items, options={'last_full_date'}, flask_context=True)
else:
dict_task['objs'] = []
pagination = None

return render_template("show_retro_hunt.html", dict_task=dict_task,
rule_content=rule_content,
bootstrap_label=bootstrap_label)
bootstrap_label=bootstrap_label, pagination=pagination)


@hunters.route('/retro_hunt/add', methods=['GET', 'POST'])
Expand Down
60 changes: 51 additions & 9 deletions var/www/templates/hunter/show_retro_hunt.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,56 @@ <h4><span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">
</tbody>
</table>
</div>
<div class="d-flex justify-content-center">
{% if pagination %}
<nav aria-label="Page navigation example">
<ul class="pagination">
{% if pagination.has_prev %}
<li class="page-item">
<a class="page-link" href="{{ url_for('hunters.retro_hunt_show_task', uuid=dict_task['uuid'], page=pagination.prev_num, objs=True) }}" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
{% endif %}

{% for i in pagination.iter_pages() %}
{% if i %}
{% if i != pagination.page %}
<li class="page-item"><a class="page-link" href="{{ url_for('hunters.retro_hunt_show_task', uuid=dict_task['uuid'], page=i, objs=True) }}">{{ i }}</a></li>
{% else %}
<li class="page-item active"><a class="page-link" href="#">{{ i }}</a></li>
{% endif %}
{% else %}
<li class="page-item disabled"><a class="page-link" href="#">...</a></li>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<li class="page-item">
<a class="page-link" href="{{ url_for('hunters.retro_hunt_show_task', uuid=dict_task['uuid'], page=pagination.next_num, objs=True) }}" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
</div>

<hr>
{% endif %}
Expand Down Expand Up @@ -286,13 +336,6 @@ <h4><span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">
}
});*/

{% if dict_task['objs'] %}
$('#objs_table').DataTable({
"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
"iDisplayLength": 10,
"order": [[ 0, "asc" ]]
});
{% endif%}

});

Expand All @@ -313,8 +356,7 @@ <h4><span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">
function getItems() {
var date_from = $('#date-range-from-input').val();
var date_to =$('#date-range-to-input').val();
{#window.location.replace("{{ url_for('hunters.retro_hunt_show_task') }}?uuid={{ dict_task['uuid'] }}&date_from="+date_from+"&date_to="+date_to);#}
window.location.replace("{{ url_for('hunters.retro_hunt_show_task') }}?uuid={{ dict_task['uuid'] }}&objs=True");
window.location.replace("{{ url_for('hunters.retro_hunt_show_task') }}?uuid={{ dict_task['uuid'] }}&objs=True&page=1");
}

</script>
Expand Down
Loading