添加可视化数据多字段选择功能

This commit is contained in:
Li Jianxuan 2014-12-09 10:40:08 +00:00
parent eea39206fd
commit 8058a8d812
5 changed files with 188 additions and 32 deletions

View File

@ -3999,6 +3999,11 @@ class Admin_DataController extends Zend_Controller_Action
'visual_datatable' => $this->_getParam('visual_datatable'),
'visual_timefield' => $this->_getParam('visual_timefield'),
'visual_valuefilter' => $this->_getParam('visual_valuefilter'),
'visual_timefield_model' => $this->_getParam('visual_timefield_model'),
'visual_timefield_year' => $this->_getParam('visual_timefield_year'),
'visual_timefield_month' => $this->_getParam('visual_timefield_month'),
'visual_timefield_day' => $this->_getParam('visual_timefield_day'),
'visual_type' => $this->_getParam('visual_type'),
);
$status = $visual->add($data);

View File

@ -55,10 +55,26 @@
</div>
</div>
<div class="control-group">
<label class="control-label">默认绘制类型</label>
<div class="controls">
<label class="radio inline">
<input type="radio" name="visual_type" id="optionsRadios1" value="line" <?= (isset($this->info['visual_type']) && $this->info['visual_type']=='line') || empty($this->info['visual_type']) ? "checked":"" ?>>
折线图
</label>
<label class="radio inline">
<input type="radio" name="visual_type" id="optionsRadios2" value="column"
<?= isset($this->info['visual_type']) && $this->info['visual_type'] == 'column' ? 'checked="checked"':"" ?>>
柱状图
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">数据表</label>
<div class="controls">
<select name="visual_datatable" id="data-table">
<option value="0">请选择</option>
<?php foreach($this->visualTable as $k=>$v){ ?>
<?php if(isset($this->info['visual_datatable']) && $this->info['visual_datatable']==$v){ ?>
<option value="<?= $v ?>" selected="selected"><?= $v ?></option>
@ -71,16 +87,47 @@
</div>
<div class="control-group">
<label class="control-label">时间字段</label>
<div class="controls" id="field-time">
<label class="control-label">时间字段模式</label>
<div class="controls" id="field-time-model">
<label class="radio inline">
<input type="radio" name="visual_timefield_model" id="model-single" value="single" <?= (isset($this->info['visual_timefield_model']) && $this->info['visual_timefield_model']=='single') || !isset($this->info['visual_timefield_model']) || empty($this->info['visual_timefield_model']) ? 'checked="checked"':'' ?> /> 单字段
</label>
<label class="radio inline">
<input type="radio" name="visual_timefield_model" id="model-multiple" value="multiple" <?= isset($this->info['visual_timefield_model']) && $this->info['visual_timefield_model']=='multiple' ? 'checked="checked"':'' ?> /> 多字段拼接
</label>
<label class="radio inline">
<input type="radio" name="visual_timefield_model" id="model-custom" value="custom" <?= isset($this->info['visual_timefield_model']) && $this->info['visual_timefield_model']=='custom' ? 'checked="checked"':'' ?>/> 自定义
</label>
<p class="help-block">时间字段支持单字段或者“年月日“字段拼接模式</p>
</div>
</div>
<div class="control-group time-field-select">
<label class="control-label">时间字段</label>
<!-- 单字段 -->
<div class="controls" id="field-time" style="<?= isset($this->info['visual_timefield_model']) && $this->info['visual_timefield_model']!='single' && !empty($this->info['visual_timefield_model']) ? 'display:none':'' ?>">
</div>
<!-- 多字段 -->
<div class="controls" id="field-time-multiple" style="<?= (isset($this->info['visual_timefield_model']) && $this->info['visual_timefield_model']!='multiple') || empty($this->info['visual_timefield_model']) ? 'display:none':'' ?>">
<input type="text" name="visual_timefield_year" placeholder="年字段" value="<?= isset($this->info['visual_timefield_year']) ? $this->info['visual_timefield_year']:'' ?>" /> -
<input type="text" name="visual_timefield_month" placeholder="月字段" value="<?= isset($this->info['visual_timefield_month']) ? $this->info['visual_timefield_month']:'' ?>" /> -
<input type="text" name="visual_timefield_day" placeholder="日字段" value="<?= isset($this->info['visual_timefield_day']) ? $this->info['visual_timefield_day']:'' ?>" />
<p class="help-block">请填写正确的字段名称,如果没有对应字段请留空(<a href="javascript:void(0);" id="open-field-helper">查看字段提示</a>)</p>
</div>
<!-- 自定义 -->
<div class="controls" id="field-time-custom" style="<?= (isset($this->info['visual_timefield_model']) && $this->info['visual_timefield_model']!='custom') || empty($this->info['visual_timefield_model']) ? 'display:none':'' ?>">
<input type="text" name="visual_timefield_custom" placeholder="时间字段读取SQL" class="input-block-level" value="<?= isset($this->info['visual_timefield_custom']) ? $this->info['visual_timefield_custom']:'' ?>" />
<p class="help-block">例如: times , (year||'-'||month||'-1')::timestamp without time zone ,不需要在最外层加括号或者双引号</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputData">数据读取SQL或表名</label>
<div class="controls">
<textarea name="data" rows="4" class="input-block-level" id="inputData"><?= !isset($this->info['data']) ? "":$this->info['data']?></textarea>
<p class="help-block">如果填写了数据表SQL程序将自动从这个SQL</p>
</div>
</div>
@ -88,7 +135,7 @@
<label class="control-label" for="inputValuefilter">过滤值</label>
<div class="controls">
<input type="text" name="visual_valuefilter" class="" id="inputValuefilter" value="<?= !isset($this->info['visual_valuefilter']) ? "":$this->info['visual_valuefilter']?>" />
<p>不予显示的值,仅数字</p>
<p class="help-block">不予显示的值,仅数字</p>
</div>
</div>
@ -142,21 +189,10 @@
return html;
}
$('#addVariable').click(function(e) {
if(null == fieldData)
{
alert('请先选择数据表和时间字段');
return false;
}
if($('#var-group').length > 0)
$('#var-group').append(makeVarSelectHtml(fieldData));
else
$('#last-control-group').prepend(makeVarSelectHtml(fieldData));
});
function delVar(dom){
$(dom).parent().parent().parent('.control-group').remove();
};
$(document).ready(function(){
$('#data-table').change(function(){
$('.var-group').remove();
@ -202,5 +238,73 @@
}
});
<?php } ?>
$('#addVariable').click(function(e) {
if(null == fieldData || $('#data-table').val() == '0')
{
alert('请先选择数据表和时间字段');
return false;
}
if($('#var-group').length > 0)
$('#var-group').append(makeVarSelectHtml(fieldData));
else
$('#last-control-group').prepend(makeVarSelectHtml(fieldData));
});
$('#model-single').change(function(){
if($(this).checked = "checked")
{
$('#field-time').show();
$('#field-time-multiple').hide();
$('#field-time-custom').hide();
}
});
$('#model-multiple').change(function(){
if($(this).checked = "checked")
{
$('#field-time').hide();
$('#field-time-multiple').show();
$('#field-time-custom').hide();
}
});
$('#model-custom').change(function(){
if($(this).checked = "checked")
{
$('#field-time').hide();
$('#field-time-multiple').hide();
$('#field-time-custom').show();
}
});
$('#open-field-helper').click(function(){
if(null == fieldData || $('#data-table').val() == '0')
{
alert('请先选择数据表和时间字段');
return false;
}
$('.modal-body p').html(fieldData.join(','));
$('#modal-show-field').modal('show');
});
});
</script>
<div id="modal-show-field" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">字段列表</h3>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>

