Skip to content

Commit

Permalink
Browse index option at advanced form #195
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusandrade committed May 20, 2013
1 parent 68902c3 commit c3aaf58
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/config-SAMPLE.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<google_analytics_tracking_id></google_analytics_tracking_id>
<maintenance>false</maintenance>
<feedback_id></feedback_id>
<browse_index_url></browse_index_url>

<search_collection_list>
<collection>
Expand Down
6 changes: 6 additions & 0 deletions locale/en/texts.ini
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ SHOW_XML="Show result in XML format"

FEEDBACK_SERVICE = "leave a comment /report a error"

SHOW_INDEX="Show Index"
PREVIOUS_KEYS="Previous (200)"
NEXT_KEYS="Next (200)"
UPDATE_KEYS="Update"


[AVAILABLE_LANGUAGES]

PT=português
Expand Down
6 changes: 6 additions & 0 deletions locale/es/texts.ini
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ SHOW_XML="Exibir resultado en XML"

FEEDBACK_SERVICE = "enviar un comentario /informar un error"

SHOW_INDEX="Mostrar Índice"
PREVIOUS_KEYS="Anteriores (200)"
NEXT_KEYS="Próximos (200)"
UPDATE_KEYS="Actualizar"


[AVAILABLE_LANGUAGES]

PT=português
Expand Down
5 changes: 5 additions & 0 deletions locale/pt/texts.ini
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ SHOW_XML="Exibir resultado em XML"

FEEDBACK_SERVICE = "enviar um comentário /comunicar um erro"

SHOW_INDEX="Mostrar Índice"
PREVIOUS_KEYS="Anteriores (200)"
NEXT_KEYS="Próximos (200)"
UPDATE_KEYS="Atualizar"

[AVAILABLE_LANGUAGES]

PT=português
Expand Down
20 changes: 20 additions & 0 deletions static/css/advanced.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.clear {clear: both;}
.advanced-form {width: 90%; margin: 0 auto;}
.advanced-form .mini {width: 90px;}
.advanced-form .q-first input {width: 75%;}
.advanced-form select.index {width: 178px;}
.advanced-form .openerIndexes {background: url(../../static/image/indexes.gif)no-repeat; padding: 2px 0 2px 18px;text-decoration: none;}
.advanced-form .openerIndexes:hover {text-decoration: underline;}
.block-q .q, .more .q {width: 54.5%;}
.indexList .vBlockR, .indexList .vBlockL {float:left;}
.indexList .vBlockL.first {width: 590px;margin: -11px 0 0 1px;}
.indexList .vBlockL {width: 498px;margin: -11px 0 0 93px;}
.indexList select {width: 100%;}
.indexList .prev, .indexList .next {margin: 0 0 8px 4px;}
.indexList .refresh {margin: 82px 0 8px 10px;}
.indexList .prev a {background: url(../../static/image/arrow-up.gif) no-repeat; padding: 2px 0 2px 18px;text-decoration: none;}
.indexList .next a {background: url(../../static/image/arrow-down.gif) no-repeat; padding: 2px 0 2px 18px;text-decoration: none;}
.indexList .refresh a {background: url(../../static/image/refresh.gif) no-repeat; padding: 2px 0 2px 18px;text-decoration: none;}
.advanced-form .openerIndexes:hover, .indexList .prev a:hover, .indexList .next a:hover, .indexList .refresh a:hover {text-decoration: underline;}

