增加了三江源自平台的数据可是化管理功能和展示功能

This commit is contained in:
Li Jianxuan 2014-06-11 08:38:38 +00:00
parent 0eeba0747c
commit 97402e262d
10 changed files with 3680 additions and 3314 deletions

View File

@ -2,6 +2,7 @@
use Helpers\View as view;
use Helpers\dbh;
use \Files\Files;
use \Westdc\Visual;
class Admin_DataController extends Zend_Controller_Action
{
@ -2633,6 +2634,7 @@ class Admin_DataController extends Zend_Controller_Action
}//fund
//数据可是化管理
public function visualAction()
{
$uuid = $this->_getParam('uuid');
@ -2640,12 +2642,40 @@ class Admin_DataController extends Zend_Controller_Action
if(!empty($uuid))
{
$visual = new Visual\Visual;
$this->_helper->viewRenderer('visual-add');
$this->view->data = ['uuid' => $uuid];
if(empty($submit))
{
$data = $visual->getVisualVars($uuid);
if(!empty($data))
{
$this->view->info = $data;
}
return true;
}
$data = array(
'uuid' => $this->_getParam('uuid'),
'vars' => $this->_getParam('var'),
'data' => $this->_getParam('data'),
'status' => $this->_getParam('status')
);
$status = $visual->add($data);
if($status === true)
{
view::Post($this,"添加成功!",-2);
return true;
}else{
$this->view->error = $status;
return true;
}
}
}

View File

@ -16,21 +16,72 @@
<div class="span9">
<h3>添加可视化要素</h3>
<hr />
<form class="form-horizontal">
<?php if(!empty($this->error)) {?>
<div class="alert alert-error">
<?= $this->error ?>
</div>
<?php }?>
<form class="form-horizontal" method="post" action="">
<div class="control-group">
<label class="control-label" for="inputUUID">UUID</label>
<div class="controls">
<input type="text" id="inputUUID" placeholder="UUID" value="<?= $this->data['uuid'] ?>" class="input-block-level">
<input type="text" id="inputUUID" placeholder="UUID" value="<?= $this->data['uuid'] ?>" class="input-block-level" name="uuid">
</div>
</div>
<div class="control-group">
<label class="control-label">状态</label>
<div class="controls">
<label class="radio inline">
<?php $checked = function(){
if(isset($this->info['status']))
{
if($this->info['status'] == 1)
{
return 'checked="checked"';
}
}else{
return 'checked="checked"';
}
}; ?>
<input type="radio" name="status" id="optionsRadios1" value="1" <?= $checked() ?>>
启用
</label>
<label class="radio inline">
<input type="radio" name="status" id="optionsRadios2" value="0"
<?= isset($this->info['status']) && $this->info['status'] == 0 ? 'checked="checked"':"" ?>>
禁用
</label>
</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>
</div>
</div>
<?php if(empty($this->info['vars'])) { ?>
<div class="control-group">
<label class="control-label" for="inputVariable">可视化要素</label>
<div class="controls">
<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level">
<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level" name="var[]">
</div>
</div>
<?php }else{ ?>
<?php $vars = array() ?>
<?php $encoder = new \Westdc\Visual\VariableEncoder; ?>
<?php $vars = $encoder->decode($this->info['vars']);?>
<?php foreach($vars as $k=>$v) { ?>
<div class="control-group">
<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>
<div class="controls">
<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level" name="var[]" value="<?= $v ?>">
</div>
</div>
<?php } ?>
<?php } ?>
<div class="control-group" id="last-control-group">
<div class="controls">
<input type="hidden" name="submit" value="1" />
<button type="button" class="btn btn-defualt" id="addVariable">添加要素</button>
<button type="submit" class="btn btn-primary">提交</button>
</div>
@ -40,12 +91,15 @@
</div>
<script type="text/javascript">
$('#addVariable').click(function(e) {
html = '<div class="control-group">
<label class="control-label" for="inputVariable">可视化要素</label>
<div class="controls">
<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level">
</div>
</div>';
$('#last-control-group').prepend();
html = '<div class="control-group">'
+ '<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>'
+ '<div class="controls">'
+ '<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level" name="var[]">'
+ '</div>'
+'</div>';
$('#last-control-group').prepend(html);
});
function delVar(dom){
$(dom).parent().parent().parent('.control-group').remove();
}
</script>

View File

@ -598,6 +598,9 @@ class DataController extends Zend_Controller_Action
$fund = new Fund($this->db);
$this->view->fund = $fund->fetch($uuid);
$visual = new \Westdc\Visual\Visual;
$this->view->visual = $visual->getVisualVars($uuid);
//判断特殊数据服务
$this->view->dataService= $this->checkDataService($uuid);
@ -2227,5 +2230,13 @@ order by m.title";
$this->view->westee=$this->db->fetchAll($sql);
}
//可视化数据
public function visualAction()
{
$visual = new \Westdc\Visual\Visual;
view::addPaginator($visual->getVisualMetadata(),$this,10);
return true;
}
}

