Browse Source

Improvement to filter, you can now see what you have selected

master
crunk 3 years ago
parent
commit
11b80eb5da
  1. 10
      library/csvparser/csvparser.py
  2. 2
      library/csvparser/varlib.csv
  3. 10
      library/static/css/dropdown.css
  4. 56
      library/static/js/dropdown.js
  5. 40
      library/static/js/script.js
  6. 2
      library/templates/index.html
  7. 12
      library/templates/menu.html

10
library/csvparser/csvparser.py

@ -26,9 +26,9 @@ def getpublications():
pubinfo = { pubinfo = {
"Title": row["Publication"], "Title": row["Publication"],
"Author": row["Author"], "Author": row["Author"],
"Type": row["Type"].lower(), "Type": row["Type"].lower().title(),
"Year": year, "Year": year,
"License": row["LicenseShort"].lower(), "License": row["LicenseShort"].lower().title(),
} }
publications[row["Id"]] = pubinfo publications[row["Id"]] = pubinfo
return publications return publications
@ -40,7 +40,7 @@ def gettypes():
csv_as_dict = csv.DictReader(libcsv) csv_as_dict = csv.DictReader(libcsv)
listoftypes = [] listoftypes = []
for row in csv_as_dict: for row in csv_as_dict:
lowertype = row["Type"].lower() lowertype = row["Type"].lower().title()
if lowertype not in listoftypes: if lowertype not in listoftypes:
listoftypes.append(lowertype) listoftypes.append(lowertype)
return listoftypes return listoftypes
@ -67,9 +67,9 @@ def getlicenses():
csv_as_dict = csv.DictReader(libcsv) csv_as_dict = csv.DictReader(libcsv)
listoflicenses = [] listoflicenses = []
for row in csv_as_dict: for row in csv_as_dict:
license = row["LicenseShort"].lower() license = row["LicenseShort"].lower().title()
if not license: if not license:
license = "no license mentioned" license = "No License Mentioned"
if license not in listoflicenses: if license not in listoflicenses:
listoflicenses.append(license) listoflicenses.append(license)
return listoflicenses return listoflicenses

2
library/csvparser/varlib.csv

@ -27,7 +27,7 @@ Id,Publication,Author,Year,Custodian,Fields,Type,Publishers,License,LicenseShort
33,"The immaterial labor union #7: immersive advertisement","Lídia Pereira and Δεριζαματζορ Προμπλεμ ιναυστραλια",,Varia,"labour, Advertisement, immersion, social media",Zine,Self-published,"Zine is published under Gnu free documentation license 1.3 unless otherwise specified ","GNU Free Documentation License",,, 33,"The immaterial labor union #7: immersive advertisement","Lídia Pereira and Δεριζαματζορ Προμπλεμ ιναυστραλια",,Varia,"labour, Advertisement, immersion, social media",Zine,Self-published,"Zine is published under Gnu free documentation license 1.3 unless otherwise specified ","GNU Free Documentation License",,,
34,"The immateriality labor union #10: immateriality","Lídia Pereira and Δεριζαματζορ Προμπλεμ ιναυστραλια",2017,Varia,"Labour, Immateriality",Zine,Self-published,"GNU Free Documentation License","GNU Free Documentation License",,, 34,"The immateriality labor union #10: immateriality","Lídia Pereira and Δεριζαματζορ Προμπλεμ ιναυστραλια",2017,Varia,"Labour, Immateriality",Zine,Self-published,"GNU Free Documentation License","GNU Free Documentation License",,,
35,"The immaterial labor union. Special Issue #1: Homebrew Server Club","Homebrew Server Club",2017,Varia,"Self-Hosting, Servers, DIY",Zine,Self-published,CC-BY-SA,"Creative commons",,, 35,"The immaterial labor union. Special Issue #1: Homebrew Server Club","Homebrew Server Club",2017,Varia,"Self-Hosting, Servers, DIY",Zine,Self-published,CC-BY-SA,"Creative commons",,,
36,"Pervasive labour union. Special issue #2: The Entreprecariat","Silvio Lorusso",2017,Varia,"Entreprecariat, Labour, Precarity",Zine,Self-published,,,,"Between April and May 2017 the Zine's name changed from Immaterial Labor Union to Pervasive Labour Union", 36,"Pervasive labour union. Special issue #2: The Entreprecariat","Silvio Lorusso",2017,Varia,"Entreprecariat, Labour, Precarity",Zine,Self-published,"No license mentioned","No license mentioned",,"Between April and May 2017 the Zine's name changed from Immaterial Labor Union to Pervasive Labour Union",
37,"'Pervasive labour union #13: Fed Up","Lídia Pereira",2019,Varia,"Labour, DIY, federation",Zine,Self-published,"GNU Free Documentation License 1.3, CC-0, Copyright (C) 2019, Julia Janssen, Peer Production License","GNU Free Documentation License",,, 37,"'Pervasive labour union #13: Fed Up","Lídia Pereira",2019,Varia,"Labour, DIY, federation",Zine,Self-published,"GNU Free Documentation License 1.3, CC-0, Copyright (C) 2019, Julia Janssen, Peer Production License","GNU Free Documentation License",,,
38,"Each Page a Function","Raphaël Bastide",2019,Varia,"Automation, Drawing, Web to Print",Paperback,"LeMegot editions","No license mentioned","No license mentioned",,, 38,"Each Page a Function","Raphaël Bastide",2019,Varia,"Automation, Drawing, Web to Print",Paperback,"LeMegot editions","No license mentioned","No license mentioned",,,
39,"In Beweging: Magazine van de Anarchistische Groep Nijmegen","Anarchistische Groep Nijmegen ",2018,Varia,"Anarchism, 1st of May, Nijmegen",Zine,Self-published,"No license mentioned","No license mentioned",,"Anarchistische Bieb de Zwarte Uil. library in Nijmegen open on saturday from 12:00 till 17:30", 39,"In Beweging: Magazine van de Anarchistische Groep Nijmegen","Anarchistische Groep Nijmegen ",2018,Varia,"Anarchism, 1st of May, Nijmegen",Zine,Self-published,"No license mentioned","No license mentioned",,"Anarchistische Bieb de Zwarte Uil. library in Nijmegen open on saturday from 12:00 till 17:30",

