Skip to content

Commit

Permalink
Merged branch export_singletables into master
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 24, 2016
2 parents 8165e5a + 66a2ad4 commit 2b06d80
Show file tree
Hide file tree
Showing 104 changed files with 23,153 additions and 35 deletions.
28 changes: 28 additions & 0 deletions application/config/third_party.php
Expand Up @@ -311,6 +311,34 @@
'jquery',
'bootstrap'
)
),

'es6promise' => array(
'basePath' => 'third_party.es6promise',
'js' => array(
'es6-promise.auto.min.js'
)
),

'dom2image' => array(
'basePath' => 'third_party.dom-to-image',
'js' => array(
'dist/dom-to-image.min.js',
)
),

'jspdf' => array(
'basePath' => 'third_party.jspdf',
'js' => array(
'jspdf.min.js',
'createpdf_worker.js'
),
'depends' => array(
'dom2image',
'es6promise',
'jquery',
'bootstrap'
)
)


Expand Down
2 changes: 2 additions & 0 deletions application/controllers/admin/statistics.php
Expand Up @@ -805,6 +805,7 @@ public function simpleStatistics($surveyid)
//Call the javascript file
$this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'statistics.js');
$this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'json-js/json2.min.js');
yii::app()->clientScript->registerPackage('jspdf');
echo $this->_renderWrappedTemplate('export', 'statistics_user_view', $aData);
}

Expand All @@ -829,6 +830,7 @@ public function setIncompleteanswers()
protected function _renderWrappedTemplate($sAction = 'export', $aViewUrls = array(), $aData = array())
{
yii::app()->clientScript->registerPackage('bootstrap-switch');
yii::app()->clientScript->registerPackage('jspdf');

$aData['menu']['closeurl'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl("/admin/survey/sa/view/surveyid/".$aData['surveyid']) );

Expand Down
1 change: 1 addition & 0 deletions application/core/LSYii_Application.php
Expand Up @@ -84,6 +84,7 @@ public function __construct($aApplicationConfig = null)
{
$this->setConfig($key, $value);
}
App()->getAssetManager()->linkAssets = true;
// Asset manager path can only be set after App was constructed because it relies on App()
App()->getAssetManager()->setBaseUrl($settings['tempurl']. '/assets');
App()->getAssetManager()->setBasePath($settings['tempdir'] . '/assets');
Expand Down
9 changes: 4 additions & 5 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -2451,6 +2451,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
//loop though the array which contains all answer data
$ColumnName_RM=array();
//echo '<pre>'; var_dump($outputs['alist']); echo '</pre>';die;
$statisticsoutput_footer = "<script>";
foreach ($outputs['alist'] as $al)
{
//picks out answer list ($outputs['alist']/$al)) that come from the multiple list above
Expand Down Expand Up @@ -3086,7 +3087,6 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
$aData['bShowCount'] = (isset($bShowCount))?$bShowCount:false;
$aData['bShowPercentage'] = (isset($bShowPercentage))?$bShowPercentage:false;
$statisticsoutput = Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_header', $aData, true);

//loop through all available answers
////
while (isset($gdata[$i]))
Expand Down Expand Up @@ -3405,7 +3405,6 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
// Generate answer
// _statisticsoutput_answer
$statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_answer', $aData, true);

$extraline = false;
$aggregated = false;
$aggregatedPercentage = false;
Expand Down Expand Up @@ -3792,11 +3791,11 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
///

$statisticsoutput .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_graphs', $aData, true);

$statisticsoutput_footer .= Yii::app()->getController()->renderPartial('/admin/export/generatestats/_statisticsoutput_footer', $aData, true);
}
$statisticsoutput .= "</table></div> <!-- in statistics helper --> \n";
$statisticsoutput .= "</table></div><!-- in statistics helper --> \n";
}

$statisticsoutput = $statisticsoutput. $statisticsoutput_footer."</script>";
return array("statisticsoutput"=>$statisticsoutput, "pdf"=>$this->pdf, "astatdata"=>$astatdata);

}
Expand Down
@@ -0,0 +1,24 @@
<?php
/**
* This view render the graphs
*
* @var $rt
* @var $qqid
* @var $labels
* @var $COLORS_FOR_SURVEY
* @var $charttype
* @var $sChartname
* @var $grawdata
* @var $color
*
*/
// TODO: move to controller
$qqid = str_replace ( '-', '__' , $qqid );
?>

