Improve pull-request

This commit is contained in:
Frederic Guillot 2015-03-10 22:37:09 -04:00
parent 788ef2bc07
commit d91b5d4aa3
20 changed files with 151 additions and 143 deletions

View File

@ -20,8 +20,8 @@ class File extends Base
$task = $this->getTask();
$this->response->html($this->taskLayout('file/new', array(
'task' => $task,
'max_size' => ini_get('upload_max_filesize'),
'task' => $task,
'max_size' => ini_get('upload_max_filesize'),
)));
}
@ -74,8 +74,8 @@ class File extends Base
if ($file['task_id'] == $task['id']) {
$this->response->html($this->template->render('file/open', array(
'file' => $file,
'task' => $task,
'file' => $file,
'task' => $task,
)));
}
}
@ -102,29 +102,31 @@ class File extends Base
}
/**
* Return the file content (work only for images) resized
* Return image thumbnails
*
* @access public
*/
public function imageThumbnail() {
public function thumbnail()
{
$task = $this->getTask();
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$width_param = $this->request->getIntegerParam('width');
$height_param = $this->request->getIntegerParam('height');
$filename = FILES_DIR . $file['path'];
$filename = FILES_DIR.$file['path'];
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
// Get new sizes
list($width, $height) = getimagesize($filename);
if ($width_param == 0 && $height_param == 0) {
$newwidth = 100;
$newheight = 100;
} elseif ($width_param > 0 && $height_param == 0) {
$newwidth = $width_param;
$newheight = floor($height * ( $width_param / $width ));
$newheight = floor($height * ($width_param / $width));
} elseif ($width_param == 0 && $height_param > 0) {
$newwidth = floor($width * ( $height_param / $height ));
$newwidth = floor($width * ($height_param / $height));
$newheight = $height_param;
} else {
$newwidth = $width_param;
@ -133,9 +135,7 @@ class File extends Base
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$info = pathinfo($file['name']);
$extension = strtolower($info['extension']);
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
switch ($extension) {
case 'jpeg':
@ -153,17 +153,18 @@ class File extends Base
break;
}
// Resize
// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$metadata = getimagesize($filename);
if (isset($metadata['mime'])) {
$this->response->contentType($metadata['mime']);
imagejpeg($thumb);
}
}
}
/**
* Remove a file
*
@ -195,8 +196,8 @@ class File extends Base
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$this->response->html($this->taskLayout('file/remove', array(
'task' => $task,
'file' => $file,
'task' => $task,
'file' => $file,
)));
}
}

View File

@ -726,4 +726,48 @@ class Helper
{
return dt('%A', strtotime('next Monday +'.($day - 1).' days'));
}
/**
* Get file icon
*
* @access public
* @param string $filename Filename
* @return string Font-Awesome-Icon-Name
*/
public function getFileIcon($filename){
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
switch ($extension) {
case 'jpeg':
case 'jpg':
case 'png':
case 'gif':
return 'fa-file-image-o';
case 'xls':
case 'xlsx':
return 'fa-file-excel-o';
case 'doc':
case 'docx':
return 'fa-file-word-o';
case 'ppt':
case 'pptx':
return 'fa-file-powerpoint-o';
case 'zip':
case 'rar':
return 'fa-archive-o';
case 'mp3':
return 'fa-audio-o';
case 'avi':
return 'fa-video-o';
case 'php':
case 'html':
case 'css':
return 'fa-code-o';
case 'pdf':
return 'fa-file-pdf-o';
}
return 'fa-file-o';
}
}

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -775,4 +775,6 @@ return array(
'Remove time slot' => 'Supprimer un créneau horaire',
'Add new time slot' => 'Ajouter un créneau horaire',
'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => 'Ces horaires sont utilisés lorsque la case « Toute la journée » est cochée pour les heures d\'absences ou supplémentaires programmées.',
'Files' => 'Fichiers',
'Images' => 'Images',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '',
// 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
);

View File