Can't render this file because it contains an unexpected character in line 11 and column 0.

10
library/static/css/dropdown.css

@ -1,12 +1,14 @@
/* Dropdown Button */ /* Dropdown Button */
/* for sorting on Year, Type, License /* for sorting on Year, Type, License
.dropbtn { */
}
/* The container <div> - needed to position the dropdown content */
.filter { .filter {
display: none; display: none;
} }
.activebtn {
background-color: #62b264;
}
.show { .show {
display: block; display: block;
} }

56
library/static/js/dropdown.js

@ -0,0 +1,56 @@
// Filter section ===================== old school code divider ================
filterSelection("all", "None");
function filterSelection(c, id) {
resetDropDownButtons();
var i;
var button = document.getElementById(id);
if(button){
button.innerText = c;
addClass(button, "activebtn");
}
var allpublications = document.getElementsByClassName("filter");
if (c == "all") {
for (i = 0; i < allpublications.length; i++) {
addClass(allpublications[i], "show");
}
}
else {
for (i = 0; i < allpublications.length; i++) {
removeClass(allpublications[i], "show");
if (allpublications[i].className.indexOf(c) > -1) {
addClass(allpublications[i], "show");
}
}
}
}
function resetDropDownButtons(){
document.getElementById("License").innerText = "License";
document.getElementById("PubType").innerText = "Type";
document.getElementById("Year").innerText = "Year";
allactivebuttons = document.getElementsByClassName("activebtn");
for(var i = 0;allactivebuttons.length; i++) {
removeClass(allactivebuttons[i], "activebtn");
}
}
function addClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
}
}
function removeClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}

40
library/static/js/script.js

@ -23,45 +23,5 @@ const cloud = document.querySelector('#cloud');
function update() { function update() {
cloud.style.boxShadow = boxShadows(30); cloud.style.boxShadow = boxShadows(30);
} }
// Filter section ===================== old school code divider ================
filterSelection("all")
function filterSelection(c) {
var i;
var allpublications = document.getElementsByClassName("filter");
if (c == "all") {
for (i = 0; i < allpublications.length; i++) {
addClass(allpublications[i], "show");
}
}
else {
for (i = 0; i < allpublications.length; i++) {
removeClass(allpublications[i], "show");
if (allpublications[i].className.indexOf(c) > -1) {
addClass(allpublications[i], "show");
}
}
}
}
function addClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
}
}
function removeClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
window.addEventListener('load', update); window.addEventListener('load', update);

2
library/templates/index.html

@ -11,5 +11,5 @@
{% endfor%} {% endfor%}
</ul> </ul>
</div> </div>
<script src="{{ url_for('static', filename='js/dropdown.js')}}"></script>
{% endblock %} {% endblock %}

12
library/templates/menu.html

@ -2,26 +2,26 @@
<button id="leftmostbtn" onclick="filterSelection('all')">All books</button> <button id="leftmostbtn" onclick="filterSelection('all')">All books</button>
<button><a href="/upload">Upload</a></button> <button><a href="/upload">Upload</a></button>
<div class="dropdown"> <div class="dropdown">
<button class="dropbtn">Type</button> <button id="PubType" class="dropbtn">Type</button>
<div class="dropdown-content"> <div class="dropdown-content">
{% for pubtype in pubtypes %} {% for pubtype in pubtypes %}
<button type="button" name="button" onclick="filterSelection('{{ pubtype }}')" >{{ pubtype.title() }}</button> <button type="button" name="button" onclick="filterSelection('{{ pubtype }}', 'PubType')" >{{ pubtype.title() }}</button>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
<div class="dropdown"> <div class="dropdown">
<button class="dropbtn">Year</button> <button id="Year" class="dropbtn">Year</button>
<div class="dropdown-content"> <div class="dropdown-content">
{% for pubyear in pubyears %} {% for pubyear in pubyears %}
<button type="button" name="button" onclick="filterSelection('{{ pubyear }}')" >{{ pubyear }}</button> <button type="button" name="button" onclick="filterSelection('{{ pubyear }}', 'Year')" >{{ pubyear }}</button>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
<div class="dropdown"> <div class="dropdown">
<button class="dropbtn">License</button> <button id="License" class="dropbtn">License</button>
<div class="dropdown-content"> <div class="dropdown-content">
{% for publicense in publicenses %} {% for publicense in publicenses %}
<button type="button" name="button" onclick="filterSelection('{{ publicense }}')" >{{ publicense }}</button> <button type="button" name="button" onclick="filterSelection('{{ publicense }}', 'License')" >{{ publicense }}</button>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

Loading…
Cancel
Save