From cf56ea1b306c7b6811e695b2ae4541f2e2c07daf Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Sun, 8 Jul 2012 16:50:51 -0300 Subject: [PATCH] irregularidades table and filterable data table --- index.html | 10 ++-- js/site.js | 170 +++++++++++++++++++++++++++++++++++++++++------------ site.css | 44 ++++++++++++++ 3 files changed, 182 insertions(+), 42 deletions(-) diff --git a/index.html b/index.html index 6ac363c..11a9917 100644 --- a/index.html +++ b/index.html @@ -119,13 +119,11 @@

As opções escolhidas podem ser somadas para cruzar dados e gerar diferente
-
-
- +
+
-
-
+
+
diff --git a/js/site.js b/js/site.js index d3e2965..d2baefd 100644 --- a/js/site.js +++ b/js/site.js @@ -196,9 +196,7 @@ function loadSection(section) { } } - var scrollSettings = { - maintainPosition: false - }; + var scrollSettings = {}; var scrollPane = $('#navegue #data'); scrollPane.jScrollPane(scrollSettings); resultsScrollApi = scrollPane.data('jsp'); @@ -237,6 +235,7 @@ function loadSection(section) { $.each(categories, function(i, category) { currentData[category] = getCategoryCurrentData(selectedFilters, category); }); + currentData.irregularidades = getIrregularidades(selectedFilters); } function getCategoryCurrentData(filters, category) { @@ -340,6 +339,14 @@ function loadSection(section) { } } +// add category filter +function addFilter(category, value) { + $('select.' + category + ' option').attr('selected', false); + $('select.' + category + ' option[value="' + value + '"]').attr('selected', true); + $('select.' + category).chosen().trigger('liszt:updated').change(); + return false; +} + function getIrregularidadesCount(filters) { var data = jLinq.from(irregularidadesData); jQuery.each(filters, function(key, value) { @@ -348,6 +355,14 @@ function getIrregularidadesCount(filters) { return data.count(); } +function getIrregularidades(filters) { + var data = jLinq.from(irregularidadesData); + jQuery.each(filters, function(key, value) { + data = data.starts(key, value); + }); + return data.select(); +} + function theMagic() { var $resultsContainer = $('#data'); @@ -355,11 +370,13 @@ function theMagic() { var $dataTable = $resultsContainer.find('#data-table'); var $links = $resultsContainer.find('#links'); var $graphsContainer = $resultsContainer.find('#graphs'); + var $irregularidadesContainer = $resultsContainer.find('#irregularidades'); $resultsHeader.empty(); $dataTable.empty(); $links.empty(); $graphsContainer.empty(); + $irregularidadesContainer.removeClass('active').empty(); if($.isEmptyObject(selectedFilters)) { $resultsContainer.find('.landing').show(); @@ -385,8 +402,6 @@ function theMagic() { title = selectedFilters.tipo + ' em ' + selectedFilters.programa; } - - $resultsHeader.append('

' + title + '