@ -111,7 +111,7 @@ class File extends Base
->asc('name')
->findAll();
}
/**
* Get all images for a given task
*
@ -127,7 +127,7 @@ class File extends Base
->asc('name')
->findAll();
}
/**
* Get all files without images for a given task
*
@ -153,76 +153,19 @@ class File extends Base
*/
public function isImage($filename)
{
$info = pathinfo($filename);
$extension = strtolower($info['extension']);
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
switch ($extension) {
case 'jpeg':
case 'jpg':
case 'png':
case 'jpg':
case 'png':
case 'gif':
return true;
break;
default:
return false;
break;
}
return false;
}
/**
* get Font-Awesome Icon for file extension
*
* @access public
* @param string $filename Filename
* @return string Font-Awesome-Icon-Name
*/
public function get_icon($filename){
$info = pathinfo($filename);
$extension = strtolower($info['extension']);
switch ($extension) {
case 'jpeg':
case 'jpg':
case 'png':
case 'gif':
$icon = 'fa-file-image-o';
break;
case 'xls':
case 'xlsx':
$icon = 'fa-file-excel-o';
break;
case 'doc':
case 'docx':
$icon = 'fa-file-word-o';
break;
case 'ppt':
case 'pptx':
$icon = 'fa-file-powerpoint-o';
break;
case 'zip':
case 'rar':
$icon = 'fa-archive-o';
break;
case 'mp3':
$icon = 'fa-audio-o';
break;
case 'avi':
$icon = 'fa-video-o';
break;
case 'php':
case 'html':
case 'css':
$icon = 'fa-code-o';
break;
case 'pdf':
$icon = 'fa-file-pdf-o';
break;
default:
$icon = 'fa-file-o';
break;
}
return $icon;
}
/**
* Generate the path for a new filename
*

View File

@ -1,27 +1,25 @@
<section>
<table>
<?php if (!empty($images)): ?>
<?php if (! empty($images)): ?>
<?php foreach ($images as $file): ?>
<tr>
<td><i class="fa fa-file-image-o fa-fw"></i>
<?=
$this->e($file['name'])
?>
<td class="column-70">
<i class="fa fa-file-image-o fa-fw"></i>
<?= $this->e($file['name']) ?>
</td>
<td>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-eye"></i> <?= $this->a(t('open'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?>
<i class="fa fa-eye"></i> <?= $this->a(t('open'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?>
</td>
</tr>
<?php endforeach ?>
<?php endif ?>
<?php if (!empty($files)): ?>
<?php if (! empty($files)): ?>
<?php foreach ($files as $file): ?>
<tr>
<td><i class="fa <?= $this->file->get_icon($file['name']) ?> fa-fw"></i>
<?=
$this->e($file['name'])
?>
<td>
<i class="fa <?= $this->getFileIcon($file['name']) ?> fa-fw"></i>
<?= $this->e($file['name']) ?>
</td>
<td>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>

View File

@ -1,56 +1,48 @@
<?php if (!empty($files) || !empty($images)): ?>
<div id="attachments" class="task-show-section">
<?php if (! empty($files) || ! empty($images)): ?>
<div id="attachments" class="task-show-section">
<div class="page-header">
<h2><?= t('Attachments') ?></h2>
</div>
<?php if (!empty($images)): ?>
<h3>
<?= t('Images') ?>
</h3>
<ul class="task-show-images">
<?php foreach ($images as $file): ?>
<li>
<div class="img_container">
<img src="<?= $this->u('file', 'imageThumbnail', array('width' => 250, 'file_id' => $file['id'], 'project_id' => $task['project_id'], 'task_id' => $file['task_id'])) ?>" alt="<?= $this->e($file['name']) ?>"/>
</div>
<p>
<?= $this->e($file['name']) ?>
</p>
<span class="task-show-file-actions task-show-image-actions">
<i class="fa fa-eye"></i> <?= $this->a(t('open'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?>
<div class="page-header">
<h2><?= t('Attachments') ?></h2>
</div>
<?php if (!empty($images)): ?>
<h3><?= t('Images') ?></h3>
<ul class="task-show-images">
<?php foreach ($images as $file): ?>
<li>
<div class="img_container">
<img src="<?= $this->u('file', 'thumbnail', array('width' => 250, 'file_id' => $file['id'], 'project_id' => $task['project_id'], 'task_id' => $file['task_id'])) ?>" alt="<?= $this->e($file['name']) ?>"/>
</div>
<p>
<?= $this->e($file['name']) ?>
</p>
<span class="task-show-file-actions task-show-image-actions">
<i class="fa fa-eye"></i> <?= $this->a(t('open'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?>
<i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
</span>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?php if (! empty($files)): ?>
<h3><?= t('Files') ?></h3>
<table class="task-show-file-table">
<?php foreach ($files as $file): ?>
<tr>
<td><i class="fa <?= $this->getFileIcon($file['name']) ?> fa-fw"></i></td>
<td>
<?= $this->e($file['name']) ?>
</td>
<td>
<span class="task-show-file-actions">
<i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
</span>
</li>
<?php endforeach ?>
</ul>
<?php endif
?>
<?php if (!empty($files)): ?>
<h3>
<?= t('Files') ?>
</h3>
<table class="task-show-file-table">
<?php foreach ($files as $file): ?>
<tr>
<td><i class="fa <?= $this->file->get_icon($file['name']) ?> fa-fw"></i></td>
<td>
<?= $this->e($file['name']) ?>
</td><td>
<span class="task-show-file-actions">
<i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
</span>
</td></tr>
<?php endforeach ?>
</table>
</div>
<?php endif
?>
<?php
endif ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>
</div>
<?php endif ?>