Skip to content

Commit

Permalink
catalogue: search done
Browse files Browse the repository at this point in the history
  • Loading branch information
hcincera committed Feb 29, 2024
1 parent e5ba07f commit 7059bad
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@app.route('/')
def index():
return render_template("catalogue.html", lecturers=db.get_lecturers(), title="TdA Žabanti")
return render_template("catalogue.html", lecturers=db.get_lecturers(), title="TdA Žabanti", all_tags=db.get_all_tags(), all_locations=db.get_all_locations())

@app.route('/favicon.ico')
def favicon():
Expand Down
25 changes: 24 additions & 1 deletion app/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,27 @@ def get_lecturers_with_tag(uuid, tag):
con = get_con()
cur = con.cursor()
res = cur.execute("SELECT * FROM lecturer_tags_map WHERE uuid=(?)", [tag["uuid"]])
return [l[0] for l in res.fetchall()]
return [l[0] for l in res.fetchall()]

def get_all_tags():
ls = get_lecturers()
tags = {}
for l in ls:
for t in (l.get("tags") or []):
tags[t["name"]] = True
ts = []
for t in tags.keys():
ts.append(t)
return ts

def get_all_locations():
ls = get_lecturers()
locs = {}
for l in ls:
loc = l.get("location")
if not loc is None:
locs[loc] = True
los = []
for s in locs.keys():
los.append(s)
return los
20 changes: 13 additions & 7 deletions app/static/catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ function on_filter_btn_clicked() {
}

function on_search() {
console.log("Query: ", searchbar.value)
console.log("Min: ", parseInt(pph_min.value))
console.log("Max: ", parseInt(pph_max.value))

for (let lecturer of lecturers.children) {
name = lecturer.children[0].children[1].children[0].children[0].innerHTML
lecturer_pph = {"innerHtml": "-1"}
Expand All @@ -32,7 +28,6 @@ function on_search() {
}
pph = parseInt(lecturer_pph.innerHTML)

console.log("Lecturer PPH: ", pph)
nameMatch = name.toLowerCase().includes(searchbar.value.toLowerCase())
let min_pph = -1
let max_pph = -1
Expand Down Expand Up @@ -73,8 +68,19 @@ function on_search() {
locationMatch = false
}

for (let c of lecturer.children) {
if (c.className.includes("lecturer-tags")) {
lecturer_tags_div = c
}
}

let checkSubset = (parentArray, subsetArray) => {
return subsetArray.every((el) => {
return parentArray.includes(el)
})
}
lecturer_tags = []
for (let tag_span of lecturer.children[2].children[1].children) {
for (let tag_span of lecturer_tags_div.children[1].children) {
lecturer_tags = lecturer_tags.concat([tag_span.innerText])
}

Expand All @@ -87,7 +93,7 @@ function on_search() {
}
}

tagMatch = lecturer_tags.includes(required_tags) || required_tags.length == 0
tagMatch = checkSubset(lecturer_tags, required_tags) || required_tags.length == 0

if (nameMatch && priceMatch && locationMatch && tagMatch) {
lecturer.style.removeProperty("display")
Expand Down
22 changes: 7 additions & 15 deletions app/templates/catalogue.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,24 @@ <h1 class="navbar-header" style="padding-top: 10px;">Katalog lektorů</h1>
<div class="row-cols-auto">
<b class="d-inline-grid">Lokality:</b>
<div id="wanted_locations" class="d-inline-block input-group">
{% for location in all_locations %}
<label class="location-toggle">
<input type="checkbox" style="display: none;">
<span class="check-strike noselect border" style="border-radius: 4px;">Brno</span>
</label>
<label class="location-toggle">
<input type="checkbox" style="display: none;">
<span class="check-strike noselect border" style="border-radius: 4px;">Praha</span>
<span class="check-strike noselect border" style="border-radius: 4px;">{{location}}</span>
</label>
{% endfor %}
</div>
</div>

<div class="row-cols-auto">
<b class="d-inline-grid">Tagy:</b>
<div id="wanted_tags" class="d-inline-block input-group">
{% for tag in all_tags %}
<label class="tag-toggle">
<input type="checkbox" style="display: none;">
<span class="check-grey noselect border" style="border-radius: 4px;">Marketing</span>
</label>
<label class="tag-toggle">
<input type="checkbox" style="display: none;">
<span class="check-grey noselect border" style="border-radius: 4px;">Sales</span>
</label>
<label class="tag-toggle">
<input type="checkbox" style="display: none;">
<span class="check-grey noselect border" style="border-radius: 4px;">Networking</span>
<span class="check-grey noselect border" style="border-radius: 4px;">{{tag}}</span>
</label>
{% endfor %}
</div>
</div>
</div>
Expand Down Expand Up @@ -101,7 +93,7 @@ <h3 class="w-100 text-center" style="margin-bottom: -20px;">
{% if (lecturer["bio"] or "") != "" %}
<span class="d-block w-100 border lecturer-bio" style="border-radius: 2px;">{{lecturer["bio"]|safe}}</span>
{% endif %}
<div class="row-cols-auto my-1">
<div class="lecturer-tags row-cols-auto my-1">
<b class="d-inline-grid">Tagy:</b>
<div class="d-inline-block">
{% for tag in lecturer["tags"] %}
Expand Down

0 comments on commit 7059bad

Please sign in to comment.