Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
135 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* HiPanel core package | ||
* | ||
* @link https://hipanel.com/ | ||
* @package hipanel-core | ||
* @license BSD-3-Clause | ||
* @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace hipanel\actions; | ||
|
||
use Yii; | ||
|
||
class VariantsAction extends RenderAction | ||
{ | ||
public array $variants; | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
} | ||
|
||
public function run() | ||
{ | ||
$headerName = $this->controller->request->headers->get(self::EXPECTED_AJAX_RESPONSE_HEADER_NAME); | ||
foreach ($this->variants as $expected => $variant) { | ||
if ($expected === $headerName) { | ||
return $variant($this); | ||
} | ||
} | ||
Yii::$app->end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace hipanel\widgets; | ||
|
||
use hiqdev\hiart\ActiveDataProvider; | ||
use Yii; | ||
use yii\base\Widget; | ||
use yii\grid\GridView; | ||
|
||
class CountEnabler extends Widget | ||
{ | ||
public ActiveDataProvider $dataProvider; | ||
|
||
public $content; | ||
|
||
public function run() | ||
{ | ||
$this->dataProvider->enableCount(); | ||
$grid = Yii::createObject([ | ||
'class' => GridView::class, | ||
'dataProvider' => $this->dataProvider, | ||
]); | ||
|
||
return call_user_func($this->content, $grid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace hipanel\widgets; | ||
|
||
interface HookInterface | ||
{ | ||
public function registerJsHook(string $paramName): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace hipanel\widgets; | ||
|
||
use hipanel\actions\Action; | ||
use yii\web\View; | ||
|
||
trait HookTrait | ||
{ | ||
public function registerJsHook(string $reqHeaderParamName): void | ||
{ | ||
$id = $this->getId(); | ||
$headerName = Action::EXPECTED_AJAX_RESPONSE_HEADER_NAME; | ||
$this->view->registerJs("$.ajax({ | ||
type: 'GET', | ||
url: document.URL, | ||
beforeSend: xhr => { | ||
xhr.setRequestHeader('{$headerName}', '{$reqHeaderParamName}'); | ||
}, | ||
success: html => { | ||
$('#{$id}').html(html); | ||
} | ||
});", View::POS_LOAD); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace hipanel\widgets; | ||
|
||
use Yii; | ||
use yii\helpers\Html; | ||
use yii\widgets\LinkPager; | ||
|
||
class PagerHook extends LinkPager implements HookInterface | ||
{ | ||
use HookTrait; | ||
|
||
public string $tag = 'div'; | ||
|
||
public string $content; | ||
|
||
public function init() | ||
{ | ||
$this->registerJsHook('pager'); | ||
} | ||
|
||
public function run() | ||
{ | ||
return Html::tag($this->tag, $this->content ?? $this->getLoader(), array_merge(['id' => $this->getId()], $this->options)); | ||
} | ||
|
||
private function getLoader(): string | ||
{ | ||
return Html::tag('span', null, ['class' => 'fa fa-spinner fa-pulse', 'style' => 'margin-right: .7rem;']) . Yii::t('hipanel', 'loading pager...'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters