mirror of https://github.com/MISP/misp-modules
chg: [website] history pagination
parent
8932741c90
commit
b776219683
|
@ -42,7 +42,7 @@ class Session_db(db.Model):
|
|||
"config_module": json.loads(self.config_module),
|
||||
"result": json.loads(self.result),
|
||||
"nb_errors": self.nb_errors,
|
||||
"query_date": self.query_date.strftime('%Y-%m-%d')
|
||||
"query_date": self.query_date.strftime('%Y-%m-%d %H:%M')
|
||||
}
|
||||
return json_dict
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Session_db(db.Model):
|
|||
"modules": json.loads(self.modules_list),
|
||||
"query": self.query_enter,
|
||||
"input": self.input_query,
|
||||
"query_date": self.query_date.strftime('%Y-%m-%d')
|
||||
"query_date": self.query_date.strftime('%Y-%m-%d %H:%M')
|
||||
}
|
||||
return json_dict
|
||||
|
||||
|
|
|
@ -18,8 +18,9 @@ def history():
|
|||
@history_blueprint.route("/get_history", methods=["GET"])
|
||||
def get_history():
|
||||
"""Get all history"""
|
||||
histories = HistoryModel.get_history()
|
||||
return histories
|
||||
page = request.args.get('page', 1, type=int)
|
||||
histories, nb_pages = HistoryModel.get_history(page)
|
||||
return {"history": histories, "nb_pages": nb_pages}
|
||||
|
||||
@history_blueprint.route("/history_session", methods=["GET"])
|
||||
def history_session():
|
||||
|
|
|
@ -13,14 +13,14 @@ def get_session(sid):
|
|||
|
||||
|
||||
|
||||
def get_history():
|
||||
def get_history(page):
|
||||
"""Return history"""
|
||||
histories_list = list()
|
||||
histories = History.query.order_by(desc(History.id))
|
||||
histories = History.query.order_by(desc(History.id)).paginate(page=page, per_page=20, max_per_page=50)
|
||||
for history in histories:
|
||||
session = Session_db.query.get(history.session_id)
|
||||
histories_list.append(session.history_json())
|
||||
return histories_list
|
||||
return histories_list, histories.pages
|
||||
|
||||
|
||||
def get_history_session():
|
||||
|
|
|
@ -9,12 +9,28 @@
|
|||
|
||||
<hr>
|
||||
<br>
|
||||
<!-- pagination -->
|
||||
<nav aria-label="Page navigation example" v-if="history && history.nb_pages > 1">
|
||||
<ul class="pagination">
|
||||
<li :class="{'page-item': true, 'disabled': current_page == 1}">
|
||||
<button class="page-link" @click="get_history(Math.max(1, current_page-1))">Previous</button>
|
||||
</li>
|
||||
<template v-for="cp in history.nb_pages">
|
||||
<li :class="{'page-item': true, 'active': current_page==cp}"><button class="page-link" @click="get_history(cp)">[[cp]]</button></li>
|
||||
</template>
|
||||
<li :class="{'page-item': true, 'disabled': current_page == history.nb_pages}">
|
||||
<button class="page-link" @click="get_history(Math.min(current_page+1, history.nb_pages))">Next</button>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<!-- pagination -->
|
||||
|
||||
<div v-if="history">
|
||||
<template v-for="h, key in history">
|
||||
<template v-for="h in history.history">
|
||||
<div class="list-group" style="margin-bottom: 20px;">
|
||||
<a :href="'/query/'+h.uuid" class="list-group-item list-group-item-action">
|
||||
<div class="d-flex w-100 justify-content-between">
|
||||
<h5 class="mb-1">[[key+1]]- [[h.query]]</h5>
|
||||
<h5 class="mb-1">[[h.query]]</h5>
|
||||
<small><i>[[h.uuid]]</i></small>
|
||||
</div>
|
||||
<p class="mb-1" style="color: green;"><u>Input Attribute</u>:</p>
|
||||
|
@ -34,7 +50,22 @@
|
|||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- pagination -->
|
||||
<nav aria-label="Page navigation example" v-if="history && history.nb_pages > 1">
|
||||
<ul class="pagination">
|
||||
<li :class="{'page-item': true, 'disabled': current_page == 1}">
|
||||
<button class="page-link" @click="get_history(Math.max(1, current_page-1))">Previous</button>
|
||||
</li>
|
||||
<template v-for="cp in history.nb_pages">
|
||||
<li :class="{'page-item': true, 'active': current_page==cp}"><button class="page-link" @click="get_history(cp)">[[cp]]</button></li>
|
||||
</template>
|
||||
<li :class="{'page-item': true, 'disabled': current_page == history.nb_pages}">
|
||||
<button class="page-link" @click="get_history(Math.min(current_page+1, history.nb_pages))">Next</button>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<!-- pagination -->
|
||||
|
||||
<span id="goTop">[<a href="#top">Go Back Top</a>]</span>
|
||||
{% endblock %}
|
||||
|
@ -51,18 +82,22 @@
|
|||
},
|
||||
setup() {
|
||||
const history = ref({})
|
||||
const current_page = ref(1)
|
||||
|
||||
async function get_history(){
|
||||
let res = await fetch("/get_history")
|
||||
async function get_history(page){
|
||||
let res = await fetch("/get_history?page=" + page)
|
||||
let loc = await res.json()
|
||||
history.value = loc
|
||||
current_page.value = page
|
||||
}
|
||||
get_history()
|
||||
get_history(1)
|
||||
|
||||
|
||||
return {
|
||||
message_list,
|
||||
history,
|
||||
current_page,
|
||||
get_history
|
||||
}
|
||||
}
|
||||
}).mount('.container')
|
||||
|
|
Loading…
Reference in New Issue