N°330 Attachments display as table : portal

This commit is contained in:
Pierre Goiffon
2019-12-16 14:44:56 +01:00
parent 473a55bde6
commit 434ed0dd4e
5 changed files with 247 additions and 81 deletions

View File

@@ -16,10 +16,20 @@
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Attachments rendering for iTop console.
*
* For the user portal, see \Combodo\iTop\Renderer\Bootstrap\FieldRenderer\BsFileUploadFieldRenderer
*/
define('ATTACHMENT_DOWNLOAD_URL', 'pages/ajax.document.php?operation=download_document&class=Attachment&field=contents&id=');
define('ATTACHMENTS_RENDERER', 'TableDetailsAttachmentsRenderer');
/**
* For now this factory is just a helper to instanciate the renderer
*/
class AttachmentsRendererFactory
{
/**
@@ -320,21 +330,32 @@ class TableDetailsAttachmentsRenderer extends AbstractAttachmentsRenderer
return;
}
$this->oPage->add('<table class="listResults attachmentsList">'.PHP_EOL);
$this->oPage->add('<thead>'.PHP_EOL);
$this->oPage->add(' <th>'.Dict::S('Attachments:File:Thumbnail').'</th>'.PHP_EOL);
$this->oPage->add(' <th>'.Dict::S('Attachments:File:Name').'</th>'.PHP_EOL);
$this->oPage->add(' <th>'.Dict::S('Attachments:File:Size').'</th>'.PHP_EOL);
$this->oPage->add(' <th>'.Dict::S('Attachments:File:Date').'</th>'.PHP_EOL);
$this->oPage->add(' <th>'.Dict::S('Attachments:File:Creator').'</th>'.PHP_EOL);
$this->oPage->add(' <th>'.Dict::S('Attachments:File:MimeType').'</th>'.PHP_EOL);
$sThumbnail = Dict::S('Attachments:File:Thumbnail');
$sFileName = Dict::S('Attachments:File:Name');
$sFileSize = Dict::S('Attachments:File:Size');
$sFileDate = Dict::S('Attachments:File:Date');
$sFileCreator = Dict::S('Attachments:File:Creator');
$sFileType = Dict::S('Attachments:File:MimeType');
$sDeleteColumn = '';
if ($bWithDeleteButton)
{
$this->oPage->add(' <th></th>'.PHP_EOL);
$sDeleteColumn = '<th></th>';
}
$this->oPage->add('</thead>'.PHP_EOL);
$this->oPage->add('<tbody>'.PHP_EOL);
$this->oPage->add(<<<HTML
<table class="listResults attachmentsList">
<thead>
<th>$sThumbnail</th>
<th>$sFileName</th>
<th>$sFileSize</th>
<th>$sFileDate</th>
<th>$sFileCreator</th>
<th>$sFileType</th>
$sDeleteColumn
</thead>
<tbody>
HTML
);
$iMaxWidth = MetaModel::GetModuleSetting('itop-attachments', 'preview_max_width', 290);
$sPreviewNotAvailable = addslashes(Dict::S('Attachments:PreviewNotAvailable'));

View File

@@ -1111,13 +1111,15 @@ table .group-actions {
.fileupload_field_content > div {
margin-bottom: 15px;
}
.attachments_container .attachmentsList thead > tr > th {
text-align: center;
}
.attachments_container .attachmentsList tbody > tr > td {
text-align: center;
}
.attachments_container .attachment {
height: 95px;
overflow-x: hidden;
text-align: center;
}
.attachments_container .attachment:hover {
background-color: #e0e0e0;
}
.attachments_container .attachment .attachment_name {
overflow-x: hidden;
@@ -1127,6 +1129,9 @@ table .group-actions {
.attachments_container .attachment .btn {
margin-top: 3px;
}
.attachments_container .attachmenthover {
background-color: #e0e0e0;
}
.upload_container input {
display: inline;
}

View File

@@ -1194,21 +1194,35 @@ table .group-actions .item-action-wrapper .panel-body > p:last-child{
.fileupload_field_content > div{
margin-bottom: 15px;
}
.attachments_container .attachment {
height: 95px;
overflow-x: hidden;
text-align: center;
}
.attachments_container .attachment:hover {
background-color: #e0e0e0;
}
.attachments_container .attachment .attachment_name{
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.attachments_container .attachment .btn{
margin-top: 3px;
.attachments_container {
.attachmentsList {
& thead > tr > th {
text-align: center;
}
& tbody > tr > td {
text-align: center;
}
}
.attachment {
height: 95px;
overflow-x: hidden;
.attachment_name {
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.btn {
margin-top: 3px;
}
&hover {
background-color: #e0e0e0;
}
}
}
.upload_container input{
display: inline;

View File

@@ -1152,6 +1152,8 @@ class ObjectController extends BrickController
$oAttachment->Set('expire', time() + MetaModel::GetConfig()->Get('draft_attachments_lifetime')); // one hour...
$oAttachment->Set('temp_id', $sTempId);
$oAttachment->Set('item_class', $sObjectClass);
$oAttachment->Set('creation_date', time());
$oAttachment->Set('user_id', UserRights::GetUserObject());
$oAttachment->SetDefaultOrgId();
$oAttachment->Set('contents', $oDocument);
$iAttId = $oAttachment->DBInsert();
@@ -1162,6 +1164,10 @@ class ObjectController extends BrickController
$aData['icon'] = utils::GetAbsoluteUrlAppRoot().'env-'.utils::GetCurrentEnvironment().'/itop-attachments/icons/image.png';
$aData['att_id'] = $iAttId;
$aData['preview'] = $oDocument->IsPreviewAvailable() ? 'true' : 'false';
$aData['file_size'] = $oDocument->GetFormatedSize();
$aData['creation_date'] = $oAttachment->Get('creation_date');
$aData['user_id_friendlyname'] = $oAttachment->Get('user_id_friendlyname');
$aData['file_type'] = $oDocument->GetMimeType();
}
catch (FileUploadException $e)
{