.advanced-form .q-first input {width: 65%;}
2 changes: 1 addition & 1 deletion static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ DIV.record DIV.data DIV.abstractFulltextList LI{
margin: 20px 0;
}
.advanced-form .q-first input {
width: 80%;
width: 70%;
}
.advanced-form select {
width: 17%;
Expand Down
Binary file added static/image/arrow-down.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/image/arrow-up.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/image/indexes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/image/refresh.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 89 additions & 1 deletion static/js/advanced.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,96 @@
var next_line = 3;

// show/refresh index list
function show_index(line, update){

element_id = $(line).attr("id");
block_id = element_id.substring(element_id.lastIndexOf('-') + 1);
if (!update){
$('#list-' + block_id).toggle();
}

init = $('#input-' + block_id).val();
index = $('#index-' + block_id).find(':selected').val();
options = $('#select-' + block_id);

options.find('option').remove().end();

$.getJSON(SEARCH_URL + "browse-index/" + index +"/?init=" + init, function(result) {
$.each(result.terms, function() {
options.append($("<option />").val(this).text(this));
});

});
}

// previous keys
function show_prev(line) {
element_id = $(line).attr("id");
block_id = element_id.substring(element_id.lastIndexOf('-') + 1);

options = $('#select-' + block_id);
init = options.find('option:first-child').val();

options.find('option').remove().end();

$.getJSON(SEARCH_URL + "browse-index/au/?dir=previous&init=" + init, function(result) {
$.each(result.terms, function() {
options.append($("<option />").val(this).text(this));
});
});
}

function show_next(line) {
element_id = $(line).attr("id");
block_id = element_id.substring(element_id.lastIndexOf('-') + 1);

options = $('#select-' + block_id);
init = options.find('option:last-child').val();
options.find('option').remove().end();

$.getJSON(SEARCH_URL + "browse-index/au/?dir=next&init=" + init, function(result) {
$.each(result.terms, function() {
options.append($("<option />").val(this).text(this));
});
});
}

// select one term from index
function select_term(line){
element_id = $(line).attr("id");
block_id = element_id.substring(element_id.lastIndexOf('-') + 1);

query_input = $('#input-' + block_id);
selected_key= $('#select-' + block_id).find(':selected').val();
query_input.val('"' + selected_key + '"');

}


function add_new_line(obj) {
var block = $(".block-q");
var previous_line = next_line-1;

var block = $(".block-q").clone();
//alert(block.html());
// update id's
block.find('#input-2').attr('id', 'input-' + next_line);
block.find('#list-2').attr('id', 'list-' + next_line);
block.find('#index-2').attr('id', 'index-' + next_line);
block.find('#select-2').attr('id', 'select-' + next_line);
block.find('#show-2').attr('id', 'show-' + next_line);
block.find('#next-2').attr('id', 'next-' + next_line);
block.find('#prev-2').attr('id', 'prev-' + next_line);
block.find('#refresh-2').attr('id', 'refresh-' + next_line);

$('#select-' + next_line).find('option').remove().end();
$('#list-' + next_line).css('display', 'none');

var html = block.html();
var more = $(".more");

// update counter
next_line++;

more.append(html);
}

Expand Down
45 changes: 39 additions & 6 deletions templates/advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

{% block extrahead %}
<script language="javascript" type="text/javascript" src="{{ constant("STATIC_URL") }}js/advanced.js"></script>
<link rel="stylesheet" href="{{ constant("STATIC_URL") }}css/advanced.css" type="text/css" media="screen">
{% endblock %}

{% block content %}
Expand All @@ -15,8 +16,12 @@ <h2>{{ texts.ADVANCED_SEARCH }}</h2>
<form name="advanced" id="advanced" onsubmit="return search();">

<div class="q-first">
<input type="text" name="q[]" class="q" value="">
<select name="index[]" class="inputText index" id="selectIndex">
<input type="text" name="q[]" class="q" value="" id="input-1">
{% if config.browse_index_url is defined and config.browse_index_url != '' %}
<a href="#" onclick="show_index(this)" class="updateIndexList openerIndexes" id="show-1">{{ texts.SHOW_INDEX }}</a>
{% endif %}

<select name="index[]" class="inputText index" id="index-1">
{% for index in collectionData.index_list.index %}
{% if params.index is defined %}
{% if index.prefix == params.index %}
Expand All @@ -29,18 +34,33 @@ <h2>{{ texts.ADVANCED_SEARCH }}</h2>
{% endif %}
{% endfor %}
</select>
<div class="indexList" style="display: none;" id="list-1">
<div class="vBlockL first">
<select class="indexTerms" multiple="multiple" size="10" id="select-1" onchange="select_term(this)">
</select>
</div>
<div class="vBlockR">
<div class="prev"><a href="#" onclick="show_prev(this)" class="prev" id="prev-1">{{ texts.PREVIOUS_KEYS }}</a></div>
<div class="next"><a href="#" onclick="show_next(this)" class="next" id="next-1">{{ texts.NEXT_KEYS }}</a></div>
<div class="refresh"><a href="#" onclick="show_index(this, true)" class="updateIndexList" id="refresh-1">{{ texts.UPDATE_KEYS }}</a></div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="block-q">
<div>
<select name="bool[]">
<select name="bool[]" class="mini">
<option value="AND">AND</option>
<option value="OR">OR</option>
<option value="AND NOT">AND NOT</option>
</select>

<input type="text" name="q[]" class="q" onkeypress="new_line(this)">

<select name="index[]" class="inputText index" id="selectIndex">
<input type="text" name="q[]" class="q" id="input-2" onkeypress="new_line(this)">
{% if config.browse_index_url is defined and config.browse_index_url != '' %}
<a href="#" onclick="show_index(this)" class="updateIndexList openerIndexes" id="show-2">{{ texts.SHOW_INDEX }}</a>
{% endif %}

<select name="index[]" class="inputText index" id="index-2">
{% for index in collectionData.index_list.index %}
{% if params.index is defined %}
{% if index.prefix == params.index %}
Expand All @@ -53,6 +73,19 @@ <h2>{{ texts.ADVANCED_SEARCH }}</h2>
{% endif %}
{% endfor %}
</select>

<div class="indexList" style="display: none;" id="list-2">
<div class="vBlockL">
<select class="indexTerms" multiple="multiple" size="10" id="select-2" onchange="select_term(this)">
</select>
</div>
<div class="vBlockR">
<div class="prev"><a href="#" onclick="show_prev(this)" class="prev" id="prev-2">{{ texts.PREVIOUS_KEYS }}</a></div>
<div class="next"><a href="#" onclick="show_next(this)" class="next" id="next-2">{{ texts.NEXT_KEYS }}</a></div>
<div class="refresh"><a href="#" onclick="show_index(this, true)" class="updateIndexList" id="refresh-2">{{ texts.UPDATE_KEYS }}</a></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div class="more"></div>
Expand Down
1 change: 1 addition & 0 deletions views/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$output_array = array();
$output_array['lang'] = $lang;
$output_array['texts'] = $texts;
$output_array['config'] = $config;
$output_array['collectionData'] = $collectionData;

return $app['twig']->render('advanced.html', $output_array);
Expand Down
39 changes: 39 additions & 0 deletions views/browse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$app->get('browse-index/{index}/', function (Request $request, $index) use ($app, $DEFAULT_PARAMS, $config) {

$init = $request->get("init");
$direction = $request->get("dir");
if ($init == ''){
$init = '"';
}

if ($direction == ''){
$direction = 'next';
}

$service_url = $config->browse_index_url . "/PreviousTermServlet?fields=" . $index . "&init=" . $init . "&maxTerms=200&direction=" . $direction;

$result = file_get_contents($service_url);

// start session
$SESSION = $app['session'];
$SESSION->start();

// log user action
log_user_action($lang, $col, $site, 'id:' . $id, '', '', '', '', 'browseindex', $SESSION->getId());

// output vars
$output_array = array();

$response = new Response($result);
$response->headers->set('Content-Type', 'application/json');

return $response;

});

?>

0 comments on commit c3aaf58

Please sign in to comment.