diff --git a/pug/search.pug b/pug/search.pug index 26045dd..77115b5 100644 --- a/pug/search.pug +++ b/pug/search.pug @@ -1,4 +1,8 @@ extends base.pug -block main - h1 Comming soon \ No newline at end of file +block vars + - var script = true + +append script + script(src='/static/js/libraries/js.cookie.js') + script(src='/static/js/search.js') \ No newline at end of file diff --git a/search.html b/search.html index 2bbe371..819ae4f 100644 --- a/search.html +++ b/search.html @@ -17,7 +17,14 @@
-

Comming soon

+ + + + + + + + \ No newline at end of file diff --git a/static/js/search.js b/static/js/search.js new file mode 100644 index 0000000..4390dd9 --- /dev/null +++ b/static/js/search.js @@ -0,0 +1,128 @@ +var app = (function(){ +return { + loadPage: function(){ + + SearchHTML.createSearch(); + } +}; +})(); + +/* + +Comments: +comment body (body) string +sort (sort) asc,desc +author (author) string +subreddit (subreddit) string +between (after/before) "date" + + +Thread: +title (title) string +selftext (body) string +sort (sort) asc,desc +author (author) string +subreddit (subreddit) string +between (after/before) "date" +over_18 (over_18) sfw,nsfw,both +locked (locked) bool + +*/ + +var ElasticSearch = (function(){ +return { + comment: function(){ + + }, + thread: function(){ + + } +}; +})(); + + +var Vars = (function(){ + var lookup = {}; + var keys = []; + var defaults = []; + +return { + loadVars: function(){ + + }, + get: function(key){ + return lookup[key]; + } +}; +})(); + + +var SearchHTML = (function(){ + var mainDiv = document.getElementById("main"); + + var createRadioInput = function(name, displayNames, values, defaultValue) { + var inputs = ""; + + for(var i = 0, len = displayNames.length; i < len; i++){ + inputs += ''; + inputs += ''; + } + return inputs; + }; + + var inputRow = function(text, input) { + + } + +return { + createSearch: function(){ + var searchBox = document.createElement("div"); + searchBox.id = "searchBox"; + + var showAdvanced = _.defaultTo(Cookies.get("showAdvanced"), true); + var searchThread = _.defaultTo(Cookies.get("searchThread"), true); +/* +Thread: +title (title) string * +selftext (body) string * +sort (sort) asc,desc * +author (author) string * +subreddit (subreddit) string * +between (after/before) "date" +over_18 (over_18) sfw,nsfw,both * +locked (locked) bool * +*/ + var html = 'Im looking for: '; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += 'Posted between time < time &l time'; + html += "Over 18: "; + html += createRadioInput("over_18", ["Both","nsfw","sfw"], ["both","nsfw","sfw"], _.defaultTo(GetVars.get("over_18"), "both")); + html += "Locked: "; + html += createRadioInput("locked", ["Both","True", "False"], ["both","true","false"], _.defaultTo(GetVars.get("locked"), "both")); + html += "Sort score: "; + html += createRadioInput("sort", ["Highest","Lowest"], ["desc","asc"], _.defaultTo(GetVars.get("sort"), "desc")); + searchBox.innerHTML = html; + + mainDiv.appendChild(searchBox); + }, + + commentResults: function(){ + + }, + + threadResults: function(){ + + } +}; +})(); + + +if(isSupported) { + app.loadPage(); +} \ No newline at end of file diff --git a/static/js/subreddit.js b/static/js/subreddit.js index e2bb184..f5fb4f4 100644 --- a/static/js/subreddit.js +++ b/static/js/subreddit.js @@ -16,12 +16,9 @@ return { var timeDifference = Time.difference(Time.toUTC(Vars.getTime())); SubredditHTML.createInfo(Reddit.subreddit, Vars.getTime()); - Reddit.fetchToken() - .then(function(){ - return fetch(ElasticSearch.subreddit(Reddit.subreddit, timeDifference, Vars.getPage())) - .catch(function(error){ + fetch(ElasticSearch.subreddit(Reddit.subreddit, timeDifference, Vars.getPage())) + .catch(function(error){ return Promise.reject("Could not get removed posts"); - }); }) .then(function(response){ if(response.ok) { @@ -33,7 +30,7 @@ return { .then(Fetch2.json) .then(function(json){ var sourceArray = json.hits.hits; - var pageNr = (Vars.getPage() - 1) * 25 + 1; + var pageNr = (Vars.getPage() - 1) * Vars.postPerPage + 1; for(var i = 0, len = sourceArray.length; i < len; i++) { SubredditHTML.createThread(sourceArray[i]._source, pageNr+i); } @@ -57,6 +54,7 @@ var Vars = (function(){ var page; return { + postPerPage: 50, isAll: _.toLower(Reddit.subreddit) === 'all', loadTime: function(){ var tmpTime = _.defaultTo(GetVars.get("t"), Cookies.get("t")); @@ -110,15 +108,15 @@ return { '},'+ '"_source":["author","url","subreddit","link_flair_text","score","title","created_utc","selftext","num_comments","domain","permalink","id","thumbnail","thumbnail_height","thumbnail_width"],'+ '"sort":[{"score":"desc"}],'+ - '"from":'+(page-1)*25+','+ - '"size":25}'; + '"from":'+(page-1)*Vars.postPerPage+','+ + '"size":'+Vars.postPerPage+'}'; } -} +}; })(); var SubredditHTML = (function(){ var mainDiv = document.getElementById("main"); -return { +return { createThread: function(thread, postRank) { var threadDiv = document.createElement("div"); threadDiv.className = "thread"; @@ -172,7 +170,6 @@ return { infoDiv.className = "subreddit-info"; infoDiv.innerHTML = 'top post of /r/'+subreddit+' from:'; - var values = ["hour", "12hour", "day", "week", "month", "6month", "year", "all"]; var display = ["past hour", "past 12 hours", "past day", "past week", "past month", "past 6 months", "past year", "all time"]; var options = ""; @@ -196,7 +193,7 @@ return { pagination.id = "pagination"; var start = Math.max(Vars.getPage()-3, 1); - var end = Math.min(start + 9, Math.ceil(totalPosts/25)); + var end = Math.min(start + 9, Math.ceil(totalPosts/Vars.postPerPage)); var links = "Page: "; var hrefBase = document.location.href.split("?")[0] + "?t=" + Vars.getTime() + "&page=";