KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dynamically add widgets to Dashboard #2789

Closed GHSix opened this topic on on Aug 9, 2022 - 4 comments

GHSix commented on Aug 9, 2022

I have this Modal that I want to show on a button click but I don´t like to have to add it to all dashboards if they may never get used by the user.

Can I have the Modal widget added dinamically when needed before to be shown?

Of, if not possible, can I add the Modal somewhere in the App so any dashboard can show it?

KoolReport commented on Aug 9, 2022

May I know what inside the Modal?

GHSix commented on Aug 9, 2022

Just text, it´s an informational popup.

Modal::create('infoModal')
                ->sub([
                    Html::div($this->getInfoContent())->raw(true)
                ])
                ->title($this->getInfoTitle())
                ->showCloseIcon(true)
                ->type('primary')
                ->size('lg')
                ->open(false)
                ->centered(false)
                ->animation('fade')
namespace Users;

trait UsersInfo
{
    function getInfoTitle()
    {
        return '<i class="fa fa-info-circle"></i> Informações de '. $this->title();
    }

    function getInfoContent()
    {
        return '
            <p>
                O painel <b><i class="'. $this->icon() .'"></i> '. $this->title() .'</b> contém algumas métricas e KPIs com informações gerais que dão um panorama acerca das atividades. <br>
                Para visualizar outros dados, selecione o painel desejado no menu à esquerda.
            </p>';
    }
}
KoolReport commented on Aug 9, 2022

You do like this:

You create your base dashboard based on our dashboard and in your base dashboard you have an action like this:

use \koolreport\dashboard\Dashboard;
use \koolreport\dashboard\notifications\Alert;

class BaseDashboard extends Dashboard
{
    protected function actionInfo($request, $response)
    {
        return Alert::create()
                ->title("User Information")
                ->type("primary")
                ->sub([
                    Html::i()->class("fa fa-info-circle"),
                    Html::b("Anything is posible"),
                ]);
    }
}

Now all of your dashboards will derive from BaseDashboard instead of our original Dashboard

class FinancialBoard extends BaseDashboard
{
...
}

Now all of your dashboard will have actionInfo because it derived from BaseDashboard.

Here is how to show the Info from accountMenu or topMenu

class App extends Application
{
...
    protected function accountMenu()
    {
        return [
            "User Info"=>MenuItem::create()
                ->onClick("dashboardAction('info')"),
            "Logout"=>MenuItem::create()
                ->icon("fa fa-lock")       
                ->onClick(Client::logout())
        ];
    }
...
}

Hope that helps.

GHSix commented on Aug 10, 2022

It works too.

Thank you.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Dashboard