Skip to content

Commit

Permalink
Merge pull request #349 from gitnnolabs/dynamic_interface_components
Browse files Browse the repository at this point in the history
Troca "-" pelo termo "por", ao selecionar mundo garante que a lista de componentes sejam refeitas, troca termos de plural para singular na interface.
  • Loading branch information
gitnnolabs authored Sep 16, 2024
2 parents 14ca01d + 451bc93 commit a1ee6f3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion education_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def prepare_creator(self, obj):
# return "directory"

def prepare_universe(self, obj):
return ["Brazil"]
return ["brazil"]

def prepare_scope(self, obj):
return ["education_directory"]
Expand Down
2 changes: 1 addition & 1 deletion event_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def prepare_creator(self, obj):
# return "directory"

def prepare_universe(self, obj):
return ["Brazil"]
return ["brazil"]

def prepare_scope(self, obj):
return ["event_directory"]
Expand Down
2 changes: 1 addition & 1 deletion infrastructure_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def prepare_creator(self, obj):
# return "directory"

def prepare_universe(self, obj):
return ["Brazil"]
return ["brazil"]

def prepare_scope(self, obj):
return ["infrastructure_directory"]
Expand Down
2 changes: 1 addition & 1 deletion policy_directory/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def prepare_creator(self, obj):
# return "directory"

def prepare_universe(self, obj):
return ["Brazil"]
return ["brazil"]

def prepare_scope(self, obj):
return ["policy_directory"]
Expand Down
46 changes: 22 additions & 24 deletions search/templates/graph/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ <h1 class="mb-1">Indicadores</h1>

<select id="universe" class="chzn-select ordem form-control">
<option value="brazil" selected="">Brasil</option>
<option value="brazil_region">Brasil - Região</option>
<option value="brazil_posgraduate">Brasil - Pós Graduação</option>
<option value="brazil_state">Brasil - Estado</option>
<option value="brazil_instituion">Brasil - Instituição</option>
<option value="brazil_region">Brasil por Região</option>
<option value="brazil_posgraduate">Brasil por Pós Graduação</option>
<option value="brazil_state">Brasil por Estado</option>
<option value="brazil_instituion">Brasil por Instituição</option>
<option value="world">Mundo</option>
<option value="world_region">Mundo - Região</option>
<option value="world_country">Mundo - País</option>
<option value="world_region">Mundo por Região</option>
<option value="world_country">Mundo por País</option>
</select>

<div id="div_world_region" style="display:none">
<div class="mt-3 mb-2">
<b>Regiões:</b>
<b>Região:</b>
</div>
<select id="world_region" name="world_region" class="chzn-select ordem form-control"
data-placeholder="Escolha um ou mais regiões...">
Expand All @@ -116,7 +116,7 @@ <h1 class="mb-1">Indicadores</h1>

<div id="div_world_country" style="display:none">
<div class="mt-3 mb-2">
<b>Paises:</b>
<b>País:</b>
</div>
<select id="world_country" name="world_country" class="chzn-select ordem form-control"
data-placeholder="Escolha um ou mais paises...">
Expand All @@ -129,7 +129,7 @@ <h1 class="mb-1">Indicadores</h1>

<div id="div_brazil_region" style="display:none">
<div class="mt-3">
<b>Regiões</b>
<b>Região</b>
</div>
<select id="regions" name="regions" class="chzn-select ordem form-control"
data-placeholder="Escolha um ou mais região..." multiple>
Expand All @@ -142,7 +142,7 @@ <h1 class="mb-1">Indicadores</h1>

<div id="div_brazil_state" style="display:none">
<div class="mt-3">
<b>Estados</b>
<b>Estado</b>
</div>
<select id="states" name="states"
class="chzn-select ordem form-control"
Expand All @@ -156,7 +156,7 @@ <h1 class="mb-1">Indicadores</h1>

