#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)) if(empty($id) || !is_numeric($id))
{ {
$data = array("error"=>"参数错误"); $data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
@ -1593,11 +1593,11 @@ class AuthorController extends Zend_Controller_Action
if($ex) if($ex)
{ {
$data = array("deleted"=>$id,"error"=>$this->alertbox('ok','删除成功')); $data = array("deleted"=>$id,"error"=>$this->alertbox('ok','删除成功'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
}else{ }else{
$data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试')); $data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
}catch(Exception $e) { }catch(Exception $e) {
@ -1605,7 +1605,7 @@ class AuthorController extends Zend_Controller_Action
if($this->debug>0) if($this->debug>0)
{$msg .= $e->getMessage();} {$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg)); $data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
} }
@ -1622,14 +1622,14 @@ class AuthorController extends Zend_Controller_Action
if(empty($id) || !is_numeric($id)) if(empty($id) || !is_numeric($id))
{ {
$data = array("error"=>"参数错误"); $data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
$db = Zend_Db::factory('Pdo_Pgsql', array( $db = Zend_Db::factory('Pdo_Pgsql', array(
'host' => 'localhost', 'host' => 'localhost',
'username' => 'postgres', 'username' => 'postgres',
'password' => '************************************', 'password' => '.yy3228899',
'dbname' => 'geonetwork', 'dbname' => 'geonetwork',
'persistent' => true 'persistent' => true
)); ));
@ -1650,7 +1650,7 @@ class AuthorController extends Zend_Controller_Action
if($row['xml']==$row_geo['data']) if($row['xml']==$row_geo['data'])
{ {
$data = array("error"=>$this->alertbox('warning','恢复失败,目前两个版本中的内容相同')); $data = array("error"=>$this->alertbox('warning','恢复失败,目前两个版本中的内容相同'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
@ -1661,11 +1661,11 @@ class AuthorController extends Zend_Controller_Action
if($ex) if($ex)
{ {
$data = array("error"=>$this->alertbox('ok','恢复成功')); $data = array("error"=>$this->alertbox('ok','恢复成功'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
}else{ }else{
$data = array("error"=>$this->alertbox('error','恢复失败,请确认权限后重试')); $data = array("error"=>$this->alertbox('error','恢复失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
}catch(Exception $e) { }catch(Exception $e) {
@ -1673,7 +1673,7 @@ class AuthorController extends Zend_Controller_Action
if($this->debug>0) if($this->debug>0)
{$msg .= $e->getMessage();} {$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg)); $data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
} }
@ -1690,7 +1690,7 @@ class AuthorController extends Zend_Controller_Action
if(empty($id) || !is_numeric($id)) if(empty($id) || !is_numeric($id))
{ {
$data = array("error"=>"参数错误"); $data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
@ -1706,7 +1706,7 @@ class AuthorController extends Zend_Controller_Action
if(!empty($row['id'])) if(!empty($row['id']))
{ {
$data = array("error"=>$this->alertbox('warning','该数据已经在评审中,请勿重复提交')); $data = array("error"=>$this->alertbox('warning','该数据已经在评审中,请勿重复提交'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
@ -1724,11 +1724,11 @@ class AuthorController extends Zend_Controller_Action
if($ex) if($ex)
{ {
$data = array("error"=>$this->alertbox('ok','提交成功!')); $data = array("error"=>$this->alertbox('ok','提交成功!'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
}else{ }else{
$data = array("error"=>$this->alertbox('error','提交失败,请确认权限后重试')); $data = array("error"=>$this->alertbox('error','提交失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $this->jsonexit($data);
return true; return true;
} }
@ -1737,16 +1737,54 @@ class AuthorController extends Zend_Controller_Action
if($this->debug>0) if($this->debug>0)
{$msg .= $e->getMessage();} {$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg)); $data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); $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; 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) private function author_first($uuid,$author)
{ {
@ -1768,6 +1806,20 @@ class AuthorController extends Zend_Controller_Action
$sth->execute(array($author,$uuid)); $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){ public function alertbox($type='',$body){
if($type == "error") 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>