* Modify diff editor page.
This commit is contained in:
+85
-32
@@ -277,19 +277,21 @@ class repo extends control
|
||||
$info = $this->scm->info($entry, $nRevision);
|
||||
$path = $entry ? $info->path : '';
|
||||
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->diff;
|
||||
$this->view->type = 'diff';
|
||||
$this->view->encoding = str_replace('-', '_', $encoding);
|
||||
$this->view->repoID = $repoID;
|
||||
$this->view->objectID = $objectID;
|
||||
$this->view->repo = $repo;
|
||||
$this->view->revision = $nRevision;
|
||||
$this->view->file = $file;
|
||||
$this->view->content = '';
|
||||
$this->view->pathInfo = $pathInfo;
|
||||
$this->view->suffix = 'c';
|
||||
$this->view->blames = array();
|
||||
$this->view->showEditor = true;
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->diff;
|
||||
$this->view->type = 'diff';
|
||||
$this->view->encoding = str_replace('-', '_', $encoding);
|
||||
$this->view->repoID = $repoID;
|
||||
$this->view->objectID = $objectID;
|
||||
$this->view->repo = $repo;
|
||||
$this->view->revision = $nRevision;
|
||||
$this->view->oldRevision = $revision;
|
||||
$this->view->file = $file;
|
||||
$this->view->entry = $entry;
|
||||
$this->view->content = '';
|
||||
$this->view->pathInfo = $pathInfo;
|
||||
$this->view->suffix = 'c';
|
||||
$this->view->blames = array();
|
||||
$this->view->showEditor = true;
|
||||
$this->display('repo', 'ajaxGetEditorContent');
|
||||
}
|
||||
|
||||
@@ -321,7 +323,6 @@ class repo extends control
|
||||
$pathInfo = pathinfo($entry);
|
||||
$encoding = empty($encoding) ? $repo->encoding : $encoding;
|
||||
$encoding = strtolower(str_replace('_', '-', $encoding));
|
||||
$blames = $this->scm->blame($entry, $revision);
|
||||
|
||||
$suffix = '';
|
||||
if(isset($pathInfo["extension"])) $suffix = strtolower($pathInfo["extension"]);
|
||||
@@ -336,24 +337,24 @@ class repo extends control
|
||||
$content = helper::convertEncoding($content, $encoding);
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->view;
|
||||
$this->view->type = 'view';
|
||||
$this->view->showBug = $showBug;
|
||||
$this->view->encoding = str_replace('-', '_', $encoding);
|
||||
$this->view->repoID = $repoID;
|
||||
$this->view->branchID = $this->cookie->repoBranch;
|
||||
$this->view->objectID = $objectID;
|
||||
$this->view->repo = $repo;
|
||||
$this->view->revision = $revision;
|
||||
$this->view->file = $file;
|
||||
$this->view->entry = $entry;
|
||||
$this->view->path = $entry;
|
||||
$this->view->info = $info;
|
||||
$this->view->suffix = $suffix;
|
||||
$this->view->content = $content ? $content : '';
|
||||
$this->view->pathInfo = $pathInfo;
|
||||
$this->view->blames = $blames ? $blames : array();
|
||||
$this->view->showEditor = (strpos($this->config->repo->images, "|$suffix|") === false and $suffix != 'binary') ? true : false;
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->view;
|
||||
$this->view->type = 'view';
|
||||
$this->view->showBug = $showBug;
|
||||
$this->view->encoding = str_replace('-', '_', $encoding);
|
||||
$this->view->repoID = $repoID;
|
||||
$this->view->branchID = $this->cookie->repoBranch;
|
||||
$this->view->objectID = $objectID;
|
||||
$this->view->repo = $repo;
|
||||
$this->view->revision = $revision;
|
||||
$this->view->oldRevision = $revision;
|
||||
$this->view->file = $file;
|
||||
$this->view->entry = $entry;
|
||||
$this->view->path = $entry;
|
||||
$this->view->info = $info;
|
||||
$this->view->suffix = $suffix;
|
||||
$this->view->content = $content ? $content : '';
|
||||
$this->view->pathInfo = $pathInfo;
|
||||
$this->view->showEditor = (strpos($this->config->repo->images, "|$suffix|") === false and $suffix != 'binary') ? true : false;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -1902,4 +1903,56 @@ class repo extends control
|
||||
$this->view->objectType = $objectType;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax get commit info.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetCommitInfo()
|
||||
{
|
||||
$line = $this->post->line;
|
||||
$repo = $this->repo->getRepoByID($this->post->repoID);
|
||||
$entry = $this->repo->decodePath($this->post->entry);
|
||||
$revision = $this->post->revision;
|
||||
$returnType = $this->post->returnType ? $this->post->returnType : 'view';
|
||||
|
||||
$this->scm->setEngine($repo);
|
||||
$blames = $this->scm->blame($entry, $this->post->revision);
|
||||
if(!$blames) $blames =$this->scm->blame($entry, $this->post->sourceRevision);
|
||||
|
||||
while($line > 0)
|
||||
{
|
||||
if(isset($blames[$line]['revision']))
|
||||
{
|
||||
$revision = $blames[$line]['revision'];
|
||||
break;
|
||||
}
|
||||
$line--;
|
||||
}
|
||||
if($returnType == 'json') return $this->send(array('result' => 'success', 'blames' => $blames));
|
||||
|
||||
$commits = $this->scm->getCommits($revision, 1);
|
||||
if(!empty($commits['commits'][$revision]))
|
||||
{
|
||||
$commit = $commits['commits'][$revision];
|
||||
|
||||
$objects = $this->repo->getLinkedObjects($commit->comment);
|
||||
$stories = $this->dao->select('id,title')->from(TABLE_STORY)->where('deleted')->eq(0)->andWhere('id')->in($objects['stories'])->fetchPairs();
|
||||
$tasks = $this->dao->select('id,name')->from(TABLE_TASK)->where('deleted')->eq(0)->andWhere('id')->in($objects['tasks'])->fetchPairs();
|
||||
$bugs = $this->dao->select('id,title')->from(TABLE_BUG)->where('deleted')->eq(0)->andWhere('id')->in($objects['bugs'])->fetchPairs();
|
||||
|
||||
$this->view->repoID = $this->post->repoID;
|
||||
$this->view->commit = $commit;
|
||||
$this->view->stories = $stories;
|
||||
$this->view->tasks = $tasks;
|
||||
$this->view->bugs = $bugs;
|
||||
$this->display();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ function createTab(filename, filepath)
|
||||
$(document).ready(function()
|
||||
{
|
||||
var diffAppose = true;
|
||||
$('#appose').hide();
|
||||
$('.dropdown #appose').hide();
|
||||
|
||||
if(browser == 'ie')
|
||||
if(!browser || browser == 'ie')
|
||||
{
|
||||
$("#inline").click(function(){$('#arrange').val('inline');this.form.submit();});
|
||||
$("#appose").click(function(){$('#arrange').val('appose');this.form.submit();});
|
||||
@@ -163,11 +163,11 @@ $(document).ready(function()
|
||||
diffAppose = !diffAppose;
|
||||
if(diffAppose)
|
||||
{
|
||||
$('#inline').show();
|
||||
$('.dropdown #inline').show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#appose').show();
|
||||
$('.dropdown #appose').show();
|
||||
}
|
||||
var type = $(this).attr('id');
|
||||
var tabID = $('.tab-nav-item.active').data('id');
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<div id='commit-box' class='open'>
|
||||
<div class='dropdown-menu commit-show'>
|
||||
<div class='commit-title'><?php echo $lang->repo->commitInfo;?></div>
|
||||
<table>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $lang->repo->revisionA;?></th>
|
||||
<td><?php echo html::a($this->repo->createLink('revision', "repoID=$repoID&objectID=0&revision={$commit->revision}"), substr($commit->revision, 0, 10));?></td>
|
||||
</tr>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $lang->repo->committer;?></th>
|
||||
<td><?php echo $commit->committer;?></td>
|
||||
</tr>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $lang->repo->comment;?></th>
|
||||
<td title='<?php echo $commit->comment;?>'><?php echo $commit->comment;?></td>
|
||||
</tr>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $lang->repo->time;?></th>
|
||||
<td><?php echo $commit->time;?></td>
|
||||
</tr>
|
||||
<?php $storyIndex = $taskIndex = $bugIndex = 1;?>
|
||||
<?php $canViewStory = common::hasPriv('story', 'view');?>
|
||||
<?php $canViewTask = common::hasPriv('task', 'view');?>
|
||||
<?php $canViewBug = common::hasPriv('bug', 'view');?>
|
||||
<?php foreach($stories as $storyID => $storyTitle):?>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $storyIndex == 1 ? $lang->repo->linkedStory : '';?></th>
|
||||
<td><?php echo $canViewStory ? html::a($this->createLink('story', 'view', "storyID=$storyID"), "#$storyID $storyTitle") : "#$storyID $storyTitle";?></td>
|
||||
</tr>
|
||||
<?php $storyIndex++;?>
|
||||
<?php endforeach;?>
|
||||
<?php foreach($tasks as $taskID => $taskName):?>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $taskIndex == 1 ? $lang->repo->linkedTask : '';?></th>
|
||||
<td><?php echo $canViewTask ? html::a($this->createLink('task', 'view', "taskID=$taskID"), "#$taskID $taskName") : "#$taskID $taskName";?></td>
|
||||
</tr>
|
||||
<?php $taskIndex++;?>
|
||||
<?php endforeach;?>
|
||||
<?php foreach($bugs as $bugID => $bugTitle):?>
|
||||
<tr class='empty'>
|
||||
<th><?php echo $bugIndex == 1 ? $lang->repo->linkedBug : '';?></th>
|
||||
<td><?php echo $canViewBug ? html::a($this->createLink('bug', 'view', "bugID=$bugID"), "#$bugID $bugTitle") : "#$bugID $bugTitle";?></td>
|
||||
</tr>
|
||||
<?php $bugIndex++;?>
|
||||
<?php endforeach;?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -28,11 +28,10 @@ js::set('canLinkTask', $canLinkTask);
|
||||
js::set('objectID', 0);
|
||||
js::set('objectType', 'story');
|
||||
js::set('pageType', $type);
|
||||
if($showEditor)
|
||||
{
|
||||
js::set('codeContent', $content);
|
||||
js::set('blames', $blames);
|
||||
}
|
||||
js::set('revision', $revision);
|
||||
js::set('sourceRevision', $oldRevision);
|
||||
js::set('encodePath', $this->repo->encodePath($entry));
|
||||
if($showEditor) js::set('codeContent', $content);
|
||||
js::import($jsRoot . '/zui/tabs/tabs.min.js');
|
||||
js::import($jsRoot . 'monaco-editor/min/vs/loader.js');
|
||||
?>
|
||||
@@ -81,6 +80,7 @@ js::import($jsRoot . 'monaco-editor/min/vs/loader.js');
|
||||
<?php include '../../common/view/footer.lite.html.php';?>
|
||||
<script>
|
||||
var editor = null;
|
||||
var blames = null;
|
||||
var globalCommit = '';
|
||||
var codeHeight = $(window).innerHeight() - $('#mainHeader').height() - $('#appsBar').height() - $('#fileTabs .tabs-navbar').height();
|
||||
if(codeHeight > 0) $.cookie('codeContainerHeight', codeHeight);
|
||||
@@ -182,6 +182,31 @@ function updateEditorInline(display){
|
||||
editor.updateOptions({renderSideBySide: display});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show commit info.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function showCommitInfo()
|
||||
{
|
||||
var link = createLink('repo', 'ajaxGetCommitInfo');
|
||||
var data = {
|
||||
repoID : repoID,
|
||||
entry : encodePath,
|
||||
revision : revision,
|
||||
sourceRevision: sourceRevision,
|
||||
line : 0,
|
||||
returnType : 'json'
|
||||
};
|
||||
|
||||
$.post(link, data, function(res)
|
||||
{
|
||||
res = JSON.parse(res);
|
||||
blames = res.blames;
|
||||
})
|
||||
}
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.btn-left').click(function() {arrowTabs('relationTabs', 1);});
|
||||
@@ -206,10 +231,11 @@ $(function()
|
||||
if(ext.indexOf('.' + file.extension) !== -1) lang = langName;
|
||||
});
|
||||
|
||||
var diffContent = null;
|
||||
if(pageType == 'diff')
|
||||
{
|
||||
var diffContent = parent.getDiffs(file.dirname + '/' + file.basename);
|
||||
editor = monaco.editor.createDiffEditor(document.getElementById('codeContainer'),
|
||||
diffContent = parent.getDiffs(file.dirname + '/' + file.basename);
|
||||
var modifiedEditor = monaco.editor.createDiffEditor(document.getElementById('codeContainer'),
|
||||
{
|
||||
readOnly: true,
|
||||
language: lang,
|
||||
@@ -227,10 +253,12 @@ $(function()
|
||||
}
|
||||
});
|
||||
|
||||
editor.setModel({
|
||||
modifiedEditor.setModel({
|
||||
original: monaco.editor.createModel(diffContent.code.old.trim("\n"), lang),
|
||||
modified: monaco.editor.createModel(diffContent.code.new.trim("\n"), lang),
|
||||
});
|
||||
|
||||
editor = modifiedEditor.getModifiedEditor();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -244,32 +272,35 @@ $(function()
|
||||
automaticLayout: true,
|
||||
EditorMinimapOptions: {enabled: false}
|
||||
});
|
||||
|
||||
editor.onMouseDown(function(obj)
|
||||
{
|
||||
var line = obj.target.position.lineNumber;
|
||||
|
||||
var blame = blames[line];
|
||||
if(!blame) return;
|
||||
|
||||
var p_line = parseInt(line);
|
||||
while(!blame.revision)
|
||||
{
|
||||
p_line--;
|
||||
blame = blames[p_line];
|
||||
}
|
||||
if($('#log').data('line') == p_line) return;
|
||||
|
||||
var time = blame.time != 'unknown' ? blame.time : '';
|
||||
var user = blame.committer != 'unknown' ? blame.committer : '';
|
||||
var version = blame.revision.toString().substring(0, 10);
|
||||
var content = blameTmpl.replace('%time', time).replace('%name', user).replace('%version', version).replace('%comment', blame.message);
|
||||
$('.history').text(content);
|
||||
$('#log').data('line', p_line);
|
||||
$('#log').css('display', 'flex');
|
||||
getRelation(blame.revision);
|
||||
})
|
||||
}
|
||||
|
||||
editor.onMouseDown(function(obj)
|
||||
{
|
||||
if(!blames) return;
|
||||
|
||||
var line = obj.target.position.lineNumber;
|
||||
if(pageType == 'diff') line = diffContent.line.new[line -1];
|
||||
|
||||
var blame = blames[line];
|
||||
if(!blame) return;
|
||||
|
||||
var p_line = parseInt(line);
|
||||
while(!blame.revision)
|
||||
{
|
||||
p_line--;
|
||||
blame = blames[p_line];
|
||||
}
|
||||
if($('#log').data('line') == p_line) return;
|
||||
|
||||
var time = blame.time != 'unknown' ? blame.time : '';
|
||||
var user = blame.committer != 'unknown' ? blame.committer : '';
|
||||
var version = blame.revision.toString().substring(0, 10);
|
||||
var content = blameTmpl.replace('%time', time).replace('%name', user).replace('%version', version).replace('%comment', blame.message);
|
||||
$('.history').text(content);
|
||||
$('#log').data('line', p_line);
|
||||
$('#log').css('display', 'flex');
|
||||
getRelation(blame.revision);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -308,5 +339,8 @@ $(function()
|
||||
var relatedHeight = codeHeight / 5 * 2 - $('#log').height() - 45;
|
||||
$('#relationTabs iframe').css('height', relatedHeight);
|
||||
});
|
||||
|
||||
/* Get file commits. */
|
||||
showCommitInfo();
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user