Commit 37179894 authored by Denis Chenu's avatar Denis Chenu
Browse files

Merge branch 'master' of framagit.org:SondagePro-LimeSurvey-plugin/statsPivotTable

* 'master' of framagit.org:SondagePro-LimeSurvey-plugin/statsPivotTable:
  [feature] Fix width for renderer when loading
  [feature] Improve look and css
  [feature] Remove some basic input
  [feature] Add code for question and answers
  [dev] Use full question text
  [dev] Clean up

# Conflicts:
#	assets/statsPivotTable.js
parents 5ac33201 d46e96c0
......@@ -4,4 +4,65 @@
* @copyright Denis Chenu <http://www.sondages.pro>
* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
*/
/* global wrapper table */
.pvtUi{table-layout:fixed;width:100%}
.pvtUi tr td:first-child,.pvtVertList{width:15em}
.pvtVals,.pvtRows{width:15em}
.pvtUi .ui-sortable{
list-style: none;
}
.pvtUi .ui-sortable-handle{width:100%;overflow:hidden;position:relative;}
.pvtUi .pvtHorizList .ui-sortable-handle{width:16em;display:inline-block}
.pvtUi .ui-sortable-handle{padding-left:2em;text-align:left}
.pvtUi .ui-sortable-handle .pvtTriangle{position:absolute;left:0.5em;top:0.5em}
.pvtUi .pvtVertList{height:25em;padding-bottom:2em}/* in td : min-height is height */
.pvtUi .pvtRendererArea{font-size:85%}
/* cloned wrapper table */
#pivot-table-clone .table-bordered > tbody > tr > td {padding-bottom:0;padding-top:0;border-width:0 1px;}
#pivot-table-clone .table-bordered {border-width:0 1px;}
/* filter part */
.pvtFilteredAttribute { font-style: italic }
.pvtFilterBox{
z-index: 100;
width: 30em;
position: absolute;
}
.pvtFilterBox h4{margin:0}
.pvtFilterBox .pvtCheckContainer p { margin: 0.2em; }
.pvtFilterBox label { font-weight: normal; }
.pvtFilterBox .count { font-style:italic;font-size: 85%;}
.pvtCheckContainer{
white-space: nowrap;
overflow-y: scroll;
width: 100%;
max-height: 20em;
}
/* pivot table */
table.pvtTable {
text-align: left;
border-collapse: collapse;
width:100%;
table-layout:fixed;
}
table.pvtTable thead tr th, table.pvtTable tbody tr th {
background-color: #e6EEEE;
border: 1px solid #CDCDCD;
padding: 0.5em;
}
table.pvtTable .pvtColLabel {text-align: center;}
table.pvtTable .pvtTotalLabel {text-align: right;}
table.pvtTable tbody tr td {
color: #3D3D3D;
padding: 0.5em;
background-color: #FFF;
border: 1px solid #CDCDCD;
vertical-align: top;
text-align: right;
}
.pvtTotal, .pvtGrandTotal { font-weight: bold; }
......@@ -5,18 +5,58 @@
* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
*/
/**
* Set first word to strong
* @link https://github.com/melbon/jquery.useWord
*/
$.fn.firstWord = function() {
var text = this.text().trim().split(" ");
var first = text.shift();
this.html((text.length > 0 ? "<strong>"+ first + "</strong> " : first) + text.join(" "));
};
$(function(){
var derivers = $.pivotUtilities.derivers;
var renderers = $.extend(
var $maxRenderWidth=$("#pivot-table-clone .pvtAxisContainer").innerWidth();
var $derivers = $.pivotUtilities.derivers;
var $renderers = $.extend(
$.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers,
$.pivotUtilities.d3_renderers,
$.pivotUtilities.export_renderers
);
$.getJSON(LS.plugin.statsPivotTable.jsonUrl, function(responses) {
$("#pivot-table").pivotUI(responses, {
renderers : renderers,
hiddenAttributes : ['id','token','lastpage','submitdate']
$.getJSON(LS.plugin.statsPivotTable.jsonUrl, function($responses) {
$("#pivot-table").pivotUI($responses, {
renderers : $renderers,
rendererOptions: {
c3: {
size : {
width:$maxRenderWidth-10,
}
},
},
onRefresh: function() {
$("#pivot-table-construct").fadeOut(400).remove();
$("#pivot-table .pvtUi").addClass('table table-condensed table-bordered');
$("#pivot-table .ui-sortable-handle").addClass('btn btn-default btn-sm btn-block');
$("#pivot-table select").addClass('form-control');
$("#pivot-table .pvtFilterBox input[type='text']").addClass('form-control input-sm');
$("#pivot-table .pvtFilterBox button").addClass('btn btn-default btn-sm');
$("#pivot-table .pvtVals").find("br").remove();
$("#pivot-table .pvtTriangle").addClass('label label-default');
$("#pivot-table table.pvtUi td").not(":last").addClass('active');
$("#pivot-table table.pvtUi td.pvtRendererArea").removeClass('active');
$("#pivot-table .pvtFilterBox").addClass("panel panel-default");
$("#pivot-table .pvtFilterBox h4").addClass("panel-heading");
$("#pivot-table .pvtFilterBox .pvtCheckContainer").addClass("panel-body");
$("#pivot-table .pvtFilterBox > p").addClass("panel-footer");
$("#pivot-table .pvtFilterBox .count").addClass("badge small");
/* Commented : this brokepivotable.js
$("#pivot-table").find(".ui-sortable-handle").each(function(){
$(this).firstWord();
});
*/
}
});
});
});
......@@ -41,6 +41,31 @@ class jsonPivotWriter extends Writer
}
/**
* @see Writer::getFullHeading , replace with code + abbreviated heading
*/
public function getFullHeading(SurveyObj $survey, FormattingOptions $oOptions, $fieldName){
$oOptions->headingTextLength=30;
$headingText=parent::getAbbreviatedHeading($survey,$oOptions,$fieldName);
$oOptions->useEMCode=true;
$headingCode=parent::getHeadingCode($survey,$oOptions,$fieldName);
return $headingCode." ".$headingText."";
}
/**
* @see Writer::getLongAnswer , replace with code + abbreviated heading
*/
public function getLongAnswer(SurveyObj $oSurvey, FormattingOptions $oOptions, $fieldName,$sValue)
{
if(is_null($sValue)){
return '';
}
$answer= parent::getLongAnswer($oSurvey,$oOptions, $fieldName,$sValue);
if($this->needCode($oSurvey->fieldMap[$fieldName]['type'],$fieldName)){
$answer = parent::getShortAnswer($oSurvey,$oOptions, $fieldName,$sValue).":".$answer;
}
return $answer;
}
public function close()
{
$sEndOutput=']';
......@@ -54,4 +79,42 @@ class jsonPivotWriter extends Writer
fclose($this->file);
}
}
/*
* Get if field need a code
* @param string $sFieldType : the field type
* @param string $sFieldName : the field name
* @return boolean
*/
public function needCode($sFieldType,$sFieldName)
{
// Have only code : 5 point, arry 5 point, arry 10 point, language (this one can/must be fixed ?)
$aOnlyCode=array("5","A","B","I");
// Not need code
$aNotneedCode=array("G","Y");
// Have only text : Text and numeric + file upload language (this one can/must be fixed ?)
$aOnlyText=array("K","N","Q","S","T","U","X",'*',';',':',"|");
// No field type, but some can have specific answers (date) : maybe default must be true ?
$aDateField=array("submitdate","startdate","datestamp");
$aInfoField=array("id","lastpage","startlanguage","ipaddr","refurl");
// Have other question type
$aOtherType=array("L","M","P","!");
// Have comment question type
$aCommentType=array("O","P");
if(in_array($sFieldType,$aOnlyCode))
return false;
if(in_array($sFieldType,$aNotneedCode))
return false;
if(in_array($sFieldType,$aOnlyText))
return false;
if(in_array($sFieldName,$aInfoField) || in_array($sFieldName,$aDateField))
return false;
if(in_array($sFieldType,$aOtherType) && substr_compare($sFieldName, "other", -5, 5) === 0)
return false;
if(in_array($sFieldType,$aCommentType))
return false;
return true;
}
}
......@@ -61,7 +61,7 @@ class statsPivotTable extends \ls\pluginmanager\PluginBase
$menuItem = new \ls\menu\MenuItem(
array(
'label' => $this->_translate('Pivot table'),
'iconClass' => 'fa fa-table',
'iconClass' => 'fa fa-pie-chart',
'href' => $href
)
);
......@@ -94,6 +94,7 @@ class statsPivotTable extends \ls\pluginmanager\PluginBase
),
);
//~ $aSorters="";
$jsInit = "var LS = LS || {};\n"
. "LS.plugin = LS.plugin || {};\n"
......@@ -109,12 +110,12 @@ class statsPivotTable extends \ls\pluginmanager\PluginBase
Yii::app()->clientScript->registerScriptFile($pivotAssetUrl."/pivot.js",CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile($pivotAssetUrl."/d3_renderers.js",CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile($pivotAssetUrl."/c3_renderers.js",CClientScript::POS_BEGIN);
//~ Yii::app()->clientScript->registerScriptFile($pivotAssetUrl."/export_renderers.js",CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile($pivotAssetUrl."/export_renderers.js",CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile($assetUrl."/statsPivotTable.js",CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerCssFile($c3AssetUrl."/c3.css");
Yii::app()->clientScript->registerCssFile($pivotAssetUrl."/pivot.css");
//Yii::app()->clientScript->registerCssFile($pivotAssetUrl."/pivot.css");
Yii::app()->clientScript->registerCssFile($assetUrl."/statsPivotTable.css");
......@@ -144,6 +145,10 @@ class statsPivotTable extends \ls\pluginmanager\PluginBase
}
$language=\Survey::model()->findByPk($iSurveyId)->language;
$aFields=array_keys(createFieldMap($iSurveyId,'full',true,false,$language));
$aFields=array_diff($aFields,
array('id','startlanguage','token','lastpage','submitdate')
);
Yii::app()->loadHelper('admin/exportresults');
Yii::import('application.helpers.viewHelper');
Yii::setPathOfAlias(get_class($this), dirname(__FILE__));
......@@ -153,19 +158,16 @@ class statsPivotTable extends \ls\pluginmanager\PluginBase
$oFormattingOptions->responseMaxRecord=SurveyDynamic::model($iSurveyId)->getMaxId();
$oFormattingOptions->selectedColumns=$aFields;
$oFormattingOptions->responseCompletionState='complete';
$oFormattingOptions->headingFormat='complete';// Maybe make own to have code + abbreviated
$oFormattingOptions->headingFormat='full';// Maybe make own to have code + abbreviated
$oFormattingOptions->answerFormat='long';
$oFormattingOptions->output='display';
/* Hack action id to set to remotecontrol */
$action = new stdClass();
$action->id='remotecontrol';
Yii::app()->controller->__set('action',$action);
/* Export as display */
$oExport=new \ExportSurveyResultsService();
$content=$oExport->exportSurvey($iSurveyId,$language, 'json-pivot',$oFormattingOptions, '');
//~ Yii::app()->controller->__set('action','direct');
//~ echo "<pre>";
//~ print_r(Yii::app()->controller->action);
//~ die("</pre>");
}
/**
......
<div class="row">
<div class="col-lg-12 content-right">
<h3><?php echo $gT['title'];?></h3>
<div id="pivot-table-construct" class="text-center"><i class="fa fa-refresh fa-spin fa-5x" aria-hidden="true"></i><span class="sr-only"><?php echo gT("loading") ?></span></div>
<div id="pivot-table-clone"><table class="pvtUi table table-condensed table-bordered"><tbody><tr><td></td><td class="pvtVals"></td><td class="pvtAxisContainer pvtHorizList pvtCols ui-sortable active"></td></tr></tbody></table></div>
<div id="pivot-table"></div>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment