Skip to content

Commit 949bf73

Browse files
committed
HP-2303: fix parts model column when export, add filter for model column
1 parent edbd117 commit 949bf73

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Diff for: src/grid/ModelColumn.php

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace hipanel\modules\stock\grid;
64

75
use DateTimeImmutable;
86
use hipanel\grid\MainColumn;
97
use hipanel\modules\stock\models\Part;
10-
use hipanel\widgets\Label;
118
use yii\helpers\Html;
129
use Yii;
1310

@@ -21,28 +18,40 @@ public function init(): void
2118
if (Yii::$app->user->can('model.read')) {
2219
$modelLabel = Html::a($modelLabel, ['@model/view', 'id' => $model->model_id]);
2320
}
21+
$id = implode('-', ['model', $model->id]);
2422
if (isset($model->warranty_till)) {
25-
$modelLabel .= $this->getWarrantyLabel($model);
23+
[$warranty, $color] = $this->getWarranty($model);
24+
$this->grid->view->registerCss("span#$id > a::after {
25+
content: '$warranty';
26+
background-color: $color;
27+
color: white;
28+
font-weight: bold;
29+
font-size: 12px;
30+
margin-left: 5px;
31+
padding: 3px 5px;
32+
border-radius: 3px;
33+
box-shadow: 2px 2px rgba(0, 0, 0, 0.1);
34+
}");
2635
}
2736

28-
return $modelLabel;
37+
return Html::tag('span', $modelLabel, ['id' => $id, 'style' => 'display: inline-block;']);
2938
};
3039
}
3140

32-
private function getWarrantyLabel(Part $model): string
41+
private function getWarranty(Part $model): array
3342
{
3443
$diffTime = date_diff(new DateTimeImmutable(), new DateTimeImmutable($model->warranty_till));
3544
$diff = (int)$diffTime->format('%y') * 12 + (int)$diffTime->format('%m');
3645
$diff = ($diffTime->invert === 1) ? $diff * -1 : $diff;
3746
$diff = ($diff <= 0) ? 'X' : $diff;
38-
$color = 'info';
47+
$color = 'deepskyblue';
3948
if ($diff <= 6) {
40-
$color = 'warning';
49+
$color = 'salmon';
4150
}
4251
if (!is_numeric($diff)) {
43-
$color = 'danger';
52+
$color = 'crimson';
4453
}
4554

46-
return Label::widget(['label' => $diff, 'tag' => 'sup', 'color' => $color]);
55+
return [$diff, $color];
4756
}
4857
}

Diff for: src/grid/PartGridView.php

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public function columns()
9898
'attribute' => 'model',
9999
'format' => 'raw',
100100
'label' => Yii::t('hipanel:stock', 'Model'),
101+
'filterOptions' => ['class' => 'narrow-filter'],
102+
'filterAttribute' => 'model_label_ilike',
101103
],
102104
'model_type' => [
103105
'class' => RefColumn::class,
@@ -209,6 +211,7 @@ public function columns()
209211
]);
210212
},
211213
'filterOptions' => ['class' => 'narrow-filter'],
214+
'contentOptions' => ['style' => 'white-space: nowrap;'],
212215
'format' => 'raw',
213216
'visible' => Yii::$app->user->can('order.read') && Yii::$app->user->can('owner-staff'),
214217
'value' => function (Part $model): string {
@@ -344,6 +347,7 @@ public function columns()
344347
'warranty_till' => [
345348
'class' => WarrantyColumn::class,
346349
'attribute' => 'warranty_till',
350+
'contentOptions' => ['style' => 'white-space: nowrap;'],
347351
'format' => ['datetime', 'php:Y-m-d'],
348352
],
349353
]);

0 commit comments

Comments
 (0)