'); if(selectedFilters.cidade && !selectedFilters.tipo && !selectedFilters.programa) { @@ -409,19 +424,22 @@ function theMagic() { var itemData = jLinq.from(tableData.programa).starts('programa', programa.programa).select(); $.each(itemData, function(key, value) { itemData = value }); var count = itemData.count; - if(!count) count = '--'; - else totalCount = totalCount + count; + var attrs; + if(!count) { + count = '--'; + attrs = false; + } else { + totalCount = totalCount + count; + attrs = 'class="filterable" onClick="addFilter(\'programa\', \'' + programa.programa + '\');"'; + } var average = Math.ceil(programa.constatacoes/32); totalAverage = Math.ceil(totalAverage + (programa.constatacoes/32)); - tableContent += '' + count + '' + programa.programa_desc + '' + average + ''; + tableContent += '' + count + '' + programa.programa_desc + '' + average + ''; }); tableContent += '' + totalCount + 'TOTAL' + totalAverage + ''; tableContent += ''; $dataTable.append(tableContent); - - $links.append('Acesse o relatório de fiscalização da cidade'); - } else if(!selectedFilters.cidade && selectedFilters.tipo && !selectedFilters.programa) { /*--TIPO gráfico pizza @@ -445,9 +463,15 @@ function theMagic() { var itemData = jLinq.from(tableData.programa).starts('programa', programa.programa).select(); $.each(itemData, function(key, value) { itemData = value }); var count = itemData.count; - if(!count) count = '--'; - else totalCount = totalCount + count; - tableContent += '' + programa.programa_desc + '' + count + ''; + var attrs; + if(!count) { + count = '--'; + attrs = false; + } else { + totalCount = totalCount + count; + attrs = 'class="filterable" onClick="addFilter(\'programa\', \'' + programa.programa + '\');"'; + } + tableContent += '' + programa.programa_desc + '' + count + ''; }); tableContent += ''; @@ -477,9 +501,15 @@ function theMagic() { var itemData = jLinq.from(tableData.tipo).starts('tipo', tipo.tipo).select(); $.each(itemData, function(key, value) { itemData = value }); var count = itemData.count; - if(!count) count = '--'; - else totalCount = totalCount + count; - tableContent += '' + tipo.tipo + '' + count + ''; + var attrs; + if(!count) { + count = '--'; + attrs = false; + } else { + totalCount = totalCount + count; + attrs = 'class="filterable" onClick="addFilter(\'tipo\', \'' + tipo.tipo + '\');"'; + } + tableContent += '' + tipo.tipo + '' + count + ''; }); tableContent += ''; @@ -509,19 +539,21 @@ function theMagic() { var itemData = jLinq.from(tableData.programa).starts('programa', programa.programa).select(); $.each(itemData, function(key, value) { itemData = value }); var count = itemData.count; - if(!count) count = '--'; - else totalCount = totalCount + count; - tableContent += '' + programa.programa_desc + '' + count + ''; + var attrs; + if(!count) { + count = '--'; + attrs = false; + } else { + totalCount = totalCount + count; + attrs = 'class="filterable" onClick="addFilter(\'programa\', \'' + programa.programa + '\');"'; + } + tableContent += '' + programa.programa_desc + '' + count + ''; }); tableContent += ''; $dataTable.append(tableContent); $dataTable.find('td.total').text(totalCount); $dataTable.find('td.total').append('irregularidades'); - - $links.append('Veja a lista de irregularidades'); - $links.append('Acesse o relatório de fiscalização da cidade'); - } else if(!selectedFilters.cidade && selectedFilters.tipo && selectedFilters.programa) { /*--TIPO+PROGRAMA gráfico barra @@ -538,16 +570,13 @@ function theMagic() { var totalCount = getIrregularidadesCount(selectedFilters); tableContent += ''; $.each(tableData.cidade, function(i, cidade) { - if(i < 10) tableContent += '' + cidade.cidade + '' + cidade.count + ''; + var attrs = 'class="filterable" onClick="addFilter(\'cidade\', \'' + cidade.cidade + '\');"'; + if(i < 10) tableContent += '' + cidade.cidade + '' + cidade.count + ''; }); tableContent += ''; - $dataTable.append(tableContent); $dataTable.find('td.total').text(totalCount); $dataTable.find('td.total').append('irregularidades'); - - $links.append('Veja a lista de irregularidades'); - } else if(selectedFilters.cidade && !selectedFilters.tipo && selectedFilters.programa) { /*--CIDADE+PROGRAMA gráfico pizza @@ -571,25 +600,70 @@ function theMagic() { var itemData = jLinq.from(tableData.tipo).starts('tipo', tipo.tipo).select(); $.each(itemData, function(key, value) { itemData = value }); var count = itemData.count; - if(!count) count = '--'; - else totalCount = totalCount + count; - tableContent += '' + tipo.tipo + '' + count + ''; + var attrs; + if(!count) { + count = '--'; + attrs = false; + } else { + totalCount = totalCount + count; + attrs = 'class="filterable" onClick="addFilter(\'tipo\', \'' + tipo.tipo + '\');"'; + } + tableContent += '' + tipo.tipo + '' + count + ''; }); tableContent += ''; $dataTable.append(tableContent); $dataTable.find('td.total').text(totalCount); $dataTable.find('td.total').append('irregularidades'); - - $links.append('Veja a lista de irregularidades'); - $links.append('Acesse o relatório de fiscalização da cidade'); } else if(selectedFilters.cidade && selectedFilters.tipo && selectedFilters.programa) { /*--CIDADE+TIPO+PROGRAMA só lista */ } + // irregularidades table + if(Object.keys(selectedFilters).length >= 2) { + var category = categories[0]; + if(category) + var categoryTitle = category.charAt(0).toUpperCase() + category.slice(1) + 's'; + if(Object.keys(selectedFilters).length == 2) + $links.append('Exibir a lista de irregularidades'); + else + $irregularidadesContainer.addClass('active'); + + var irregularidadesContent = ''; + irregularidadesContent += ''; + if(category) irregularidadesContent += ''; + irregularidadesContent += ''; + $.each(currentData.irregularidades, function(i, irregularidade) { + irregularidadesContent += ''; + if(category) irregularidadesContent += ''; + irregularidadesContent += ''; + }) + irregularidadesContent += '
' + categoryTitle + 'Irregularidades
' + irregularidade[category] + '

' + irregularidade.constatacao + '

'; + $irregularidadesContainer.append(irregularidadesContent); + } + + if(selectedFilters.cidade) { + $links.append('Acesse o relatório de fiscalização da cidade'); + } + + $('.irregularidades-toggle').click(function() { + if(!$irregularidadesContainer.hasClass('active')) { + $irregularidadesContainer.addClass('active'); + $(this).text('Esconder a lista de irregularidades'); + resultsScrollApi.reinitialise(); + $() + } else { + $irregularidadesContainer.removeClass('active'); + $(this).text('Exibir a lista de irregularidades'); + resultsScrollApi.reinitialise(); + } + return false; + }); + resultsScrollApi.reinitialise(); + $('.jspPane, .jspDrag').css({'top':0}); } function getCidadeGraphData(filters) { @@ -770,4 +844,28 @@ function drawCidade(cidade, containerId) { }; -})(jQuery); \ No newline at end of file +})(jQuery); + + +// class friendly text helper +var normalize = (function() { + var from = "ÃÀÁÄÂÈÉËÊÌÍÏÎÒÓÖÔÙÚÜÛãàáäâèéëêìíïîòóöôùúüûÑñÇç", + to = "AAAAAEEEEIIIIOOOOUUUUaaaaaeeeeiiiioooouuuunncc", + mapping = {}; + + for(var i=0; i