View File

@ -1,5 +1,7 @@
<?php
use Westdc\Visual\Factory;
use Westdc\Visual;
use Westdc\Metadata;
use Helpers\View as view;
class VisualController extends Zend_Controller_Action
{
@ -45,25 +47,56 @@ class VisualController extends Zend_Controller_Action
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$uuid = $this->_getParam("uuid");
$record_type = $this->_getParam("dataset");
$record_subset = $this->_getParam("subdataset");
if(empty($record_type))
return true;
$record = Factory::Bootstrap($record_type);
$record = new Visual\Record($uuid,$record_subset);
//$record = Visual\Factory::Bootstrap($record_type);
if(!empty($record_subset))
{
$record->subset = $record_subset;
}
$data = $record->outPut();
$data = $record();
$this->jsonexit($data);
return true;
}//dataAction() Ajax获取数据
//viewAction
public function viewAction()
{
$uuid = $this->_getParam('uuid');
if(empty($uuid) || \Helpers\Uuid::test($uuid) == false)
{
view::Post($this,"参数错误",-1);
return;
}
$visual = new Visual\Visual;
$this->view->data = $visual->getVisualVars($uuid);
if(empty($this->view->data))
{
view::Post($this,"此数据不支持可视化",-1);
return;
}
$metadata = new Metadata\Metadata;
$this->view->info = $metadata->view($uuid);
}
/*
* jsonexit() 退出并返回json数据

View File

@ -7,7 +7,7 @@
$this->breadcrumb('<a href="/data">'.$this->config->title->data.'</a>');
$this->breadcrumb('查看元数据');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'google_map_v3');
//$this->theme->AppendPlus($this,'google_map_v3');
$this->theme->AppendPlus($this,'colorbox');
if(!empty($this->dataService)) {
$this->theme->AppendModel($this,"dataservice");
@ -402,9 +402,16 @@ endforeach;
放入数据篮
</a>
<?php endif;endif; ?>
<?php if(isset($this->visual['vars'])) { ?>
<a href="/visual/view/uuid/<?= $md->uuid ?>" class="btn btn-block" title="此数据支持在线可视化查看">
可视化查看
</a>
<?php } ?>
<!--
<a href="javascript:void(0);" class="btn btn-block" title="喜欢此数据可以将它放到收藏夹中下次浏览">
收藏此数据
</a>
-->
</div>
</div>
<hr />
@ -491,8 +498,15 @@ endforeach;
</div>
<script src="/js/metadata-view.js"></script>
<script type="text/javascript" charset="utf-8">
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
$(function() {
google.maps.event.addDomListener(window, 'load', initialize);
//google.maps.event.addDomListener(window, 'load', initialize);
$(".colorbox").colorbox({photo:"true"});
$('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');});
$('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');});

View File

@ -0,0 +1,37 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->data);
if (!empty($this->codename)) $this->headTitle($this->codename);
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/metadata.css');
$this->nav[] = array('link'=>"/data/visual",'title'=>'可视化数据列表');
$this->theme->AppendPlus($this,'colorbox');
?>
<div class="row-fluid">
<?= $this->render('breadcrumbs.phtml') ?>
<?= $this->partial('data/tools.phtml'); ?>
</div>
<?php if (!empty($this->paginator)) : ?>
<div id='metacontent'>
<?php echo $this->paginator; ?>
<hr />
<?php foreach($this->paginator as $md) : ?>
<div class="mditem">
<div class="thumb">
<a href="/service/bigthumb/uuid/<?= $md['uuid'] ?>" class="colorbox">
<img src="/service/thumb/id/<?php echo $md['id'];?>" />
</a>
</div>
<h2><a href="/data/<?php echo $md['uuid']; ?>"><?php echo $this->escape($md['title']);?></a></h2>
<span><?php echo mb_strlen($md['description'])>400?$this->escape(mb_substr($md['description'],0,400,'UTF-8').'...'):$this->escape($md['description']);?></span>
</div>
<?php endforeach; ?>
<?php echo $this->paginator; ?>
</div>
<?php endif; ?>
<script>
$(document).ready(function(){
$(".colorbox").colorbox({rel:"colorbox",photo:"true",transition:"fade"});
$(".colorbox").colorbox({photo:"true"});
});
</script>

View File

@ -17,7 +17,12 @@
{
$user = $auth->getIdentity();
echo '<a href="/account"><i class="icon-user"></i> '.$user->username.'</a> ';
if ($user->usertype=="administrator") echo '<a href="/admin"><i class="icon-cog"></i> 后台 </a><a href="/data/order"><i class="icon-shopping-cart"></i> 数据篮 </a> <a href="/account/logout">退出</a> ';
if ($user->usertype=="administrator")
{
echo '<a href="/admin"><i class="icon-cog"></i> 后台 </a>';
}
echo '<a href="/data/order"><i class="icon-shopping-cart"></i> 数据篮 </a>';
echo '<a href="/account/logout">退出</a>';
} else {
echo '<a href="/account/login">登 录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="/account/register">注 册</a>';
} ?>

View File

@ -0,0 +1,106 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->data);
$this->headTitle()->setSeparator(' - ');
$theme = new Theme;
$theme->appendPlus($this,'highstock');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/data">数据与服务</a>');
$this->breadcrumb('数据可视化');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row">
<div class="span12">
<h3><?= $this->info['title'] ?> <small>数据可视化查看</small></h3>
<h4><small>请在需要查看的可视化要素上点击以描绘图表,再次点击可取消显示</small></h4>
<hr />
<?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['vars']);?>
<?php foreach($vars as $k=>$v) { ?>
<a class="btn btn-default control-btn" href="javascript:void(0);" data-dataset="<?= $v['dataset'] ?>" data-subdataset="<?= $v['subdataset'] ?>" data-seriename="<?= $v['seriename'] ?>">
<?= $v['seriename'] ?>
</a>
<?php } ?>
</div>
<!-- 页面内容 -->
<div class="span12">
<div id="datachart" style="width:100%;height:500px;"></div>
<a class="btn btn-primary control-btn-cls" href="javascript:void(0);">
清除图像
</a>
</div>
<!-- //页面内容 -->
</div>
<script>
_this = {};
$(function() {
$('#datachart').highcharts('StockChart', {
rangeSelector : {
selected : 1,
inputEnabled: $('#container').width() > 480
},
credits : {
enabled : false
}
});
var chart = $('#datachart').highcharts();
$(".control-btn").click(function(){
uuid = '<?= $this->info['uuid'] ?>';
dataset = $(this).data('dataset');
subdataset = $(this).data('subdataset');
seriename = $(this).data('seriename');
for(i in chart.series)
{
if(chart.series[i].name == seriename)
{
chart.series[i].remove();
return;
}
}
$.ajax({
'url': '/visual/data',
'data': 'uuid=' + uuid + '&dataset=' + dataset + '&subdataset=' + subdataset,
'method': 'GET',
'dataType': 'json',
'success': function(data){
chart.addSeries({
name: seriename,
data: data,
type : 'column'
});
},
'timeout': 30000,
'global' : true
});
});
$(".control-btn-cls").click(function(e) {
for(i in chart.series)
{
chart.series[i].remove();
}
});
});
$( document ).ajaxSend(function() {
$('#loading').css('display','none');
});
$( document ).ajaxSend(function() {
$('#loading').css('display','block');
});
$( document ).ajaxSend(function() {
$('#loading').css('display','none');
});
</script>

View File

@ -0,0 +1,48 @@
<?php
namespace Helpers;
// 三段
// 一段是微秒 一段是地址 一段是随机数
class Uuid
{
private $valueBeforeMD5;
private $valueAfterMD5;
function __construct()
{
$address = $this->getLocalHost();
$this->valueBeforeMD5 = $address.':'.$this->currentTimeMillis().':'.$this->nextLong();
$this->valueAfterMD5 = md5($this->valueBeforeMD5);
}
function toString()
{
$raw = strtoupper($this->valueAfterMD5);
return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);
}
private function nextLong()
{
$tmp = rand(0,1)?'-':'';
return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);
}
private function currentTimeMillis()
{
list($usec, $sec) = explode(" ",microtime());
return $sec.substr($usec, 2, 3);
}
private function getLocalHost()
{
$address = isset($_ENV["COMPUTERNAME"]) ? $_ENV["COMPUTERNAME"]."/":"".'/';
$address.= $_SERVER["SERVER_ADDR"];
return strtolower($address);
}
static function test($uuid)
{
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
return false;
}else{
return true;
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Westdc\Metadata;
class Metadata
{
private $db; //传入PDO对象.
//使用到的公共变量
public $tbl_metadata = "metadata";
function __construct()
{
$this->db = \Zend_Registry::get('db');
}
function view($uuid)
{
if(\Helpers\Uuid::test($uuid) !== true)
{
return "参数错误";
}
$sql = "SELECT * FROM ".$this->tbl_metadata." WHERE uuid='$uuid'";
$rs = $this->db->query($sql);
return $rs->fetch();
}
}