Browse Source

Mod results style; integrate front/back end.

Add:
        static/js/index.js
                -Modify functions to add actual result codelets to the `results`
                column: redefine `populateResults()` as a wrapper for
                `loadMoreResults()`, introduce a `Deferred` return-type to
                `queryServer()`, and change some incorrect object field names
                (eg, "html_code", which should've been "code") in
                `createResult()`.

Fix:
        static/sass/index.sass
                -Allow codelet-scrolling, and modify result component widths.
tags/v1.0^2
Severyn Kozak 10 years ago
parent
commit
7f4cd92ae1
2 changed files with 43 additions and 54 deletions
  1. +35
    -47
      static/js/index.js
  2. +8
    -7
      static/sass/index.sass

+ 35
- 47
static/js/index.js View File

@@ -141,13 +141,13 @@ var codeExample = '<table class="highlighttable"><tr><td class="linenos"><div cl


var testCodelet = { var testCodelet = {
'url': 'https://github.com/earwig/bitshift/blob/develop/app.py', 'url': 'https://github.com/earwig/bitshift/blob/develop/app.py',
'filename': 'app.py',
'name': 'app.py',
'language': 'python', 'language': 'python',
'date_created': 'May 10, 2014', 'date_created': 'May 10, 2014',
'date_modified': '2 days ago', 'date_modified': '2 days ago',
'origin': ['GitHub', 'https://github.com', ''], 'origin': ['GitHub', 'https://github.com', ''],
'authors': ['sevko', 'earwig'], 'authors': ['sevko', 'earwig'],
'html_code': codeExample
'code': codeExample
}; };


// Enable infinite scrolling down the results page. // Enable infinite scrolling down the results page.
@@ -210,26 +210,6 @@ function clearResults(){
} }


/* /*
* Query the server with the current search string, and populate `div#results`
* with its response.
*/
function populateResults(){
searchResultsPage = 1;
var results = queryServer();

for(var result = 0; result < results.length; result++){
var newDiv = results[result];
resultsDiv.appendChild(newDiv);
setTimeout(
(function(divReference){
return function(){
divReference.classList.add("cascade");
};
}(newDiv)), result * 20);
}
}

/*
* Create a result element based upon a codelet instance. * Create a result element based upon a codelet instance.
* *
* @return {Element} The result element. * @return {Element} The result element.
@@ -276,7 +256,7 @@ function createResult(codelet) {


//Add the bulk of the html //Add the bulk of the html
title.innerHTML = ' &raquo; <a href="' + codelet.url + '">' title.innerHTML = ' &raquo; <a href="' + codelet.url + '">'
+ codelet.filename + '</a>';
+ codelet.name + '</a>';
site.innerHTML = '<a href="' + codelet.origin[1] + '">' + codelet.origin[0] +'</a>'; site.innerHTML = '<a href="' + codelet.origin[1] + '">' + codelet.origin[0] +'</a>';
nextMatch.innerHTML = 'next match'; nextMatch.innerHTML = 'next match';
prevMatch.innerHTML = 'prev match'; prevMatch.innerHTML = 'prev match';
@@ -295,7 +275,7 @@ function createResult(codelet) {
authors.innerHTML = authorsHtml; authors.innerHTML = authorsHtml;


// Needs to be processed on the server // Needs to be processed on the server
codeElt.innerHTML = '<div id=tablecontainer>' + codelet.html_code + '</div>';
codeElt.innerHTML = '<div id=tablecontainer>' + codelet.code + '</div>';


//Event binding //Event binding
$(newDiv).on('mousemove', function(e) { $(newDiv).on('mousemove', function(e) {
@@ -408,39 +388,49 @@ function queryServer(){
"p" : searchResultsPage++ "p" : searchResultsPage++
}); });


var resultDivs = [];
var results = $.Deferred();
$.getJSON(queryUrl, function(result){ $.getJSON(queryUrl, function(result){
var resultDivs = [];
if("error" in result) if("error" in result)
insertErrorMessage(result["error"]); insertErrorMessage(result["error"]);
else else
for(var codelet = 0; codelet < result["results"].length; codelet++)
resultDivs.push(result["results"][codelet]);
for(var codelet = 0; codelet < result["results"].length; codelet++){
resultDivs.push(createResult(result["results"][codelet]));
console.log(result["results"][codelet]);
}
results.resolve(resultDivs);
}); });


for(var result = 0; result < 20; result++){
var newDiv = createResult(testCodelet);
resultDivs.push(newDiv)
}
return results;
}


return resultDivs;
/*
* Query the server with the current search string, and populate `div#results`
* with its response.
*/
function populateResults(){
searchResultsPage = 1;
loadMoreResults();
} }


/* /*
* Adds more results to `div#results`.
* Query the server for the next results page, and add its codelets to
* `div#results`.
*/ */
function loadMoreResults(){ function loadMoreResults(){
var results = queryServer();
for(var result = 0; result < results.length; result++){
var newDiv = results[result];
resultsDiv.appendChild(newDiv);
setTimeout(
(function(divReference){
return function(){
divReference.classList.add("cascade");
};
}(newDiv)),
result * 20);
}
queryServer().done(function(results){
for(var result = 0; result < results.length; result++){
var newDiv = results[result];
resultsDiv.appendChild(newDiv);
setTimeout(
(function(divReference){
return function(){
divReference.classList.add("cascade");
};
}(newDiv)),
result * 20);
}
});
} }


/* /*
@@ -453,5 +443,3 @@ function insertErrorMessage(msg){
error.append(msg); error.append(msg);
resultsDiv.appendChild(error[0]); resultsDiv.appendChild(error[0]);
} }

// loadMoreResults();

+ 8
- 7
static/sass/index.sass View File

@@ -6,8 +6,8 @@
@import variables @import variables


$minSearchFieldsWidth: 490px $minSearchFieldsWidth: 490px
$resultWidth: 1000px
$codeWidth: 650px
$resultWidth: 800px
$codeWidth: 700px
$hiddenInfoWidth: 250px $hiddenInfoWidth: 250px


.ui-datepicker .ui-datepicker
@@ -366,8 +366,9 @@ div.result
@extend .t1 @extend .t1
margin-bottom: 15% margin-bottom: 15%


&.display-all table tr
@include opaque(1.0)
&.display-all
table tr
@include opaque(1.0)


div#display-info div#display-info
font-size: 1.3em font-size: 1.3em
@@ -384,14 +385,14 @@ td#code
@include vendor(transition, width 0.2s ease-in-out) @include vendor(transition, width 0.2s ease-in-out)


width: $codeWidth width: $codeWidth
max-width: $codeWidth
height: inherit height: inherit
padding: 0px padding: 0px
border: 1px solid #bbb


#tablecontainer #tablecontainer
overflow: hidden
width: 100% width: 100%
height: inherit height: inherit
overflow: auto
background-color: #49483e background-color: #49483e
position: relative position: relative
z-index: 1 z-index: 1
@@ -414,7 +415,7 @@ td#code


div#hidden-info div#hidden-info
width: $hiddenInfoWidth width: $hiddenInfoWidth
margin-left: -$hiddenInfoWidth - 10px
margin-left: -$hiddenInfoWidth - 200px
height: 100% height: 100%
padding-top: 40px padding-top: 40px
font-size: 1.2em font-size: 1.2em


Loading…
Cancel
Save