Jump to content

ProcessDashboard


Pete

Recommended Posts

This module creates a blank dashboard page in your site admin and sets it as default when you login instead of the page list.

It came from a need in a few projects where I was creating modules for various user roles to use and I didn't want them to see the page list at all, but needed to display various stats and quick access buttons.

For example, if you have a person who is creating invoices or doing other back-office stuff in various other Process modules then as an admin you wouldn't want them to access the page tree anyway, and there are other scenarios where you might want to have a dashboard instead of launching straight into the page list.

It also requires (and adds) a permission - "dashboard" - so you can create new roles and assign the dashboard permission to those roles - something you might want to do fairly commonly if you have a lot of admin modules that you want to restrict access to.

Editing the template is simple - there is a dashboard.php template file in the /site/modules/ProcessDashboard/ folder (decided to leave it in there to keep it safe, but I might be tempted to move it into /site/templates/ ) as well as .js and .css files ready to add your code to. You can use the API as you usually would to create your dashboard experience. For example, display data based on user roles or even specific users using code like this:

if ($user->hasRole('invoices') {
    echo "Hi staff member $user->name. View invoices to be processed below:
        ...
        ...";
}
 
if ($user->name == 'pete') {
    // Show some super-awesome stuff here
}

You can also do away with the dashboard.php template file and edit the module directly, putting your code and output in the execute() function (the way most Process modules are written) but I decided to include the separate template file to make it easier for more people to use.

This does touch on areas a few other modules have addressed to some degree (like diogo's Custom Admin Pages) but this is designed for one purpose - instant dashboard creation.

You can download the module here: http://modules.processwire.com/modules/process-dashboard/

This module also uses code from diogo's ProcessHomeAdmin module so that the default admin page can be overridden.

  • Like 20
Link to comment
Share on other sites

It's worth mentioning that whilst I've made it easy for newcomers to modules to create a dashboard template, it is worth learning how Process modules work so that you can create your own to do some amazing stuff in the ProcessWire admin.

See the ProcessHello module as a starting point: https://github.com/ryancramerdesign/ProcessHello

EDIT: There was also another way to do this module - I could have skipped creating a separate dashboard page under the admin page and simply made the admin page load the dashboard, however I quite like having the link in the menu at the top of the page so it's really obvious how to get back there.

  • Like 3
Link to comment
Share on other sites

  • 10 months later...

I installed this and it seems a non admin user with dashboard permissions can see the dashboard or page list, but they can not click on the processwire logo to go back to the admin home / dashboard link.  It does a redirect loop.   They can only click the tabs on the right.

They also can not click admin in the breadcrumb trail on the page list to get back to the dashboard.

Do you know how to fix this?

Link to comment
Share on other sites

What this module does, is make the new dashboard page the new home for the admin section, instead of the page list, so shouldnt the process wire logo and breadcrum also go to this new home since that is where the login script takes all users after they login?

Link to comment
Share on other sites

On my installation clicking the PW logo or Admin link from the breadcrumb does take me to the dashboard as expected.

I can't remember, but I think at first install it appeared to the right of Pages in the menu - I think (trying to remember) it needs to be the first child page under /processwire/ in the tree in order to work like this.

Link to comment
Share on other sites

  • 9 months later...
  • 1 month later...

Hi!

I'm using your Dashboard module. I want to make the bookmarks accessible there.

I'v already played with some of the admin helper functions like so:

$admin = $this->wire('pages')->get($config->adminRootPageID);

function printNav(Page $pa)
{
	echo "<ul>";
	foreach($pa->children("check_access=0") as $p) {
	        if(!$p->viewable()) continue;

	        $title = $p->title;
	        if(strlen($title)) {
	            //$icon = $this->getPageIcon($p);
	            echo "<li>";
	            echo "<a class='has-items has-ajax-items' data-from='topnav-page-$p' data-json='{$p->url}navJSON/' " .
	 "href='$p->url'>$title</a>";
	 			if($p->numChildren) printNav($p);
	 			echo "</li>";
	        }
	}
	echo "</ul>";
}

echo printNav($admin);

It's already displaying the Navbar. But I dont know how the ajax stuff works.

Also Ajax isnt required here.

So I hope, you can give me a hint how to solve this.

Thank you

robig

Link to comment
Share on other sites

  • 1 month later...

@Pete -

i'm wondering how to 'addon' to this module in the sense that your module provides a blank canvas for setting up a dashboard, but i'd like to avoid changing anything in your module and also avoid putting anything custom into the module folder;

what i did to hack this was change the dashboard module like this:

public function execute() {
    // Redirect calls for the admin homepage to the dashboard (first child page)
    if ($this->page->id == 2) {
        $this->session->redirect($this->page->child->url);
    }

	$dashboard = $this->getDashboard();
	return $dashboard->render();
}

public function ___getDashboard() {
    $t = new TemplateFile($this->config->paths->siteModules . __CLASS__ . "/dashboard.php");
    return $t;
}

then in my dashboard widgets module, i have this:

public function init() {
    $this->addHookAfter('ProcessDashboard::getDashboard', $this, 'getCustomDashboard');
}

public function getCustomDashboard(HookEvent $event) {
    $template = $event->return;
    $event->replace = true;
    $template = new TemplateFile($this->config->paths->siteModules . __CLASS__ . "/dashboard.php");
    $event->return = $template;
}

let me know what you think, if this would be a possible change that wouldn't affect existing sites, but would allow other modules to hook into the main dashboard for rendering...

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...

@Pete

In PW 3.0.33 the users with permission 'dashboard' are not redirected to the dashboard after log in.

In my case I got stuck with a white screen (url /processwire/dashboard/ was working)

EDIT:

This code did the trick for me (for now): 

if ($this->page->id == 2) {
	// Before	
	// $this->session->redirect($this->page->child->url);
	
	// NOW
	$this->session->redirect($this->pages->get(1028)->url);
}

 

Link to comment
Share on other sites

  • 4 months later...

@KarlvonKarton

so the issue you are having is that the child page is access restricted and that's why you get the blank screen; to solve this you just need to add a selector to the child api call like so:

if ($this->page->id == 2) {
    $childPage = $this->page->child('check_access=0');
    $this->session->redirect($childPage->url);
}

then you don't have to hardcode the ID of the dashboard page into the module...

Somehow this may have worked as it was originally in earlier versions of PW, but i encountered the same issue as you and had to make that change.

  • Like 2
Link to comment
Share on other sites

  • 9 months later...

Thanks for this module! I had to change a few things to get this to work with PW 3.0.84

a) add PW namespace

b) change page id from 2 to 3 (2 = admin root, but 3 = page, which is the actual default landing page after login)

