#318 增加了与前一个版本对比的功能

This commit is contained in:
Li Jianxuan 2012-03-28 03:38:22 +00:00
parent 0752c8fce5
commit 9b6155333e
2 changed files with 153 additions and 30 deletions

View File

@ -1580,7 +1580,7 @@ class AuthorController extends Zend_Controller_Action
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
$this->jsonexit($data);
return true;
}
@ -1593,20 +1593,20 @@ class AuthorController extends Zend_Controller_Action
if($ex)
{
$data = array("deleted"=>$id,"error"=>$this->alertbox('ok','删除成功'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}else{
$data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
}catch(Exception $e) {
$msg = "删除失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
}
@ -1622,14 +1622,14 @@ class AuthorController extends Zend_Controller_Action
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
$this->jsonexit($data);
return true;
}
$db = Zend_Db::factory('Pdo_Pgsql', array(
'host' => 'localhost',
'username' => 'postgres',
'password' => '************************************',
'password' => '.yy3228899',
'dbname' => 'geonetwork',
'persistent' => true
));
@ -1650,8 +1650,8 @@ class AuthorController extends Zend_Controller_Action
if($row['xml']==$row_geo['data'])
{
$data = array("error"=>$this->alertbox('warning','恢复失败,目前两个版本中的内容相同'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
$sql = "UPDATE metadata SET data=? WHERE uuid=?";
@ -1661,20 +1661,20 @@ class AuthorController extends Zend_Controller_Action
if($ex)
{
$data = array("error"=>$this->alertbox('ok','恢复成功'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}else{
$data = array("error"=>$this->alertbox('error','恢复失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
}catch(Exception $e) {
$msg = "恢复失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
}
@ -1690,7 +1690,7 @@ class AuthorController extends Zend_Controller_Action
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
$this->jsonexit($data);
return true;
}
@ -1706,7 +1706,7 @@ class AuthorController extends Zend_Controller_Action
if(!empty($row['id']))
{
$data = array("error"=>$this->alertbox('warning','该数据已经在评审中,请勿重复提交'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
$this->jsonexit($data);
return true;
}
@ -1724,12 +1724,12 @@ class AuthorController extends Zend_Controller_Action
if($ex)
{
$data = array("error"=>$this->alertbox('ok','提交成功!'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}else{
$data = array("error"=>$this->alertbox('error','提交失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
}catch(Exception $e) {
@ -1737,15 +1737,53 @@ class AuthorController extends Zend_Controller_Action
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
$this->jsonexit($data);
return true;
}
}//发布到评审
//与前一个版本对比
else if($ac == "diff")
{
$this->_helper->viewRenderer('version-diff');
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$this->view->error = "参数错误";
return true;
}
$sql = "SELECT v.uuid,md.title FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.uuid
LEFT JOIN metadata md ON v.uuid=md.uuid
WHERE v.id=? AND a.userid=?";
$sth = $this->db->prepare($sql);
$sth -> execute(array($id,$u_id));
$row = $sth->fetch();
$sql = "SELECT v.* FROM mdversion v
WHERE v.uuid=?
ORDER BY v.ts_created DESC
LIMIT ?";
$sth = $this->db->prepare($sql);
$sth -> execute(array($row['uuid'],2));
$rows = $sth->fetchAll();
if(count($rows)<2)
{
$this->view->error = "对比失败:之前没有版本可以对比";
return true;
}
$this->view->info = $row;
$this->view->data = $rows;
}
}// versionAction() 数据版本管理
}// versionAction() 数据版本管理
//成为作者后的后继处理工作
private function author_first($uuid,$author)
@ -1768,6 +1806,20 @@ class AuthorController extends Zend_Controller_Action
$sth->execute(array($author,$uuid));
}
/*
* jsonexit() 退出并返回json数据
*
* param array $data 要返回的JSON数据可以是任意数组
*
* return JSON-response
*/
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}//jsonexit() 退出并返回json数据
//ajax 提示框
public function alertbox($type='',$body){
if($type == "error")
{

View File

@ -0,0 +1,71 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/js/diffview.js');
$this->headScript()->appendFile('/js/difflib.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/diffview.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('查看数据作者');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<div id="tabs-controller">
<ul>
<li class="box-shadow"><a class="text-shadow" href="/author/version">所有版本概况</a></li>
<li class="box-shadow"><a class="text-shadow" href="/author/version/ac/bydata">逐数据浏览</a></li>
</ul>
</div>
<?php
if(!empty($this->error))
{
echo $this->error;
}
else
{?>
<h2><?php echo $this->info['title'];?></h2>
<div id="diffoutput" style="width:100%"> </div>
<textarea id="basetext" style="display:none;"><?php echo $this->data[1]['xml'];?></textarea>
<textarea id="newtext" style="display:none;"><?php echo $this->data[0]['xml'];?></textarea>
<?php
}
?>
</div>
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
function diffUsingJS() {
var base = difflib.stringAsLines($('#basetext').val());
var newtxt = difflib.stringAsLines($('#newtext').val());
var sm = new difflib.SequenceMatcher(base, newtxt);
var opcodes = sm.get_opcodes();
$("#diffoutput").append(diffview.buildView({
baseTextLines: base,
newTextLines: newtxt,
opcodes: opcodes,
// set the display titles for each resource
baseTextName: "<?php echo date("Y-m-d H:i",strtotime($this->data[1]['ts_created'])); ?>",
newTextName: "<?php echo date("Y-m-d H:i",strtotime($this->data[0]['ts_created'])); ?>",
contextSize: null,
viewType: 0
}));
}
diffUsingJS();
</script>