Permalink
Browse files

Media : add filesize, display filesize and dimensions in appdesk prev…

…iew and CRUD form
  • Loading branch information...
felixgilles committed Jun 17, 2013
1 parent 6a36a0f commit 8880d9d41bf807d18694ed0b43ad20589ffb3ab4
@@ -134,8 +134,6 @@ public function save($item, $data)
{
$return = parent::save($item, $data) + array(
'thumbnailUrl' => $this->item->get_public_path_resized(512, 512),
'media_file' => $this->item->media_file,
'media_ext' => $this->item->media_ext,
);
if ($this->item->is_image() != $this->clone->is_image()) {
$return += array(
@@ -64,6 +64,12 @@ class Model_Media extends \Nos\Orm\Model
'null' => true,
'convert_empty_to_null' => true,
),
'media_filesize' => array(
'default' => null,
'data_type' => 'smallint unsigned',
'null' => true,
'convert_empty_to_null' => true,
),
'media_created_at' => array(
'data_type' => 'timestamp',
'null' => false,
@@ -113,7 +119,7 @@ class Model_Media extends \Nos\Orm\Model
);
protected static $_observers = array(
'\Orm\Observer_Self' => array(
'Orm\Observer_Self' => array(
),
'Orm\Observer_CreatedAt' => array(
'mysql_timestamp' => true,
@@ -252,9 +258,15 @@ public function get_public_path_resized($max_width = 0, $max_height = 0)
public function _event_before_save()
{
parent::_event_before_save();
$is_image = @getimagesize(APPPATH.$this->get_private_path());
if ($is_image !== false) {
list($this->media_width, $this->media_height) = $is_image;
$file = APPPATH.$this->get_private_path();
if (is_file($file)) {
$is_image = @getimagesize($file);
if ($is_image !== false) {
list($this->media_width, $this->media_height) = $is_image;
}
$this->media_filesize = filesize($file);
}
}
}
@@ -67,6 +67,11 @@
'ensurePxWidth' => true,
'allowSizing' => false,
),
'filename' => array(
'value' => function ($item) {
return $item->media_file.'.'.$item->media_ext;
},
),
'file' => array(
'column' => 'media_file',
),
@@ -96,6 +101,16 @@
'width' => array(
'column' => 'media_width',
),
'filesize' => array(
'value' => function ($item) {
return empty($item->media_filesize) ? false : \Str::humanFileSize($item->media_filesize);
},
),
'dimensions' => array(
'value' => function ($item) {
return empty($item->media_width) ? false : $item->media_width.' × '.$item->media_height;
},
),
'thumbnailAlternate' => array(
'value' => $media_icon(64),
),
@@ -43,14 +43,14 @@
'preview' => true,
'options' => array(
'meta' => array(
'fileName' => array(
'filename' => array(
'label' => __('File name:'),
),
'pathFolder' => array(
'label' => __('Path:'),
'filesize' => array(
'label' => __('File size:'),
),
'extension' => array(
'label' => __('Extension:'),
'dimensions' => array(
'label' => __('Dimensions:'),
),
),
'actions' => array('Nos\Media\Model_Media.edit', 'Nos\Media\Model_Media.delete', 'Nos\Media\Model_Media.visualise'),
@@ -0,0 +1,20 @@
<?php
namespace Nos\Media\Migrations;
use Nos\Media\Model_Media;
class Media_Filesize extends \Nos\Migration
{
public function up()
{
parent::up();
foreach (Model_Media::find('all') as $media) {
$file = APPPATH.$media->get_private_path();
if (is_file($file)) {
$media->media_filesize = filesize($file);
$media->save();
}
}
}
}
@@ -0,0 +1 @@
ALTER TABLE `nos_media` ADD `media_filesize` INT( 10 ) UNSIGNED NULL DEFAULT NULL AFTER `media_height`;
@@ -52,6 +52,20 @@
<th style="vertical-align: top;"><?= $fieldset->field('media_folder_id')->label; ?></th>
<td><?= $fieldset->field('media_folder_id')->build(); ?></td>
</tr>
<tr>
<th style="vertical-align: top;"><?= __('File size:') ?></th>
<td class="media_filesize"><?= \Str::humanFileSize($item->media_filesize) ?></td>
</tr>
<?php
if ($item->is_image()) {
?>
<tr>
<th style="vertical-align: top;"><?= __('Dimensions:') ?></th>
<td class="media_dimensions"><?= $item->media_width.' × '.$item->media_height ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -207,21 +207,23 @@ define('jquery-nos-preview',
.addClass('ui-widget-content wijmo-wijgrid-data');
$.each(o.meta, function(key, meta) {
var tr = $('<tr></tr>').addClass('wijmo-wijgrid-row ui-widget-content wijmo-wijgrid-datarow' + (i%2 ? ' wijmo-wijgrid-alternatingrow' : ''))
.appendTo(table);
$('<th><div></div></th>').addClass('wijgridtd wijdata-type-string')
.appendTo(tr)
.find('div')
.addClass('wijmo-wijgrid-innercell')
.html(meta.label || '');
$('<td><div></div></td>').addClass('wijgridtd wijdata-type-string')
.appendTo(tr)
.find('div')
.addClass('wijmo-wijgrid-innercell')
.text(data[key] || '');
i++;
if (data[key]) {
var tr = $('<tr></tr>').addClass('wijmo-wijgrid-row ui-widget-content wijmo-wijgrid-datarow' + (i%2 ? ' wijmo-wijgrid-alternatingrow' : ''))
.appendTo(table);
$('<th><div></div></th>').addClass('wijgridtd wijdata-type-string')
.appendTo(tr)
.find('div')
.addClass('wijmo-wijgrid-innercell')
.html(meta.label || '');
$('<td><div></div></td>').addClass('wijgridtd wijdata-type-string')
.appendTo(tr)
.find('div')
.addClass('wijmo-wijgrid-innercell')
.text(data[key] || '');
i++;
}
});
return self;
@@ -41,11 +41,17 @@ define('jquery-nos-media-edit-form',
src: json.thumbnailUrl + '?' + (new Date().getTime())
});
}
if (json.media_file) {
$slug.val(json.media_file);
if (json.dataset.file) {
$slug.val(json.dataset.file);
}
if (json.media_ext) {
$container.find('.media_extension').text(json.media_ext);
if (json.dataset.ext) {
$container.find('.media_extension').text(json.dataset.ext);
}
if (json.dataset.filesize) {
$container.find('.media_filesize').text(json.dataset.filesize);
}
if (json.dataset.dimensions) {
$container.find('.media_dimensions').text(json.dataset.dimensions);
}
});
});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 8880d9d

Please sign in to comment.