KoolReport's Forum

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

Dynamic loading of dashboards doesn't work correctly #3249

Closed Christian Voß opened this topic on on Feb 16 - 3 comments

Christian Voß commented on Feb 16

Hi,

I believe I found a bug on the dashboard app. I'm trying to dynamically load dashboards of the same type. One for each site the current user has access to:

protected function dashboards()
    {
        $user = Auth::user()->id;
        $dashboards = [
            "Overview Board" => overviewBoard::create()->icon("fa fa-user"),
        ];
        $resourceBoards = [];
        foreach($user->sites->sortBy('name') as $site) {
           $resourceBoards[$site->name] = resourceBoard::create('resourceBoard_' . $site->id)
           ->icon("fa fa-user")->params([
            "site_id" => $site->id,    
        ]);
        }
        if (count($resourceBoards) > 1) {
            $dashboards["Resource Boards"] = Group::create()->icon("fa fa-list-alt")->sub($resourceBoards); 
        } elseif (count($resourceBoards) == 1) {
            $dashboards["Resource Board"] = $resourceBoards[0];
        }
        return $dashboards;       
    }

If a user has access to more than one site, this function should give me a menu item called "Resource Boards" which, when clicked gives me the option to select my resourceBoard for each site. The menu is created correctly and as expected, but whenever I click on the menu items for the sites, only the first dashboard is loaded.

I.e. if I click 'UK' or 'USA' the 'UAE' dashboard gets loaded, as it is the first in the list.

Is this a bug or am I doing an obvious mistake?

Thanks

Christian

Christian Voß commented on Feb 16

Ok, I just checked the documentation in a bit more detail and it seems that you cannot have more than one dashboard of the same type in an application. It works with widgets, but apparently not with dashboards. It this correct? Are the any plans to change this, because I think it would be a good feature. Or is there any other way to achieve the same result?

KoolReport commented on Feb 16

Let try this:

        foreach($user->sites->sortBy('name') as $site) {
           $resourceBoards[$site->name] = resourceBoard::create()->name('resourceBoard_' . $site->id)
           ->icon("fa fa-user")->params([
            "site_id" => $site->id,    
           ]);
       }

It is because you use the same class for different dashboard so each dashboard should have different name. By default, it will take the classname as the name of dashboard, the UAE will be the first to choose.

Please let us know.

Christian Voß commented on Feb 16

Perfect, thank you very much! That worked well.

Have a great day.

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
solved

Dashboard