Browse Source

replace groupsof, take, and drop functions with Ramda.js functions

master
wes 9 years ago
parent
commit
e72096e6c1
  1. 1
      src/archive.py
  2. 1
      src/mcmaster/classes.py
  3. 5
      src/scripts/row.tag
  4. 47
      src/scripts/search.js
  5. 2
      src/styles/search.scss
  6. 3
      src/templates/search.html

1
src/archive.py

@ -28,7 +28,6 @@ def searchIA(title, author):
urls.append("https://archive.org/details/%s" % result["identifier"]) urls.append("https://archive.org/details/%s" % result["identifier"])
return urls return urls
# Example, search for David Hume's Enquiry Concerning Human Understanding # Example, search for David Hume's Enquiry Concerning Human Understanding
#for url in searchIA("Hume", "Enquiry Concerning Human Understanding"): #for url in searchIA("Hume", "Enquiry Concerning Human Understanding"):
#print url #print url

1
src/mcmaster/classes.py

@ -300,7 +300,6 @@ def request(codes, lists, semester):
return return
codes.task_done() codes.task_done()
class CourseInfo(object): class CourseInfo(object):
def __init__(self, threadcount, semester): def __init__(self, threadcount, semester):
self._codes = False self._codes = False

5
src/scripts/row.tag

@ -1,5 +1,8 @@
<row> <row>
<class class="course text-ellipsis text-justify rounded card column col-md-4" each="{ classrow }" data="{ this }"></class> <class class="course text-ellipsis text-justify rounded card column col-md-4"
each="{ classrow }"
data="{ this }">
</class>
this.classrow = opts.classrow this.classrow = opts.classrow
</row> </row>

47
src/scripts/search.js

@ -8,6 +8,7 @@ function makeResourceGetter(self) {
"author" : this.bookauthor "author" : this.bookauthor
}; };
var url = "/search/resources"; var url = "/search/resources";
$.getJSON(url, { $.getJSON(url, {
data : JSON.stringify(params) data : JSON.stringify(params)
}).done(function(results) { }).done(function(results) {
@ -22,8 +23,8 @@ function makeResourceGetter(self) {
if (!(results.openlib && results.iarchive)) { if (!(results.openlib && results.iarchive)) {
self.noResources = true; self.noResources = true;
} }
self.loading = false;
self.update(); self.update({"loading" : false});
}); });
} }
return getResources; return getResources;
@ -52,19 +53,8 @@ riot.mount("search", {
showHelp : false, showHelp : false,
booksLoading : false booksLoading : false
}); });
riot.mount("results", {notLoading : true});
function autocomplete(element, endpoint) { riot.mount("results", {notLoading : true});
// The element should be an input class
$(element).autocomplete({
source : endpoint,
my : "right top",
at : "left bottom",
collision : "none",
autofocus : true,
delay : 100
});
}
function realBook(book) { function realBook(book) {
var noAdoption = book.booktitle.indexOf("No Adoption"); var noAdoption = book.booktitle.indexOf("No Adoption");
@ -84,31 +74,18 @@ function filterCourses(courses) {
} }
} }
return courses.filter( return R.filter(
function (c) { function (c) {
return c.prof != "Staff"; return c.prof != "Staff";
}); }, courses);
}
function take(n, xs) {
return xs.slice(0, n);
}
function drop(n, xs) {
return xs.slice(n, xs.length);
} }
function groupsof(n, xs) { function groupsof(n, xs) {
var groups = []; return R.unfold(
while (xs.length != 0) { function(xs) {
if (xs.length < n) { if (R.length(xs) > 0) {
groups.push({"row" : take(xs.length, xs)} ); return [{"row" : R.take(n, xs)}, R.drop(n, xs)];
xs = drop(xs.length, xs);
}
else {
groups.push({"row" : take(n, xs)});
xs = drop(n, xs);
}
} }
return groups; return false;
}, xs);
} }

2
src/styles/search.scss

@ -74,7 +74,7 @@ a {
} }
.book-title { .book-title {
margin-right: 10px !important; margin-right: 0px !important;
} }
.form-item { .form-item {

3
src/templates/search.html

@ -42,7 +42,8 @@
{% block scripts %} {% block scripts %}
{{super()}} {{super()}}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.6.3/riot+compiler.min.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/riot/2.6.3/riot+compiler.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js"></script>
<script type="text/javascript" src="/scripts/tags.min.js"></script> <script type="text/javascript" src="/scripts/tags.min.js"></script>
<script type="text/javascript" src="/scripts/search.min.js"></script> <script type="text/javascript" src="/scripts/search.min.js"></script>
{% endblock %} {% endblock %}

Loading…
Cancel
Save