Added ticket 86, preview attached files to issues.

This commit is contained in:
Loic d'Anterroches 2008-12-30 18:00:59 +01:00
parent e6b19a695b
commit 2078d69a83
8 changed files with 80 additions and 6 deletions

View File

@ -323,12 +323,50 @@ class IDF_Views_Issue
$prj = $request->project;
$attach = Pluf_Shortcuts_GetObjectOr404('IDF_IssueFile', $match[2]);
$prj->inOr404($attach->get_comment()->get_issue());
$info = IDF_Views_Source::getMimeType($attach->filename);
$mime = 'application/octet-stream';
if (strpos($info[0], 'image/') === 0) {
$mime = $info[0];
}
$res = new Pluf_HTTP_Response_File(Pluf::f('upload_issue_path').'/'.$attach->attachment,
'application/octet-stream');
$res->headers['Content-Disposition'] = 'attachment; filename="'.$attach->filename.'"';
$mime);
if ($mime == 'application/octet-stream') {
$res->headers['Content-Disposition'] = 'attachment; filename="'.$attach->filename.'"';
}
return $res;
}
/**
* View a given attachment.
*/
public $viewAttachment_precond = array('IDF_Precondition::accessIssues');
public function viewAttachment($request, $match)
{
$prj = $request->project;
$attach = Pluf_Shortcuts_GetObjectOr404('IDF_IssueFile', $match[2]);
$prj->inOr404($attach->get_comment()->get_issue());
// If one cannot see the attachement, redirect to the
// getAttachment view.
$info = IDF_Views_Source::getMimeType($attach->filename);
if (!IDF_Views_Source::isText($info)) {
return $this->getAttachment($request, $match);
}
// Now we want to look at the file but with links back to the
// issue.
$file = IDF_Views_Source::highLight($info,
file_get_contents(Pluf::f('upload_issue_path').'/'.$attach->attachment));
$title = sprintf(__('View %s'), $attach->filename);
return Pluf_Shortcuts_RenderToResponse('idf/issues/attachment.html',
array(
'attachment' => $attach,
'page_title' => $title,
'comment' => $attach->get_comment(),
'issue' => $attach->get_comment()->get_issue(),
'file' => $file,
),
$request);
}
/**
* View list of issues for a given project with a given status.
*/

View File

@ -401,7 +401,7 @@ class IDF_Views_Source
if (0 === strpos($fileinfo[0], 'text/')) {
return true;
}
$ext = 'mdtext php js cpp php-dist h gitignore sh py pl rb '
$ext = 'mdtext php js cpp php-dist h gitignore sh py pl rb diff patch'
.Pluf::f('idf_extra_text_ext', '');
return (in_array($fileinfo[2], explode(' ', $ext)));
}

View File

@ -174,6 +174,12 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/issues/attachment/(\d+)/(.*)$#',
'model' => 'IDF_Views_Issue',
'method' => 'getAttachment');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/issues/view/attachment/(\d+)/(.*)$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views_Issue',
'method' => 'viewAttachment');
// ---------- SCM ----------------------------------------
$ctl[] = array('regex' => '#^/p/([\-\w]+)/source/tree/([^/]+)/$#',

View File

@ -0,0 +1,26 @@
{extends "idf/issues/base.html"}
{block extraheader}<link rel="stylesheet" type="text/css" href="{media '/idf/css/prettify.css'}" />{/block}
{block docclass}yui-t2{assign $inIssue=true}{/block}
{block body}
<table class="code" summary=" ">
<tbody>
{$file}
</tbody>
</table>
{aurl 'url', 'IDF_Views_Issue::getAttachment', array($project.shortname, $attachment.id, $attachment.filename)}
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this file'}</a></p>
{/block}
{block context}
{aurl 'url', 'IDF_Views_Issue::view', array($project.shortname, $issue.id)}
{assign $url = $url~'#ic'~$comment.id}
<p>{blocktrans}Attachment to issue <a href="{$url}">{$issue.id}</a>{/blocktrans}</p>
{ashowuser 'submitter', $attachment.get_submitter(), $request}
<p><strong>{trans 'Created:'}</strong> <span class="nobrk">{$attachment.creation_dtime|dateago}</span> <span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>
{/block}
{block javascript}
<script type="text/javascript" src="{media '/idf/js/prettify.js'}"></script>
<script type="text/javascript">prettyPrint();</script>
{/block}

View File

@ -8,6 +8,10 @@
<input accesskey="4" type="text" value="{$q}" name="q" size="20" />
<input type="submit" name="s" value="{trans 'Search'}" />
</form>
{if $inIssue} |
{aurl 'url', 'IDF_Views_Issue::view', array($project.shortname, $issue.id)}
<a href="{$url}">{trans 'Back to the issue'}</a>
{/if}
{superblock}
</div>
{/block}

View File

@ -16,7 +16,7 @@ to you:{/blocktrans}
{if $attachments.count() > 0}
{trans 'Attachments:'}{foreach $attachments as $a}
- {$a.filename|safe} - {$a.filesize|ssize}
{$url_base}{url 'IDF_Views_Issue::getAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach}
{$url_base}{url 'IDF_Views_Issue::viewAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach}
{/if}
--
{trans 'Issue:'} {$url_base}{url 'IDF_Views_Issue::view', array($project.shortname, $issue.id)}

View File

@ -20,7 +20,7 @@
{trans 'Attachments:'}{foreach $attachments as $a}
- {$a.filename|safe} - {$a.filesize|ssize}
{$url_base}{url 'IDF_Views_Issue::getAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach}
{$url_base}{url 'IDF_Views_Issue::viewAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach}
{/if}
{/foreach}

View File

@ -20,7 +20,7 @@
{if $attachments.count() > 0}
<hr align="left" class="attach" />
<ul>
{foreach $attachments as $a}<li><a href="{url 'IDF_Views_Issue::getAttachment', array($project.shortname, $a.id, $a.filename)}">{$a.filename}</a> - {$a.filesize|size}</li>{/foreach}
{foreach $attachments as $a}<li><a href="{url 'IDF_Views_Issue::viewAttachment', array($project.shortname, $a.id, $a.filename)}">{$a.filename}</a> - {$a.filesize|size}</li>{/foreach}
</ul>{/if}
{if $i> 0 and $c.changedIssue()}
<div class="issue-changes">