Get moduleId for Dashboard object #2145
-
Sorry for question here, but i really need help. I've implement Dashboad for module warnings and errors. And i want show button, after each dashboard item. How can i done this? I found instruction: https://luya.io/guide/app-admin-module-dashboardobjects How can i get moduleId for this link in PHP or Angular? I have multiple rows in my Dashboard object, linked with multiple modules. Can i someway get moduleId in PHP or Angular? This code for my Dashboard: public $dashboardObjects = [
[
'class' => '\luya\admin\dashboard\BasicDashboardObject',
'title' => 'Warnings',
'dataApiUrl' => 'config/dashboard/warnings',
'wrapperOptions' => [
'class' => 'card',
'tag' => 'div',
'ng-show' => 'data.length',
],
'template' => '<div ng-repeat="item in data">
<div class="alert" ng-bind-html="item" ng-class="{\'alert-success\': item.type == \'success\', \'alert-danger\': item.type == \'error\', \'alert-warning\': item.type == \'warning\', \'alert-info\': item.type == \'info\'}">
<i class="material-icons toasts-toast-icon" ng-show="item.type == \'success\'">check_circle</i>
<i class="material-icons toasts-toast-icon" ng-show="item.type == \'error\'">error_outline</i>
<i class="material-icons toasts-toast-icon" ng-show="item.type == \'warning\'">warning</i>
<i class="material-icons toasts-toast-icon" ng-show="item.type == \'info\'">info_outline</i>
<div class="ml-4">
<div ng-bind-html="item.message | trustAsUnsafe"></div>
<a ng-if="item.sref" ui-sref="default.route(item.sref)" class="btn btn-info mt-2">Go to page</a>
</div>
</div>
</div>',
],
]; This is WarningsItem model: use yii\base\BaseObject;
class WarningItem extends BaseObject
{
const TYPE_ERROR = 'error';
const TYPE_WARNING = 'warning';
const TYPE_SUCCESS = 'success';
/**
* @var string Type of warning: error|warning|success
*/
public $type;
/**
* @var string
*/
public $message;
public $sref;
} That way i collect warnings: public function actionWarnings()
{
$warnings = [];
foreach (Yii::$app->getModules() as $module) {
if ($module instanceof WarningItemsInterface) {
$warnings = array_merge($warnings, $module->getWarningItems());
}
}
return $warnings;
} And that way i've create warnings (in module): public function getWarningItems(): array
{
$warnings = [];
$warnings[] = new WarningItem([
'type' => WarningItem::TYPE_ERROR,
'message' => 'Some text...',
'sref' => [/*'moduleId' => 7, */'moduleRouteId' => 'config', 'controllerId' => 'config', 'actionId' => 'robots'],
]);
return $warnings;
} And this is how it look likes: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @chemezov Good one! For now you can see the module id only in the Does that answer your question? |
Beta Was this translation helpful? Give feedback.
Hi @chemezov
Good one! For now you can see the module id only in the
api-admin-menu
xhr response, afaikDoes that answer your question?