added primitive code search
This commit is contained in:
parent
34986f34fe
commit
227c326645
@ -10,6 +10,7 @@ class Code extends Controller
|
|||||||
var $VIEW_REVISION = 'code_revision';
|
var $VIEW_REVISION = 'code_revision';
|
||||||
var $VIEW_DIFF = 'code_diff';
|
var $VIEW_DIFF = 'code_diff';
|
||||||
var $VIEW_FETCH = 'code_fetch';
|
var $VIEW_FETCH = 'code_fetch';
|
||||||
|
var $VIEW_SEARCH = 'code_search';
|
||||||
|
|
||||||
function Code ()
|
function Code ()
|
||||||
{
|
{
|
||||||
@ -409,7 +410,7 @@ class Code extends Controller
|
|||||||
else if ($file['type'] == 'file')
|
else if ($file['type'] == 'file')
|
||||||
{
|
{
|
||||||
header ('Content-Description: File Transfer');
|
header ('Content-Description: File Transfer');
|
||||||
header('Content-Type: application/octet-stream');
|
header ('Content-Type: application/octet-stream');
|
||||||
header ('Content-Disposition: attachment; filename='. basename($path));
|
header ('Content-Disposition: attachment; filename='. basename($path));
|
||||||
header ('Content-Transfer-Encoding: binary');
|
header ('Content-Transfer-Encoding: binary');
|
||||||
header ('Content-Length: ' . strlen($file['content']));
|
header ('Content-Length: ' . strlen($file['content']));
|
||||||
@ -435,6 +436,108 @@ class Code extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _search_code ($project, $login)
|
||||||
|
{
|
||||||
|
$this->load->helper ('form');
|
||||||
|
$this->load->library ('form_validation');
|
||||||
|
|
||||||
|
$data['login'] = $login;
|
||||||
|
$data['message'] = '';
|
||||||
|
|
||||||
|
$this->form_validation->set_rules ('search_pattern', 'pattern', 'required');
|
||||||
|
$this->form_validation->set_rules ('search_folder', 'folder', '');
|
||||||
|
$this->form_validation->set_error_delimiters('<span class="form_field_error">','</span>');
|
||||||
|
|
||||||
|
if ($this->input->post('search_pattern'))
|
||||||
|
{
|
||||||
|
$pattern = $this->input->post('search_pattern');
|
||||||
|
$path = $this->input->post('search_folder');
|
||||||
|
$path = $this->_normalize_path ($path);
|
||||||
|
$rev = SVN_REVISION_HEAD;
|
||||||
|
|
||||||
|
$file = $this->subversion->getFile ($project->id, $path, $rev);
|
||||||
|
if ($file === FALSE)
|
||||||
|
{
|
||||||
|
$data['project'] = $project;
|
||||||
|
$data['message'] = "Failed to get file - %path";
|
||||||
|
$this->load->view ($this->VIEW_ERROR, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->form_validation->run())
|
||||||
|
{
|
||||||
|
$data['project'] = $project;
|
||||||
|
$data['headpath'] = $path;
|
||||||
|
$data['pattern'] = $pattern;
|
||||||
|
$data['file'] = $file;
|
||||||
|
|
||||||
|
$data['revision'] = $rev;
|
||||||
|
$data['prev_revision'] =
|
||||||
|
$this->subversion->getPrevRev ($project->id, $path, $rev);
|
||||||
|
$data['next_revision'] =
|
||||||
|
$this->subversion->getNextRev ($project->id, $path, $rev);
|
||||||
|
|
||||||
|
$this->load->view ($this->VIEW_SEARCH, $data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO: arrange to display an error message...
|
||||||
|
$data['project'] = $project;
|
||||||
|
$data['headpath'] = $path;
|
||||||
|
$data['file'] = $file;
|
||||||
|
|
||||||
|
$data['revision'] = $rev;
|
||||||
|
$data['prev_revision'] =
|
||||||
|
$this->subversion->getPrevRev ($project->id, $path, $rev);
|
||||||
|
$data['next_revision'] =
|
||||||
|
$this->subversion->getNextRev ($project->id, $path, $rev);
|
||||||
|
$this->load->view ($this->VIEW_FOLDER, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data['project'] = $project;
|
||||||
|
$data['message'] = 'Failed to search';
|
||||||
|
$this->load->view ($this->VIEW_ERROR, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function search ($projectid = '', $rev = SVN_REVISION_HEAD)
|
||||||
|
{
|
||||||
|
$this->load->model ('ProjectModel', 'projects');
|
||||||
|
$this->load->model ('SubversionModel', 'subversion');
|
||||||
|
|
||||||
|
$login = $this->login->getUser ();
|
||||||
|
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
|
||||||
|
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
|
||||||
|
|
||||||
|
$project = $this->projects->get ($projectid);
|
||||||
|
if ($project === FALSE)
|
||||||
|
{
|
||||||
|
$data['login'] = $login;
|
||||||
|
$data['message'] = 'DATABASE ERROR';
|
||||||
|
$this->load->view ($this->VIEW_ERROR, $data);
|
||||||
|
}
|
||||||
|
else if ($project === NULL)
|
||||||
|
{
|
||||||
|
$data['login'] = $login;
|
||||||
|
$data['message'] =
|
||||||
|
$this->lang->line('MSG_NO_SUCH_PROJECT') .
|
||||||
|
" - {$projectid}";
|
||||||
|
$this->load->view ($this->VIEW_ERROR, $data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($project->public !== 'Y' && $login['id'] == '')
|
||||||
|
{
|
||||||
|
// non-public projects require sign-in.
|
||||||
|
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->_search_code ($project, $login);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _normalize_path ($path)
|
function _normalize_path ($path)
|
||||||
{
|
{
|
||||||
$path = preg_replace('/[\/]+/', '/', $path);
|
$path = preg_replace('/[\/]+/', '/', $path);
|
||||||
|
@ -125,11 +125,18 @@ $this->load->view (
|
|||||||
|
|
||||||
|
|
||||||
<div class="infostrip" id="code_folder_mainarea_infostrip">
|
<div class="infostrip" id="code_folder_mainarea_infostrip">
|
||||||
|
<?=form_open("code/search/{$project->id}/", 'id="code_folder_search_form"')?>
|
||||||
|
<?=form_hidden ('search_folder', set_value('search_folder', $file['fullpath']), 'id="code_folder_search_folder"')?>
|
||||||
|
<?=form_input ('search_pattern', set_value('search_pattern', ''), 'id="code_folder_search_pattern"')?>
|
||||||
|
<?=form_submit ('search_submit', $this->lang->line('Search'), 'id="code_folder_search_submit"')?>
|
||||||
|
|
|
||||||
<?=$this->lang->line('Revision')?>: <?=$file['created_rev']?>
|
<?=$this->lang->line('Revision')?>: <?=$file['created_rev']?>
|
||||||
<?php if ($file_count > 0): ?>
|
<?php if ($file_count > 0): ?>
|
||||||
|
|
|
|
||||||
<a id="code_folder_mainarea_details_button" href='#'><?=$this->lang->line('Details')?></a>
|
<a id="code_folder_mainarea_details_button" href='#'><?=$this->lang->line('Details')?></a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?=form_close()?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="code_folder_mainarea_result">
|
<div id="code_folder_mainarea_result">
|
||||||
|
Loading…
Reference in New Issue
Block a user