if ($this->page->id === 3) {

(and then the two lines from @Macrura above)

c) 

//        $t = new TemplateFile($this->config->paths->siteModules . __CLASS__ . "/dashboard.php"); // this creates a URL like site/modules\ProcessWire/ProcessDashboard/
        $t = new TemplateFile($this->config->paths->siteModules . "ProcessDashboard/dashboard.php");

Perhaps you could re-check, and publish a new version that officially supports PW 3 ?

  • Like 1
Link to comment
Share on other sites

  • 4 months later...
On 11/18/2017 at 12:53 PM, dragan said:

Thanks for this module! I had to change a few things to get this to work with PW 3.0.84

a) add PW namespace

b) change page id from 2 to 3 (2 = admin root, but 3 = page, which is the actual default landing page after login)


if ($this->page->id === 3) {

(and then the two lines from @Macrura above)

c) 


//        $t = new TemplateFile($this->config->paths->siteModules . __CLASS__ . "/dashboard.php"); // this creates a URL like site/modules\ProcessWire/ProcessDashboard/
        $t = new TemplateFile($this->config->paths->siteModules . "ProcessDashboard/dashboard.php");

Perhaps you could re-check, and publish a new version that officially supports PW 3 ?

@dragan  thanks for this, it solved my issues with the module

Link to comment
Share on other sites

My dashboard child pages are not showing in breadcrumbs, how can I get them to display ?

for example, I added a page in admin under dashboard and when I navigate to it in the cms I can see it fine but the breadcrumb still shows "home > dashboard" instead of "home > dashboard > My Page".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...