<div id="div_brazil_institution" style="display:none">
<div class="mt-3">
<b>Institutições:</b>
<b>Institutição:</b>
</div>
<select id="institutions" name="institutions" class="chzn-select ordem form-control"
data-placeholder="Escolha uma ou mais instituições..." multiple>
Expand Down Expand Up @@ -550,9 +550,9 @@ <h5 class="mb-1">{{ f.label }}</h5>
if ($("#type").val() != "all" && $("#scope").val() == "document") {
data["default_filter"] += "," + "type:" + $("#type").val()
}
//if ($("#states").val() != "") {
// data["default_filter"] += "," + '"states:"' + $("#states").val()
//}
if ($("#type").val() != "all") {
data["type"]= $("#type").val()
}
if ($("#classification").val() != "all" && $("#scope").val() != "document") {
data["default_filter"] += "," + 'classification:"' + $("#classification").val() + '"'
}
Expand Down Expand Up @@ -951,8 +951,6 @@ <h5 class="mb-1">{{ f.label }}</h5>
$(component_id + ' option:not(:first)').remove();
}

//Preciso descobrir como remover todos os items nenos o primeiro da lista.

if (include_all){
$(component_id).append(`<option value="" selected="">${trans["all"]}</option>`);
}
Expand All @@ -967,7 +965,7 @@ <h5 class="mb-1">{{ f.label }}</h5>
}


function get_facets(q){
function get_facets(q, scope=false){
$.ajax({
url: '/search/graph/context_facet',
type: 'GET',
Expand All @@ -976,16 +974,13 @@ <h5 class="mb-1">{{ f.label }}</h5>
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success: function(response) {
trans = response.translate;
console.log(response.facets.scope);
//fill_components(response.facets.scope, trans, "#scope", include_all=false);
console.log(response.facets.type);
trans = response.translate;
if(scope){
fill_components(response.facets.scope, trans, "#scope", include_all=false);
}
fill_components(response.facets.type, trans, "#type", include_all=false, empty=false, empty_without_first=true);
console.log(response.facets.classification);
fill_components(response.facets.classification, trans, "#classification", include_all=false, empty=false, empty_without_first=true);
console.log(response.facets.database);
fill_components(response.facets.database, trans, "#database", include_all=false);
console.log(response.facets.graphs);
fill_components(response.facets.graphs, trans, "#graph_type", include_all=true);
},
error: function(jqXHR, textStatus, errorThrown) {
Expand All @@ -1004,6 +999,9 @@ <h5 class="mb-1">{{ f.label }}</h5>
if ($(this).val() == "brazil"){
get_facets(q="universe:brazil");
}
if ($(this).val() == "world"){
get_facets(q="universe:world", scope=true);
}
}

if(select.id == "scope"){
Expand Down
4 changes: 2 additions & 2 deletions search/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def generate_string(
A formatted string according to the specification.
"""
if len(terms) > 1:
terms_str = preposition_text + ", ".join(terms[:-1]) + prol_text + _(" no ") + terms[-1]
terms_str = preposition_text + ", ".join(terms[:-1]) + prol_text + _(" no ") + terms[-1].title()
else:
terms_str = "no %s" % terms[0]
terms_str = "no %s" % terms[0].title()

if year_range[0] == year_range[1]:
inicial_text = _("Distribuição")
Expand Down
15 changes: 10 additions & 5 deletions search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,18 @@ def context_facet(request):
query = request.POST.get("q", "*:*")
query = request.GET.get("q", "*:*")

filters["f.grpahs.facet.sort"] = "index"

search_results = solr.search(query, **filters)

filters["f.graphs.facet.sort"] = "index"

# Get from database or index, when brazil is get from index otherwise database
if query == "universe:brazil":
search_results = solr.search(query, **filters)
facets = search_results.facets["facet_fields"]
else:
facets = IndicatorData.objects.get(data_type="facets").raw

return JsonResponse(
{
"facets": search_results.facets["facet_fields"],
"facets": facets,
"translate": choices.translates,
}
)

0 comments on commit a1ee6f3

Please sign in to comment.