Skip to content

Commit

Permalink
Add filetree filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jmforsythe committed May 24, 2024
1 parent 8ca629c commit 299c6b2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 31 deletions.
11 changes: 9 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def treemap_page(name):
@cache_on_db_change
@valid_db_check
def filetree_json(name):
if request.args.keys():
valid_keys = ("email_include", "email_exclude", "commit_include", "commit_exclude", "filename_include", "filename_exclude", "datetime_include", "datetime_exclude")
params = {key: tuple(request.args.getlist(key)) for key in valid_keys if key in request.args.keys()}
params_frozen = frozenset(params.items())
return get_json_with_params(name, params_frozen)

# If no parameters are given, use specially cached result
this_repo_dir = repos_dir / pathlib.Path(name)
db_path = (this_repo_dir / this_repo_dir.stem).with_suffix(".db")
json_path = this_repo_dir / "filetree.json"
Expand All @@ -95,7 +102,7 @@ def highight_json(name):
valid_keys = ("email_include", "email_exclude", "commit_include", "commit_exclude", "filename_include", "filename_exclude", "datetime_include", "datetime_exclude")
params = {key: tuple(request.args.getlist(key)) for key in valid_keys if key in request.args.keys()}
params_frozen = frozenset(params.items())
return get_highlight_json(name, params_frozen)
return get_json_with_params(name, params_frozen)

@app.route("/<path:name>/.gitmodules")
@cache_on_db_change
Expand Down Expand Up @@ -125,7 +132,7 @@ def sql_query(name, query):
return out

@functools.lru_cache(maxsize=100)
def get_highlight_json(name, params):
def get_json_with_params(name, params):
this_repo_dir = repos_dir / pathlib.Path(name)
db_path = (this_repo_dir / this_repo_dir.stem).with_suffix(".db")
params_dict = {a[0]: a[1] for a in params}
Expand Down
2 changes: 1 addition & 1 deletion server/database_to_JSON.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_filtered_query(filter):
params.extend(date_expand)

if len(wheres_inner) == 0:
wheres_inner = ["0"]
wheres_inner = ["1"]
query = base_query.replace("JOIN_LINE", " ".join(joins)).replace("WHERE_LINE", " AND ".join(wheres)).replace("WHERE_INNER_LINE", " AND ".join(wheres_inner))
return query, tuple(params)

Expand Down
78 changes: 50 additions & 28 deletions static/javascript/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ function make_list_item(text) {
close_button.onclick = () => {
el.parentElement.removeChild(el)
}
let filetree_button = document.createElement("button")
el.appendChild(filetree_button)
filetree_button.innerText = "!"
filetree_button.width = "1em"
filetree_button.classList.add("filetree_button")
filetree_button.onclick = (event) => {
event.stopPropagation()
el.classList.toggle("filetree")
}
filetree_button.title = "Toggle filetree filtering\nIf enabled controls boxes being displayed at all instead of just colouring"
el.onclick = () => {
el.classList.toggle("item_negated")
}
Expand Down Expand Up @@ -47,13 +57,14 @@ function date_entry_setup(filter_id) {
}
}

function get_include_exclude(filter_name, filter_id) {
function get_include_exclude(filter_name, filter_id, filetree) {
let filter = document.getElementById(filter_id)
let filter_list = filter.querySelector(".item_list")
let children = filter_list.querySelectorAll(".list_item")
let include = []
let exclude = []
children.forEach((c) => {
if (!filetree && !c.classList.contains("filetree")) return
if (c.classList.contains("item_negated")) {
exclude.push(c.querySelector(".list_item_text").innerText)
} else {
Expand Down Expand Up @@ -152,9 +163,13 @@ function get_hue() {

function get_query_object() {
const query_list = [["email", "email_filter"], ["commit", "commit_filter"], ["filename", "filename_filter"], ["datetime", "datetime_filter"]]
let query = {}
query_list.forEach((q) => query = {...query, ...get_include_exclude(...q)})
return query
let query_filetree = {}
let query_highlight = {}
query_list.forEach((q) => {
query_filetree = {...query_filetree, ...get_include_exclude(...q, true)}
query_highlight = {...query_highlight, ...get_include_exclude(...q, false)}
})
return {filetree: query_filetree, highlight: query_highlight}
}

function submit_query_setup() {
Expand All @@ -163,7 +178,7 @@ function submit_query_setup() {
submit_button.onclick = () => {
const query = get_query_object()
save_query(query)
display_filetree_with_params({}, query, get_hue())
display_filetree_with_params(query.filetree, query.highlight, get_hue())
}
}
}
Expand Down Expand Up @@ -214,33 +229,40 @@ function export_svg_setup() {
}

function save_query(query) {
localStorage.setItem(document.title + "_stored_query", JSON.stringify(query))
localStorage.setItem(document.title + "_stored_query_filetree", JSON.stringify(query.filetree))
localStorage.setItem(document.title + "_stored_query_highlight", JSON.stringify(query.highlight))
}

function load_query() {
const query_list = [["email", "email_filter"], ["commit", "commit_filter"], ["filename", "filename_filter"], ["datetime", "datetime_filter"]]
const query = JSON.parse(localStorage.getItem(document.title + "_stored_query"))
if (!query) return
query_list.forEach((q) => {
const name = q[0]
const filter_id = q[1]
const filter = document.getElementById(filter_id)
const filter_list = filter.querySelector(".item_list")
if (name+"_include" in query) {
query[name+"_include"].forEach((val) => {
if (val && val != "") {
filter_list.appendChild(make_list_item(val))
}
})
}
if (name+"_exclude" in query) {
query[name+"_exclude"].forEach((val) => {
if (val && val != "") {
filter_list.appendChild(make_list_item(val)).classList.toggle("item_negated")
}
})
}
})
function get_part(part_name, filetree) {
const query = JSON.parse(localStorage.getItem(`${document.title}_stored_query_${part_name}`))
if (!query) return
query_list.forEach((q) => {
const name = q[0]
const filter_id = q[1]
const filter = document.getElementById(filter_id)
const filter_list = filter.querySelector(".item_list")
if (name+"_include" in query) {
query[name+"_include"].forEach((val) => {
if (val && val != "") {
filter_list.appendChild(make_list_item(val))
if (filetree) filter_list.lastChild.classList.toggle("filetree")
}
})
}
if (name+"_exclude" in query) {
query[name+"_exclude"].forEach((val) => {
if (val && val != "") {
filter_list.appendChild(make_list_item(val)).classList.toggle("item_negated")
if (filetree) filter_list.lastChild.classList.toggle("filetree")
}
})
}
})
}
get_part("filetree",true)
get_part("highlight")
}

function main() {
Expand Down
8 changes: 8 additions & 0 deletions static/stylesheets/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ input[type=number] {
color: #909090;
}

.list_item.filetree .list_item_text {
font-weight: bold;
}

.list_item.filetree .filetree_button {
color: red;
}

.control_box {
display: flex;
border: black 1px solid;
Expand Down

0 comments on commit 299c6b2

Please sign in to comment.