View File

@ -27,7 +27,7 @@
<p class="content"><?= $item['description']; ?></p>
<p>
操作:
<a href="/admin/data/visual/uuid/<?php echo $item['uuid'];?>">编辑可视化要素</a> |
<a href="/admin/data/visual/uuid/<?php echo $item['uuid'];?>">编辑可视化要素</a> |
<a href="/visual/view/uuid/<?= $item['uuid'] ?>">前台预览</a>
</p>
</li>

View File

@ -18,8 +18,8 @@ $this->nav[] = array('link'=>"/data/visual",'title'=>'可视化数据列表');
<div class="row-fluid">
<div class="span6">
<div class="btn-group linetypes" data-toggle="buttons-radio">
<button type="button" class="btn active" value="line">折线图</button>
<button type="button" class="btn" value="column">柱状图</button>
<button type="button" class="btn<?= (isset($this->data['visual_type']) && $this->data['visual_type'] == 'line') || empty($this->data['visual_type']) ? " active":"" ?>" value="line">折线图</button>
<button type="button" class="btn<?= isset($this->data['visual_type']) && $this->data['visual_type'] == 'column' ? " active":"" ?>" value="column">柱状图</button>
</div>
</div>
<div class="span6 text-right">
@ -52,6 +52,13 @@ _this = {};
_this.linetype = 'line';
_this.utctimezone = false;
$(function() {
$('.linetypes button').each(function(){
if($(this).hasClass('active'))
{
_this.linetype = $(this).val();
}
});
$('.linetypes button').click(function(e) {
_this.linetype = $(this).val();
@ -89,7 +96,7 @@ $(function() {
week: '%Y<br/>%m-%d',
month: '%Y-%m',
year: '%Y'
},
}
},

View File

@ -4,10 +4,9 @@ namespace Westdc\Visual;
class Record extends Database
{
public $subdataset;
public $subdataset,$valueFilter;
public $timeFiled = "utctime";
public $valueFilter;
private $sql;
@ -37,10 +36,51 @@ class Record extends Database
$var_data = $visual->getVisualVars($uuid);
$this->timeFiled = $var_data['visual_timefield'];
$this->valueFilter = (float)$var_data['visual_valuefilter'];
$this->sql = $this->makeSql($var_data['visual_datatable'],$this->subdataset);
if(!empty($var_data['visual_valuefilter']))
$this->valueFilter = (float)$var_data['visual_valuefilter'];
if($var_data['visual_timefield_model'] == 'single') {
$this->timeFiled = '"' . $var_data['visual_timefield'] . '"';
}//single
elseif($var_data['visual_timefield_model'] == 'multiple'){
$timefield_temp = "(";
if(!empty($var_data['visual_timefield_year']))
{
$timefield_temp .= $var_data['visual_timefield_year'] . "::character varying||";
}
$timefield_temp .= "'-'";
if(!empty($var_data['visual_timefield_month']))
{
$timefield_temp .= "||".$var_data['visual_timefield_month']."::character varying||";
}else{
$timefield_temp .= '1';
}
$timefield_temp .= "'-";
if(!empty($var_data['visual_timefield_day']))
{
$timefield_temp .= "'||".$var_data['visual_timefield_day'] . '::character varying';
}else{
$timefield_temp .= "1'";
}
$timefield_temp .= ")";
$timefield_temp .= "::timestamp without time zone";
$this->timeFiled = $timefield_temp;
}//multiple
elseif($var_data['visual_timefield_model'] == 'custom'){
$this->timeFiled = $var_data['visual_timefield_model'];
}//custom
if(isset($var_data['data']) && !empty($var_data['data']))
$this->sql = $this->makeSql($var_data['data'],$this->subdataset);
else
$this->sql = $this->makeSql($var_data['visual_datatable'],$this->subdataset);
//echo $this->sql;exit();
}
@ -82,12 +122,12 @@ class Record extends Database
FROM $table as tbl
$wheresql
ORDER BY
extract(YEAR from \"{$this->timeFiled}\") ASC,
extract(MONTH from \"{$this->timeFiled}\") ASC,
extract(DAY from \"{$this->timeFiled}\") ASC,
extract(HOUR from \"{$this->timeFiled}\") ASC,
extract(MINUTE from \"{$this->timeFiled}\") ASC,
extract(SECOND from \"{$this->timeFiled}\") ASC
extract(YEAR from {$this->timeFiled}) ASC,
extract(MONTH from {$this->timeFiled}) ASC,
extract(DAY from {$this->timeFiled}) ASC,
extract(HOUR from {$this->timeFiled}) ASC,
extract(MINUTE from {$this->timeFiled}) ASC,
extract(SECOND from {$this->timeFiled}) ASC
";
return $sql;