statisticsData['quid'+'<?php echo $qqid; ?>'] = {
labels : <?php echo json_encode($graph_labels); ?>,
grawdata : <?php echo json_encode($grawdata); ?>, // the datas to generate the graph
labels_percent : <?php echo json_encode($graph_labels_percent); ?>, // the array of labels
grawdata_percent : <?php echo json_encode($grawdata_percent);?> // the datas to generate the graph using percentages (pie, Doughnut, polar )
};
Expand Up @@ -133,10 +133,11 @@
<?php endif;?>
</td>
</tr>

<script>
<?php
/*<script>
var labels_<?php echo $qqid; ?>=<?php echo json_encode($graph_labels); // the array of labels ?>;
var grawdata_<?php echo $qqid;?>=<?php echo json_encode($grawdata); // the datas to generate the graph ?>;
var labels_percent_<?php echo $qqid; ?>=<?php echo json_encode($graph_labels_percent); // the array of labels ?>;
var grawdata_percent_<?php echo $qqid;?>=<?php echo json_encode($grawdata_percent); // the datas to generate the graph using percentages (pie, Doughnut, polar ) ?>;
</script>
</script>*/
?>
Expand Up @@ -9,14 +9,17 @@
*/
?>
<!-- _statisticsoutput_header -->
<div class="col-lg-<?php echo $nbcols; ?> sol-sm-12 printable">
<table class='statisticstable table table-bordered printable'>
<div class="col-lg-<?php echo $nbcols; ?> sol-sm-12 printable" >
<table class='statisticstable table table-bordered printable' id="quid_<?php echo $outputs['parentqid'];?>">
<thead>
<tr class='success'>
<th colspan='4' align='center' style='text-align: center; '>
<strong>
<?php echo sprintf(gT("Field summary for %s"),$outputs['qtitle']); ?>
</strong>
<button class="pull-right action_js_export_to_pdf btn btn-default btn-sm" data-question-id="quid_<?php echo $outputs['parentqid'];?>" data-toggle="tooltip" title="<?php eT('Export this question to PDF.'); ?>">
<i class="fa fa-file-pdf-o"></i>
</button>
</th>
</tr>
<tr>
Expand Down
Expand Up @@ -4,10 +4,12 @@
*/
?>
<script type='text/javascript'>
var statisticsData = {};
var graphUrl="<?php echo Yii::app()->getController()->createUrl("admin/statistics/sa/graph"); ?>";
var sStatisticsLanguage="<?php echo $sStatisticsLanguage; ?>";
var listColumnUrl="<?php echo Yii::app()->getController()->createUrl("admin/statistics/sa/listcolumn/surveyid/".$surveyid."/column/"); ?>";
var showTextInline="<?php echo $showtextinline ?>";
var jspdfworker="<?php echo yii::app()->clientScript->getPackageBaseUrl('jspdf'); ?>";
</script>

<?php
Expand Down
8 changes: 3 additions & 5 deletions application/views/admin/export/statistics_view.php
Expand Up @@ -115,7 +115,9 @@
<div class="alert alert-info" role="alert" id="view-stats-alert-info">
<?php eT('Please select filters and click on the "View statistics" button to generate the statistics.');?>
</div>

<?php else:?>
<?php echo $output; ?>
<?php endif;?>
<div id="statsContainerLoading" >
<p><?php eT('Please wait, loading data...');?></p>
<div class="preloader loading">
Expand All @@ -127,10 +129,6 @@
<span class="slice"></span>
</div>
</div>

<?php else:?>
<?php echo $output; ?>
<?php endif;?>
</div>
</div>
</div>
Expand Down
86 changes: 76 additions & 10 deletions scripts/admin/statistics.js
Expand Up @@ -94,8 +94,9 @@ function init_chart_js_graph_with_datasets($type,$qid)
var canvasId = 'chartjs-'+$qid;
var $canvas = document.getElementById(canvasId).getContext("2d");
var $canva = $('#'+canvasId);
var $labels = eval("labels_"+$qid);
var $grawdata = eval("grawdata_"+$qid);
var $statistics = statisticsData['quid'+$qid];
var $labels = $statistics.labels
var $grawdata = $statistics.grawdata
var $color = $canva.data('color');

