Skip to content

Commit

Permalink
chg: [query] query with same parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Mar 11, 2024
1 parent f0fff0d commit 99e2ce7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions website/app/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def run_modules():
if "modules" in request.json:
if "query_as_same" in request.json:
session = SessionModel.Session_class(request.json, query_as_same=True, parent_id=request.json["parent_id"])
elif "query_as_params" in request.json:
session = SessionModel.Session_class(request.json, query_as_same=True, parent_id=request.json["same_query_id"])
else:
session = SessionModel.Session_class(request.json)
HomeModel.set_flask_session(session, request.json["parent_id"])
Expand Down
47 changes: 45 additions & 2 deletions website/app/templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@ <h2>{{query}}</h2>
<div class="btn-group" style="float: right;" role="group" aria-label="Basic mixed styles example">
<a style="float: right;" class="btn btn-primary" href="/" title="Do a new query with no relation with this one">New query</a>
<a style="float: right;" class="btn btn-secondary" href="/?query={{query}}" title="New query with same name">Query</a>
</div>
<div class="dropdown" style="float: right;">
<button class="btn btn-primary dropdown-toggle" title="New query with same parameters" style="border-radius: 0;" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
Query as same
</button>
<div class="dropdown-menu p-4" style="min-width: 200px;">
<div class="mb-3">
<label for="query_as_params" class="form-label">To query:</label>
<input type="email" class="form-control" id="query_as_params" placeholder="{{query}}">
<div id="query_as_params_error" style="color:brown"></div>
</div>
<button type="submit" class="btn btn-primary btn-sm" @click="query_as_params()" style="border-radius: 50px;">Query</button>
</div>
</div>
</div>



<div class="card card-body">
Expand Down Expand Up @@ -341,6 +355,7 @@ <h2 class="accordion-header">
history.value = loc
}

// query 'value' with same parameters with a parent
async function query_as_same(value){
let result_dict = {"modules": query_info.value["modules"],
"input": query_info.value["input_query"],
Expand All @@ -361,6 +376,33 @@ <h2 class="accordion-header">
}
}

// query 'value' with same parameters without a parent
async function query_as_params(){
let loc = $("#query_as_params").val()
$("#query_as_params_error").text("")
if(loc){
let result_dict = {"modules": query_info.value["modules"],
"input": query_info.value["input_query"],
"query": loc,
"config": {},
"same_query_id": sid.value,
"parent_id": ""
}
const res = await fetch('/run_modules',{
headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" },
method: "POST",
body: JSON.stringify(result_dict)
})
if(await res.status == 201){
let loc = await res.json()
await nextTick()
window.location.href="/query/" + loc['id']
}
}else{
$("#query_as_params_error").text("Please give value")
}
}

onMounted(() => {
queryInfo()
actionQuery()
Expand All @@ -382,7 +424,8 @@ <h2 class="accordion-header">
parseMispObject,
parseMispAttr,
active_tab,
query_as_same
query_as_same,
query_as_params
}
}
}).mount('.container-fluid')
Expand Down

0 comments on commit 99e2ce7

Please sign in to comment.