feat: display images in list

This commit is contained in:
b1ek 2024-08-20 14:55:10 +10:00
parent 1fc412ba57
commit f9d29e15f5
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 33 additions and 1 deletions

View File

@ -24,7 +24,7 @@ class ParameterSearch extends Parameter
public function search($params): ActiveDataProvider
{
$query = Parameter::find();
$query = Parameter::find()->with(['icon', 'iconGray']);
$dataProvider = new ActiveDataProvider([
'query' => $query,

View File

@ -1,4 +1,5 @@
<?php
use app\models\Parameter;
use yii\helpers\Html;
use yii\bootstrap5\ActiveForm;
use yii\grid\GridView;
@ -7,6 +8,7 @@ use yii\grid\GridView;
$this->title = 'params list';
?>
<h1>Parameters</h1>
@ -23,4 +25,34 @@ $this->title = 'params list';
<?= GridView::widget([
'dataProvider' => $provider,
'filterModel' => $searchModel,
'columns' => [
'id', 'title', 'type',
[
'label' => 'Icon',
'value' => function (Parameter $model) {
if ($model->icon) {
$url = '/api/image?sha256=' . $model->getRelatedRecords()['icon']->sha256;
return Html::a(Html::img($url, [ 'width' => 150, 'height' => 150 ]), $url, [ 'alt' => 'icon', 'target' => '_blank' ]);
}
},
'format' => 'raw',
],
[
'label' => 'Gray Icon',
'value' => function (Parameter $model) {
if ($model->iconGray) {
$url = '/api/image?sha256=' . $model->getRelatedRecords()['iconGray']->sha256;
return Html::a(Html::img($url, [ 'width' => 150, 'height' => 150 ]), $url, [ 'alt' => 'grayscale icon', 'target' => '_blank' ]);
}
},
'format' => 'raw',
],
[
'label' => 'Edit',
'value' => function (Parameter $model) {
return Html::a('Edit', '/list/edit?id=' . $model->id);
},
'format' => 'raw',
],
]
]); ?>