$('#legend-no-percent-'+$qid).show();
Expand Down Expand Up @@ -146,8 +147,9 @@ function init_chart_js_graph_with_datas($type,$qid)
var $canvas = document.getElementById(canvasId).getContext("2d");
var $canva = $('#'+canvasId);
var $color = $canva.data('color');
var $labels = eval("labels_percent_"+$qid);
var $grawdata = eval("grawdata_percent_"+$qid);
var $statistics = statisticsData['quid'+$qid];
var $labels = $statistics.labels
var $grawdata = $statistics.grawdata
var $chartDef = new Array();

$('#legend-no-percent-'+$qid).hide();
Expand Down Expand Up @@ -180,9 +182,7 @@ function init_chart_js_graph_with_datas($type,$qid)
);
}

$(document).ready(function() {
//for nicely printed statistics
$('body').addClass('onStatistics');
var onDocumentReady = function(){

if ($('#completionstateSimpleStat').length>0)
{
Expand Down Expand Up @@ -267,8 +267,6 @@ $(document).ready(function() {
$type = $(this).data('type');
$qid = $(this).data('qid');

console.log($type);

// chartjs
if($type == 'Bar' || $type == 'Radar' || $type == 'Line' )
{
Expand Down Expand Up @@ -565,7 +563,10 @@ $(document).ready(function() {
{
changeGraphType('showpie', this.parentNode);
});
});
};
$(document).ready(onDocumentReady);
$(document).on('triggerReady', onDocumentReady);


var isWaiting = {};

Expand Down Expand Up @@ -729,3 +730,68 @@ function changeGraphType (cmd, id) {
});

}


var createPDFworker = function(tableArray){
"use strict";
return new Promise(function(res,rej){
var createPDF = new CreatePDF();

$.each(tableArray, function(i,table){
var sizes = {h: $(table).height(), w: $(table).width()};
var answerObject = createPDF('sendImg', {html: table, sizes: sizes});
});

createPDF('getParseHtmlPromise').then(function(resolve){
var answerObject = createPDF('exportPdf');
var newWindow = window.open(answerObject.msg,600,800);
res('done');
}, function(reject){
rej(arguments);
});
});
};

$(document).ready(function(){
$('body').addClass('onStatistics');

$('body').on('click','.action_js_export_to_pdf', function(){

// var thisTable = $('#'+$(this).data('questionId'));
// domtoimage.toPng(thisTable[0]).then(
// function(image){
// $('body').prepend($('<img/>').attr('src',image));
// }
// )

// var thisTable = $('#'+$(this).data('questionId'));
// console.log(thisTable.html());


var overlay = $('<div></div>')
.attr('id','overlay')
.css({
position: 'fixed',
width: "100%",
height:"100%",
top:0,
"z-index" : 5000,
"pointer-events": 'none',
left:0,
right:0,
bottom:0,
"background-color": "hsla(0,0%,65%,0.6)"
});
$('#statsContainerLoading').clone().css({display: 'block',position: 'fixed', top:"25%",left:0, width: "100%"}).appendTo(overlay);
overlay.appendTo('body');

var thisTable = $('#'+$(this).data('questionId'));
thisTable.find('button').css({display:'none'});
createPDFworker.call(null,thisTable).then(
function(success){overlay.remove(); thisTable.find('button').css({display:''});},
function(){console.log(arguments);}
)


});
});
18 changes: 8 additions & 10 deletions styles/Sea_Green/css/lime-admin-common.css
Expand Up @@ -2260,12 +2260,15 @@ input[type="file"].form-control {

html,body {
margin: 0;
max-width: 100%;
max-width: 90%;
}
body{
max-width: 100%;
text-align: left;
padding: 12px;
overflow: visible;
position: absolute;
top: 24px;
left: 14px;
}

body.onStatistics a:not(.printable),
Expand Down Expand Up @@ -2294,16 +2297,11 @@ input[type="file"].form-control {
margin-left: 0;
margin-right: 0;
}
body.onStatistics>div.printable
{
margin: 2px !important;
padding: 2px !important;
body.onStatistics div:not(.printable) {
margin: 0 !important;
padding: 0 !important;
}

div.legend span {
margin: initial !important;
padding: initial !important;
}

/*body.onStatistics td:not(.printable),
body.onStatistics th:not(.printable),*/
Expand Down
1 change: 1 addition & 0 deletions third_party/dom-to-image/.gitattributes
@@ -0,0 +1 @@
dist/*.min.js -diff
5 changes: 5 additions & 0 deletions third_party/dom-to-image/.gitignore
@@ -0,0 +1,5 @@
node_modules
bower_components
*.iml
.tags
.tags*

0 comments on commit 2b06d80

Please sign in to comment.